Merge pull request #510 from KostyaSha/pr495 · docker-java/docker-java@67ef8ec

File tree

6 files changed

lines changed

    • main/java/com/github/dockerjava

    • test/java/com/github/dockerjava

6 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -179,6 +179,9 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons

179179

@CheckForNull

180180

String getPidMode();

181181
182+

@CheckForNull

183+

String getCgroupParent();

184+
182185

@CheckForNull

183186

Boolean isTty();

184187

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

402405
403406

CreateContainerCmd withWorkingDir(String workingDir);

404407
408+

CreateContainerCmd withCgroupParent(String cgroupParent);

409+
405410

/**

406411

* Set the PID (Process) Namespace mode for the container, 'host': use the host's PID namespace inside the container

407412

*/

Original file line numberDiff line numberDiff line change

@@ -5,6 +5,8 @@

55

import java.util.List;

66

import java.util.Map;

77
8+

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

9+

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

810

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

911
1012

import com.fasterxml.jackson.annotation.JsonIgnore;

@@ -408,9 +410,8 @@ public String getPidMode() {

408410

}

409411
410412

@Override

411-

public String toString() {

412-

return new ToStringBuilder(this).append("create container ").append(name != null ? "name=" + name + " " : "")

413-

.append(this).toString();

413+

public String getCgroupParent() {

414+

return hostConfig.getCgroupParent();

414415

}

415416
416417

@Override

@@ -871,11 +872,32 @@ public CreateContainerCmd withWorkingDir(String workingDir) {

871872

return this;

872873

}

873874
875+

@Override

876+

public CreateContainerCmd withCgroupParent(final String cgroupParent) {

877+

checkNotNull(cgroupParent, "cgroupParent was not specified");

878+

this.hostConfig.withCgroupParent(cgroupParent);

879+

return this;

880+

}

881+
874882

@Override

875883

public CreateContainerCmd withPidMode(String pidMode) {

876884

checkNotNull(pidMode, "pidMode was not specified");

877885

this.hostConfig.withPidMode(pidMode);

878886

return this;

879887

}

880888
889+

@Override

890+

public String toString() {

891+

return ToStringBuilder.reflectionToString(this);

892+

}

893+
894+

@Override

895+

public boolean equals(Object o) {

896+

return EqualsBuilder.reflectionEquals(this, o);

897+

}

898+
899+

@Override

900+

public int hashCode() {

901+

return HashCodeBuilder.reflectionHashCode(this);

902+

}

881903

}

Original file line numberDiff line numberDiff line change

@@ -69,7 +69,7 @@ public void afterMethod(ITestResult result) {

6969

super.afterMethod(result);

7070

}

7171
72-

@Test

72+

@Test(expectedExceptions = ConflictException.class)

7373

public void createContainerWithExistingName() throws DockerException {

7474
7575

String containerName = "generated_" + new SecureRandom().nextInt();

@@ -81,11 +81,7 @@ public void createContainerWithExistingName() throws DockerException {

8181
8282

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

8383
84-

try {

85-

dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("env").withName(containerName).exec();

86-

fail("expected ConflictException");

87-

} catch (ConflictException e) {

88-

}

84+

dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("env").withName(containerName).exec();

8985

}

9086
9187

@Test

@@ -617,4 +613,18 @@ public void onNext(Frame item) {

617613

super.onNext(item);

618614

}

619615

}

616+
617+

@Test(groups = "ignoreInCircleCi")

618+

public void createContainerWithCgroupParent() throws DockerException {

619+

CreateContainerResponse container = dockerClient.createContainerCmd("busybox")

620+

.withCgroupParent("/parent").exec();

621+
622+

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

623+
624+

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

625+
626+

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

627+
628+

assertThat(inspectContainer.getHostConfig().getCgroupParent(), is("/parent"));

629+

}

620630

}

Original file line numberDiff line numberDiff line change

@@ -63,14 +63,9 @@ public void inspectContainer() throws DockerException {

6363
6464

}

6565
66-

@Test

66+

@Test(expectedExceptions = NotFoundException.class)

6767

public void inspectNonExistingContainer() throws DockerException {

68-
69-

try {

70-

dockerClient.inspectContainerCmd("non-existing").exec();

71-

fail("expected NotFoundException");

72-

} catch (NotFoundException e) {

73-

}

68+

dockerClient.inspectContainerCmd("non-existing").exec();

7469

}

7570
7671

@Test

Original file line numberDiff line numberDiff line change

@@ -67,7 +67,7 @@ public void afterMethod(ITestResult result) {

6767

super.afterMethod(result);

6868

}

6969
70-

@Test

70+

@Test(expectedExceptions = ConflictException.class)

7171

public void createContainerWithExistingName() throws DockerException {

7272
7373

String containerName = "generated_" + new SecureRandom().nextInt();

@@ -79,11 +79,7 @@ public void createContainerWithExistingName() throws DockerException {

7979
8080

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

8181
82-

try {

83-

dockerClient.createContainerCmd("busybox").withCmd("env").withName(containerName).exec();

84-

fail("expected ConflictException");

85-

} catch (ConflictException e) {

86-

}

82+

dockerClient.createContainerCmd("busybox").withCmd("env").withName(containerName).exec();

8783

}

8884
8985

@Test

@@ -554,4 +550,18 @@ public void createContainerWithLogConfig() throws DockerException {

554550

// null becomes empty string

555551

assertEquals(inspectContainerResponse.getHostConfig().getLogConfig().type, logConfig.type);

556552

}

553+
554+

@Test(groups = "ignoreInCircleCi")

555+

public void createContainerWithCgroupParent() throws DockerException {

556+

CreateContainerResponse container = dockerClient.createContainerCmd("busybox")

557+

.withCgroupParent("/parent").exec();

558+
559+

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

560+
561+

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

562+
563+

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

564+
565+

assertThat(inspectContainer.getHostConfig().getCgroupParent(), is("/parent"));

566+

}

557567

}

Original file line numberDiff line numberDiff line change

@@ -63,14 +63,9 @@ public void inspectContainer() throws DockerException {

6363
6464

}

6565
66-

@Test

66+

@Test(expectedExceptions = NotFoundException.class)

6767

public void inspectNonExistingContainer() throws DockerException {

68-
69-

try {

70-

dockerClient.inspectContainerCmd("non-existing").exec();

71-

fail("expected NotFoundException");

72-

} catch (NotFoundException e) {

73-

}

68+

dockerClient.inspectContainerCmd("non-existing").exec();

7469

}

7570
7671

@Test