Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@
import java.io.InputStream;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.ExecStartCmd;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.Frame;

@JsonInclude(Include.NON_NULL)
public class ExecStartCmdImpl extends AbstrAsyncDockerCmd<ExecStartCmd, Frame> implements ExecStartCmd {

@JsonIgnore
private String execId;

private Boolean detach, tty;
@JsonProperty("Detach")
private Boolean detach;

@JsonProperty("Tty")
private Boolean tty;

@JsonIgnore
private InputStream stdin;

public ExecStartCmdImpl(ExecStartCmd.Exec exec, String execId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void onNext(Frame frame) {
try {
switch (frame.getStreamType()) {
case STDOUT:
case RAW:
if (stdout != null) {
stdout.write(frame.getPayload());
stdout.flush();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dockerjava.jaxrs;

import static javax.ws.rs.client.Entity.entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;

Expand Down Expand Up @@ -30,6 +31,6 @@ protected AbstractCallbackNotifier<Frame> callbackNotifier(ExecStartCmd command,
LOGGER.trace("POST: {}", webTarget);

return new POSTCallbackNotifier<Frame>(new FrameStreamProcessor(), resultCallback, webTarget.request().accept(
MediaType.APPLICATION_JSON), null);
MediaType.APPLICATION_JSON), entity(command, MediaType.APPLICATION_JSON));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.dockerjava.netty.handler;

import java.util.Arrays;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
Expand Down Expand Up @@ -74,14 +76,14 @@ private Frame decode() {

headerCnt += headerCount;

if (headerCnt < HEADER_SIZE) {
return null;
}

streamType = streamType(header[0]);

if (streamType.equals(StreamType.RAW)) {
return new Frame(streamType, header);
return new Frame(streamType, Arrays.copyOf(header, headerCount));
}

if (headerCnt < HEADER_SIZE) {
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void execStart() throws Exception {
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withCmd("touch", "/execStartTest.log").exec();
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(
new ExecStartResultCallback(System.out, System.err));
new ExecStartResultCallback(System.out, System.err)).awaitCompletion();

InputStream response = dockerClient.copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
Boolean bytesAvailable = response.available() > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void afterMethod(ITestResult result) {
}

@Test(groups = "ignoreInCircleCi")
public void inspectExec() throws IOException {
public void inspectExec() throws Exception {
String containerName = "generated_" + new SecureRandom().nextInt();

CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
Expand All @@ -56,34 +56,34 @@ public void inspectExec() throws IOException {

dockerClient.startContainerCmd(container.getId()).exec();

ExecCreateCmdResponse touchFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").exec();
LOG.info("Created exec {}", touchFileCmdCreateResponse.toString());
assertThat(touchFileCmdCreateResponse.getId(), not(isEmptyString()));
ExecCreateCmdResponse checkFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
LOG.info("Created exec {}", checkFileCmdCreateResponse.toString());
assertThat(checkFileCmdCreateResponse.getId(), not(isEmptyString()));

// Check that file does not exist
dockerClient.execStartCmd(container.getId())
.withExecId(checkFileCmdCreateResponse.getId()).exec(new ExecStartResultCallback(System.out, System.err));

InspectExecResponse first = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
assertThat(first.getExitCode(), is(0));
ExecCreateCmdResponse checkFileExec1 = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
LOG.info("Created exec {}", checkFileExec1.toString());
assertThat(checkFileExec1.getId(), not(isEmptyString()));
dockerClient.execStartCmd(checkFileExec1.getId()).exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();
InspectExecResponse first = dockerClient.inspectExecCmd(checkFileExec1.getId()).exec();
assertThat(first.getExitCode(), is(1));

// Create the file
ExecCreateCmdResponse touchFileExec = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").exec();
LOG.info("Created exec {}", touchFileExec.toString());
assertThat(touchFileExec.getId(), not(isEmptyString()));
dockerClient.execStartCmd(container.getId())
.withExecId(touchFileCmdCreateResponse.getId()).exec(new ExecStartResultCallback(System.out, System.err));

InspectExecResponse second = dockerClient.inspectExecCmd(touchFileCmdCreateResponse.getId()).exec();
.withExecId(touchFileExec.getId()).exec(new ExecStartResultCallback(System.out, System.err));
InspectExecResponse second = dockerClient.inspectExecCmd(touchFileExec.getId()).exec();
assertThat(second.getExitCode(), is(0));


// Check that file does exist now
ExecCreateCmdResponse checkFileExec2 = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
LOG.info("Created exec {}", checkFileExec2.toString());
assertThat(checkFileExec2.getId(), not(isEmptyString()));
dockerClient.execStartCmd(container.getId())
.withExecId(checkFileCmdCreateResponse.getId()).exec(new ExecStartResultCallback(System.out, System.err));

InspectExecResponse third = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
.withExecId(checkFileExec2.getId()).exec(new ExecStartResultCallback(System.out, System.err));
InspectExecResponse third = dockerClient.inspectExecCmd(checkFileExec2.getId()).exec();
assertThat(third.getExitCode(), is(0));

// Get container info and check its roundtrip to ensure the consistency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public void execStart() throws Exception {
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(
new ExecStartResultCallback(System.out, System.err));

InputStream response = dockerClient.copyFileFromContainerCmd(container.getId(), "/execStartTest.log").exec();
LOG.info("Wait for 5 seconds");
Thread.sleep(5000);

InputStream response = dockerClient.copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();

Boolean bytesAvailable = response.available() > 0;
assertTrue(bytesAvailable, "The file was not copied from the container.");
Expand All @@ -88,7 +91,7 @@ public void execStartAttached() throws Exception {
dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true)
.exec(new ExecStartResultCallback(System.out, System.err));

InputStream response = dockerClient.copyFileFromContainerCmd(container.getId(), "/execStartTest.log").exec();
InputStream response = dockerClient.copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
Boolean bytesAvailable = response.available() > 0;
assertTrue(bytesAvailable, "The file was not copied from the container.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,44 @@ public void afterMethod(ITestResult result) {
}

@Test(groups = "ignoreInCircleCi")
public void inspectExecTest() throws IOException {
public void inspectExec() throws Exception {
String containerName = "generated_" + new SecureRandom().nextInt();

CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("top")
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999")
.withName(containerName).exec();
LOG.info("Created container {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));

dockerClient.startContainerCmd(container.getId()).exec();

ExecCreateCmdResponse touchFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").withTty(true).exec();
LOG.info("Created exec {}", touchFileCmdCreateResponse.toString());
assertThat(touchFileCmdCreateResponse.getId(), not(isEmptyString()));
ExecCreateCmdResponse checkFileCmdCreateResponse = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
LOG.info("Created exec {}", checkFileCmdCreateResponse.toString());
assertThat(checkFileCmdCreateResponse.getId(), not(isEmptyString()));

// Check that file does not exist
dockerClient.execStartCmd(container.getId()).withDetach(false).withTty(true)
.withExecId(checkFileCmdCreateResponse.getId())
.exec(new ExecStartResultCallback(System.out, System.err));

InspectExecResponse first = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
assertEquals(first.isRunning(), new Boolean(false));
ExecCreateCmdResponse checkFileExec1 = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(false).withAttachStderr(false).withCmd("test", "-e", "/marker").exec();
LOG.info("Created exec {}", checkFileExec1.toString());
assertThat(checkFileExec1.getId(), not(isEmptyString()));
dockerClient.execStartCmd(checkFileExec1.getId()).exec(new ExecStartResultCallback(System.out, System.err));
InspectExecResponse first = dockerClient.inspectExecCmd(checkFileExec1.getId()).exec();
assertThat(first.getExitCode(), is(1));

// Create the file
dockerClient.execStartCmd(container.getId()).withDetach(false).withTty(true)
.withExecId(touchFileCmdCreateResponse.getId())
.exec(new ExecStartResultCallback(System.out, System.err));

InspectExecResponse second = dockerClient.inspectExecCmd(touchFileCmdCreateResponse.getId()).exec();
assertEquals(first.isRunning(), new Boolean(false));
ExecCreateCmdResponse touchFileExec = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("touch", "/marker").exec();
LOG.info("Created exec {}", touchFileExec.toString());
assertThat(touchFileExec.getId(), not(isEmptyString()));
dockerClient.execStartCmd(container.getId())
.withExecId(touchFileExec.getId()).exec(new ExecStartResultCallback(System.out, System.err));
InspectExecResponse second = dockerClient.inspectExecCmd(touchFileExec.getId()).exec();
assertThat(second.getExitCode(), is(0));

// Check that file does exist now
dockerClient.execStartCmd(container.getId()).withExecId(checkFileCmdCreateResponse.getId())
.exec(new ExecStartResultCallback(System.out, System.err));

InspectExecResponse third = dockerClient.inspectExecCmd(checkFileCmdCreateResponse.getId()).exec();
// Check that file does exist now
ExecCreateCmdResponse checkFileExec2 = dockerClient.execCreateCmd(container.getId())
.withAttachStdout(true).withAttachStderr(true).withCmd("test", "-e", "/marker").exec();
LOG.info("Created exec {}", checkFileExec2.toString());
assertThat(checkFileExec2.getId(), not(isEmptyString()));
dockerClient.execStartCmd(container.getId())
.withExecId(checkFileExec2.getId()).exec(new ExecStartResultCallback(System.out, System.err));
InspectExecResponse third = dockerClient.inspectExecCmd(checkFileExec2.getId()).exec();
assertThat(third.getExitCode(), is(0));

// Get container info and check its roundtrip to ensure the consistency
Expand Down