X Tutup
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 @@ -3,6 +3,9 @@
import java.util.List;
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;

import com.fasterxml.jackson.annotation.JsonIgnore;
Expand All @@ -16,6 +19,8 @@
import com.github.dockerjava.api.model.VolumeRW;
import com.github.dockerjava.api.model.VolumesRW;

import javax.annotation.CheckForNull;

/**
*
* @author Konstantin Pelykh (kpelykh@gmail.com)
Expand Down Expand Up @@ -225,48 +230,183 @@ public String toString() {
@JsonIgnoreProperties(ignoreUnknown = true)
public class ContainerState {

/**
* @since {@link RemoteApiVersion#VERSION_1_20}
*/
@CheckForNull
@JsonProperty("Status")
private String status;

/**
* @since < {@link RemoteApiVersion#VERSION_1_16}
*/
@CheckForNull
@JsonProperty("Running")
private Boolean running;

/**
* @since {@link RemoteApiVersion#VERSION_1_17}
*/
@CheckForNull
@JsonProperty("Paused")
private Boolean paused;

/**
* @since {@link RemoteApiVersion#VERSION_1_17}
*/
@CheckForNull
@JsonProperty("Restarting")
private Boolean restarting;

/**
* @since {@link RemoteApiVersion#VERSION_1_17}
*/
@CheckForNull
@JsonProperty("OOMKilled")
private Boolean oomKilled;

/**
* <a href="https://github.com/docker/docker/pull/18127">Unclear</a>
* @since {@link RemoteApiVersion#UNKNOWN_VERSION}
*/
@CheckForNull
@JsonProperty("Dead")
private Boolean dead;

/**
* @since < {@link RemoteApiVersion#VERSION_1_16}
*/
@CheckForNull
@JsonProperty("Pid")
private Integer pid;

/**
* @since < {@link RemoteApiVersion#VERSION_1_16}
*/
@CheckForNull
@JsonProperty("ExitCode")
private Integer exitCode;

/**
* @since {@link RemoteApiVersion#VERSION_1_17}
*/
@CheckForNull
@JsonProperty("Error")
private String error;

/**
* @since < {@link RemoteApiVersion#VERSION_1_16}
*/
@CheckForNull
@JsonProperty("StartedAt")
private String startedAt;

/**
* @since {@link RemoteApiVersion#VERSION_1_17}
*/
@CheckForNull
@JsonProperty("FinishedAt")
private String finishedAt;

public Boolean isRunning() {

/**
* See {@link #status}
*/
@CheckForNull
public String getStatus() {
return status;
}

/**
* See {@link #running}
*/
@CheckForNull
public Boolean getRunning() {
return running;
}

public Boolean isPaused() {
/**
* See {@link #paused}
*/
@CheckForNull
public Boolean getPaused() {
return paused;
}

/**
* See {@link #restarting}
*/
@CheckForNull
public Boolean getRestarting() {
return restarting;
}

/**
* See {@link #oomKilled}
*/
@CheckForNull
public Boolean getOOMKilled() {
return oomKilled;
}

/**
* See {@link #dead}
*/
@CheckForNull
public Boolean getDead() {
return dead;
}

/**
* See {@link #pid}
*/
@CheckForNull
public Integer getPid() {
return pid;
}

/**
* See {@link #exitCode}
*/
@CheckForNull
public Integer getExitCode() {
return exitCode;
}

/**
* See {@link #error}
*/
@CheckForNull
public String getError() {
return error;
}

/**
* See {@link #startedAt}
*/
@CheckForNull
public String getStartedAt() {
return startedAt;
}

/**
* See {@link #finishedAt}
*/
@CheckForNull
public String getFinishedAt() {
return finishedAt;
}

@Override
public boolean equals(Object o) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@marcuslinke please check, btw why nested classes are used? Can they be extracted into model objects?

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.

Nesting classes makes sense when the inner class is used only in the context of the surrounding class and not anywhere else. Beside this it also documents the classes relationship in my oppinion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But you will have only field with cleaner class instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Keeping as is.

return EqualsBuilder.reflectionEquals(this, o);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
Expand Down
44 changes: 42 additions & 2 deletions src/main/java/com/github/dockerjava/core/RemoteApiVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import java.util.regex.Pattern;

/**
* Bean to encapsulate the version of the Docker Remote API (REST API)
* Bean to encapsulate the version of the
* <a href="http://docs.docker.com/engine/reference/api/docker_remote_api/">Docker Remote (REST) API</a>
* <p>
* Contains the minor and major version of the API as well as operations to compare API versions.
*
Expand All @@ -19,10 +20,49 @@
public class RemoteApiVersion implements Serializable {
private static final long serialVersionUID = -5382212999262115459L;

private static final Pattern VERSION_REGEX = Pattern.compile("v?(\\d+)\\.(\\d+)");

/**
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.16/">Docker API 1.16</a>
*/
public static final RemoteApiVersion VERSION_1_16 = RemoteApiVersion.create(1, 16);

/**
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.17/">Docker API 1.17</a>
*/
public static final RemoteApiVersion VERSION_1_17 = RemoteApiVersion.create(1, 17);

/**
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.18/">Docker API 1.18</a>
*/
public static final RemoteApiVersion VERSION_1_18 = RemoteApiVersion.create(1, 18);

/**
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.19/">Docker API 1.19</a>
*/
public static final RemoteApiVersion VERSION_1_19 = RemoteApiVersion.create(1, 19);

private static final Pattern VERSION_REGEX = Pattern.compile("v?(\\d+)\\.(\\d+)");
/**
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.20/">Docker API 1.20</a>
*/
public static final RemoteApiVersion VERSION_1_20 = RemoteApiVersion.create(1, 20);


/**
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/">Docker API 1.21</a>
*/
public static final RemoteApiVersion VERSION_1_21 = RemoteApiVersion.create(1, 21);

/**
* @see <a href="https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api_v1.22.md">Docker API 1.22</a>
*/
public static final RemoteApiVersion VERSION_1_22 = RemoteApiVersion.create(1, 22);


/**
* Unknown, docker doesn't reflect reality.
* I.e. we implemented method, but for javadoc it not clear when it was added.
*/
private static final RemoteApiVersion UNKNOWN_VERSION = new RemoteApiVersion(0, 0) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/
public enum CommandJSONSamples implements JSONResourceRef {

inspectContainerResponse_full, inspectContainerResponse_empty;
inspectContainerResponse_full,
inspectContainerResponse_full_1_21,
inspectContainerResponse_empty;

@Override
public String getFileName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
*/
package com.github.dockerjava.api.command;

import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;

import java.io.IOException;

import org.testng.annotations.Test;
import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.isEmptyString;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.IsNot.not;
import static org.testng.Assert.*;

/**
* Tests for {@link InspectContainerResponse}.
*
*
* @author Oleg Nenashev
*/
public class InspectContainerResponseTest {
Expand All @@ -48,6 +51,22 @@ public void roundTrip_full() throws IOException {
assertTrue(response.getVolumesRW()[0].getAccessMode().toBoolean());
}

@Test
public void roundTrip_1_21_full() throws IOException {
InspectContainerResponse[] responses = testRoundTrip(CommandJSONSamples.inspectContainerResponse_full_1_21,
InspectContainerResponse[].class);
assertEquals(1, responses.length);
final InspectContainerResponse response = responses[0];
final InspectContainerResponse.ContainerState state = response.getState();
assertThat(state, not(nullValue()));

assertFalse(state.getDead());
assertThat(state.getStatus(), containsString("running"));
assertFalse(state.getRestarting());
assertFalse(state.getOOMKilled());
assertThat(state.getError(), isEmptyString());
}

@Test
public void roundTrip_empty() throws IOException {
testRoundTrip(CommandJSONSamples.inspectContainerResponse_empty, InspectContainerResponse[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void createContainerWithLink() throws DockerException {
InspectContainerResponse inspectContainerResponse1 = dockerClient.inspectContainerCmd(container1.getId())
.exec();
LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
assertThat(inspectContainerResponse1.getState().getRunning(), is(true));

CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withName("container2")
.withCmd("env").withLinks(new Link("container1", "container1Link")).exec();
Expand Down Expand Up @@ -406,9 +406,9 @@ public void createContainerWithLinking() throws DockerException {
assertThat(inspectContainerResponse1.getName(), equalTo("/container1"));
assertThat(inspectContainerResponse1.getImageId(), not(isEmptyString()));
assertThat(inspectContainerResponse1.getState(), is(notNullValue()));
assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
assertThat(inspectContainerResponse1.getState().getRunning(), is(true));

if (!inspectContainerResponse1.getState().isRunning()) {
if (!inspectContainerResponse1.getState().getRunning()) {
assertThat(inspectContainerResponse1.getState().getExitCode(), is(equalTo(0)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void killContainer() throws DockerException {
InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
LOG.info("Container Inspect: {}", inspectContainerResponse.toString());

assertThat(inspectContainerResponse.getState().isRunning(), is(equalTo(false)));
assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false)));
assertThat(inspectContainerResponse.getState().getExitCode(), not(equalTo(0)));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void restartContainer() throws DockerException {

assertThat(startTime, not(equalTo(startTime2)));

assertThat(inspectContainerResponse.getState().isRunning(), is(equalTo(true)));
assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(true)));

dockerClient.killContainerCmd(container.getId()).exec();
}
Expand Down
Loading
X Tutup