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 @@ -179,6 +179,9 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
@CheckForNull
String getPidMode();

@CheckForNull
String getCgroupParent();

@CheckForNull
Boolean isTty();

Expand Down Expand Up @@ -402,6 +405,8 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons

CreateContainerCmd withWorkingDir(String workingDir);

CreateContainerCmd withCgroupParent(String cgroupParent);

/**
* Set the PID (Process) Namespace mode for the container, 'host': use the host's PID namespace inside the container
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -408,9 +410,8 @@ public String getPidMode() {
}

@Override
public String toString() {
return new ToStringBuilder(this).append("create container ").append(name != null ? "name=" + name + " " : "")
.append(this).toString();
public String getCgroupParent() {
return hostConfig.getCgroupParent();
}

@Override
Expand Down Expand Up @@ -871,11 +872,32 @@ public CreateContainerCmd withWorkingDir(String workingDir) {
return this;
}

@Override
public CreateContainerCmd withCgroupParent(final String cgroupParent) {
checkNotNull(cgroupParent, "cgroupParent was not specified");
this.hostConfig.withCgroupParent(cgroupParent);
return this;
}

@Override
public CreateContainerCmd withPidMode(String pidMode) {
checkNotNull(pidMode, "pidMode was not specified");
this.hostConfig.withPidMode(pidMode);
return this;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}

@Override
public boolean equals(Object o) {
return EqualsBuilder.reflectionEquals(this, o);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void afterMethod(ITestResult result) {
super.afterMethod(result);
}

@Test
@Test(expectedExceptions = ConflictException.class)
public void createContainerWithExistingName() throws DockerException {

String containerName = "generated_" + new SecureRandom().nextInt();
Expand All @@ -81,11 +81,7 @@ public void createContainerWithExistingName() throws DockerException {

assertThat(container.getId(), not(isEmptyString()));

try {
dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("env").withName(containerName).exec();
fail("expected ConflictException");
} catch (ConflictException e) {
}
dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("env").withName(containerName).exec();
}

@Test
Expand Down Expand Up @@ -617,4 +613,18 @@ public void onNext(Frame item) {
super.onNext(item);
}
}

@Test(groups = "ignoreInCircleCi")
public void createContainerWithCgroupParent() throws DockerException {
CreateContainerResponse container = dockerClient.createContainerCmd("busybox")
.withCgroupParent("/parent").exec();

LOG.info("Created container {}", container.toString());

assertThat(container.getId(), not(isEmptyString()));

InspectContainerResponse inspectContainer = dockerClient.inspectContainerCmd(container.getId()).exec();

assertThat(inspectContainer.getHostConfig().getCgroupParent(), is("/parent"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,9 @@ public void inspectContainer() throws DockerException {

}

@Test
@Test(expectedExceptions = NotFoundException.class)
public void inspectNonExistingContainer() throws DockerException {

try {
dockerClient.inspectContainerCmd("non-existing").exec();
fail("expected NotFoundException");
} catch (NotFoundException e) {
}
dockerClient.inspectContainerCmd("non-existing").exec();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void afterMethod(ITestResult result) {
super.afterMethod(result);
}

@Test
@Test(expectedExceptions = ConflictException.class)
public void createContainerWithExistingName() throws DockerException {

String containerName = "generated_" + new SecureRandom().nextInt();
Expand All @@ -79,11 +79,7 @@ public void createContainerWithExistingName() throws DockerException {

assertThat(container.getId(), not(isEmptyString()));

try {
dockerClient.createContainerCmd("busybox").withCmd("env").withName(containerName).exec();
fail("expected ConflictException");
} catch (ConflictException e) {
}
dockerClient.createContainerCmd("busybox").withCmd("env").withName(containerName).exec();
}

@Test
Expand Down Expand Up @@ -554,4 +550,18 @@ public void createContainerWithLogConfig() throws DockerException {
// null becomes empty string
assertEquals(inspectContainerResponse.getHostConfig().getLogConfig().type, logConfig.type);
}

@Test(groups = "ignoreInCircleCi")
public void createContainerWithCgroupParent() throws DockerException {
CreateContainerResponse container = dockerClient.createContainerCmd("busybox")
.withCgroupParent("/parent").exec();

LOG.info("Created container {}", container.toString());

assertThat(container.getId(), not(isEmptyString()));

InspectContainerResponse inspectContainer = dockerClient.inspectContainerCmd(container.getId()).exec();

assertThat(inspectContainer.getHostConfig().getCgroupParent(), is("/parent"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,9 @@ public void inspectContainer() throws DockerException {

}

@Test
@Test(expectedExceptions = NotFoundException.class)
public void inspectNonExistingContainer() throws DockerException {

try {
dockerClient.inspectContainerCmd("non-existing").exec();
fail("expected NotFoundException");
} catch (NotFoundException e) {
}
dockerClient.inspectContainerCmd("non-existing").exec();
}

@Test
Expand Down