Skip to content

Commit f4bf1f0

Browse files
loganbrunsvuminhkh
authored andcommitted
Issue 761: Inspect command response should include docker swarm node info
#761 It is useful to be able to tell which node a container is running on for various scenarios such as routing traffic dynamically to it. I've tested a change to add this information and will create a PR shortly.
1 parent 5323605 commit f4bf1f0

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.github.dockerjava.api.model.ContainerConfig;
1515
import com.github.dockerjava.api.model.HostConfig;
1616
import com.github.dockerjava.api.model.NetworkSettings;
17+
import com.github.dockerjava.api.model.Node;
1718
import com.github.dockerjava.api.model.Volume;
1819
import com.github.dockerjava.api.model.VolumeBind;
1920
import com.github.dockerjava.api.model.VolumeBinds;
@@ -83,6 +84,9 @@ public class InspectContainerResponse {
8384
@JsonProperty("NetworkSettings")
8485
private NetworkSettings networkSettings;
8586

87+
@JsonProperty("Node")
88+
private Node node;
89+
8690
@JsonProperty("Path")
8791
private String path;
8892

@@ -147,6 +151,10 @@ public NetworkSettings getNetworkSettings() {
147151
return networkSettings;
148152
}
149153

154+
public Node getNode() {
155+
return node;
156+
}
157+
150158
public String getResolvConfPath() {
151159
return resolvConfPath;
152160
}

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,50 @@
11
package com.github.dockerjava.api.model;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonInclude;
45
import com.fasterxml.jackson.annotation.JsonInclude.Include;
56
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import org.apache.commons.lang.builder.ToStringBuilder;
8+
9+
import java.util.Map;
610

711
import java.io.Serializable;
812

913
/**
1014
* A node as returned by the /events API, for instance, when Swarm is used.
1115
*/
1216
@JsonInclude(Include.NON_NULL)
17+
@JsonIgnoreProperties(ignoreUnknown = true)
1318
public class Node implements Serializable {
1419
private static final long serialVersionUID = 1L;
1520

1621
@JsonProperty("Name")
1722
private String name;
1823

19-
@JsonProperty("Id")
24+
@JsonProperty("ID")
2025
private String id;
2126

2227
@JsonProperty("Addr")
2328
private String addr;
2429

25-
@JsonProperty("Ip")
30+
@JsonProperty("IP")
2631
private String ip;
2732

33+
@JsonProperty("Cpus")
34+
private Integer cpus;
35+
36+
@JsonProperty("Memory")
37+
private Long memory;
38+
39+
@JsonProperty("Labels")
40+
private Map<String, String> labels;
41+
42+
@JsonProperty("Version")
43+
private String version;
44+
45+
@JsonProperty("DeltaDuration")
46+
private Long deltaDuration;
47+
2848
public String getName() {
2949
return name;
3050
}
@@ -40,4 +60,29 @@ public String getAddr() {
4060
public String getIp() {
4161
return ip;
4262
}
63+
64+
public Integer getCpus() {
65+
return cpus;
66+
}
67+
68+
public Long getMemory() {
69+
return memory;
70+
}
71+
72+
public Map<String, String> getLabels() {
73+
return labels;
74+
}
75+
76+
public String getVersion() {
77+
return version;
78+
}
79+
80+
public Long getDeltaDuration() {
81+
return deltaDuration;
82+
}
83+
84+
@Override
85+
public String toString() {
86+
return ToStringBuilder.reflectionToString(this);
87+
}
4388
}

0 commit comments

Comments
 (0)