Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EcsCommandExecutor: return failure status when exit code is empty #1724

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,13 @@ CommandStatus createNextCommandStatus(
// To fetch log until all logs is written in CloudWatch,
// finish this poll once and wait finish marker in head of this method in next poll, considering risk of crushing in this poll.
nextStatus.put("task_finished_at", Instant.now().getEpochSecond());
// Set exit code of container finished to nextStatus
nextStatus.put("status_code", task.getContainers().get(0).getExitCode());
// Set exit code of container finished to nextStatus.
// If exit code doesn't exist, something's wrong with execution, so set status code to 1 to make workflow fail
Integer exitCode = task.getContainers().get(0).getExitCode();
if (exitCode == null) {
logger.debug("Container has no exit code. The status code will be set as error (1)");
}
nextStatus.put("status_code", exitCode != null ? exitCode : 1);
}

// always return false to check if all logs are fetched. (return in head of this method after checking finish marker.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,35 @@ public void testGetErrorMessageFromTask()
}
}
}

@Test
public void testErrorOnEmptyExitCodeFromContainer()
throws Exception
{
final EcsClient ecsClient = mock(EcsClient.class);
final CommandContext commandContext = mock(CommandContext.class);
final EcsCommandExecutor executor = spy(new EcsCommandExecutor(
systemConfig, ecsClientFactory, dockerCommandExecutor,
storageManager, projectArchiveLoader, commandLogger));
final Task task = mock(Task.class);
final Container container = mock(Container.class);

final ObjectNode previousStatusJson = om.createObjectNode();
previousStatusJson.put("cluster_name", "my_cluster");
previousStatusJson.put("task_arn", "my_task_arn");
previousStatusJson.put("executor_state", om.createObjectNode());
previousStatusJson.put("awslogs", om.createObjectNode().nullNode());

doReturn(mock(EcsClientConfig.class)).when(executor).createEcsClientConfig(any(Optional.class), any(Config.class), any(Config.class));
doReturn(ecsClient).when(ecsClientFactory).createClient(any(EcsClientConfig.class));
doReturn(mock(TaskRequest.class)).when(commandContext).getTaskRequest();
doReturn("stopped").when(task).getLastStatus();
doReturn(null).when(container).getExitCode();
doReturn(Arrays.asList(container)).when(task).getContainers();
doReturn(task).when(ecsClient).getTask(previousStatusJson.get("cluster_name").asText(), previousStatusJson.get("task_arn").asText());

CommandStatus commandStatus = executor.poll(commandContext, previousStatusJson);

assertThat(commandStatus.getStatusCode(), is(1));
}
}