mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-16 18:15:17 +00:00
- Add Latest App Run Endpoint (#13511)
- Remove not required fields from app_extension table
This commit is contained in:
parent
352b025fd7
commit
e577333b54
@ -217,8 +217,6 @@ CREATE TABLE IF NOT EXISTS apps_marketplace (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS apps_extension_time_series (
|
CREATE TABLE IF NOT EXISTS apps_extension_time_series (
|
||||||
appId VARCHAR(36) GENERATED ALWAYS AS (json ->> '$.appId') STORED NOT NULL,
|
appId VARCHAR(36) GENERATED ALWAYS AS (json ->> '$.appId') STORED NOT NULL,
|
||||||
extension VARCHAR(256) NOT NULL,
|
|
||||||
jsonSchema VARCHAR(256) NOT NULL,
|
|
||||||
json JSON NOT NULL,
|
json JSON NOT NULL,
|
||||||
timestamp BIGINT UNSIGNED GENERATED ALWAYS AS (json ->> '$.timestamp') NOT NULL
|
timestamp BIGINT UNSIGNED GENERATED ALWAYS AS (json ->> '$.timestamp') NOT NULL
|
||||||
);
|
);
|
||||||
|
|||||||
@ -227,8 +227,6 @@ CREATE TABLE IF NOT EXISTS apps_marketplace (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS apps_extension_time_series (
|
CREATE TABLE IF NOT EXISTS apps_extension_time_series (
|
||||||
appId VARCHAR(36) GENERATED ALWAYS AS (json ->> 'appId') STORED NOT NULL,
|
appId VARCHAR(36) GENERATED ALWAYS AS (json ->> 'appId') STORED NOT NULL,
|
||||||
extension VARCHAR(256) NOT NULL,
|
|
||||||
jsonSchema VARCHAR(256) NOT NULL,
|
|
||||||
json JSONB NOT NULL,
|
json JSONB NOT NULL,
|
||||||
timestamp BIGINT GENERATED ALWAYS AS ((json ->> 'timestamp')::bigint) STORED NOT NULL
|
timestamp BIGINT GENERATED ALWAYS AS ((json ->> 'timestamp')::bigint) STORED NOT NULL
|
||||||
);
|
);
|
||||||
@ -51,9 +51,7 @@ public abstract class AbstractOmAppJobListener implements JobListener {
|
|||||||
dataMap.put(SCHEDULED_APP_RUN_EXTENSION, runRecord);
|
dataMap.put(SCHEDULED_APP_RUN_EXTENSION, runRecord);
|
||||||
|
|
||||||
// Run the Scheduled Run Record on the time series
|
// Run the Scheduled Run Record on the time series
|
||||||
collectionDAO
|
collectionDAO.appExtensionTimeSeriesDao().insert(JsonUtils.pojoToJson(runRecord));
|
||||||
.appExtensionTimeSeriesDao()
|
|
||||||
.insert(SCHEDULED_APP_RUN_EXTENSION, SCHEDULED_APP_RUN_RECORD_SCHEMA, JsonUtils.pojoToJson(runRecord));
|
|
||||||
|
|
||||||
this.doJobToBeExecuted(jobExecutionContext);
|
this.doJobToBeExecuted(jobExecutionContext);
|
||||||
}
|
}
|
||||||
@ -85,11 +83,7 @@ public abstract class AbstractOmAppJobListener implements JobListener {
|
|||||||
|
|
||||||
collectionDAO
|
collectionDAO
|
||||||
.appExtensionTimeSeriesDao()
|
.appExtensionTimeSeriesDao()
|
||||||
.update(
|
.update(runRecord.getAppId().toString(), JsonUtils.pojoToJson(runRecord), runRecord.getTimestamp());
|
||||||
runRecord.getAppId().toString(),
|
|
||||||
SCHEDULED_APP_RUN_EXTENSION,
|
|
||||||
JsonUtils.pojoToJson(runRecord),
|
|
||||||
runRecord.getTimestamp());
|
|
||||||
|
|
||||||
this.doJobWasExecuted(jobExecutionContext, jobException);
|
this.doJobWasExecuted(jobExecutionContext, jobException);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -203,6 +203,11 @@ public class AppRepository extends EntityRepository<App> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AppRunRecord getLatestAppRuns(UUID appId) {
|
||||||
|
String json = daoCollection.appExtensionTimeSeriesDao().getLatestAppRun(appId);
|
||||||
|
return JsonUtils.readValue(json, AppRunRecord.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityUpdater getUpdater(App original, App updated, Operation operation) {
|
public EntityUpdater getUpdater(App original, App updated, Operation operation) {
|
||||||
return new AppRepository.AppUpdater(original, updated, operation);
|
return new AppRepository.AppUpdater(original, updated, operation);
|
||||||
|
|||||||
@ -3334,35 +3334,22 @@ public interface CollectionDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface AppExtensionTimeSeries {
|
interface AppExtensionTimeSeries {
|
||||||
|
@ConnectionAwareSqlUpdate(
|
||||||
@SqlQuery("SELECT json FROM apps_extension_time_series WHERE appId = :appId ORDER BY timestamp DESC LIMIT 1")
|
value = "INSERT INTO apps_extension_time_series(json) " + "VALUES (:json)",
|
||||||
String getLatestAppRun(@Bind("appId") String appId);
|
connectionType = MYSQL)
|
||||||
|
@ConnectionAwareSqlUpdate(
|
||||||
|
value = "INSERT INTO apps_extension_time_series(json) " + "VALUES ((:json :: jsonb))",
|
||||||
|
connectionType = POSTGRES)
|
||||||
|
void insert(@Bind("json") String json);
|
||||||
|
|
||||||
@ConnectionAwareSqlUpdate(
|
@ConnectionAwareSqlUpdate(
|
||||||
value =
|
value = "UPDATE apps_extension_time_series set json = :json where appId=:appId and timestamp=:timestamp",
|
||||||
"INSERT INTO apps_extension_time_series(extension, jsonSchema, json) "
|
|
||||||
+ "VALUES (:extension, :jsonSchema, :json)",
|
|
||||||
connectionType = MYSQL)
|
connectionType = MYSQL)
|
||||||
@ConnectionAwareSqlUpdate(
|
@ConnectionAwareSqlUpdate(
|
||||||
value =
|
value =
|
||||||
"INSERT INTO apps_extension_time_series(extension, jsonSchema, json) "
|
"UPDATE apps_extension_time_series set json = (:json :: jsonb) where appId=:appId and timestamp=:timestamp",
|
||||||
+ "VALUES (:extension, :jsonSchema, (:json :: jsonb))",
|
|
||||||
connectionType = POSTGRES)
|
connectionType = POSTGRES)
|
||||||
void insert(@Bind("extension") String extension, @Bind("jsonSchema") String jsonSchema, @Bind("json") String json);
|
void update(@Bind("appId") String appId, @Bind("json") String json, @Bind("timestamp") Long timestamp);
|
||||||
|
|
||||||
@ConnectionAwareSqlUpdate(
|
|
||||||
value =
|
|
||||||
"UPDATE apps_extension_time_series set json = :json where appId=:appId and extension=:extension and timestamp=:timestamp",
|
|
||||||
connectionType = MYSQL)
|
|
||||||
@ConnectionAwareSqlUpdate(
|
|
||||||
value =
|
|
||||||
"UPDATE apps_extension_time_series set json = (:json :: jsonb) where appId=:appId and extension=:extension and timestamp=:timestamp",
|
|
||||||
connectionType = POSTGRES)
|
|
||||||
void update(
|
|
||||||
@Bind("appId") String appId,
|
|
||||||
@Bind("extension") String extension,
|
|
||||||
@Bind("json") String json,
|
|
||||||
@Bind("timestamp") Long timestamp);
|
|
||||||
|
|
||||||
@SqlQuery("SELECT count(*) FROM apps_extension_time_series where appId = :appId")
|
@SqlQuery("SELECT count(*) FROM apps_extension_time_series where appId = :appId")
|
||||||
int listAppRunRecordCount(@Bind("appId") String appId);
|
int listAppRunRecordCount(@Bind("appId") String appId);
|
||||||
@ -3370,6 +3357,14 @@ public interface CollectionDAO {
|
|||||||
@SqlQuery(
|
@SqlQuery(
|
||||||
"SELECT json FROM apps_extension_time_series where appId = :appId ORDER BY timestamp DESC LIMIT :limit OFFSET :offset")
|
"SELECT json FROM apps_extension_time_series where appId = :appId ORDER BY timestamp DESC LIMIT :limit OFFSET :offset")
|
||||||
List<String> listAppRunRecord(@Bind("appId") String appId, @Bind("limit") int limit, @Bind("offset") int offset);
|
List<String> listAppRunRecord(@Bind("appId") String appId, @Bind("limit") int limit, @Bind("offset") int offset);
|
||||||
|
|
||||||
|
default String getLatestAppRun(UUID appId) {
|
||||||
|
List<String> result = listAppRunRecord(appId.toString(), 1, 0);
|
||||||
|
if (result != null && !result.isEmpty()) {
|
||||||
|
return result.get(0);
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No Available Application Run Records.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ReportDataTimeSeriesDAO extends EntityTimeSeriesDAO {
|
interface ReportDataTimeSeriesDAO extends EntityTimeSeriesDAO {
|
||||||
|
|||||||
@ -225,6 +225,26 @@ public class AppResource extends EntityResource<App, AppRepository> {
|
|||||||
return repository.listAppRuns(installation.getId(), limitParam, offset);
|
return repository.listAppRuns(installation.getId(), limitParam, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/name/{name}/runs/latest")
|
||||||
|
@Operation(
|
||||||
|
operationId = "latestAppRunRecord",
|
||||||
|
summary = "Get Latest App Run Record",
|
||||||
|
description = "Get a latest applications Run Record.",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
responseCode = "200",
|
||||||
|
description = "List of Installed Applications Runs",
|
||||||
|
content = @Content(mediaType = "application/json", schema = @Schema(implementation = AppRunRecord.class)))
|
||||||
|
})
|
||||||
|
public AppRunRecord listLatestAppRun(
|
||||||
|
@Context UriInfo uriInfo,
|
||||||
|
@Context SecurityContext securityContext,
|
||||||
|
@Parameter(description = "Name of the App", schema = @Schema(type = "string")) @PathParam("name") String name) {
|
||||||
|
App installation = repository.getByName(uriInfo, name, repository.getFields("id"));
|
||||||
|
return repository.getLatestAppRuns(installation.getId());
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{id}/versions")
|
@Path("/{id}/versions")
|
||||||
@Operation(
|
@Operation(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user