-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Introduce InspectContainerResponse.Mounts #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import java.util.Map; | ||
|
|
||
| import com.github.dockerjava.core.RemoteApiVersion; | ||
|
|
||
| import org.apache.commons.lang.builder.EqualsBuilder; | ||
| import org.apache.commons.lang.builder.HashCodeBuilder; | ||
| import org.apache.commons.lang.builder.ToStringBuilder; | ||
|
|
@@ -14,6 +15,7 @@ | |
| import com.github.dockerjava.api.model.ContainerConfig; | ||
| import com.github.dockerjava.api.model.HostConfig; | ||
| import com.github.dockerjava.api.model.Ports; | ||
| import com.github.dockerjava.api.model.Volume; | ||
| import com.github.dockerjava.api.model.VolumeBind; | ||
| import com.github.dockerjava.api.model.VolumeBinds; | ||
| import com.github.dockerjava.api.model.VolumeRW; | ||
|
|
@@ -89,6 +91,9 @@ public class InspectContainerResponse { | |
| @JsonProperty("VolumesRW") | ||
| private VolumesRW volumesRW; | ||
|
|
||
| @JsonProperty("Mounts") | ||
| private List<Mount> mounts; | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
@@ -134,7 +139,13 @@ public VolumeBind[] getVolumes() { | |
| return volumes == null ? null : volumes.getBinds(); | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated As of {@link RemoteApiVersion#VERSION_1_20} | ||
| * use {@link #getMounts()} instead | ||
| */ | ||
| @JsonIgnore | ||
| @Deprecated | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it be not available in JSON response or it just deprecated by docker and fill be removed in future?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| @CheckForNull | ||
| public VolumeRW[] getVolumesRW() { | ||
| return volumesRW == null ? null : volumesRW.getVolumesRW(); | ||
| } | ||
|
|
@@ -167,6 +178,14 @@ public String getMountLabel() { | |
| return mountLabel; | ||
| } | ||
|
|
||
| /** | ||
| * @since {@link RemoteApiVersion#VERSION_1_20} | ||
| */ | ||
| @CheckForNull | ||
| public List<Mount> getMounts() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CheckForNull? on < 1.20 expected to be null |
||
| return mounts; | ||
| } | ||
|
|
||
| public List<String> getExecIds() { | ||
| return execIds; | ||
| } | ||
|
|
@@ -413,4 +432,81 @@ public String toString() { | |
| } | ||
| } | ||
|
|
||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public static class Mount { | ||
|
|
||
| /** | ||
| * @since {@link RemoteApiVersion#VERSION_1_20} | ||
| */ | ||
| @CheckForNull | ||
| @JsonProperty("Name") | ||
| private String name; | ||
|
|
||
| /** | ||
| * @since {@link RemoteApiVersion#VERSION_1_20} | ||
| */ | ||
| @CheckForNull | ||
| @JsonProperty("Source") | ||
| private String source; | ||
|
|
||
| /** | ||
| * @since {@link RemoteApiVersion#VERSION_1_20} | ||
| */ | ||
| @CheckForNull | ||
| @JsonProperty("Destination") | ||
| private Volume destination; | ||
|
|
||
| /** | ||
| * @since {@link RemoteApiVersion#VERSION_1_20} | ||
| */ | ||
| @CheckForNull | ||
| @JsonProperty("Driver") | ||
| private String driver; | ||
|
|
||
| /** | ||
| * @since {@link RemoteApiVersion#VERSION_1_20} | ||
| */ | ||
| @CheckForNull | ||
| @JsonProperty("Mode") | ||
| private String mode; | ||
|
|
||
| /** | ||
| * @since {@link RemoteApiVersion#VERSION_1_20} | ||
| */ | ||
| @CheckForNull | ||
| @JsonProperty("RW") | ||
| private Boolean rw; | ||
|
|
||
| @CheckForNull | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @CheckForNull | ||
| public String getSource() { | ||
| return source; | ||
| } | ||
|
|
||
| @CheckForNull | ||
| public Volume getDestination() { | ||
| return destination; | ||
| } | ||
|
|
||
| @CheckForNull | ||
| public String getDriver() { | ||
| return driver; | ||
| } | ||
|
|
||
| @CheckForNull | ||
| public String getMode() { | ||
| return mode; | ||
| } | ||
|
|
||
| @CheckForNull | ||
| public Boolean getRW() { | ||
| return rw; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package com.github.dockerjava.client; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.contains; | ||
| import static org.hamcrest.Matchers.containsInAnyOrder; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
@@ -15,14 +15,17 @@ | |
|
|
||
| import org.apache.commons.io.IOUtils; | ||
| import org.apache.commons.io.LineIterator; | ||
| import org.hamcrest.FeatureMatcher; | ||
| import org.hamcrest.Matcher; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.testng.Assert; | ||
| import org.testng.ITestResult; | ||
|
|
||
| import com.github.dockerjava.api.DockerClient; | ||
| import com.github.dockerjava.api.exception.DockerException; | ||
| import com.github.dockerjava.api.command.InspectContainerResponse; | ||
| import com.github.dockerjava.api.command.InspectContainerResponse.Mount; | ||
| import com.github.dockerjava.api.exception.DockerException; | ||
| import com.github.dockerjava.api.model.Frame; | ||
| import com.github.dockerjava.api.model.Volume; | ||
| import com.github.dockerjava.api.model.VolumeBind; | ||
|
|
@@ -32,13 +35,12 @@ | |
| import com.github.dockerjava.core.command.BuildImageResultCallback; | ||
| import com.github.dockerjava.core.command.LogContainerResultCallback; | ||
| import com.github.dockerjava.core.command.PullImageResultCallback; | ||
| import com.google.common.base.Joiner; | ||
|
|
||
| public abstract class AbstractDockerClientTest extends Assert { | ||
|
|
||
| public static final Logger LOG = LoggerFactory.getLogger(AbstractDockerClientTest.class); | ||
|
|
||
| private String apiVersion = "1.19"; | ||
| private String apiVersion = "1.21"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be changed to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would make sense. Will do as suggested.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems thats not that simple. |
||
|
|
||
| protected DockerClient dockerClient; | ||
|
|
||
|
|
@@ -172,21 +174,23 @@ public static Boolean available(int port) { | |
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Asserts that {@link InspectContainerResponse#getVolumes()} (<code>.Volumes</code>) has {@link VolumeBind}s for | ||
| * the given {@link Volume}s | ||
| */ | ||
| public static void assertContainerHasVolumes(InspectContainerResponse inspectContainerResponse, | ||
| Volume... expectedVolumes) { | ||
|
|
||
| List<Volume> volumes = new ArrayList<Volume>(); | ||
| VolumeBind[] volumeBinds = inspectContainerResponse.getVolumes(); | ||
| if (volumeBinds != null) { | ||
| for (VolumeBind bind : volumeBinds) { | ||
| volumes.add(new Volume(bind.getContainerPath())); | ||
| protected MountedVolumes mountedVolumes(Matcher<? super List<Volume>> subMatcher) { | ||
| return new MountedVolumes(subMatcher, "Mounted volumes", "mountedVolumes"); | ||
| } | ||
|
|
||
| private static class MountedVolumes extends FeatureMatcher<InspectContainerResponse, List<Volume>> { | ||
| public MountedVolumes(Matcher<? super List<Volume>> subMatcher, String featureDescription, String featureName) { | ||
| super(subMatcher, featureDescription, featureName); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Volume> featureValueOf(InspectContainerResponse item) { | ||
| List<Volume> volumes = new ArrayList<Volume>(); | ||
| for (Mount mount : item.getMounts()) { | ||
| volumes.add(mount.getDestination()); | ||
| } | ||
| return volumes; | ||
| } | ||
| assertThat(volumes, contains(expectedVolumes)); | ||
| } | ||
|
|
||
| protected String containerLog(String containerId) throws Exception { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,5 @@ | ||
| package com.github.dockerjava.core.command; | ||
|
|
||
| import com.github.dockerjava.api.exception.ConflictException; | ||
| import com.github.dockerjava.api.exception.DockerException; | ||
| import com.github.dockerjava.api.command.CreateContainerResponse; | ||
| import com.github.dockerjava.api.command.InspectContainerResponse; | ||
| import com.github.dockerjava.api.model.AccessMode; | ||
| import com.github.dockerjava.api.model.Bind; | ||
| import com.github.dockerjava.api.model.Device; | ||
| import com.github.dockerjava.api.model.ExposedPort; | ||
| import com.github.dockerjava.api.model.Link; | ||
| import com.github.dockerjava.api.model.LogConfig; | ||
| import com.github.dockerjava.api.model.Ports; | ||
| import com.github.dockerjava.api.model.RestartPolicy; | ||
| import com.github.dockerjava.api.model.Ulimit; | ||
| import com.github.dockerjava.api.model.Volume; | ||
| import com.github.dockerjava.api.model.VolumeRW; | ||
| import com.github.dockerjava.api.model.VolumesFrom; | ||
| import com.github.dockerjava.client.AbstractDockerClientTest; | ||
| import org.testng.ITestResult; | ||
| import org.testng.annotations.AfterMethod; | ||
| import org.testng.annotations.AfterTest; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.BeforeTest; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static com.github.dockerjava.api.model.Capability.MKNOD; | ||
| import static com.github.dockerjava.api.model.Capability.NET_ADMIN; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
|
|
@@ -45,7 +21,28 @@ | |
| import java.util.Map; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import org.testng.ITestResult; | ||
| import org.testng.annotations.AfterMethod; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the settings in your IDE about imports?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Just trying understand your styling and materialise later in checkstyle)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eclipse code formatting options doesn't have options for static import order AFAIK. |
||
| import org.testng.annotations.AfterTest; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.BeforeTest; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import com.github.dockerjava.api.command.CreateContainerResponse; | ||
| import com.github.dockerjava.api.command.InspectContainerResponse; | ||
| import com.github.dockerjava.api.exception.ConflictException; | ||
| import com.github.dockerjava.api.exception.DockerException; | ||
| import com.github.dockerjava.api.model.Bind; | ||
| import com.github.dockerjava.api.model.Device; | ||
| import com.github.dockerjava.api.model.ExposedPort; | ||
| import com.github.dockerjava.api.model.Link; | ||
| import com.github.dockerjava.api.model.LogConfig; | ||
| import com.github.dockerjava.api.model.Ports; | ||
| import com.github.dockerjava.api.model.RestartPolicy; | ||
| import com.github.dockerjava.api.model.Ulimit; | ||
| import com.github.dockerjava.api.model.Volume; | ||
| import com.github.dockerjava.api.model.VolumesFrom; | ||
| import com.github.dockerjava.client.AbstractDockerClientTest; | ||
|
|
||
| @Test(groups = "integration") | ||
| public class CreateContainerCmdImplTest extends AbstractDockerClientTest { | ||
|
|
@@ -107,9 +104,12 @@ public void createContainerWithVolume() throws DockerException { | |
|
|
||
| assertThat(inspectContainerResponse.getConfig().getVolumes().keySet(), contains("/var/log")); | ||
|
|
||
| assertThat(inspectContainerResponse.getVolumesRW(), hasItemInArray(new VolumeRW(volume, AccessMode.rw))); | ||
| assertThat(inspectContainerResponse.getMounts().get(0).getDestination(), equalTo(volume)); | ||
| assertThat(inspectContainerResponse.getMounts().get(0).getMode(), equalTo("")); | ||
| assertThat(inspectContainerResponse.getMounts().get(0).getRW(), equalTo(true)); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void createContainerWithReadOnlyVolume() throws DockerException { | ||
|
|
||
|
|
@@ -128,7 +128,9 @@ public void createContainerWithReadOnlyVolume() throws DockerException { | |
|
|
||
| assertThat(inspectContainerResponse.getConfig().getVolumes().keySet(), contains("/srv/test")); | ||
|
|
||
| assertThat(Arrays.asList(inspectContainerResponse.getVolumesRW()), contains(new VolumeRW(volume))); | ||
| assertThat(inspectContainerResponse.getMounts().get(0).getDestination(), equalTo(volume)); | ||
| // TODO: Create a read-only volume and test like this | ||
| // assertFalse(inspectContainerResponse.getMounts().get(0).getRW()); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -151,7 +153,7 @@ public void createContainerWithVolumesFrom() throws DockerException { | |
| InspectContainerResponse inspectContainerResponse1 = dockerClient.inspectContainerCmd(container1.getId()) | ||
| .exec(); | ||
|
|
||
| assertContainerHasVolumes(inspectContainerResponse1, volume1, volume2); | ||
| assertThat(inspectContainerResponse1, mountedVolumes(containsInAnyOrder(volume1, volume2))); | ||
|
|
||
| // create a second container with volumes from first container | ||
| CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") | ||
|
|
@@ -177,7 +179,8 @@ public void createContainerWithVolumesFrom() throws DockerException { | |
|
|
||
| assertThat(inspectContainerResponse2.getHostConfig().getVolumesFrom(), hasItemInArray(new VolumesFrom( | ||
| container1Name))); | ||
| assertContainerHasVolumes(inspectContainerResponse2, volume1, volume2); | ||
|
|
||
| assertThat(inspectContainerResponse2, mountedVolumes(containsInAnyOrder(volume1, volume2))); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mountclass itself may appear in any time, but field appeared@since 1.20?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Field 'Mounts' exists since 1.20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you javadoc it? :) Better mark versions while you know them, because later it will be difficult to compare all of them

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know... Will do :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to the getter