Search in sources :

Example 1 with Volumes

use of com.github.dockerjava.api.model.Volumes in project camel by apache.

the class DockerProducer method executeCommitContainerRequest.

/*********************
     * Container Requests
     ********************/
/**
     * Produces a commit container request
     *
     * @param client
     * @param message
     * @return
     * @throws DockerException
     */
private CommitCmd executeCommitContainerRequest(DockerClient client, Message message) throws DockerException {
    LOGGER.debug("Executing Docker Commit Container Request");
    String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
    ObjectHelper.notNull(containerId, "Container ID must be specified");
    CommitCmd commitCmd = client.commitCmd(containerId);
    String author = DockerHelper.getProperty(DockerConstants.DOCKER_AUTHOR, configuration, message, String.class);
    if (author != null) {
        commitCmd.withAuthor(author);
    }
    Boolean attachStdErr = DockerHelper.getProperty(DockerConstants.DOCKER_ATTACH_STD_ERR, configuration, message, Boolean.class);
    if (attachStdErr != null) {
        commitCmd.withAttachStderr(attachStdErr);
    }
    Boolean attachStdIn = DockerHelper.getProperty(DockerConstants.DOCKER_ATTACH_STD_IN, configuration, message, Boolean.class);
    if (attachStdIn != null) {
        commitCmd.withAttachStdin(attachStdIn);
    }
    Boolean attachStdOut = DockerHelper.getProperty(DockerConstants.DOCKER_ATTACH_STD_OUT, configuration, message, Boolean.class);
    if (attachStdOut != null) {
        commitCmd.withAttachStdout(attachStdOut);
    }
    String[] cmds = DockerHelper.parseDelimitedStringHeader(DockerConstants.DOCKER_CMD, message);
    if (cmds != null) {
        commitCmd.withCmd(cmds);
    }
    Boolean disableNetwork = DockerHelper.getProperty(DockerConstants.DOCKER_DISABLE_NETWORK, configuration, message, Boolean.class);
    if (disableNetwork != null) {
        commitCmd.withDisableNetwork(disableNetwork);
    }
    String[] envs = DockerHelper.parseDelimitedStringHeader(DockerConstants.DOCKER_ENV, message);
    if (envs != null) {
        commitCmd.withEnv(envs);
    }
    ExposedPorts exposedPorts = DockerHelper.getProperty(DockerConstants.DOCKER_EXPOSED_PORTS, configuration, message, ExposedPorts.class);
    if (exposedPorts != null) {
        commitCmd.withExposedPorts(exposedPorts);
    }
    String hostname = DockerHelper.getProperty(DockerConstants.DOCKER_HOSTNAME, configuration, message, String.class);
    if (hostname != null) {
        commitCmd.withHostname(hostname);
    }
    Integer memory = DockerHelper.getProperty(DockerConstants.DOCKER_MEMORY, configuration, message, Integer.class);
    if (memory != null) {
        commitCmd.withMemory(memory);
    }
    Integer memorySwap = DockerHelper.getProperty(DockerConstants.DOCKER_MEMORY_SWAP, configuration, message, Integer.class);
    if (memorySwap != null) {
        commitCmd.withMemorySwap(memorySwap);
    }
    String msg = DockerHelper.getProperty(DockerConstants.DOCKER_MESSAGE, configuration, message, String.class);
    if (msg != null) {
        commitCmd.withMessage(msg);
    }
    Boolean openStdIn = DockerHelper.getProperty(DockerConstants.DOCKER_OPEN_STD_IN, configuration, message, Boolean.class);
    if (openStdIn != null) {
        commitCmd.withOpenStdin(openStdIn);
    }
    Boolean pause = DockerHelper.getProperty(DockerConstants.DOCKER_PAUSE, configuration, message, Boolean.class);
    if (pause != null) {
        commitCmd.withPause(pause);
    }
    String[] portSpecs = DockerHelper.parseDelimitedStringHeader(DockerConstants.DOCKER_PORT_SPECS, message);
    if (portSpecs != null) {
        commitCmd.withPortSpecs(portSpecs);
    }
    String repository = DockerHelper.getProperty(DockerConstants.DOCKER_REPOSITORY, configuration, message, String.class);
    if (repository != null) {
        commitCmd.withRepository(repository);
    }
    Boolean stdInOnce = DockerHelper.getProperty(DockerConstants.DOCKER_STD_IN_ONCE, configuration, message, Boolean.class);
    if (stdInOnce != null) {
        commitCmd.withStdinOnce(stdInOnce);
    }
    String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
    if (tag != null) {
        commitCmd.withTag(tag);
    }
    Boolean tty = DockerHelper.getProperty(DockerConstants.DOCKER_TTY, configuration, message, Boolean.class);
    if (tty != null) {
        commitCmd.withTty(tty);
    }
    String user = DockerHelper.getProperty(DockerConstants.DOCKER_USER, configuration, message, String.class);
    if (user != null) {
        commitCmd.withUser(user);
    }
    Volumes volumes = DockerHelper.getProperty(DockerConstants.DOCKER_VOLUMES, configuration, message, Volumes.class);
    if (volumes != null) {
        commitCmd.withVolumes(volumes);
    }
    String workingDir = DockerHelper.getProperty(DockerConstants.DOCKER_WORKING_DIR, configuration, message, String.class);
    if (workingDir != null) {
        commitCmd.withWorkingDir(workingDir);
    }
    return commitCmd;
}
Also used : CommitCmd(com.github.dockerjava.api.command.CommitCmd) Volumes(com.github.dockerjava.api.model.Volumes) ExposedPorts(com.github.dockerjava.api.model.ExposedPorts)

Example 2 with Volumes

use of com.github.dockerjava.api.model.Volumes in project camel by apache.

the class CommitContainerCmdHeaderTest method commitContainerHeaderTest.

@Test
public void commitContainerHeaderTest() {
    String containerId = "9c09acd48a25";
    String env = "FOO=bar";
    boolean attachStdErr = true;
    boolean attachStdOut = true;
    boolean attachStdIn = false;
    boolean disableNetwork = false;
    boolean openStdIn = false;
    String portSpecs = "80";
    boolean stdInOnce = false;
    String tag = "1.0";
    String repository = "docker/empty";
    String cmd = "whoami";
    String author = "cameluser";
    String message = "Camel Docker Container Commit";
    boolean pause = false;
    ExposedPorts exposedPorts = new ExposedPorts(ExposedPort.tcp(22));
    Integer memory = 2048;
    Integer swapMemory = 512;
    String workingDir = "/opt";
    String user = "docker";
    Volumes volumes = new Volumes(new Volume("/example"));
    boolean tty = true;
    String hostname = "dockerhostname";
    Map<String, Object> headers = getDefaultParameters();
    headers.put(DockerConstants.DOCKER_CONTAINER_ID, containerId);
    headers.put(DockerConstants.DOCKER_ENV, env);
    headers.put(DockerConstants.DOCKER_ATTACH_STD_IN, attachStdIn);
    headers.put(DockerConstants.DOCKER_ATTACH_STD_ERR, attachStdErr);
    headers.put(DockerConstants.DOCKER_ATTACH_STD_OUT, attachStdOut);
    headers.put(DockerConstants.DOCKER_DISABLE_NETWORK, disableNetwork);
    headers.put(DockerConstants.DOCKER_TAG, tag);
    headers.put(DockerConstants.DOCKER_REPOSITORY, repository);
    headers.put(DockerConstants.DOCKER_CMD, cmd);
    headers.put(DockerConstants.DOCKER_AUTHOR, author);
    headers.put(DockerConstants.DOCKER_MESSAGE, message);
    headers.put(DockerConstants.DOCKER_PAUSE, pause);
    headers.put(DockerConstants.DOCKER_EXPOSED_PORTS, exposedPorts);
    headers.put(DockerConstants.DOCKER_MEMORY, memory);
    headers.put(DockerConstants.DOCKER_MEMORY_SWAP, swapMemory);
    headers.put(DockerConstants.DOCKER_WORKING_DIR, workingDir);
    headers.put(DockerConstants.DOCKER_USER, user);
    headers.put(DockerConstants.DOCKER_VOLUMES, volumes);
    headers.put(DockerConstants.DOCKER_TTY, tty);
    headers.put(DockerConstants.DOCKER_HOSTNAME, hostname);
    headers.put(DockerConstants.DOCKER_OPEN_STD_IN, openStdIn);
    headers.put(DockerConstants.DOCKER_STD_IN_ONCE, stdInOnce);
    headers.put(DockerConstants.DOCKER_PORT_SPECS, portSpecs);
    template.sendBodyAndHeaders("direct:in", "", headers);
    Mockito.verify(dockerClient, Mockito.times(1)).commitCmd(containerId);
    Mockito.verify(mockObject, Mockito.times(1)).withEnv(env);
    Mockito.verify(mockObject, Mockito.times(1)).withAttachStderr(attachStdErr);
    Mockito.verify(mockObject, Mockito.times(1)).withAttachStdin(attachStdIn);
    Mockito.verify(mockObject, Mockito.times(1)).withAttachStdout(attachStdOut);
    Mockito.verify(mockObject, Mockito.times(1)).withDisableNetwork(disableNetwork);
    Mockito.verify(mockObject, Mockito.times(1)).withTag(tag);
    Mockito.verify(mockObject, Mockito.times(1)).withRepository(repository);
    Mockito.verify(mockObject, Mockito.times(1)).withCmd(cmd);
    Mockito.verify(mockObject, Mockito.times(1)).withAuthor(author);
    Mockito.verify(mockObject, Mockito.times(1)).withMessage(message);
    Mockito.verify(mockObject, Mockito.times(1)).withPause(pause);
    Mockito.verify(mockObject, Mockito.times(1)).withExposedPorts(exposedPorts);
    Mockito.verify(mockObject, Mockito.times(1)).withMemory(memory);
    Mockito.verify(mockObject, Mockito.times(1)).withMemorySwap(swapMemory);
    Mockito.verify(mockObject, Mockito.times(1)).withWorkingDir(workingDir);
    Mockito.verify(mockObject, Mockito.times(1)).withUser(user);
    Mockito.verify(mockObject, Mockito.times(1)).withVolumes(volumes);
    Mockito.verify(mockObject, Mockito.times(1)).withTty(tty);
    Mockito.verify(mockObject, Mockito.times(1)).withHostname(hostname);
    Mockito.verify(mockObject, Mockito.times(1)).withOpenStdin(openStdIn);
    Mockito.verify(mockObject, Mockito.times(1)).withStdinOnce(stdInOnce);
    Mockito.verify(mockObject, Mockito.times(1)).withPortSpecs(portSpecs);
}
Also used : Volumes(com.github.dockerjava.api.model.Volumes) Volume(com.github.dockerjava.api.model.Volume) ExposedPorts(com.github.dockerjava.api.model.ExposedPorts) Test(org.junit.Test)

Aggregations

ExposedPorts (com.github.dockerjava.api.model.ExposedPorts)2 Volumes (com.github.dockerjava.api.model.Volumes)2 CommitCmd (com.github.dockerjava.api.command.CommitCmd)1 Volume (com.github.dockerjava.api.model.Volume)1 Test (org.junit.Test)1