Search in sources :

Example 1 with LogContainerCmd

use of com.github.dockerjava.api.command.LogContainerCmd in project camel by apache.

the class AsyncDockerProducer method executeLogContainerRequest.

/**
     * Produce a log container request
     *
     * @param client
     * @param message
     * @return
     */
private LogContainerCmd executeLogContainerRequest(DockerClient client, Message message) {
    LOGGER.debug("Executing Docker Log Container Request");
    String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
    ObjectHelper.notNull(containerId, "Container ID must be specified");
    LogContainerCmd logContainerCmd = client.logContainerCmd(containerId);
    Boolean followStream = DockerHelper.getProperty(DockerConstants.DOCKER_FOLLOW_STREAM, configuration, message, Boolean.class);
    if (followStream != null) {
        logContainerCmd.withFollowStream(followStream);
    }
    Boolean stdErr = DockerHelper.getProperty(DockerConstants.DOCKER_STD_ERR, configuration, message, Boolean.class);
    if (stdErr != null) {
        logContainerCmd.withStdErr(stdErr);
    }
    Boolean stdOut = DockerHelper.getProperty(DockerConstants.DOCKER_STD_OUT, configuration, message, Boolean.class);
    if (stdOut != null) {
        logContainerCmd.withStdOut(stdOut);
    }
    Integer tail = DockerHelper.getProperty(DockerConstants.DOCKER_TAIL, configuration, message, Integer.class);
    if (tail != null) {
        logContainerCmd.withTail(tail);
    }
    Boolean tailAll = DockerHelper.getProperty(DockerConstants.DOCKER_TAIL_ALL, configuration, message, Boolean.class);
    if (tailAll != null && tailAll) {
        logContainerCmd.withTailAll();
    }
    Boolean timestamps = DockerHelper.getProperty(DockerConstants.DOCKER_TIMESTAMPS, configuration, message, Boolean.class);
    if (timestamps != null) {
        logContainerCmd.withTimestamps(timestamps);
    }
    return logContainerCmd;
}
Also used : LogContainerCmd(com.github.dockerjava.api.command.LogContainerCmd)

Example 2 with LogContainerCmd

use of com.github.dockerjava.api.command.LogContainerCmd in project testcontainers-java by testcontainers.

the class LogUtils method followOutput.

/**
 * {@inheritDoc}
 */
public void followOutput(DockerClient dockerClient, String containerId, Consumer<OutputFrame> consumer, OutputFrame.OutputType... types) {
    final LogContainerCmd cmd = dockerClient.logContainerCmd(containerId).withFollowStream(true).withSince(0);
    final FrameConsumerResultCallback callback = new FrameConsumerResultCallback();
    for (OutputFrame.OutputType type : types) {
        callback.addConsumer(type, consumer);
        if (type == STDOUT)
            cmd.withStdOut(true);
        if (type == STDERR)
            cmd.withStdErr(true);
    }
    cmd.exec(callback);
}
Also used : FrameConsumerResultCallback(org.testcontainers.containers.output.FrameConsumerResultCallback) OutputFrame(org.testcontainers.containers.output.OutputFrame) LogContainerCmd(com.github.dockerjava.api.command.LogContainerCmd)

Aggregations

LogContainerCmd (com.github.dockerjava.api.command.LogContainerCmd)2 FrameConsumerResultCallback (org.testcontainers.containers.output.FrameConsumerResultCallback)1 OutputFrame (org.testcontainers.containers.output.OutputFrame)1