Skip to content

Commit 2027416

Browse files
authored
Merge pull request #717 from docker-java/swarm
Swarm branch to future 3.1.0 master
2 parents 8463994 + b707758 commit 2027416

File tree

182 files changed

+9920
-141
lines changed

Some content is hidden

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

182 files changed

+9920
-141
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ env:
2323

2424
matrix:
2525
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="17.05.0~ce-0~ubuntu-trusty" DEPLOY=true COVERITY=true
26+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2377" DOCKER_VERSION="17.05.0~ce-0~ubuntu-trusty" SWARM_VERSION="1.2.6"
2627
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="17.05.0~ce-0~ubuntu-trusty"
28+
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2377" DOCKER_VERSION="1.13.1-0~ubuntu-trusty" SWARM_VERSION="1.2.6"
2729
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.13.1-0~ubuntu-trusty"
2830
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.13.1-0~ubuntu-trusty"
2931
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.12.6-0~ubuntu-trusty"

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@
430430
<version>${maven-surefire-plugin.version}</version>
431431
<configuration>
432432
<rerunFailingTestsCount>3</rerunFailingTestsCount>
433-
<excludedGroups>integration,integration-auth</excludedGroups>
433+
<excludedGroups>integration,integration-auth,swarm-integration</excludedGroups>
434434
</configuration>
435435
</plugin>
436436

@@ -450,7 +450,7 @@
450450
<perCoreThreadCount>true</perCoreThreadCount>
451451
<threadCount>1</threadCount>
452452
<groups>integration</groups>
453-
<excludedGroups>integration-auth</excludedGroups>
453+
<excludedGroups>integration-auth,swarm-integration</excludedGroups>
454454
<includes>
455455
<include>**/*Test.java</include>
456456
</includes>

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

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

3-
import java.io.Closeable;
4-
import java.io.File;
5-
import java.io.IOException;
6-
import java.io.InputStream;
7-
8-
import javax.annotation.Nonnull;
9-
103
import com.github.dockerjava.api.command.AttachContainerCmd;
114
import com.github.dockerjava.api.command.AuthCmd;
125
import com.github.dockerjava.api.command.BuildImageCmd;
@@ -19,21 +12,28 @@
1912
import com.github.dockerjava.api.command.CreateContainerCmd;
2013
import com.github.dockerjava.api.command.CreateImageCmd;
2114
import com.github.dockerjava.api.command.CreateNetworkCmd;
15+
import com.github.dockerjava.api.command.CreateServiceCmd;
2216
import com.github.dockerjava.api.command.CreateVolumeCmd;
2317
import com.github.dockerjava.api.command.DisconnectFromNetworkCmd;
2418
import com.github.dockerjava.api.command.EventsCmd;
2519
import com.github.dockerjava.api.command.ExecCreateCmd;
2620
import com.github.dockerjava.api.command.ExecStartCmd;
2721
import com.github.dockerjava.api.command.InfoCmd;
22+
import com.github.dockerjava.api.command.InitializeSwarmCmd;
2823
import com.github.dockerjava.api.command.InspectContainerCmd;
2924
import com.github.dockerjava.api.command.InspectExecCmd;
3025
import com.github.dockerjava.api.command.InspectImageCmd;
3126
import com.github.dockerjava.api.command.InspectNetworkCmd;
27+
import com.github.dockerjava.api.command.InspectServiceCmd;
28+
import com.github.dockerjava.api.command.InspectSwarmCmd;
3229
import com.github.dockerjava.api.command.InspectVolumeCmd;
30+
import com.github.dockerjava.api.command.JoinSwarmCmd;
3331
import com.github.dockerjava.api.command.KillContainerCmd;
32+
import com.github.dockerjava.api.command.LeaveSwarmCmd;
3433
import com.github.dockerjava.api.command.ListContainersCmd;
3534
import com.github.dockerjava.api.command.ListImagesCmd;
3635
import com.github.dockerjava.api.command.ListNetworksCmd;
36+
import com.github.dockerjava.api.command.ListServicesCmd;
3737
import com.github.dockerjava.api.command.ListVolumesCmd;
3838
import com.github.dockerjava.api.command.LoadImageCmd;
3939
import com.github.dockerjava.api.command.LogContainerCmd;
@@ -44,7 +44,9 @@
4444
import com.github.dockerjava.api.command.RemoveContainerCmd;
4545
import com.github.dockerjava.api.command.RemoveImageCmd;
4646
import com.github.dockerjava.api.command.RemoveNetworkCmd;
47+
import com.github.dockerjava.api.command.RemoveServiceCmd;
4748
import com.github.dockerjava.api.command.RemoveVolumeCmd;
49+
import com.github.dockerjava.api.command.RenameContainerCmd;
4850
import com.github.dockerjava.api.command.RestartContainerCmd;
4951
import com.github.dockerjava.api.command.SaveImageCmd;
5052
import com.github.dockerjava.api.command.SearchImagesCmd;
@@ -55,14 +57,23 @@
5557
import com.github.dockerjava.api.command.TopContainerCmd;
5658
import com.github.dockerjava.api.command.UnpauseContainerCmd;
5759
import com.github.dockerjava.api.command.UpdateContainerCmd;
60+
import com.github.dockerjava.api.command.UpdateServiceCmd;
61+
import com.github.dockerjava.api.command.UpdateSwarmCmd;
5862
import com.github.dockerjava.api.command.VersionCmd;
5963
import com.github.dockerjava.api.command.WaitContainerCmd;
60-
import com.github.dockerjava.api.command.RenameContainerCmd;
6164
import com.github.dockerjava.api.exception.DockerException;
6265
import com.github.dockerjava.api.model.AuthConfig;
6366
import com.github.dockerjava.api.model.Identifier;
67+
import com.github.dockerjava.api.model.ServiceSpec;
68+
import com.github.dockerjava.api.model.SwarmSpec;
6469
import com.github.dockerjava.core.RemoteApiVersion;
6570

71+
import javax.annotation.Nonnull;
72+
import java.io.Closeable;
73+
import java.io.File;
74+
import java.io.IOException;
75+
import java.io.InputStream;
76+
6677
// https://godoc.org/github.com/fsouza/go-dockerclient
6778
public interface DockerClient extends Closeable {
6879

@@ -255,6 +266,87 @@ public interface DockerClient extends Closeable {
255266

256267
DisconnectFromNetworkCmd disconnectFromNetworkCmd();
257268

269+
/**
270+
* Enables swarm mode for the docker engine and creates a new swarm cluster
271+
*
272+
* @since 1.24
273+
* @param swarmSpec the specification for the swarm
274+
* @return the command
275+
*/
276+
InitializeSwarmCmd initializeSwarmCmd(SwarmSpec swarmSpec);
277+
278+
/**
279+
* Gets information about the swarm the docker engine is currently in
280+
*
281+
* @since 1.24
282+
* @return the command
283+
*/
284+
InspectSwarmCmd inspectSwarmCmd();
285+
286+
/**
287+
* Enables swarm mode for the docker engine and joins an existing swarm cluster
288+
*
289+
* @since 1.24
290+
* @return the command
291+
*/
292+
JoinSwarmCmd joinSwarmCmd();
293+
294+
/**
295+
* Disables swarm node for the docker engine and leaves the swarm cluster
296+
*
297+
* @since 1.24
298+
* @return the command
299+
*/
300+
LeaveSwarmCmd leaveSwarmCmd();
301+
302+
/**
303+
* Updates the swarm specification
304+
*
305+
* @since 1.24
306+
* @param swarmSpec the specification for the swarm
307+
* @return the command
308+
*/
309+
UpdateSwarmCmd updateSwarmCmd(SwarmSpec swarmSpec);
310+
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+
258350
@Override
259351
void close() throws IOException;
260352

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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,83 @@ public interface DockerCmdExecFactory extends Closeable {
117117

118118
DisconnectFromNetworkCmd.Exec createDisconnectFromNetworkCmdExec();
119119

120+
// swarm
121+
InitializeSwarmCmd.Exec createInitializeSwarmCmdExec();
122+
123+
InspectSwarmCmd.Exec createInspectSwarmCmdExec();
124+
125+
JoinSwarmCmd.Exec createJoinSwarmCmdExec();
126+
127+
LeaveSwarmCmd.Exec createLeaveSwarmCmdExec();
128+
129+
UpdateSwarmCmd.Exec createUpdateSwarmCmdExec();
130+
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+
166+
// nodes
167+
168+
/**
169+
* List all nodes. Node operations require the engine to be part of a swarm
170+
*
171+
* @since {@link RemoteApiVersion#VERSION_1_24}
172+
*/
173+
ListSwarmNodesCmd.Exec listSwarmNodeCmdExec();
174+
175+
/**
176+
* Return low-level information on the node. Node operations require the engine to be part of a swarm
177+
*
178+
* @since {@link RemoteApiVersion#VERSION_1_24}
179+
*/
180+
InspectSwarmNodeCmd.Exec inspectSwarmNodeCmdExec();
181+
182+
/**
183+
* Remove a node from the swarm. Node operations require the engine to be part of a swarm
184+
*
185+
* @since {@link RemoteApiVersion#VERSION_1_24}
186+
*/
187+
RemoveSwarmNodeCmd.Exec removeSwarmNodeCmdExec();
188+
189+
/**
190+
* Update a node. Node operations require the engine to be part of a swarm
191+
*
192+
* @since {@link RemoteApiVersion#VERSION_1_24}
193+
*/
194+
UpdateSwarmNodeCmd.Exec updateSwarmNodeCmdExec();
195+
196+
120197
@Override
121198
void close() throws IOException;
122199

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.dockerjava.api.command;
2+
3+
4+
import com.github.dockerjava.api.model.SwarmSpec;
5+
6+
import javax.annotation.CheckForNull;
7+
8+
public interface InitializeSwarmCmd extends SyncDockerCmd<Void> {
9+
10+
@CheckForNull
11+
String getListenAddr();
12+
13+
InitializeSwarmCmd withListenAddr(String listenAddr);
14+
15+
@CheckForNull
16+
String getAdvertiseAddr();
17+
18+
InitializeSwarmCmd withAdvertiseAddr(String advertiseAddr);
19+
20+
@CheckForNull
21+
Boolean isForceNewCluster();
22+
23+
InitializeSwarmCmd withForceNewCluster(Boolean forceNewCluster);
24+
25+
@CheckForNull
26+
SwarmSpec getSwarmSpec();
27+
28+
InitializeSwarmCmd withSwarmSpec(SwarmSpec swarmSpec);
29+
30+
@Override
31+
Void exec();
32+
33+
interface Exec extends DockerCmdSyncExec<InitializeSwarmCmd, Void> {
34+
35+
}
36+
}
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+
}

0 commit comments

Comments
 (0)