From aad8969c71ae25e6fb20e37052d62a4a538e5ba1 Mon Sep 17 00:00:00 2001 From: sushi30 Date: Mon, 15 Jul 2024 16:44:29 +0200 Subject: [PATCH 1/2] fix: raise for triggering system app --- .../org/openmetadata/service/resources/apps/AppResource.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java index e30a9b218bb6..adb11a506297 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java @@ -887,6 +887,10 @@ public Response triggerApplicationRun( String name) { EntityUtil.Fields fields = getFields(String.format("%s,bot,pipelines", FIELD_OWNER)); App app = repository.getByName(uriInfo, name, fields); + if (Boolean.TRUE.equals(app.getSystem())) { + throw new IllegalArgumentException( + CatalogExceptionMessage.systemEntityModifyNotAllowed(app.getName(), "SystemApp")); + } if (app.getAppType().equals(AppType.Internal)) { ApplicationHandler.getInstance() .triggerApplicationOnDemand(app, Entity.getCollectionDAO(), searchRepository); From 2d9538acb3ca91593fd1d7de00c64ec9d8f9e083 Mon Sep 17 00:00:00 2001 From: sushi30 Date: Wed, 17 Jul 2024 13:41:09 +0200 Subject: [PATCH 2/2] added scheduleType ScheduledOrManual --- .../mysql/postDataMigrationSQLScript.sql | 9 +++++++++ .../postgres/postDataMigrationSQLScript.sql | 9 +++++++++ .../apps/AbstractNativeApplication.java | 6 +++--- .../exception/CatalogExceptionMessage.java | 2 +- .../service/resources/apps/AppResource.java | 4 ---- .../DataInsightsApplication.json | 2 +- .../DataInsightsReportApplication.json | 2 +- .../SearchIndexingApplication.json | 2 +- .../resources/apps/AppsResourceTest.java | 8 ++++++++ .../json/data/app/ExampleAppNoTrigger.json | 9 +++++++++ .../ExampleAppNoTrigger.json | 20 +++++++++++++++++++ .../json/schema/entity/applications/app.json | 6 +++++- 12 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 openmetadata-service/src/test/resources/json/data/app/ExampleAppNoTrigger.json create mode 100644 openmetadata-service/src/test/resources/json/data/appMarketPlaceDefinition/ExampleAppNoTrigger.json diff --git a/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql index 306fdd27d6d5..a701afc772d8 100644 --- a/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.5.0/mysql/postDataMigrationSQLScript.sql @@ -23,3 +23,12 @@ WHERE name IN ( 'columnValuesToBeBetween', 'tableRowCountToBeBetween' ); + +-- Update schedule type for applications +UPDATE installed_apps +SET json = JSON_MERGE_PATCH(json, '{"scheduleType": "ScheduledOrManual"}') +WHERE JSON_UNQUOTE(json->'$.scheduleType') = 'Scheduled'; + +-- recreate all scheduled apps +DELETE FROM apps_marketplace +WHERE JSON_UNQUOTE(json->'$.scheduleType') = 'Scheduled'; diff --git a/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql index 2c578286e40c..295e6593ddbd 100644 --- a/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.5.0/postgres/postDataMigrationSQLScript.sql @@ -22,3 +22,12 @@ WHERE name IN ( 'columnValuesToBeBetween', 'tableRowCountToBeBetween' ); + +-- Update schedule type for applications +UPDATE installed_apps +SET json = json || '{"scheduleType": "ScheduledOrManual"}' +WHERE json->>'scheduleType' = 'Scheduled'; + +-- recreate all scheduled apps +DELETE FROM apps_marketplace +WHERE json->>'scheduleType' = 'Scheduled'; \ No newline at end of file diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/apps/AbstractNativeApplication.java b/openmetadata-service/src/main/java/org/openmetadata/service/apps/AbstractNativeApplication.java index f92d546dbde2..d1b83fb07192 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/apps/AbstractNativeApplication.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/apps/AbstractNativeApplication.java @@ -2,7 +2,7 @@ import static org.openmetadata.service.apps.scheduler.AbstractOmAppJobListener.JOB_LISTENER_NAME; import static org.openmetadata.service.apps.scheduler.AppScheduler.APP_NAME; -import static org.openmetadata.service.exception.CatalogExceptionMessage.LIVE_APP_SCHEDULE_ERR; +import static org.openmetadata.service.exception.CatalogExceptionMessage.NO_MANUAL_TRIGGER_ERR; import java.util.List; import lombok.Getter; @@ -89,13 +89,13 @@ public void install() { @Override public void triggerOnDemand() { // Validate Native Application - if (app.getScheduleType().equals(ScheduleType.Scheduled)) { + if (app.getScheduleType().equals(ScheduleType.ScheduledOrManual)) { AppRuntime runtime = getAppRuntime(app); validateServerExecutableApp(runtime); // Trigger the application AppScheduler.getInstance().triggerOnDemandApplication(app); } else { - throw new IllegalArgumentException(LIVE_APP_SCHEDULE_ERR); + throw new IllegalArgumentException(NO_MANUAL_TRIGGER_ERR); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java index 1263269beb65..443caed5e133 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java @@ -99,7 +99,7 @@ public final class CatalogExceptionMessage { public static final String TOKEN_EXPIRY_ERROR = "Email Verification Token %s is expired. Please issue a new request for email verification."; public static final String INVALID_BOT_USER = "Revoke Token can only be applied to Bot Users."; - public static final String LIVE_APP_SCHEDULE_ERR = "Live Application cannot scheduled."; + public static final String NO_MANUAL_TRIGGER_ERR = "App does not support manual trigger."; public static final String INVALID_APP_TYPE = "Application Type is not valid."; private CatalogExceptionMessage() {} diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java index adb11a506297..e30a9b218bb6 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java @@ -887,10 +887,6 @@ public Response triggerApplicationRun( String name) { EntityUtil.Fields fields = getFields(String.format("%s,bot,pipelines", FIELD_OWNER)); App app = repository.getByName(uriInfo, name, fields); - if (Boolean.TRUE.equals(app.getSystem())) { - throw new IllegalArgumentException( - CatalogExceptionMessage.systemEntityModifyNotAllowed(app.getName(), "SystemApp")); - } if (app.getAppType().equals(AppType.Internal)) { ApplicationHandler.getInstance() .triggerApplicationOnDemand(app, Entity.getCollectionDAO(), searchRepository); diff --git a/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsApplication.json b/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsApplication.json index 452391f940da..59470bea43b9 100644 --- a/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsApplication.json +++ b/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsApplication.json @@ -9,7 +9,7 @@ "developerUrl": "https://www.getcollate.io", "privacyPolicyUrl": "https://www.getcollate.io", "supportEmail": "support@getcollate.io", - "scheduleType": "Scheduled", + "scheduleType": "ScheduledOrManual", "permission": "All", "className": "org.openmetadata.service.apps.bundles.insights.DataInsightsApp", "runtime": { diff --git a/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsReportApplication.json b/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsReportApplication.json index 34353d31d59a..f371834234d4 100644 --- a/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsReportApplication.json +++ b/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/DataInsightsReportApplication.json @@ -9,7 +9,7 @@ "developerUrl": "https://www.getcollate.io", "privacyPolicyUrl": "https://www.getcollate.io", "supportEmail": "support@getcollate.io", - "scheduleType": "Scheduled", + "scheduleType": "ScheduledOrManual", "permission": "All", "className": "org.openmetadata.service.apps.bundles.insights.DataInsightsReportApp", "runtime": { diff --git a/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/SearchIndexingApplication.json b/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/SearchIndexingApplication.json index 90d6dbfc4c14..0b95c8295998 100644 --- a/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/SearchIndexingApplication.json +++ b/openmetadata-service/src/main/resources/json/data/appMarketPlaceDefinition/SearchIndexingApplication.json @@ -9,7 +9,7 @@ "developerUrl": "https://www.getcollate.io", "privacyPolicyUrl": "https://www.getcollate.io", "supportEmail": "support@getcollate.io", - "scheduleType": "Scheduled", + "scheduleType": "ScheduledOrManual", "permission": "All", "className": "org.openmetadata.service.apps.bundles.searchIndex.SearchIndexApp", "runtime": { diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/apps/AppsResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/apps/AppsResourceTest.java index 8ffd3dd1b4d9..ce4d65cb1504 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/apps/AppsResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/apps/AppsResourceTest.java @@ -108,6 +108,14 @@ void post_trigger_app_200() throws HttpResponseException, InterruptedException { } } + @Test + void post_trigger_no_trigger_app_400() { + assertResponseContains( + () -> postTriggerApp("ExampleAppNoTrigger", ADMIN_AUTH_HEADERS), + BAD_REQUEST, + "App does not support manual trigger."); + } + @Override public void validateCreatedEntity( App createdEntity, CreateApp request, Map authHeaders) diff --git a/openmetadata-service/src/test/resources/json/data/app/ExampleAppNoTrigger.json b/openmetadata-service/src/test/resources/json/data/app/ExampleAppNoTrigger.json new file mode 100644 index 000000000000..80189a929ec3 --- /dev/null +++ b/openmetadata-service/src/test/resources/json/data/app/ExampleAppNoTrigger.json @@ -0,0 +1,9 @@ +{ + "name": "ExampleAppNoTrigger", + "displayName": "Example App No Trigger", + "appConfiguration": {}, + "appSchedule": { + "scheduleTimeline": "Custom", + "cronExpression": "0 0 1/1 * *" + } +} \ No newline at end of file diff --git a/openmetadata-service/src/test/resources/json/data/appMarketPlaceDefinition/ExampleAppNoTrigger.json b/openmetadata-service/src/test/resources/json/data/appMarketPlaceDefinition/ExampleAppNoTrigger.json new file mode 100644 index 000000000000..dbd02bf8e862 --- /dev/null +++ b/openmetadata-service/src/test/resources/json/data/appMarketPlaceDefinition/ExampleAppNoTrigger.json @@ -0,0 +1,20 @@ +{ + "name": "ExampleAppNoTrigger", + "displayName": "Example App No Trigger", + "description": "An example app without manual trigger.", + "features": "Dont try this at home.", + "appType": "internal", + "appScreenshots": [ + ], + "developer": "ACME Labs", + "developerUrl": "https://www.example.com", + "privacyPolicyUrl": "https://www.example.com", + "supportEmail": "use@example.com", + "scheduleType": "Scheduled", + "permission": "All", + "className": "org.openmetadata.service.apps.bundles.searchIndex.SearchIndexApp", + "runtime": { + "enabled": true + }, + "appConfiguration": {} +} diff --git a/openmetadata-spec/src/main/resources/json/schema/entity/applications/app.json b/openmetadata-spec/src/main/resources/json/schema/entity/applications/app.json index 98a6cf6c41c3..9badba82c7d2 100644 --- a/openmetadata-spec/src/main/resources/json/schema/entity/applications/app.json +++ b/openmetadata-spec/src/main/resources/json/schema/entity/applications/app.json @@ -13,7 +13,8 @@ "type": "string", "enum": [ "Live", - "Scheduled" + "Scheduled", + "ScheduledOrManual" ], "javaEnums": [ { @@ -21,6 +22,9 @@ }, { "name": "Scheduled" + }, + { + "name": "ScheduledOrManual" } ] },