@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof ContainerExit) { ContainerExit that = (ContainerExit) o; return (this.statusCode.equals(that.statusCode())); } return false; }
@Override public ContainerExit waitContainer(final String containerId) throws DockerException, InterruptedException { // XXX (dano): We're doing this poll loop instead of docker.waitContainer() because we saw the // agent hang forever on waitContainer after the socket got into a weird half-open // state where the kernel (netstat/lsof) would only show one end of the connection // and restarting docker would not close the socket. ¯\_(ツ)_/¯ while (true) { final ContainerInfo info = inspectContainer(containerId); if (!info.state().running()) { return ContainerExit.create(info.state().exitCode()); } Thread.sleep(WAIT_INSPECT_INTERVAL_MILLIS); } } }
@Override public ContainerExit waitContainer(final String containerId) throws DockerException, InterruptedException { // XXX (dano): We're doing this poll loop instead of docker.waitContainer() because we saw the // agent hang forever on waitContainer after the socket got into a weird half-open // state where the kernel (netstat/lsof) would only show one end of the connection // and restarting docker would not close the socket. ¯\_(ツ)_/¯ while (true) { final ContainerInfo info = inspectContainer(containerId); if (!info.state().running()) { return new ContainerExit(info.state().exitCode()); } Thread.sleep(WAIT_INSPECT_INTERVAL_MILLIS); } } }
log.info("container exited: {}: {}: {}", config, containerId, exit.statusCode()); listener.exited(exit.statusCode()); return exit.statusCode();
@Test public void test() throws Exception { startDefaultMaster(); final String id = "test-" + toHexString(new SecureRandom().nextInt()); final String namespace = "helios-" + id; final String intruder1 = intruder(namespace); final String intruder2 = intruder(namespace); // Start a container in the agent namespace startContainer(intruder1); // Start agent final HeliosClient client = defaultClient(); startDefaultAgent(testHost(), "--id=" + id); awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS); awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS); // With LXC, killing a container results in exit code 0. // In docker 1.5 killing a container results in exit code 137, in previous versions it's -1. final String executionDriver = docker.info().executionDriver(); final List<Long> expectedExitCodes = (executionDriver != null && executionDriver.startsWith("lxc-")) ? Collections.singletonList(0L) : asList(-1L, 137L); // Wait for the agent to kill the container final ContainerExit exit1 = docker.waitContainer(intruder1); assertThat(exit1.statusCode(), isIn(expectedExitCodes)); // Start another container in the agent namespace startContainer(intruder2); // Wait for the agent to kill the second container as well final ContainerExit exit2 = docker.waitContainer(intruder2); assertThat(exit2.statusCode(), isIn(expectedExitCodes)); }
assertThat(exit.statusCode(), is(0L));
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof ContainerExit) { ContainerExit that = (ContainerExit) o; return (this.statusCode.equals(that.statusCode())); } return false; }
private TaskExecutionResult collectTaskExecutionResult(DockerTask task, String containerId) throws DockerException, InterruptedException { final ContainerExit exit = docker.waitContainer(containerId); log.info("Container " + containerId + " finished with exit code " + exit.statusCode()); TaskExecutionResult result = new TaskExecutionResult(task); // TODO : Do some descent exception treatment if (exit.statusCode() != 0) { result.markAsFinished(exit.statusCode()); } else { result.markAsFinishedWithSuccess(); } log.info("Collecting container logs for " + containerId); String logs = docker.logs(containerId, LogsParam.stdout(), LogsParam.stderr()).readFully(); // Remove the last new line if needed if (logs.endsWith("\n")) { logs = logs.substring(0, logs.length() - 1); } result.setOutput(logs); return result; }
log.info("container exited: {}: {}: {}", config, containerId, exit.statusCode()); listener.exited(exit.statusCode()); return exit.statusCode();
LOGGER.info("The container has finished with status code: "+exitStatus.statusCode()); if (!this.repairnatorConfig.isSkipDelete() && exitStatus.statusCode() == 0) { LOGGER.info("Container will be removed."); docker.removeContainer(containerId);
LOGGER.info("(BUILD ID " + this.inputBuildId.getBuggyBuildId() + ") The container has finished with status code: "+exitStatus.statusCode()); if (!this.repairnatorConfig.isSkipDelete() && exitStatus.statusCode() == 0) { LOGGER.info("(BUILD ID " + this.inputBuildId.getBuggyBuildId() + ") Container will be removed."); docker.removeContainer(this.containerId); if (exitStatus.statusCode() == 0) { serialize("TREATED"); } else { serialize("ERROR:CODE" + exitStatus.statusCode());