mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(codepipeline): preserve external actions while stopping (#3726)
* fix(codepipeline): preserve external actions while stopping * fix(codepipeline): publish stop mode across threads --------- Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
bd005ac9c7
commit
b3d46d5024
3 files changed
+310
-13
No files matched your search
+44
-11
@@ -516,8 +516,10 @@ public class CodePipelineService {
|
||||
throw new AwsException("PipelineExecutionNotStoppableException",
|
||||
"Pipeline execution is already in a terminal state", 400);
|
||||
}
|
||||
execution.setStopRequested(true);
|
||||
// Publish the stop mode before the stop signal. The provider polling loop reads
|
||||
// stopRequested first, so observing it also observes the matching abandon value.
|
||||
execution.setAbandon(request.path("abandon").asBoolean(false));
|
||||
execution.setStopRequested(true);
|
||||
execution.setStatus("Stopping");
|
||||
execution.setStatusSummary(request.path("reason").asText("Stop requested."));
|
||||
execution.setLastUpdateTime(now());
|
||||
@@ -1142,16 +1144,21 @@ public class CodePipelineService {
|
||||
null, null, null, null, null, null, null);
|
||||
state.setExternalExecutionId(build.getId());
|
||||
while (!Boolean.TRUE.equals(build.getBuildComplete())) {
|
||||
if (execution.isStopRequested()) {
|
||||
codeBuildService.stopBuild(execution.getRegion(), execution.getAccountId(), build.getId());
|
||||
break;
|
||||
if (abandonExternalActionIfRequested(execution, state)) {
|
||||
return;
|
||||
}
|
||||
TimeUnit.MILLISECONDS.sleep(POLL_INTERVAL_MS);
|
||||
build = codeBuildService.getBuild(execution.getRegion(), execution.getAccountId(), build.getId());
|
||||
}
|
||||
if (abandonExternalActionIfRequested(execution, state)) {
|
||||
return;
|
||||
}
|
||||
if (!"SUCCEEDED".equals(build.getBuildStatus())) {
|
||||
throw new AwsException("ActionExecutionFailed",
|
||||
"CodeBuild build " + build.getId() + " finished with " + build.getBuildStatus(), 400);
|
||||
String message = "CodeBuild build " + build.getId() + " finished with " + build.getBuildStatus();
|
||||
if (recordExternalActionFailureWhileStopping(execution, state, message)) {
|
||||
return;
|
||||
}
|
||||
throw new AwsException("ActionExecutionFailed", message, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1170,16 +1177,42 @@ public class CodePipelineService {
|
||||
state.setExternalExecutionId(deploymentId);
|
||||
Deployment deployment = codeDeployService.getDeployment(execution.getRegion(), deploymentId);
|
||||
while (!List.of("Succeeded", "Failed", "Stopped").contains(deployment.getStatus())) {
|
||||
if (execution.isStopRequested()) {
|
||||
codeDeployService.stopDeployment(execution.getRegion(), deploymentId);
|
||||
if (abandonExternalActionIfRequested(execution, state)) {
|
||||
return;
|
||||
}
|
||||
TimeUnit.MILLISECONDS.sleep(POLL_INTERVAL_MS);
|
||||
deployment = codeDeployService.getDeployment(execution.getRegion(), deploymentId);
|
||||
}
|
||||
if (!"Succeeded".equals(deployment.getStatus())) {
|
||||
throw new AwsException("ActionExecutionFailed",
|
||||
"CodeDeploy deployment finished with " + deployment.getStatus(), 400);
|
||||
if (abandonExternalActionIfRequested(execution, state)) {
|
||||
return;
|
||||
}
|
||||
if (!"Succeeded".equals(deployment.getStatus())) {
|
||||
String message = "CodeDeploy deployment finished with " + deployment.getStatus();
|
||||
if (recordExternalActionFailureWhileStopping(execution, state, message)) {
|
||||
return;
|
||||
}
|
||||
throw new AwsException("ActionExecutionFailed", message, 400);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean abandonExternalActionIfRequested(CodePipelineExecution execution, ActionExecution state) {
|
||||
if (!execution.isStopRequested() || !execution.isAbandon()) {
|
||||
return false;
|
||||
}
|
||||
state.setStatus("Abandoned");
|
||||
state.setSummary("Action abandoned.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean recordExternalActionFailureWhileStopping(CodePipelineExecution execution,
|
||||
ActionExecution state, String message) {
|
||||
if (!execution.isStopRequested()) {
|
||||
return false;
|
||||
}
|
||||
state.setStatus("Failed");
|
||||
state.setSummary(message);
|
||||
state.setErrorDetails(Map.of("code", "ActionExecutionFailed", "message", message));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeLambda(CodePipelineExecution execution, JsonNode action, ActionExecution state) {
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ public class CodePipelineExecution {
|
||||
private List<ActionExecution> actionExecutions = new ArrayList<>();
|
||||
private Map<String, String> stageExecutionStatuses = new LinkedHashMap<>();
|
||||
private String currentStage;
|
||||
private boolean stopRequested;
|
||||
private boolean abandon;
|
||||
private volatile boolean stopRequested;
|
||||
private volatile boolean abandon;
|
||||
private String rollbackTargetPipelineExecutionId;
|
||||
|
||||
public String getAccountId() {
|
||||
|
||||
Reference in new issue
Block a user