Skip to content

Commit e80848b

Browse files
fengxxKostyaSha
authored andcommitted
update docker service related model (docker-java#917)
* add JsonIgnoreProperties(ignoreUnknown = true) add labels and forceUpdate add PortConfig.PublishMode change command from String to List<String> * use uppercase name for enum * update test * support ListTasksCmd * add Platforms to ServicePlacement, supported in v1.30
1 parent d6941ba commit e80848b

28 files changed

+1038
-8
lines changed

src/main/java/com/github/dockerjava/api/DockerClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.github.dockerjava.api.command.ListImagesCmd;
3535
import com.github.dockerjava.api.command.ListNetworksCmd;
3636
import com.github.dockerjava.api.command.ListServicesCmd;
37+
import com.github.dockerjava.api.command.ListTasksCmd;
3738
import com.github.dockerjava.api.command.ListVolumesCmd;
3839
import com.github.dockerjava.api.command.LoadImageCmd;
3940
import com.github.dockerjava.api.command.LogContainerCmd;
@@ -347,6 +348,14 @@ public interface DockerClient extends Closeable {
347348
*/
348349
RemoveServiceCmd removeServiceCmd(String serviceId);
349350

351+
/**
352+
* List tasks in the swarm cluster
353+
*
354+
* @return the command
355+
* @since 1.24
356+
*/
357+
ListTasksCmd listTasksCmd();
358+
350359
@Override
351360
void close() throws IOException;
352361

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ public interface DockerCmdExecFactory extends Closeable {
193193
*/
194194
UpdateSwarmNodeCmd.Exec updateSwarmNodeCmdExec();
195195

196+
/**
197+
* Update a node. Node operations require the engine to be part of a swarm
198+
*
199+
* @since {@link RemoteApiVersion#VERSION_1_24}
200+
*/
201+
ListTasksCmd.Exec listTasksCmdExec();
196202

197203
@Override
198204
void close() throws IOException;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.NotFoundException;
4+
import com.github.dockerjava.api.model.Task;
5+
6+
import javax.annotation.CheckForNull;
7+
8+
public interface InspectTaskCmd extends SyncDockerCmd<Task> {
9+
@CheckForNull
10+
String getTaskId();
11+
12+
InspectTaskCmd withTaskId();
13+
14+
@Override
15+
Task exec() throws NotFoundException;
16+
17+
interface Exec extends DockerCmdSyncExec<InspectTaskCmd, Task> {
18+
}
19+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.NotFoundException;
4+
import com.github.dockerjava.api.model.Task;
5+
import com.github.dockerjava.api.model.TaskState;
6+
7+
import javax.annotation.CheckForNull;
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
public interface ListTasksCmd extends SyncDockerCmd<List<Task>> {
12+
@CheckForNull
13+
Map<String, List<String>> getFilters();
14+
15+
/**
16+
* @param labels - Show only tasks with the passed labels.
17+
* Labels is a {@link Map} that contains label keys and values
18+
*/
19+
ListTasksCmd withLabelFilter(Map<String, String> labels);
20+
21+
/**
22+
* @param labels - Show only tasks with the passed labels.
23+
*/
24+
ListTasksCmd withLabelFilter(String... labels);
25+
26+
/**
27+
* @param ids Task id(s)
28+
*/
29+
ListTasksCmd withIdFilter(String... ids);
30+
31+
/**
32+
* @param names Task name(s)
33+
*/
34+
ListTasksCmd withNameFilter(String... names);
35+
36+
/**
37+
* @param nodeNames Node id(s) or name(s)
38+
*/
39+
ListTasksCmd withNodeFilter(String... nodeNames);
40+
41+
/**
42+
* @param serviceNames Service name(s)
43+
*/
44+
ListTasksCmd withServiceFilter(String... serviceNames);
45+
46+
/**
47+
* @param desiredState The desired-state filter can take the values running, shutdown, or accepted.
48+
*/
49+
ListTasksCmd withStateFilter(TaskState... desiredState);
50+
51+
@Override
52+
List<Task> exec() throws NotFoundException;
53+
54+
interface Exec extends DockerCmdSyncExec<ListTasksCmd, List<Task>> {
55+
}
56+
}

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
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import java.io.Serializable;
4+
5+
public class DiscreteResourceSpec extends GenericResource<String> implements Serializable {
6+
private static final long serialVersionUID = 1L;
7+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.io.Serializable;
6+
7+
public abstract class GenericResource<T> implements Serializable {
8+
private static final long serialVersionUID = 1L;
9+
10+
@JsonProperty("Kind")
11+
String kind;
12+
@JsonProperty("Value")
13+
T value = null;
14+
15+
public String getKind() {
16+
return kind;
17+
}
18+
19+
public GenericResource withKind(String kind) {
20+
this.kind = kind;
21+
return this;
22+
}
23+
24+
public T getValue() {
25+
return value;
26+
}
27+
28+
public GenericResource withValue(T value) {
29+
this.value = value;
30+
return this;
31+
}
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.github.dockerjava.core.RemoteApiVersion;
6+
7+
import java.io.Serializable;
8+
9+
/**
10+
* @since {@link RemoteApiVersion#VERSION_1_24}
11+
*/
12+
@JsonIgnoreProperties(ignoreUnknown = true)
13+
@JsonInclude(JsonInclude.Include.NON_NULL)
14+
public class NamedResourceSpec extends GenericResource<Integer> implements Serializable {
15+
private static final long serialVersionUID = 1L;
16+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.github.dockerjava.core.RemoteApiVersion;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* @since {@link RemoteApiVersion#VERSION_1_24}
12+
* The version number of the object such as node, service, etc. This is needed to avoid conflicting writes.
13+
* The client must send the version number along with the modified specification when updating these objects.
14+
* This approach ensures safe concurrency and determinism in that the change on the object may not be applied
15+
* if the version number has changed from the last read. In other words, if two update requests specify the
16+
* same base version, only one of the requests can succeed. As a result, two separate update requests that
17+
* happen at the same time will not unintentionally overwrite each other.
18+
*/
19+
@JsonIgnoreProperties(ignoreUnknown = true)
20+
@JsonInclude(JsonInclude.Include.NON_NULL)
21+
public class ObjectVersion implements Serializable {
22+
private static final long serialVersionUID = 1L;
23+
24+
@JsonProperty("Index")
25+
private Integer index = null;
26+
27+
public Integer getIndex() {
28+
return index;
29+
}
30+
31+
public ObjectVersion withIndex(Integer index) {
32+
this.index = index;
33+
return this;
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return String.valueOf(index);
39+
}
40+
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public class PortConfig implements Serializable {
4040
@JsonProperty("PublishedPort")
4141
private int publishedPort;
4242

43+
/**
44+
* @since 1.25
45+
* docker 1.13
46+
* https://github.com/mrjana/docker/blob/14ac9f60d0174256e0713701ebffaf5ca827da71/api/types/swarm/network.go
47+
*/
48+
@JsonProperty("PublishMode")
49+
private PublishMode publishMode;
50+
4351
/**
4452
* @see #name
4553
*/
@@ -103,6 +111,16 @@ public PortConfig withPublishedPort(int publishedPort) {
103111
return this;
104112
}
105113

114+
@CheckForNull
115+
public PublishMode getPublishMode() {
116+
return publishMode;
117+
}
118+
119+
public PortConfig withPublishMode(PublishMode publishMode) {
120+
this.publishMode = publishMode;
121+
return this;
122+
}
123+
106124
@Override
107125
public String toString() {
108126
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
@@ -117,4 +135,13 @@ public boolean equals(Object o) {
117135
public int hashCode() {
118136
return HashCodeBuilder.reflectionHashCode(this);
119137
}
138+
139+
public enum PublishMode {
140+
//ingress load balancing using routing mesh.
141+
@JsonProperty("ingress")
142+
ingress,
143+
//direct host level access on the host where the task is running.
144+
@JsonProperty("host")
145+
host
146+
}
120147
}

0 commit comments

Comments
 (0)