Added healthcheck support in container inspect JSON result · kylechase/docker-java@a3be9a5 · GitHub
Skip to content

Commit a3be9a5

Browse files
Lubos.PalisekKostyaSha
authored andcommitted
Added healthcheck support in container inspect JSON result
1 parent e8146ac commit a3be9a5

7 files changed

Lines changed: 326 additions & 3 deletions

File tree

Lines changed: 30 additions & 0 deletions
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
public class HealthStateLog {
8+
9+
@JsonProperty("Start")
10+
private String start;
11+
12+
@JsonProperty("End")
13+
private String end;
14+
15+
@JsonProperty("ExitCode")
16+
private Integer exitCode;
17+
18+
@JsonProperty("Output")
19+
private String output;
20+
21+
public String getStart() {
22+
return start;
23+
}
24+
25+
public String getEnd() {
26+
return end;
27+
}
28+
29+
public Integer getExitCode() {
30+
return exitCode;
31+
}
32+
33+
public String getOutput() {
34+
return output;
35+
}
36+
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public String getId() {
112112
}
113113

114114
public Integer getSizeRootFs() {
115-
return sizeRootFs;
115+
return sizeRootFs;
116116
}
117117

118118
public String getCreated() {
@@ -302,6 +302,13 @@ public class ContainerState {
302302
@JsonProperty("FinishedAt")
303303
private String finishedAt;
304304

305+
306+
/**
307+
* @since Docker version 1.12
308+
*/
309+
@JsonProperty("Health")
310+
private HealthState health;
311+
305312
/**
306313
* See {@link #status}
307314
*/
@@ -390,6 +397,10 @@ public String getFinishedAt() {
390397
return finishedAt;
391398
}
392399

400+
public HealthState getHealth() {
401+
return health;
402+
}
403+
393404
@Override
394405
public boolean equals(Object o) {
395406
return EqualsBuilder.reflectionEquals(this, o);

src/main/java/com/github/dockerjava/api/model/ContainerConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public class ContainerConfig implements Serializable {
8686
@JsonProperty("WorkingDir")
8787
private String workingDir;
8888

89+
@JsonProperty("Healthcheck")
90+
private HealthCheck healthCheck;
91+
8992
@JsonIgnore
9093
public ExposedPort[] getExposedPorts() {
9194
return exposedPorts != null ? exposedPorts.getExposedPorts() : null;
@@ -411,6 +414,14 @@ public String getWorkingDir() {
411414
return workingDir;
412415
}
413416

417+
/**
418+
* @see #healthCheck
419+
*/
420+
@CheckForNull
421+
public HealthCheck getHealthcheck() {
422+
return healthCheck;
423+
}
424+
414425
/**
415426
* @see #workingDir
416427
*/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2017 cdancy.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.dockerjava.api.model;
17+
18+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19+
import com.fasterxml.jackson.annotation.JsonInclude;
20+
import com.fasterxml.jackson.annotation.JsonProperty;
21+
import java.io.Serializable;
22+
23+
/**
24+
*
25+
* @author cdancy
26+
*/
27+
@JsonIgnoreProperties(ignoreUnknown = true)
28+
@JsonInclude(JsonInclude.Include.NON_NULL)
29+
public class HealthCheck implements Serializable {
30+
private static final long serialVersionUID = 1L;
31+
32+
@JsonProperty("Interval")
33+
private Long interval;
34+
35+
@JsonProperty("Timeout")
36+
private Long timeout;
37+
38+
public Long getInterval() {
39+
return interval;
40+
}
41+
42+
public Long getTimeout() {
43+
return timeout;
44+
}
45+
}

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

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

18-
import org.testng.annotations.Test;
19-
18+
import com.fasterxml.jackson.databind.JavaType;
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.github.dockerjava.api.model.Event;
21+
import com.github.dockerjava.core.RemoteApiVersion;
22+
import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip;
2023
import java.io.IOException;
2124

25+
import org.testng.annotations.Test;
26+
2227
import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
2328
import static org.hamcrest.MatcherAssert.assertThat;
2429
import static org.hamcrest.Matchers.containsString;
@@ -55,6 +60,24 @@ public void roundTrip_full() throws IOException {
5560
assertThat(response.getLogPath(), is("/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1-json.log"));
5661
}
5762

63+
@Test
64+
public void roundTrip_full_healthcheck() throws IOException {
65+
66+
final ObjectMapper mapper = new ObjectMapper();
67+
final JavaType type = mapper.getTypeFactory().uncheckedSimpleType(InspectContainerResponse.class);
68+
69+
final InspectContainerResponse response = testRoundTrip(RemoteApiVersion.VERSION_1_24,
70+
"/containers/inspect/1.json",
71+
type
72+
);
73+
74+
assertEquals(response.getState().getHealth().getStatus(), "healthy");
75+
assertEquals(response.getState().getHealth().getFailingStreak(), new Integer(0));
76+
assertEquals(response.getState().getHealth().getLog().size(), 2);
77+
assertEquals(response.getState().getHealth().getLog().get(0).getOutput(), "Hello");
78+
assertEquals(response.getState().getHealth().getLog().get(1).getOutput(), "World");
79+
}
80+
5881
@Test
5982
public void roundTrip_1_21_full() throws IOException {
6083
InspectContainerResponse[] responses = testRoundTrip(CommandJSONSamples.inspectContainerResponse_full_1_21,
Lines changed: 167 additions & 0 deletions

0 commit comments

Comments
 (0)