Skip to content

Commit 4da8b8c

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 d0d842f commit 4da8b8c

File tree

64 files changed

+3984
-3
lines changed

Some content is hidden

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

64 files changed

+3984
-3
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

@@ -298,6 +304,45 @@ public interface DockerClient extends Closeable {
298304
*/
299305
UpdateSwarmCmd updateSwarmCmd(SwarmSpec swarmSpec);
300306

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

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+
}
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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.github.dockerjava.core.RemoteApiVersion;
5+
6+
/**
7+
* @since {@link RemoteApiVersion#VERSION_1_24}
8+
*/
9+
public enum BindPropagation {
10+
@JsonProperty("rprivate")
11+
R_PRIVATE,
12+
13+
@JsonProperty("private")
14+
PRIVATE,
15+
16+
@JsonProperty("rshared")
17+
R_SHARED,
18+
19+
@JsonProperty("shared")
20+
SHARED,
21+
22+
@JsonProperty("rslave")
23+
R_SLAVE,
24+
25+
@JsonProperty("slave")
26+
SLAVE
27+
}

0 commit comments

Comments
 (0)