mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(codepipeline): wait for custom jobs while stopping (#3678)
* fix(codepipeline): preserve custom action stop status * fix(codepipeline): wait for custom jobs while stopping Signed-off-by: XuJian <xujian.top@gmail.com> * test(codepipeline): cover custom jobs while stopping Signed-off-by: XuJian <xujian.top@gmail.com> --------- Signed-off-by: XuJian <xujian.top@gmail.com> Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
86072aaa84
commit
c317fa52d2
2 files changed
+203
-6
No files matched your search
+12
-4
@@ -1244,7 +1244,7 @@ public class CodePipelineService {
|
||||
stored.set("job", job);
|
||||
storeItem(execution.getAccountId(), execution.getRegion(), "job", jobId, "Created", stored);
|
||||
state.setExternalExecutionId(jobId);
|
||||
while (!execution.isStopRequested()) {
|
||||
while (!(execution.isStopRequested() && execution.isAbandon())) {
|
||||
CodePipelineStoredItem current = requireItem(
|
||||
execution.getAccountId(), execution.getRegion(), "job", jobId, "JobNotFoundException");
|
||||
if ("Succeeded".equals(current.getStatus())) {
|
||||
@@ -1256,12 +1256,20 @@ public class CodePipelineService {
|
||||
return;
|
||||
}
|
||||
if ("Failed".equals(current.getStatus())) {
|
||||
throw new AwsException("ActionExecutionFailed",
|
||||
current.getData().path("result").path("failureDetails").path("message")
|
||||
.asText("Custom action failed"), 400);
|
||||
String message = current.getData().path("result").path("failureDetails").path("message")
|
||||
.asText("Custom action failed");
|
||||
if (execution.isStopRequested()) {
|
||||
state.setStatus("Failed");
|
||||
state.setSummary(message);
|
||||
state.setErrorDetails(Map.of("code", "ActionExecutionFailed", "message", message));
|
||||
return;
|
||||
}
|
||||
throw new AwsException("ActionExecutionFailed", message, 400);
|
||||
}
|
||||
TimeUnit.MILLISECONDS.sleep(POLL_INTERVAL_MS);
|
||||
}
|
||||
state.setStatus("Abandoned");
|
||||
state.setSummary("Action abandoned.");
|
||||
}
|
||||
|
||||
private void applyExecutionMode(CodePipelineExecution execution) {
|
||||
|
||||
+191
-2
@@ -851,6 +851,191 @@ class CodePipelineIntegrationTest {
|
||||
""").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void stoppingCustomActionWaitsForWorkerSuccess() throws Exception {
|
||||
String provider = "StopWaitSuccessWorker";
|
||||
String pipelineName = "custom-worker-stop-wait-success";
|
||||
createCustomWorkerPipeline(provider, pipelineName);
|
||||
String executionId = post("StartPipelineExecution", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName)).then().extract().path("pipelineExecutionId");
|
||||
String jobId = waitForJob(provider).path("jobs[0].id");
|
||||
|
||||
post("StopPipelineExecution", """
|
||||
{
|
||||
"pipelineName": "%s",
|
||||
"pipelineExecutionId": "%s",
|
||||
"reason": "Wait for the custom worker"
|
||||
}
|
||||
""".formatted(pipelineName, executionId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
assertCustomWorkerIsStopping(pipelineName);
|
||||
post("PutJobSuccessResult", """
|
||||
{
|
||||
"jobId": "%s",
|
||||
"executionDetails": {
|
||||
"summary": "worker completed after stop request",
|
||||
"externalExecutionId": "stop-wait-success",
|
||||
"percentComplete": 100
|
||||
}
|
||||
}
|
||||
""".formatted(jobId)).then().statusCode(200);
|
||||
|
||||
waitForExecution(pipelineName, executionId, "Stopped");
|
||||
post("GetPipelineState", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("stageStates[0].latestExecution.status", equalTo("Stopped"))
|
||||
.body("stageStates[0].actionStates[0].latestExecution.status", equalTo("Succeeded"))
|
||||
.body("stageStates[1].latestExecution", nullValue());
|
||||
|
||||
deleteCustomWorkerPipeline(provider, pipelineName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void stoppingCustomActionWaitsForWorkerFailure() throws Exception {
|
||||
String provider = "StopWaitFailureWorker";
|
||||
String pipelineName = "custom-worker-stop-wait-failure";
|
||||
createCustomWorkerPipeline(provider, pipelineName);
|
||||
String executionId = post("StartPipelineExecution", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName)).then().extract().path("pipelineExecutionId");
|
||||
String jobId = waitForJob(provider).path("jobs[0].id");
|
||||
|
||||
post("StopPipelineExecution", """
|
||||
{
|
||||
"pipelineName": "%s",
|
||||
"pipelineExecutionId": "%s",
|
||||
"reason": "Wait for the failing custom worker"
|
||||
}
|
||||
""".formatted(pipelineName, executionId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
assertCustomWorkerIsStopping(pipelineName);
|
||||
post("PutJobFailureResult", """
|
||||
{
|
||||
"jobId": "%s",
|
||||
"failureDetails": {
|
||||
"type": "JobFailed",
|
||||
"message": "worker failed after stop request",
|
||||
"externalExecutionId": "stop-wait-failure"
|
||||
}
|
||||
}
|
||||
""".formatted(jobId)).then().statusCode(200);
|
||||
|
||||
waitForExecution(pipelineName, executionId, "Stopped");
|
||||
post("GetPipelineState", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("stageStates[0].latestExecution.status", equalTo("Failed"))
|
||||
.body("stageStates[0].actionStates[0].latestExecution.status", equalTo("Failed"))
|
||||
.body("stageStates[1].latestExecution", nullValue());
|
||||
|
||||
deleteCustomWorkerPipeline(provider, pipelineName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void abandoningCustomActionStopsWaitingImmediately() throws Exception {
|
||||
String provider = "AbandonWorker";
|
||||
String pipelineName = "custom-worker-stop-abandon";
|
||||
createCustomWorkerPipeline(provider, pipelineName);
|
||||
String executionId = post("StartPipelineExecution", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName)).then().extract().path("pipelineExecutionId");
|
||||
waitForJob(provider);
|
||||
|
||||
post("StopPipelineExecution", """
|
||||
{
|
||||
"pipelineName": "%s",
|
||||
"pipelineExecutionId": "%s",
|
||||
"abandon": true,
|
||||
"reason": "Abandon the custom worker"
|
||||
}
|
||||
""".formatted(pipelineName, executionId))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
waitForExecution(pipelineName, executionId, "Stopped");
|
||||
post("GetPipelineState", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("stageStates[0].latestExecution.status", equalTo("Stopped"))
|
||||
.body("stageStates[0].actionStates[0].latestExecution.status", equalTo("Abandoned"))
|
||||
.body("stageStates[1].latestExecution", nullValue());
|
||||
|
||||
deleteCustomWorkerPipeline(provider, pipelineName);
|
||||
}
|
||||
|
||||
private void createCustomWorkerPipeline(String provider, String pipelineName) {
|
||||
post("CreateCustomActionType", """
|
||||
{
|
||||
"category": "Build",
|
||||
"provider": "%s",
|
||||
"version": "1",
|
||||
"inputArtifactDetails": {"minimumCount": 0, "maximumCount": 0},
|
||||
"outputArtifactDetails": {"minimumCount": 0, "maximumCount": 0}
|
||||
}
|
||||
""".formatted(provider))
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
post("CreatePipeline", pipeline(pipelineName, """
|
||||
{
|
||||
"name": "Build",
|
||||
"actions": [{
|
||||
"name": "WorkerBuild",
|
||||
"actionTypeId": {
|
||||
"category": "Build",
|
||||
"owner": "Custom",
|
||||
"provider": "%s",
|
||||
"version": "1"
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "Complete",
|
||||
"actions": [{
|
||||
"name": "ManualApproval",
|
||||
"actionTypeId": {
|
||||
"category": "Approval",
|
||||
"owner": "AWS",
|
||||
"provider": "Manual",
|
||||
"version": "1"
|
||||
}
|
||||
}]
|
||||
}
|
||||
""".formatted(provider))).then().statusCode(200);
|
||||
}
|
||||
|
||||
private void assertCustomWorkerIsStopping(String pipelineName) {
|
||||
post("GetPipelineState", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("stageStates[0].latestExecution.status", equalTo("Stopping"))
|
||||
.body("stageStates[0].actionStates[0].latestExecution.status", equalTo("InProgress"))
|
||||
.body("stageStates[1].latestExecution", nullValue());
|
||||
}
|
||||
|
||||
private void deleteCustomWorkerPipeline(String provider, String pipelineName) {
|
||||
post("DeletePipeline", """
|
||||
{"name": "%s"}
|
||||
""".formatted(pipelineName)).then().statusCode(200);
|
||||
post("DeleteCustomActionType", """
|
||||
{"category": "Build", "provider": "%s", "version": "1"}
|
||||
""".formatted(provider)).then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void putApprovalResultApprovesAndRejectsManualApprovalActions() throws Exception {
|
||||
String pipelineName = "approval-test-pipeline";
|
||||
@@ -1429,6 +1614,10 @@ class CodePipelineIntegrationTest {
|
||||
}
|
||||
|
||||
private Response waitForJob() throws Exception {
|
||||
return waitForJob("FlociWorker");
|
||||
}
|
||||
|
||||
private Response waitForJob(String provider) throws Exception {
|
||||
Instant deadline = Instant.now().plus(Duration.ofSeconds(5));
|
||||
Response response;
|
||||
do {
|
||||
@@ -1437,11 +1626,11 @@ class CodePipelineIntegrationTest {
|
||||
"actionTypeId": {
|
||||
"category": "Build",
|
||||
"owner": "Custom",
|
||||
"provider": "FlociWorker",
|
||||
"provider": "%s",
|
||||
"version": "1"
|
||||
}
|
||||
}
|
||||
""");
|
||||
""".formatted(provider));
|
||||
if (response.jsonPath().getList("jobs").size() == 1) {
|
||||
return response;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user