Skip to content

Commit 145d9e5

Browse files
committed
add JsonIgnoreProperties(ignoreUnknown = true)
change command from string to List<String> add labels and forceUpdate
1 parent 995d81f commit 145d9e5

4 files changed

Lines changed: 66 additions & 6 deletions

File tree

‎src/main/java/com/github/dockerjava/api/model/ContainerSpec.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.api.model;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45
import com.github.dockerjava.core.RemoteApiVersion;
56
import org.apache.commons.lang.builder.EqualsBuilder;
@@ -17,6 +18,7 @@
1718
*
1819
* @since {@link RemoteApiVersion#VERSION_1_24}
1920
*/
21+
@JsonIgnoreProperties(ignoreUnknown = true)
2022
public class ContainerSpec implements Serializable {
2123
public static final Long serialVersionUID = 1L;
2224

@@ -36,7 +38,7 @@ public class ContainerSpec implements Serializable {
3638
* @since 1.24
3739
*/
3840
@JsonProperty("Command")
39-
private String command;
41+
private List<String> command;
4042

4143
/**
4244
* @since 1.24
@@ -122,14 +124,14 @@ public ContainerSpec withLabels(Map<String, String> labels) {
122124
* @see #command
123125
*/
124126
@CheckForNull
125-
public String getCommand() {
127+
public List<String> getCommand() {
126128
return command;
127129
}
128130

129131
/**
130132
* @see #command
131133
*/
132-
public ContainerSpec withCommand(String command) {
134+
public ContainerSpec withCommand(List<String> command) {
133135
this.command = command;
134136
return this;
135137
}

‎src/main/java/com/github/dockerjava/api/model/ServiceSpec.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.api.model;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45
import com.github.dockerjava.core.RemoteApiVersion;
56
import org.apache.commons.lang.builder.EqualsBuilder;
@@ -10,10 +11,12 @@
1011
import javax.annotation.CheckForNull;
1112
import java.io.Serializable;
1213
import java.util.List;
14+
import java.util.Map;
1315

1416
/**
1517
* @since {@link RemoteApiVersion#VERSION_1_24}
1618
*/
19+
@JsonIgnoreProperties(ignoreUnknown = true)
1720
public class ServiceSpec implements Serializable {
1821
public static final Long serialVersionUID = 1L;
1922

@@ -53,6 +56,12 @@ public class ServiceSpec implements Serializable {
5356
@JsonProperty("EndpointSpec")
5457
private EndpointSpec endpointSpec;
5558

59+
/**
60+
* @since 1.24
61+
*/
62+
@JsonProperty("Labels")
63+
private Map<String, String> labels;
64+
5665
/**
5766
* @see #name
5867
*/
@@ -148,6 +157,22 @@ public ServiceSpec withEndpointSpec(EndpointSpec endpointSpec) {
148157
return this;
149158
}
150159

160+
/**
161+
* @see #labels
162+
*/
163+
public ServiceSpec withLabels(Map<String, String> labels) {
164+
this.labels = labels;
165+
return this;
166+
}
167+
168+
/**
169+
* @see #labels
170+
*/
171+
@CheckForNull
172+
public Map<String, String> getLabels() {
173+
return labels;
174+
}
175+
151176
@Override
152177
public String toString() {
153178
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);

‎src/main/java/com/github/dockerjava/api/model/TaskSpec.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.api.model;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45
import com.github.dockerjava.core.RemoteApiVersion;
56
import org.apache.commons.lang.builder.EqualsBuilder;
@@ -13,6 +14,7 @@
1314
/**
1415
* @since {@link RemoteApiVersion#VERSION_1_24}
1516
*/
17+
@JsonIgnoreProperties(ignoreUnknown = true)
1618
public class TaskSpec implements Serializable {
1719
public static final Long serialVersionUID = 1L;
1820

@@ -46,6 +48,14 @@ public class TaskSpec implements Serializable {
4648
@JsonProperty("LogDriver")
4749
private Driver logDriver;
4850

51+
/**
52+
* @since 1.24
53+
* a counter that triggers an update even if no relevant parameters have been changed
54+
* a random value will work if it is incrementing.
55+
*/
56+
@JsonProperty("ForceUpdate")
57+
private Integer forceUpdate;
58+
4959
/**
5060
* @see #containerSpec
5161
*/
@@ -126,6 +136,21 @@ public TaskSpec withLogDriver(Driver logDriver) {
126136
return this;
127137
}
128138

139+
/**
140+
* @see #forceUpdate
141+
*/
142+
@CheckForNull
143+
public Integer getForceUpdate() {
144+
return forceUpdate;
145+
}
146+
147+
/**
148+
* @see #forceUpdate
149+
*/
150+
public void setForceUpdate(Integer forceUpdate) {
151+
this.forceUpdate = forceUpdate;
152+
}
153+
129154
@Override
130155
public String toString() {
131156
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);

‎src/test/java/com/github/dockerjava/core/command/CreateServiceCmdExecTest.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
import org.testng.collections.Lists;
2222

2323
import java.lang.reflect.Method;
24+
import java.util.Arrays;
25+
import java.util.HashMap;
2426
import java.util.List;
27+
import java.util.Map;
2528

2629
import static org.hamcrest.MatcherAssert.assertThat;
30+
import static org.hamcrest.Matchers.containsString;
2731
import static org.hamcrest.Matchers.hasSize;
2832
import static org.hamcrest.Matchers.is;
33+
import static org.hamcrest.Matchers.notNullValue;
2934

3035
@Test(groups = "swarm-integration")
3136
public class CreateServiceCmdExecTest extends AbstractSwarmDockerClientTest {
@@ -59,11 +64,14 @@ public void testCreateService() throws DockerException {
5964
.withListenAddr("127.0.0.1")
6065
.withAdvertiseAddr("127.0.0.1")
6166
.exec();
62-
67+
List<String> command = Arrays.asList("sleep", "300");
68+
Map<String,String> labels=new HashMap<>();
69+
labels.put("com.docker.java.usage","test");
6370
dockerClient.createServiceCmd(new ServiceSpec()
6471
.withName(SERVICE_NAME)
72+
.withLabels(labels)
6573
.withTaskTemplate(new TaskSpec()
66-
.withContainerSpec(new ContainerSpec()
74+
.withContainerSpec(new ContainerSpec().withCommand(command)
6775
.withImage("busybox"))))
6876
.exec();
6977

@@ -72,7 +80,7 @@ public void testCreateService() throws DockerException {
7280
.exec();
7381

7482
assertThat(services, hasSize(1));
75-
83+
assertThat(services.get(0).getSpec().getLabels().get("com.docker.java.usage"), is("test"));
7684
dockerClient.removeServiceCmd(SERVICE_NAME).exec();
7785
}
7886

0 commit comments

Comments
 (0)