Skip to content

Commit

Permalink
MINOR [GEN-799]: add option to disable manual trigger using scheduleT…
Browse files Browse the repository at this point in the history
…ype (#17031)

* fix: raise for triggering system app

* added scheduleType ScheduledOrManual
  • Loading branch information
sushi30 authored and harshach committed Jul 24, 2024
1 parent 0cb41f1 commit 89b8b95
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ WHERE name IN (
'columnValuesSumToBeBetween',
'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';
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ WHERE name IN (
'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';
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,13 +90,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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> authHeaders)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ExampleAppNoTrigger",
"displayName": "Example App No Trigger",
"appConfiguration": {},
"appSchedule": {
"scheduleTimeline": "Custom",
"cronExpression": "0 0 1/1 * *"
}
}
Original file line number Diff line number Diff line change
@@ -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": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
"type": "string",
"enum": [
"Live",
"Scheduled"
"Scheduled",
"ScheduledOrManual"
],
"javaEnums": [
{
"name": "Live"
},
{
"name": "Scheduled"
},
{
"name": "ScheduledOrManual"
}
]
},
Expand Down

0 comments on commit 89b8b95

Please sign in to comment.