Skip to content

Commit

Permalink
Add abort compensation for MTA
Browse files Browse the repository at this point in the history
Signed-off-by: gabriel-farache <[email protected]>
  • Loading branch information
gabriel-farache committed Dec 13, 2024
1 parent a1cd3e0 commit a57b776
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 86 deletions.
2 changes: 1 addition & 1 deletion workflows/mta-v7.x/mta.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
171 changes: 87 additions & 84 deletions workflows/mta-v7.x/mta.sw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,50 +104,65 @@ 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:
Expand Down Expand Up @@ -191,6 +208,7 @@ states:
- name: SubmitAnalysis
type: operation
actionMode: sequential
compensatedBy: CancelTaskAbort
actions:
- name: submitTaskgroup
functionRef:
Expand All @@ -213,29 +231,21 @@ 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
arguments:
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")))
Expand Down Expand Up @@ -273,11 +283,6 @@ states:
toStateData: .application.mandatoriesIncidents
functionRef:
refName: countMandatoriesIncidents
- name: "logMandatoriesIncidents"
functionRef:
refName: "logInfo"
arguments:
message: "\"Mandatory incidents: \\(.application.mandatoriesIncidents|tostring)\""
transition: CountNonMandatoriesIncidents
- name: CountNonMandatoriesIncidents
type: operation
Expand All @@ -288,11 +293,6 @@ states:
toStateData: .application.nonMandatoriesIncidents
functionRef:
refName: countNonMandatoriesIncidents
- name: "logNonMandatoriesIncidents"
functionRef:
refName: "logInfo"
arguments:
message: "\"Non-mandatory incidents: \\(.application.nonMandatoriesIncidents|tostring)\""
transition: CheckMandatoriesIncidents
- name: CheckMandatoriesIncidents
type: switch
Expand Down Expand Up @@ -444,11 +444,6 @@ states:
type: operation
actionMode: sequential
actions:
- name: logInfo
functionRef:
refName: "logInfo"
arguments:
message: "\"Logging data: \\(.)\""
- name: "CreateTickets"
functionRef:
refName: createTicket
Expand Down Expand Up @@ -496,18 +491,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
Expand All @@ -524,17 +510,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
Expand All @@ -559,8 +537,33 @@ states:
- name: reportFailure
functionRef:
refName: errorResult
actionDataFilter:
toStateData: ".result"
stateDataFilter:
output: ". += .result"
end: true
- name: CancelTaskAbort
type: operation
usedForCompensation: true
actions:
- name: logInfo
functionRef:
refName: logInfo
arguments:
message: '${"MTA workflow: " + $WORKFLOW.instanceId + " was aborted while task was still in progress}"'
- name: "abortTasks"
functionRef:
refName: deleteTaskGroup
arguments:
id: ".taskgroup.id"
- 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
3 changes: 2 additions & 1 deletion workflows/shared/schemas/workflow-result-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"enum": [
"error",
"success",
"warning"
"warning",
"aborted"
]
},
"message": {
Expand Down

0 comments on commit a57b776

Please sign in to comment.