use of com.github.dockerjava.api.exception.NotModifiedException in project elastest-torm by elastest.
the class DockerService2 method endContainer.
/**
******************************
*/
/**
*** End execution methods ****
*/
/**
******************************
*/
public void endContainer(String containerName) {
DockerClient dockerClient = this.getDockerClient();
if (existsContainer(containerName)) {
String containerId = getContainerIdByName(containerName);
int timeout = 60;
try {
logger.info("Stopping " + containerName + " container");
dockerClient.stopContainerCmd(containerId).withTimeout(timeout).exec();
// Wait
dockerClient.waitContainerCmd(containerId).exec(new WaitContainerResultCallback()).awaitStatusCode();
} catch (DockerClientException e) {
// throw new TJobStoppedException();
} catch (NotModifiedException e) {
logger.info("Container " + containerName + " is already stopped");
} catch (Exception e) {
logger.info("Error during stop " + containerName + " container {}", e);
} finally {
try {
logger.info("Removing " + containerName + " container");
dockerClient.removeContainerCmd(containerId).exec();
} catch (DockerClientException e) {
// throw new TJobStoppedException();
} catch (Exception e) {
logger.info("Error during remove " + containerName + " container");
}
createdContainers.remove(containerId);
}
} else {
logger.info("Could not end " + containerName + " container -> Not started.");
}
}
Aggregations