Search in sources :

Example 66 with ContainerInfo

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()));
    }
}
Also used : ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Example 67 with ContainerInfo

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());
    }
}
Also used : ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) ProcessFailedException(com.hubspot.singularity.runner.base.shared.ProcessFailedException) SingularityClientException(com.hubspot.singularity.client.SingularityClientException) IOException(java.io.IOException)

Example 68 with ContainerInfo

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;
    }
}
Also used : Path(java.nio.file.Path) DockerException(com.spotify.docker.client.exceptions.DockerException) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerException(com.spotify.docker.client.exceptions.DockerException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) IOException(java.io.IOException)

Aggregations

ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)68 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)45 Test (org.junit.Test)41 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)35 Matchers.containsString (org.hamcrest.Matchers.containsString)33 Long.toHexString (java.lang.Long.toHexString)31 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)31 DockerException (com.spotify.docker.client.exceptions.DockerException)15 HostConfig (com.spotify.docker.client.messages.HostConfig)15 IOException (java.io.IOException)9 DockerClient (com.spotify.docker.client.DockerClient)8 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)7 DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)5 Container (com.spotify.docker.client.messages.Container)5 ImageInfo (com.spotify.docker.client.messages.ImageInfo)5 LogStream (com.spotify.docker.client.LogStream)4 ImageNotFoundException (com.spotify.docker.client.exceptions.ImageNotFoundException)4 AttachedNetwork (com.spotify.docker.client.messages.AttachedNetwork)4 Path (java.nio.file.Path)4 ContainerMount (com.spotify.docker.client.messages.ContainerMount)3