Skip to content

Commit 55e4869

Browse files
YoguKostyaSha
authored andcommitted
Add endpoints for Service in swarm mode
Fix service tests Add missing withDriver() method Fix json name of Networks in ServiceSpec Add tests to add network to services Do not fail on empty beans
1 parent 9a341ac commit 55e4869

File tree

67 files changed

+4121
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4121
-6
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.github.dockerjava.api.command.CreateContainerCmd;
1313
import com.github.dockerjava.api.command.CreateImageCmd;
1414
import com.github.dockerjava.api.command.CreateNetworkCmd;
15+
import com.github.dockerjava.api.command.CreateServiceCmd;
1516
import com.github.dockerjava.api.command.CreateVolumeCmd;
1617
import com.github.dockerjava.api.command.DisconnectFromNetworkCmd;
1718
import com.github.dockerjava.api.command.EventsCmd;
@@ -23,6 +24,7 @@
2324
import com.github.dockerjava.api.command.InspectExecCmd;
2425
import com.github.dockerjava.api.command.InspectImageCmd;
2526
import com.github.dockerjava.api.command.InspectNetworkCmd;
27+
import com.github.dockerjava.api.command.InspectServiceCmd;
2628
import com.github.dockerjava.api.command.InspectSwarmCmd;
2729
import com.github.dockerjava.api.command.InspectVolumeCmd;
2830
import com.github.dockerjava.api.command.JoinSwarmCmd;
@@ -31,6 +33,7 @@
3133
import com.github.dockerjava.api.command.ListContainersCmd;
3234
import com.github.dockerjava.api.command.ListImagesCmd;
3335
import com.github.dockerjava.api.command.ListNetworksCmd;
36+
import com.github.dockerjava.api.command.ListServicesCmd;
3437
import com.github.dockerjava.api.command.ListVolumesCmd;
3538
import com.github.dockerjava.api.command.LoadImageCmd;
3639
import com.github.dockerjava.api.command.LogContainerCmd;
@@ -41,6 +44,7 @@
4144
import com.github.dockerjava.api.command.RemoveContainerCmd;
4245
import com.github.dockerjava.api.command.RemoveImageCmd;
4346
import com.github.dockerjava.api.command.RemoveNetworkCmd;
47+
import com.github.dockerjava.api.command.RemoveServiceCmd;
4448
import com.github.dockerjava.api.command.RemoveVolumeCmd;
4549
import com.github.dockerjava.api.command.RenameContainerCmd;
4650
import com.github.dockerjava.api.command.RestartContainerCmd;
@@ -53,12 +57,14 @@
5357
import com.github.dockerjava.api.command.TopContainerCmd;
5458
import com.github.dockerjava.api.command.UnpauseContainerCmd;
5559
import com.github.dockerjava.api.command.UpdateContainerCmd;
60+
import com.github.dockerjava.api.command.UpdateServiceCmd;
5661
import com.github.dockerjava.api.command.UpdateSwarmCmd;
5762
import com.github.dockerjava.api.command.VersionCmd;
5863
import com.github.dockerjava.api.command.WaitContainerCmd;
5964
import com.github.dockerjava.api.exception.DockerException;
6065
import com.github.dockerjava.api.model.AuthConfig;
6166
import com.github.dockerjava.api.model.Identifier;
67+
import com.github.dockerjava.api.model.ServiceSpec;
6268
import com.github.dockerjava.api.model.SwarmSpec;
6369
import com.github.dockerjava.core.RemoteApiVersion;
6470

@@ -302,6 +308,45 @@ public interface DockerClient extends Closeable {
302308
*/
303309
UpdateSwarmCmd updateSwarmCmd(SwarmSpec swarmSpec);
304310

311+
/**
312+
* Command to list all services in a docker swarm. Only applicable if docker runs in swarm mode.
313+
*
314+
* @since {@link RemoteApiVersion#VERSION_1_24}
315+
* @return command
316+
*/
317+
ListServicesCmd listServicesCmd();
318+
319+
/**
320+
* Command to create a service in a docker swarm. Only applicable if docker runs in swarm mode.
321+
*
322+
* @since {@link RemoteApiVersion#VERSION_1_24}
323+
* @param serviceSpec the service specification
324+
* @return command
325+
*/
326+
CreateServiceCmd createServiceCmd(ServiceSpec serviceSpec);
327+
328+
/**
329+
* Command to inspect a service
330+
* @param serviceId service id or service name
331+
* @return command
332+
*/
333+
InspectServiceCmd inspectServiceCmd(String serviceId);
334+
335+
/**
336+
* Command to update a service specification
337+
* @param serviceId service id
338+
* @param serviceSpec the new service specification
339+
* @return command
340+
*/
341+
UpdateServiceCmd updateServiceCmd(String serviceId, ServiceSpec serviceSpec);
342+
343+
/**
344+
* Command to remove a service
345+
* @param serviceId service id or service name
346+
* @return command
347+
*/
348+
RemoveServiceCmd removeServiceCmd(String serviceId);
349+
305350
@Override
306351
void close() throws IOException;
307352

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.ConflictException;
4+
import com.github.dockerjava.api.model.ServiceSpec;
5+
import com.github.dockerjava.core.RemoteApiVersion;
6+
7+
import javax.annotation.CheckForNull;
8+
9+
/**
10+
* Command to create a new service
11+
*
12+
* @since {@link RemoteApiVersion#VERSION_1_24}
13+
*/
14+
public interface CreateServiceCmd extends SyncDockerCmd<CreateServiceResponse> {
15+
16+
@CheckForNull
17+
ServiceSpec getServiceSpec();
18+
19+
CreateServiceCmd withServiceSpec(ServiceSpec serviceSpec);
20+
21+
/**
22+
* @throws ConflictException
23+
* Named service already exists
24+
*/
25+
@Override
26+
CreateServiceResponse exec() throws ConflictException;
27+
28+
interface Exec extends DockerCmdSyncExec<CreateServiceCmd, CreateServiceResponse> {
29+
}
30+
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
6+
import org.apache.commons.lang.builder.ToStringStyle;
7+
8+
/**
9+
* The response of a {@link CreateServiceCmd}
10+
*/
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
public class CreateServiceResponse {
13+
@JsonProperty("ID")
14+
private String id;
15+
16+
public String getId() {
17+
return id;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
23+
}
24+
}

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,43 @@ public interface DockerCmdExecFactory extends Closeable {
128128

129129
UpdateSwarmCmd.Exec createUpdateSwarmCmdExec();
130130

131+
/**
132+
* Command to list all services in a docker swarm. Only applicable if docker runs in swarm mode.
133+
*
134+
* @since {@link RemoteApiVersion#VERSION_1_24}
135+
*/
136+
ListServicesCmd.Exec createListServicesCmdExec();
137+
138+
/**
139+
* Command to create a new service in a docker swarm. Only applicable if docker runs in swarm mode.
140+
*
141+
* @since {@link RemoteApiVersion#VERSION_1_24}
142+
*/
143+
CreateServiceCmd.Exec createCreateServiceCmdExec();
144+
145+
/**
146+
* Command to inspect a service in a docker swarm. Only applicable if docker runs in swarm mode.
147+
*
148+
* @since {@link RemoteApiVersion#VERSION_1_24}
149+
*/
150+
InspectServiceCmd.Exec createInspectServiceCmdExec();
151+
152+
/**
153+
* Command to update a service specification in a docker swarm. Only applicable if docker runs in swarm mode.
154+
*
155+
* @since {@link RemoteApiVersion#VERSION_1_24}
156+
*/
157+
UpdateServiceCmd.Exec createUpdateServiceCmdExec();
158+
159+
/**
160+
* Command to remove a service in a docker swarm. Only applicable if docker runs in swarm mode.
161+
*
162+
* @since {@link RemoteApiVersion#VERSION_1_24}
163+
*/
164+
RemoveServiceCmd.Exec createRemoveServiceCmdExec();
165+
131166
// nodes
167+
132168
/**
133169
* List all nodes. Node operations require the engine to be part of a swarm
134170
*
@@ -158,8 +194,6 @@ public interface DockerCmdExecFactory extends Closeable {
158194
UpdateSwarmNodeCmd.Exec updateSwarmNodeCmdExec();
159195

160196

161-
162-
163197
@Override
164198
void close() throws IOException;
165199

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.NotFoundException;
4+
import com.github.dockerjava.api.model.Service;
5+
6+
import javax.annotation.CheckForNull;
7+
import javax.annotation.Nonnull;
8+
9+
public interface InspectServiceCmd extends SyncDockerCmd<Service> {
10+
11+
@CheckForNull
12+
String getServiceId();
13+
14+
InspectServiceCmd withServiceId(@Nonnull String serviceId);
15+
16+
/**
17+
* @throws NotFoundException
18+
* No such service
19+
*/
20+
@Override
21+
Service exec() throws NotFoundException;
22+
23+
interface Exec extends DockerCmdSyncExec<InspectServiceCmd, Service> {
24+
}
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.model.Service;
4+
import com.github.dockerjava.core.RemoteApiVersion;
5+
6+
import javax.annotation.CheckForNull;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
/**
11+
* Command to list all services in a docker swarm. Only applicable if docker runs in swarm mode.
12+
*
13+
* @since {@link RemoteApiVersion#VERSION_1_24}
14+
*/
15+
public interface ListServicesCmd extends SyncDockerCmd<List<Service>> {
16+
17+
@CheckForNull
18+
Map<String, List<String>> getFilters();
19+
20+
/**
21+
* @param ids
22+
* - Show only services with the given ids
23+
*/
24+
ListServicesCmd withIdFilter(List<String> ids);
25+
/**
26+
*
27+
* @param names
28+
* - Show only services with the given names
29+
*/
30+
ListServicesCmd withNameFilter(List<String> names);
31+
32+
interface Exec extends DockerCmdSyncExec<ListServicesCmd, List<Service>> {
33+
}
34+
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.exception.NotFoundException;
4+
5+
import javax.annotation.CheckForNull;
6+
import javax.annotation.Nonnull;
7+
8+
/**
9+
* Remove a service.
10+
*/
11+
public interface RemoveServiceCmd extends SyncDockerCmd<Void> {
12+
13+
@CheckForNull
14+
String getServiceId();
15+
16+
RemoveServiceCmd withServiceId(@Nonnull String serviceId);
17+
18+
/**
19+
* @throws NotFoundException
20+
* No such service
21+
*/
22+
@Override
23+
Void exec() throws NotFoundException;
24+
25+
interface Exec extends DockerCmdSyncExec<RemoveServiceCmd, Void> {
26+
}
27+
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.dockerjava.api.command;
2+
3+
import com.github.dockerjava.api.model.ServiceSpec;
4+
import com.github.dockerjava.core.RemoteApiVersion;
5+
6+
import javax.annotation.CheckForNull;
7+
import javax.annotation.Nonnull;
8+
9+
/**
10+
* @since {@link RemoteApiVersion#VERSION_1_24}
11+
*/
12+
public interface UpdateServiceCmd extends SyncDockerCmd<Void> {
13+
@CheckForNull
14+
String getServiceId();
15+
16+
UpdateServiceCmd withServiceId(@Nonnull String serviceId);
17+
18+
@CheckForNull
19+
ServiceSpec getServiceSpec();
20+
21+
UpdateServiceCmd withServiceSpec(ServiceSpec serviceSpec);
22+
23+
@CheckForNull
24+
Long getVersion();
25+
26+
UpdateServiceCmd withVersion(Long version);
27+
28+
interface Exec extends DockerCmdSyncExec<UpdateServiceCmd, Void> {
29+
}
30+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.github.dockerjava.core.RemoteApiVersion;
5+
import org.apache.commons.lang.builder.EqualsBuilder;
6+
import org.apache.commons.lang.builder.HashCodeBuilder;
7+
import org.apache.commons.lang.builder.ToStringBuilder;
8+
import org.apache.commons.lang.builder.ToStringStyle;
9+
10+
import java.io.Serializable;
11+
12+
/**
13+
* @since {@link RemoteApiVersion#VERSION_1_24}
14+
*/
15+
public class BindOptions implements Serializable {
16+
private static final long serialVersionUID = 1L;
17+
18+
/**
19+
* @since 1.24
20+
*/
21+
@JsonProperty("Propagation")
22+
BindPropagation propagation;
23+
24+
/**
25+
* @see #propagation
26+
*/
27+
public BindPropagation getPropagation() {
28+
return propagation;
29+
}
30+
31+
/**
32+
* @see #propagation
33+
*/
34+
public BindOptions withPropagation(BindPropagation propagation) {
35+
this.propagation = propagation;
36+
return this;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
42+
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
return EqualsBuilder.reflectionEquals(this, o);
47+
}
48+
49+
@Override
50+
public int hashCode() {
51+
return HashCodeBuilder.reflectionHashCode(this);
52+
}
53+
54+
}

0 commit comments

Comments
 (0)