Search in sources :

Example 1 with NotModifiedException

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.");
    }
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) DockerClientException(com.github.dockerjava.api.exception.DockerClientException) WaitContainerResultCallback(com.github.dockerjava.core.command.WaitContainerResultCallback) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotModifiedException(com.github.dockerjava.api.exception.NotModifiedException) DockerClientException(com.github.dockerjava.api.exception.DockerClientException) InternalServerErrorException(com.github.dockerjava.api.exception.InternalServerErrorException) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NotModifiedException(com.github.dockerjava.api.exception.NotModifiedException)

Aggregations

DockerClient (com.github.dockerjava.api.DockerClient)1 DockerClientException (com.github.dockerjava.api.exception.DockerClientException)1 InternalServerErrorException (com.github.dockerjava.api.exception.InternalServerErrorException)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 NotModifiedException (com.github.dockerjava.api.exception.NotModifiedException)1 WaitContainerResultCallback (com.github.dockerjava.core.command.WaitContainerResultCallback)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1