From 5d89b53ad4433a759e475c93d5fc48834ffba237 Mon Sep 17 00:00:00 2001 From: gabriel-farache Date: Tue, 19 Nov 2024 12:43:11 +0100 Subject: [PATCH] Add abort compensation for MTA Signed-off-by: gabriel-farache --- mta-v7.x/mta.svg | 2 +- mta-v7.x/mta.sw.yaml | 209 ++++++++++++--------- shared/schemas/workflow-result-schema.json | 3 +- 3 files changed, 124 insertions(+), 90 deletions(-) diff --git a/mta-v7.x/mta.svg b/mta-v7.x/mta.svg index 3db4eb91..771671e2 100644 --- a/mta-v7.x/mta.svg +++ b/mta-v7.x/mta.svg @@ -1 +1 @@ -StartCreateApplicationCreateTaskgroupSubmitAnalysispollResultscheckReportDoneTaskFailedErrorGetApplicationAnal ysis CountMandatoriesI ncidents CountNonMandato riesIncidents CheckMandatoriesI ncidents GetTrackersTrackersExistTrackersDoesNotEx istError GetTrackerTrackerExistsTrackerDoesNotExi stError GetTrackerProjectsTrackerProjectsExis t TrackerProjectsDoe sNotExistError GetTrackerProjectTrackerProjectExistTrackerProjectDoes NotExistError GetTrackerProjectIs sueTypes TrackerProjectIssue TypesExist TrackerProjectIssueTypesDoesNotExist Error CreateMigrationWa ve CreateJiraCheckMandatoriesI ncidentsAfterIssueC reation NotifyCompletionreportCompletionEndNotifyMandatoriesIncidentsInApplicati on reportCompletionWithMandatoriesIncid entsInApplication EndNotifyFailureBackst age reportFailureEndhasMandatorie... hasMandatorie... NotifyTracker NotifyTracker (.trackers != null) (.trackers != null) (.tracker != null) (.tracker != null) (.trackerProject... (.trackerProject... (.trackerProject ... (.trackerProject ... (.trackerProject... (.trackerProject... hasMandatorie... hasMandatorie... taskFailed taskFailed taskNotCompleted taskNotCompleted \ No newline at end of file +StartCreateApplicationCreateTaskgroupSubmitAnalysispollResultscheckReportDoneTaskFailedErrorGetApplicationAnal ysis CountMandatoriesI ncidents CountNonMandato riesIncidents CheckMandatoriesI ncidents GetTrackersTrackersExistTrackersDoesNotEx istError GetTrackerTrackerExistsTrackerDoesNotExi stError GetTrackerProjectsTrackerProjectsExis t TrackerProjectsDoe sNotExistError GetTrackerProjectTrackerProjectExistTrackerProjectDoes NotExistError GetTrackerProjectIs sueTypes TrackerProjectIssue TypesExist TrackerProjectIssueTypesDoesNotExist Error CreateMigrationWa ve CreateJiraCheckMandatoriesI ncidentsAfterIssueC reation NotifyCompletionEndNotifyMandatoriesIncidentsInApplicati on EndNotifyFailureBackst age EndallOfCancelTaskAbortreportAbortEndhasMandatorie... hasMandatorie... NotifyTracker NotifyTracker (.trackers != null) (.trackers != null) (.tracker != null) (.tracker != null) (.trackerProject... (.trackerProject... (.trackerProject ... (.trackerProject ... (.trackerProject... (.trackerProject... hasMandatorie... hasMandatorie... taskFailed taskFailed taskNotCompleted taskNotCompleted \ No newline at end of file diff --git a/mta-v7.x/mta.sw.yaml b/mta-v7.x/mta.sw.yaml index 08170404..2f5843fd 100644 --- a/mta-v7.x/mta.sw.yaml +++ b/mta-v7.x/mta.sw.yaml @@ -22,6 +22,8 @@ functions: - name: filterApplication type: expression operation: "{application: .applications|map(select(.repository.url == .repositoryURL))[0]}" + - name: deleteTaskGroup + operation: specs/mta.json#deleteTaskGroup - name: getApplication operation: specs/mta.json#getApplications - name: getApplicationAnalysis @@ -102,55 +104,71 @@ functions: - name: successResult type: expression operation: '{ - "completedWith":"success", - "message": "MTA v7.x analysis completed for " + .repositoryURL, - "outputs":[ - { - "key":"MTA Analysis Result URL", - "value": $SECRET.mta.url + "/hub/applications/" + (.application.id|tostring) + "/analysis/report", - "format":"link" - }, - { - "key":"Migration Wave Ticket URL", - "value": (if .migrationWaveJiraTicket != null then .migrationWaveJiraTicket.link else "" end), - "format":"link" - } - ], - "nextWorkflows":[ - { - "id":"m2k", - "name":"Move2Kube workflow" - } - ] + result: { + completedWith:"success", + message: "MTA v7.x analysis completed for " + .repositoryURL, + outputs:[ + { + key:"MTA Analysis Result URL", + value: $SECRET.mta.url + "/hub/applications/" + (.application.id|tostring) + "/analysis/report", + format:"link" + }, + { + key:"Migration Wave Ticket URL", + value: (if .migrationWaveJiraTicket != null then .migrationWaveJiraTicket.link else "" end), + format:"link" + } + ], + nextWorkflows:[ + { + id:"m2k", + name:"Move2Kube workflow" + } + ] + } }' - name: mandatoriesIncidentsResult type: expression operation: '{ - "completedWith": "warning", - "message": "MTA analysis for " + .application.repository.url + " completed with " + (.application.mandatoriesIncidents|tostring) + " incidents in mandatory issues that need to be fixed before being able to provide any next possible workflow. Check the analysis report." + (if .migrationWaveJiraTicket != null then " Application was exported to issue manager." else "" end), - "outputs": [ - { - "key":"MTA Analysis Result URL", - "value": ($SECRET.mta.url + "/hub/applications/" + (.application.id|tostring) + "/analysis/report"), - "format": "link" - }, - { - "key":"Migration Wave Ticket URL", - "value": (if .migrationWaveJiraTicket != null then .migrationWaveJiraTicket.link else "" end), - "format": "link" - } - ] + result: { + completedWith: "warning", + message: "MTA analysis for " + .application.repository.url + " completed with " + (.application.mandatoriesIncidents|tostring) + " incidents in mandatory issues that need to be fixed before being able to provide any next possible workflow. Check the analysis report." + (if .migrationWaveJiraTicket != null then " Application was exported to issue manager." else "" end), + outputs: [ + { + key:"MTA Analysis Result URL", + value: ($SECRET.mta.url + "/hub/applications/" + (.application.id|tostring) + "/analysis/report"), + format: "link" + }, + { + key:"Migration Wave Ticket URL", + value: (if .migrationWaveJiraTicket != null then .migrationWaveJiraTicket.link else "" end), + format: "link" + } + ] + } }' - name: errorResult type: expression operation: '{ - "completedWith":"error", - "message": "MTA analysis for " + .application.repository.url + " failed: " + .exitMessage + ". Check logs of task pod: " + .taskgroup.tasks[0].pod + result: { + completedWith:"error", + message: "MTA analysis for " + .application.repository.url + " failed: " + .exitMessage + ". Check logs of task pod: " + .taskgroup.tasks[0].pod + } + }' + + - name: abortResult + type: expression + operation: '{ + result: { + completedWith:"aborted", + message: "MTA analysis for " + .application.repository.url + " aborted, all in progress tasks were cancelled." + } }' states: - name: CreateApplication type: operation + compensatedBy: reportAbort actions: - name: createApplication actionDataFilter: @@ -164,6 +182,7 @@ states: kind: git transition: CreateTaskgroup - name: CreateTaskgroup + compensatedBy: reportAbort type: operation actionMode: sequential actions: @@ -191,6 +210,7 @@ states: - name: SubmitAnalysis type: operation actionMode: sequential + compensatedBy: CancelTaskAbort actions: - name: submitTaskgroup functionRef: @@ -213,15 +233,9 @@ states: transition: pollResults - name: pollResults type: operation + compensatedBy: CancelTaskAbort actionMode: sequential actions: - - name: "SleepBeforeChecking" - functionRef: - refName: "logInfo" - arguments: - message: '"Sleeping before checking the analysis result "' - sleep: - after: PT30S - name: "getTaskgroup" functionRef: refName: getTaskgroup @@ -229,13 +243,11 @@ states: id: ".taskgroup.id" actionDataFilter: toStateData: .taskgroup - - name: "logTaskGroup" - functionRef: - refName: "logInfo" - arguments: - message: "\"Logging data: \\(.)\"" + sleep: + before: PT30S transition: checkReportDone - name: checkReportDone + compensatedBy: CancelTaskAbort type: switch dataConditions: - condition: (.taskgroup.state == "Ready" and (.taskgroup.tasks[0].state == "Running" or (.taskgroup.tasks[0].state == "Pending" or .taskgroup.tasks[0].state == "Postponed"))) @@ -247,12 +259,14 @@ states: defaultCondition: transition: GetApplicationAnalysis - name: TaskFailedError + compensatedBy: reportAbort type: operation actions: - name: Fill exitMessage functionRef: TaskFailedErrorExitMessage transition: NotifyFailureBackstage - name: GetApplicationAnalysis + compensatedBy: reportAbort type: operation actionMode: sequential actions: @@ -265,6 +279,7 @@ states: toStateData: ".applicationAnalysis" transition: CountMandatoriesIncidents - name: CountMandatoriesIncidents + compensatedBy: reportAbort type: operation actionMode: sequential actions: @@ -273,13 +288,9 @@ states: toStateData: .application.mandatoriesIncidents functionRef: refName: countMandatoriesIncidents - - name: "logMandatoriesIncidents" - functionRef: - refName: "logInfo" - arguments: - message: "\"Mandatory incidents: \\(.application.mandatoriesIncidents|tostring)\"" transition: CountNonMandatoriesIncidents - name: CountNonMandatoriesIncidents + compensatedBy: reportAbort type: operation actionMode: sequential actions: @@ -288,13 +299,9 @@ states: toStateData: .application.nonMandatoriesIncidents functionRef: refName: countNonMandatoriesIncidents - - name: "logNonMandatoriesIncidents" - functionRef: - refName: "logInfo" - arguments: - message: "\"Non-mandatory incidents: \\(.application.nonMandatoriesIncidents|tostring)\"" transition: CheckMandatoriesIncidents - name: CheckMandatoriesIncidents + compensatedBy: reportAbort type: switch dataConditions: - condition: .application.mandatoriesIncidents > 0 @@ -306,6 +313,7 @@ states: defaultCondition: transition: NotifyCompletion - name: GetTrackers + compensatedBy: reportAbort type: operation actions: - name: GetTrackers @@ -315,6 +323,7 @@ states: toStateData: ".trackers" transition: TrackersExist - name: TrackersExist + compensatedBy: reportAbort type: switch dataConditions: - condition: (.trackers != null) @@ -322,12 +331,14 @@ states: defaultCondition: transition: TrackersDoesNotExistError - name: TrackersDoesNotExistError + compensatedBy: reportAbort type: operation actions: - name: Fill exitMessage functionRef: TrackersDoesNotExistErrorExitMessage transition: NotifyFailureBackstage - name: GetTracker + compensatedBy: reportAbort type: operation actions: - condition: .trackers != null @@ -339,6 +350,7 @@ states: toStateData: ".tracker" transition: TrackerExists - name: TrackerExists + compensatedBy: reportAbort type: switch dataConditions: - condition: (.tracker != null) @@ -346,12 +358,14 @@ states: defaultCondition: transition: TrackerDoesNotExistError - name: TrackerDoesNotExistError + compensatedBy: reportAbort type: operation actions: - name: Fill exitMessage functionRef: TrackerDoesNotExistErrorExitMessage transition: NotifyFailureBackstage - name: GetTrackerProjects + compensatedBy: reportAbort type: operation actions: - condition: .tracker != null @@ -363,6 +377,7 @@ states: toStateData: ".trackerProjects" transition: TrackerProjectsExist - name: TrackerProjectsExist + compensatedBy: reportAbort type: switch dataConditions: - condition: (.trackerProjects != null) @@ -370,12 +385,14 @@ states: defaultCondition: transition: TrackerProjectsDoesNotExistError - name: TrackerProjectsDoesNotExistError + compensatedBy: reportAbort type: operation actions: - name: Fill exitMessage functionRef: TrackerProjectsDoesNotExistErrorExitMessage transition: NotifyFailureBackstage - name: GetTrackerProject + compensatedBy: reportAbort type: operation actions: - condition: .trackerProjects != null @@ -388,6 +405,7 @@ states: toStateData: ".trackerProject" transition: TrackerProjectExist - name: TrackerProjectExist + compensatedBy: reportAbort type: switch dataConditions: - condition: (.trackerProject != null) @@ -395,12 +413,14 @@ states: defaultCondition: transition: TrackerProjectDoesNotExistError - name: TrackerProjectDoesNotExistError + compensatedBy: reportAbort type: operation actions: - name: Fill exitMessage functionRef: TrackerProjectDoesNotExistErrorExitMessage transition: NotifyFailureBackstage - name: GetTrackerProjectIssueTypes + compensatedBy: reportAbort type: operation actions: - condition: .trackerProject != null @@ -413,6 +433,7 @@ states: toStateData: ".trackerProjectIssueTypes" transition: TrackerProjectIssueTypesExist - name: TrackerProjectIssueTypesExist + compensatedBy: reportAbort type: switch dataConditions: - condition: (.trackerProjectIssueTypes != null) @@ -420,12 +441,14 @@ states: defaultCondition: transition: TrackerProjectIssueTypesDoesNotExistError - name: TrackerProjectIssueTypesDoesNotExistError + compensatedBy: reportAbort type: operation actions: - name: Fill exitMessage functionRef: TrackerProjectIssueTypesDoesNotExistErrorExitMessage transition: NotifyFailureBackstage - name: CreateMigrationWave + compensatedBy: reportAbort type: operation actions: - functionRef: @@ -441,14 +464,10 @@ states: toStateData: ".createdMigrationWave" transition: CreateJira - name: CreateJira + compensatedBy: reportAbort type: operation actionMode: sequential actions: - - name: logInfo - functionRef: - refName: "logInfo" - arguments: - message: "\"Logging data: \\(.)\"" - name: "CreateTickets" functionRef: refName: createTicket @@ -474,6 +493,7 @@ states: toStateData: ".migrationWaveJiraTicket" transition: CheckMandatoriesIncidentsAfterIssueCreation - name: CheckMandatoriesIncidentsAfterIssueCreation + compensatedBy: reportAbort type: switch dataConditions: - condition: .application.mandatoriesIncidents > 0 @@ -496,18 +516,9 @@ states: topic: "MTA Analysis Workflow" link: '$SECRET.mta.url + "/hub/applications/" + (.application.id|tostring) + "/analysis/report"' severity: "normal" - transition: reportCompletion - - name: reportCompletion - type: operation - actionMode: sequential - actions: - name: reportCompletion functionRef: refName: successResult - actionDataFilter: - toStateData: ".result" - stateDataFilter: - output: ". += .result" end: true - name: NotifyMandatoriesIncidentsInApplication type: operation @@ -524,17 +535,9 @@ states: topic: "MTA Analysis Workflow" link: '$SECRET.mta.url + "/hub/applications/" + (.application.id|tostring) + "/analysis/report"' severity: "high" - transition: reportCompletionWithMandatoriesIncidentsInApplication - - name: reportCompletionWithMandatoriesIncidentsInApplication - type: operation - actions: - name: reportCompletionWithMandatoriesIncidentsInApplication functionRef: refName: mandatoriesIncidentsResult - actionDataFilter: - toStateData: ".result" - stateDataFilter: - output: ". += .result" end: true - name: NotifyFailureBackstage type: operation @@ -552,15 +555,45 @@ states: description: '"MTA analysis for " + .application.repository.url + " failed: " + .exitMessage + ". Check logs of task pod: " + .taskgroup.tasks[0].pod' topic: "MTA Analysis Workflow" severity: "critical" - transition: reportFailure - - name: reportFailure - type: operation - actions: - name: reportFailure functionRef: refName: errorResult - actionDataFilter: - toStateData: ".result" - stateDataFilter: - output: ". += .result" end: true + - name: CancelTaskAbort + type: parallel + usedForCompensation: true + branches: + - name: printSystemOut + actions: + - name: printSystemOut + functionRef: + refName: systemOut + arguments: + message: '${"MTA workflow: " + $WORKFLOW.instanceId + " was aborted while task was still in progress}"' + - name: "abortTasks" + actions: + - name: "abortTasks" + functionRef: + refName: deleteTaskGroup + arguments: + id: ".taskgroup.id" + transition: reportAbort + - name: reportAbort + type: operation + usedForCompensation: true + actions: + - name: createNotification + functionRef: + refName: createNotification + arguments: + recipients: + type: "entity" + entityRef: .recipients + payload: + title: "MTA analysis aborted" + description: '"MTA analysis for " + .application.repository.url + " aborted while tasks still in progress, tasks were cancelled"' + topic: "MTA Analysis Workflow" + severity: "critical" + - name: reportAbort + functionRef: + refName: abortResult diff --git a/shared/schemas/workflow-result-schema.json b/shared/schemas/workflow-result-schema.json index f2e91416..226bf09e 100644 --- a/shared/schemas/workflow-result-schema.json +++ b/shared/schemas/workflow-result-schema.json @@ -10,7 +10,8 @@ "enum": [ "error", "success", - "warning" + "warning", + "aborted" ] }, "message": {