use of com.spotify.docker.client.messages.ContainerInfo in project shinyproxy by openanalytics.
the class DockerEngineBackend method calculateTargetURL.
@Override
protected void calculateTargetURL(DockerContainerProxy proxy) throws Exception {
super.calculateTargetURL(proxy);
// See comments on https://github.com/docker/for-win/issues/1009
if (proxy.getTarget().contains(proxy.getName())) {
ContainerInfo info = dockerClient.inspectContainer(proxy.getContainerId());
proxy.setTarget(proxy.getTarget().replace(proxy.getName(), info.config().hostname()));
}
}
use of com.spotify.docker.client.messages.ContainerInfo in project Singularity by HubSpot.
the class SingularityExecutorCleanup method stopContainer.
private void stopContainer(Container container) {
try {
ContainerInfo containerInfo = dockerUtils.inspectContainer(container.id());
if (containerInfo.state().running()) {
dockerUtils.stopContainer(container.id(), executorConfiguration.getDockerStopTimeout());
LOG.debug("Forcefully stopped container {}", container.names());
}
dockerUtils.removeContainer(container.id(), true);
LOG.debug("Removed container {}", container.names());
} catch (Exception e) {
LOG.error("Failed to stop or remove container {}", container.names(), e);
exceptionNotifier.notify(String.format("Failed stopping container (%s)", e.getMessage()), e, Collections.<String, String>emptyMap());
}
}
use of com.spotify.docker.client.messages.ContainerInfo in project Singularity by HubSpot.
the class SingularityExecutorTaskCleanup method cleanup.
public TaskCleanupResult cleanup(boolean cleanupTaskAppDirectory, boolean cleanupLogs, boolean isDocker) {
final Path taskDirectory = Paths.get(taskDefinition.getTaskDirectory());
boolean dockerCleanSuccess = true;
if (isDocker) {
try {
String containerName = String.format("%s%s", configuration.getDockerPrefix(), taskDefinition.getTaskId());
ContainerInfo containerInfo = dockerUtils.inspectContainer(containerName);
if (containerInfo.state().running()) {
dockerUtils.stopContainer(containerName, configuration.getDockerStopTimeout());
}
dockerUtils.removeContainer(containerName, true);
} catch (DockerException e) {
if (ExceptionChainParser.exceptionChainContains(e, ContainerNotFoundException.class)) {
log.trace("Container for task {} was already removed", taskDefinition.getTaskId());
} else {
log.error("Could not ensure removal of container", e);
dockerCleanSuccess = false;
}
} catch (Exception e) {
log.error("Could not ensure removal of container", e);
dockerCleanSuccess = false;
}
}
if (!Files.exists(taskDirectory)) {
log.info("Directory {} didn't exist for cleanup", taskDirectory);
taskLogManager.removeLogrotateFile();
return finishTaskCleanup(dockerCleanSuccess);
}
boolean logTearDownSuccess = taskLogManager.teardown();
log.info("Rotated and marked logs for upload for {} ({})", taskDirectory, logTearDownSuccess);
if (!cleanupLogs) {
log.debug("Not finishing cleanup because log files will be preserved for 15 minutes after task termination");
return TaskCleanupResult.WAITING;
}
boolean rotatedLogfileDeleteSuccess = checkForLogrotateAdditionalFilesToDelete(taskDefinition);
log.info("Deleted rotated logfiles ({})", rotatedLogfileDeleteSuccess);
if (!cleanupTaskAppDirectory) {
log.debug("Not finishing cleanup because taskApp directory is being preserved");
return TaskCleanupResult.WAITING;
}
boolean cleanupTaskAppDirectorySuccess = cleanupTaskAppDirectory();
log.info("Cleaned up task app directory ({})", cleanupTaskAppDirectorySuccess);
if (logTearDownSuccess && cleanupTaskAppDirectorySuccess) {
return finishTaskCleanup(dockerCleanSuccess);
} else {
return TaskCleanupResult.ERROR;
}
}
Aggregations