X Tutup
Skip to content

Commit 58d9407

Browse files
committed
Merge pull request #378 from KostyaSha/pr/372
Pr/372
2 parents 570fa09 + ef093ab commit 58d9407

File tree

11 files changed

+375
-31
lines changed

11 files changed

+375
-31
lines changed

src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.util.List;
44
import java.util.Map;
55

6+
import com.github.dockerjava.core.RemoteApiVersion;
7+
import org.apache.commons.lang.builder.EqualsBuilder;
8+
import org.apache.commons.lang.builder.HashCodeBuilder;
69
import org.apache.commons.lang.builder.ToStringBuilder;
710

811
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -16,6 +19,8 @@
1619
import com.github.dockerjava.api.model.VolumeRW;
1720
import com.github.dockerjava.api.model.VolumesRW;
1821

22+
import javax.annotation.CheckForNull;
23+
1924
/**
2025
*
2126
* @author Konstantin Pelykh (kpelykh@gmail.com)
@@ -225,48 +230,183 @@ public String toString() {
225230
@JsonIgnoreProperties(ignoreUnknown = true)
226231
public class ContainerState {
227232

233+
/**
234+
* @since {@link RemoteApiVersion#VERSION_1_20}
235+
*/
236+
@CheckForNull
237+
@JsonProperty("Status")
238+
private String status;
239+
240+
/**
241+
* @since < {@link RemoteApiVersion#VERSION_1_16}
242+
*/
243+
@CheckForNull
228244
@JsonProperty("Running")
229245
private Boolean running;
230246

247+
/**
248+
* @since {@link RemoteApiVersion#VERSION_1_17}
249+
*/
250+
@CheckForNull
231251
@JsonProperty("Paused")
232252
private Boolean paused;
233253

254+
/**
255+
* @since {@link RemoteApiVersion#VERSION_1_17}
256+
*/
257+
@CheckForNull
258+
@JsonProperty("Restarting")
259+
private Boolean restarting;
260+
261+
/**
262+
* @since {@link RemoteApiVersion#VERSION_1_17}
263+
*/
264+
@CheckForNull
265+
@JsonProperty("OOMKilled")
266+
private Boolean oomKilled;
267+
268+
/**
269+
* <a href="https://github.com/docker/docker/pull/18127">Unclear</a>
270+
* @since {@link RemoteApiVersion#UNKNOWN_VERSION}
271+
*/
272+
@CheckForNull
273+
@JsonProperty("Dead")
274+
private Boolean dead;
275+
276+
/**
277+
* @since < {@link RemoteApiVersion#VERSION_1_16}
278+
*/
279+
@CheckForNull
234280
@JsonProperty("Pid")
235281
private Integer pid;
236282

283+
/**
284+
* @since < {@link RemoteApiVersion#VERSION_1_16}
285+
*/
286+
@CheckForNull
237287
@JsonProperty("ExitCode")
238288
private Integer exitCode;
239289

290+
/**
291+
* @since {@link RemoteApiVersion#VERSION_1_17}
292+
*/
293+
@CheckForNull
294+
@JsonProperty("Error")
295+
private String error;
296+
297+
/**
298+
* @since < {@link RemoteApiVersion#VERSION_1_16}
299+
*/
300+
@CheckForNull
240301
@JsonProperty("StartedAt")
241302
private String startedAt;
242303

304+
/**
305+
* @since {@link RemoteApiVersion#VERSION_1_17}
306+
*/
307+
@CheckForNull
243308
@JsonProperty("FinishedAt")
244309
private String finishedAt;
245310

246-
public Boolean isRunning() {
311+
312+
/**
313+
* See {@link #status}
314+
*/
315+
@CheckForNull
316+
public String getStatus() {
317+
return status;
318+
}
319+
320+
/**
321+
* See {@link #running}
322+
*/
323+
@CheckForNull
324+
public Boolean getRunning() {
247325
return running;
248326
}
249327

250-
public Boolean isPaused() {
328+
/**
329+
* See {@link #paused}
330+
*/
331+
@CheckForNull
332+
public Boolean getPaused() {
251333
return paused;
252334
}
253335

336+
/**
337+
* See {@link #restarting}
338+
*/
339+
@CheckForNull
340+
public Boolean getRestarting() {
341+
return restarting;
342+
}
343+
344+
/**
345+
* See {@link #oomKilled}
346+
*/
347+
@CheckForNull
348+
public Boolean getOOMKilled() {
349+
return oomKilled;
350+
}
351+
352+
/**
353+
* See {@link #dead}
354+
*/
355+
@CheckForNull
356+
public Boolean getDead() {
357+
return dead;
358+
}
359+
360+
/**
361+
* See {@link #pid}
362+
*/
363+
@CheckForNull
254364
public Integer getPid() {
255365
return pid;
256366
}
257367

368+
/**
369+
* See {@link #exitCode}
370+
*/
371+
@CheckForNull
258372
public Integer getExitCode() {
259373
return exitCode;
260374
}
261375

376+
/**
377+
* See {@link #error}
378+
*/
379+
@CheckForNull
380+
public String getError() {
381+
return error;
382+
}
383+
384+
/**
385+
* See {@link #startedAt}
386+
*/
387+
@CheckForNull
262388
public String getStartedAt() {
263389
return startedAt;
264390
}
265391

392+
/**
393+
* See {@link #finishedAt}
394+
*/
395+
@CheckForNull
266396
public String getFinishedAt() {
267397
return finishedAt;
268398
}
269399

400+
@Override
401+
public boolean equals(Object o) {
402+
return EqualsBuilder.reflectionEquals(this, o);
403+
}
404+
405+
@Override
406+
public int hashCode() {
407+
return HashCodeBuilder.reflectionHashCode(this);
408+
}
409+
270410
@Override
271411
public String toString() {
272412
return ToStringBuilder.reflectionToString(this);

src/main/java/com/github/dockerjava/core/RemoteApiVersion.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import java.util.regex.Pattern;
1111

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

23+
private static final Pattern VERSION_REGEX = Pattern.compile("v?(\\d+)\\.(\\d+)");
24+
25+
/**
26+
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.16/">Docker API 1.16</a>
27+
*/
28+
public static final RemoteApiVersion VERSION_1_16 = RemoteApiVersion.create(1, 16);
29+
30+
/**
31+
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.17/">Docker API 1.17</a>
32+
*/
33+
public static final RemoteApiVersion VERSION_1_17 = RemoteApiVersion.create(1, 17);
34+
35+
/**
36+
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.18/">Docker API 1.18</a>
37+
*/
38+
public static final RemoteApiVersion VERSION_1_18 = RemoteApiVersion.create(1, 18);
39+
40+
/**
41+
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.19/">Docker API 1.19</a>
42+
*/
2243
public static final RemoteApiVersion VERSION_1_19 = RemoteApiVersion.create(1, 19);
2344

24-
private static final Pattern VERSION_REGEX = Pattern.compile("v?(\\d+)\\.(\\d+)");
45+
/**
46+
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.20/">Docker API 1.20</a>
47+
*/
48+
public static final RemoteApiVersion VERSION_1_20 = RemoteApiVersion.create(1, 20);
49+
50+
51+
/**
52+
* @see <a href="http://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/">Docker API 1.21</a>
53+
*/
54+
public static final RemoteApiVersion VERSION_1_21 = RemoteApiVersion.create(1, 21);
55+
56+
/**
57+
* @see <a href="https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api_v1.22.md">Docker API 1.22</a>
58+
*/
59+
public static final RemoteApiVersion VERSION_1_22 = RemoteApiVersion.create(1, 22);
60+
2561

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

2868
@Override

src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
*/
2525
public enum CommandJSONSamples implements JSONResourceRef {
2626

27-
inspectContainerResponse_full, inspectContainerResponse_empty;
27+
inspectContainerResponse_full,
28+
inspectContainerResponse_full_1_21,
29+
inspectContainerResponse_empty;
2830

2931
@Override
3032
public String getFileName() {

src/test/java/com/github/dockerjava/api/command/InspectContainerResponseTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@
1515
*/
1616
package com.github.dockerjava.api.command;
1717

18-
import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
19-
import static org.testng.Assert.assertEquals;
20-
import static org.testng.Assert.assertFalse;
21-
import static org.testng.Assert.assertTrue;
18+
import org.testng.annotations.Test;
2219

2320
import java.io.IOException;
2421

25-
import org.testng.annotations.Test;
22+
import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
23+
import static org.hamcrest.MatcherAssert.assertThat;
24+
import static org.hamcrest.Matchers.containsString;
25+
import static org.hamcrest.Matchers.isEmptyString;
26+
import static org.hamcrest.Matchers.nullValue;
27+
import static org.hamcrest.core.IsNot.not;
28+
import static org.testng.Assert.*;
2629

2730
/**
2831
* Tests for {@link InspectContainerResponse}.
29-
*
32+
*
3033
* @author Oleg Nenashev
3134
*/
3235
public class InspectContainerResponseTest {
@@ -48,6 +51,22 @@ public void roundTrip_full() throws IOException {
4851
assertTrue(response.getVolumesRW()[0].getAccessMode().toBoolean());
4952
}
5053

54+
@Test
55+
public void roundTrip_1_21_full() throws IOException {
56+
InspectContainerResponse[] responses = testRoundTrip(CommandJSONSamples.inspectContainerResponse_full_1_21,
57+
InspectContainerResponse[].class);
58+
assertEquals(1, responses.length);
59+
final InspectContainerResponse response = responses[0];
60+
final InspectContainerResponse.ContainerState state = response.getState();
61+
assertThat(state, not(nullValue()));
62+
63+
assertFalse(state.getDead());
64+
assertThat(state.getStatus(), containsString("running"));
65+
assertFalse(state.getRestarting());
66+
assertFalse(state.getOOMKilled());
67+
assertThat(state.getError(), isEmptyString());
68+
}
69+
5170
@Test
5271
public void roundTrip_empty() throws IOException {
5372
testRoundTrip(CommandJSONSamples.inspectContainerResponse_empty, InspectContainerResponse[].class);

src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public void createContainerWithLink() throws DockerException {
253253
InspectContainerResponse inspectContainerResponse1 = dockerClient.inspectContainerCmd(container1.getId())
254254
.exec();
255255
LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
256-
assertThat(inspectContainerResponse1.getState().isRunning(), is(true));
256+
assertThat(inspectContainerResponse1.getState().getRunning(), is(true));
257257

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

411-
if (!inspectContainerResponse1.getState().isRunning()) {
411+
if (!inspectContainerResponse1.getState().getRunning()) {
412412
assertThat(inspectContainerResponse1.getState().getExitCode(), is(equalTo(0)));
413413
}
414414

src/test/java/com/github/dockerjava/core/command/KillContainerCmdImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void killContainer() throws DockerException {
6262
InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
6363
LOG.info("Container Inspect: {}", inspectContainerResponse.toString());
6464

65-
assertThat(inspectContainerResponse.getState().isRunning(), is(equalTo(false)));
65+
assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false)));
6666
assertThat(inspectContainerResponse.getState().getExitCode(), not(equalTo(0)));
6767

6868
}

src/test/java/com/github/dockerjava/core/command/RestartContainerCmdImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void restartContainer() throws DockerException {
6666

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

69-
assertThat(inspectContainerResponse.getState().isRunning(), is(equalTo(true)));
69+
assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(true)));
7070

7171
dockerClient.killContainerCmd(container.getId()).exec();
7272
}

0 commit comments

Comments
 (0)
X Tutup