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 @@ -12,6 +12,10 @@ public interface InspectContainerCmd extends SyncDockerCmd<InspectContainerRespo

InspectContainerCmd withContainerId(@Nonnull String containerId);

InspectContainerCmd withSize(Boolean showSize);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or then primitive here


boolean getSize();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be object?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed while merge.


/**
* @throws NotFoundException
* No such container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class InspectContainerResponse {
@JsonProperty("Id")
private String id;

@JsonProperty("SizeRootFs")
private Integer sizeRootFs;

@JsonProperty("Image")
private String imageId;

Expand Down Expand Up @@ -102,6 +105,10 @@ public String getId() {
return id;
}

public Integer getSizeRootFs() {
return sizeRootFs;
}

public String getCreated() {
return created;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class InspectContainerCmdImpl extends AbstrDockerCmd<InspectContainerCmd,
InspectContainerCmd {

private String containerId;
private boolean size;

public InspectContainerCmdImpl(InspectContainerCmd.Exec exec, String containerId) {
super(exec);
Expand All @@ -31,6 +32,17 @@ public InspectContainerCmd withContainerId(String containerId) {
return this;
}

@Override
public InspectContainerCmd withSize(Boolean showSize) {
this.size = showSize;
return this;
}

@Override
public boolean getSize() {
return size;
}

/**
* @throws NotFoundException
* No such container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public InspectContainerCmdExec(WebTarget baseResource, DockerClientConfig docker

@Override
protected InspectContainerResponse execute(InspectContainerCmd command) {
WebTarget webResource = getBaseResource().path("/containers/{id}/json").resolveTemplate("id",
command.getContainerId());
WebTarget webResource = getBaseResource().path("/containers/{id}/json")
.queryParam("size", command.getSize())
.resolveTemplate("id", command.getContainerId());

LOGGER.debug("GET: {}", webResource);
return webResource.request().accept(MediaType.APPLICATION_JSON).get(InspectContainerResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.lang.reflect.Method;
import java.security.SecureRandom;

import com.github.dockerjava.api.command.InspectContainerCmd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.ITestResult;
Expand Down Expand Up @@ -63,6 +64,24 @@ public void inspectContainer() throws DockerException {

}

@Test()
public void inspectContainerWithSize() throws DockerException {

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

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

InspectContainerCmd command = dockerClient.inspectContainerCmd(container.getId()).withSize(true);
assertTrue(command.getSize());
InspectContainerResponse containerInfo = command.exec();
assertEquals(containerInfo.getId(), container.getId());
assertNotNull(containerInfo.getSizeRootFs());
assertTrue(containerInfo.getSizeRootFs().intValue() > 0 );
}

@Test(expectedExceptions = NotFoundException.class)
public void inspectNonExistingContainer() throws DockerException {
dockerClient.inspectContainerCmd("non-existing").exec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.lang.reflect.Method;
import java.security.SecureRandom;

import com.github.dockerjava.api.command.InspectContainerCmd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.ITestResult;
Expand Down Expand Up @@ -63,6 +64,25 @@ public void inspectContainer() throws DockerException {

}

@Test()
public void inspectContainerWithSize() throws DockerException {

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

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

InspectContainerCmd command = dockerClient.inspectContainerCmd(container.getId())
.withSize(true);
assertTrue(command.getSize());
InspectContainerResponse containerInfo = command.exec();
assertEquals(containerInfo.getId(), container.getId());
assertNotNull(containerInfo.getSizeRootFs());
assertTrue(containerInfo.getSizeRootFs().intValue() > 0 );
}

@Test(expectedExceptions = NotFoundException.class)
public void inspectNonExistingContainer() throws DockerException {
dockerClient.inspectContainerCmd("non-existing").exec();
Expand Down