Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 599aeb7

Browse filesBrowse files
ziminghua訾明华bsideup
authored
add RemoveSwarmNodeCmd (docker-java#1735)
* add missing cmd `RemoveSwarmNodeCmd` in client * Update docker-java/src/test/java/com/github/dockerjava/cmd/swarm/RemoveSwarmNodeCmdExecIT.java Co-authored-by: Sergei Egorov <bsideup@gmail.com> * Update docker-java/src/test/java/com/github/dockerjava/cmd/swarm/RemoveSwarmNodeCmdExecIT.java Co-authored-by: Sergei Egorov <bsideup@gmail.com> * force remove node Co-authored-by: 訾明华 <zmh01@digibird.com.cn> Co-authored-by: Sergei Egorov <bsideup@gmail.com>
1 parent 8e77a69 commit 599aeb7
Copy full SHA for 599aeb7

6 files changed

+71-4Lines changed: 71 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docker-java-api/src/main/java/com/github/dockerjava/api/DockerClient.java‎

Copy file name to clipboardExpand all lines: docker-java-api/src/main/java/com/github/dockerjava/api/DockerClient.java
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.github.dockerjava.api.command.RemoveNetworkCmd;
5757
import com.github.dockerjava.api.command.RemoveSecretCmd;
5858
import com.github.dockerjava.api.command.RemoveServiceCmd;
59+
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
5960
import com.github.dockerjava.api.command.RemoveVolumeCmd;
6061
import com.github.dockerjava.api.command.RenameContainerCmd;
6162
import com.github.dockerjava.api.command.ResizeContainerCmd;
@@ -342,6 +343,15 @@ public interface DockerClient extends Closeable {
342343
*/
343344
UpdateSwarmNodeCmd updateSwarmNodeCmd();
344345

346+
/**
347+
* Remove the swarm node
348+
*
349+
* @param swarmNodeId swarmNodeId
350+
* @return the command
351+
* @since 1.24
352+
*/
353+
RemoveSwarmNodeCmd removeSwarmNodeCmd(String swarmNodeId);
354+
345355
/**
346356
* List nodes in swarm
347357
*
Collapse file

‎docker-java-api/src/main/java/com/github/dockerjava/api/DockerClientDelegate.java‎

Copy file name to clipboardExpand all lines: docker-java-api/src/main/java/com/github/dockerjava/api/DockerClientDelegate.java
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.github.dockerjava.api.command.RemoveNetworkCmd;
5757
import com.github.dockerjava.api.command.RemoveSecretCmd;
5858
import com.github.dockerjava.api.command.RemoveServiceCmd;
59+
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
5960
import com.github.dockerjava.api.command.RemoveVolumeCmd;
6061
import com.github.dockerjava.api.command.RenameContainerCmd;
6162
import com.github.dockerjava.api.command.ResizeContainerCmd;
@@ -423,6 +424,11 @@ public UpdateSwarmNodeCmd updateSwarmNodeCmd() {
423424
return getDockerClient().updateSwarmNodeCmd();
424425
}
425426

427+
@Override
428+
public RemoveSwarmNodeCmd removeSwarmNodeCmd(String swarmNodeId) {
429+
return getDockerClient().removeSwarmNodeCmd(swarmNodeId);
430+
}
431+
426432
@Override
427433
public ListSwarmNodesCmd listSwarmNodesCmd() {
428434
return getDockerClient().listSwarmNodesCmd();
Collapse file

‎docker-java-api/src/main/java/com/github/dockerjava/api/command/RemoveSwarmNodeCmd.java‎

Copy file name to clipboardExpand all lines: docker-java-api/src/main/java/com/github/dockerjava/api/command/RemoveSwarmNodeCmd.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface RemoveSwarmNodeCmd extends SyncDockerCmd<Void> {
1818
@CheckForNull
1919
Boolean hasForceEnabled();
2020

21-
RemoveSwarmNodeCmd withContainerId(@Nonnull String containerId);
21+
RemoveSwarmNodeCmd withSwarmNodeId(@Nonnull String swarmNodeId);
2222

2323
RemoveSwarmNodeCmd withForce(Boolean force);
2424

Collapse file

‎docker-java-core/src/main/java/com/github/dockerjava/core/DockerClientImpl.java‎

Copy file name to clipboardExpand all lines: docker-java-core/src/main/java/com/github/dockerjava/core/DockerClientImpl.java
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.github.dockerjava.api.command.RemoveNetworkCmd;
5959
import com.github.dockerjava.api.command.RemoveSecretCmd;
6060
import com.github.dockerjava.api.command.RemoveServiceCmd;
61+
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
6162
import com.github.dockerjava.api.command.RemoveVolumeCmd;
6263
import com.github.dockerjava.api.command.RenameContainerCmd;
6364
import com.github.dockerjava.api.command.ResizeContainerCmd;
@@ -140,6 +141,7 @@
140141
import com.github.dockerjava.core.command.RemoveNetworkCmdImpl;
141142
import com.github.dockerjava.core.command.RemoveSecretCmdImpl;
142143
import com.github.dockerjava.core.command.RemoveServiceCmdImpl;
144+
import com.github.dockerjava.core.command.RemoveSwarmNodeCmdImpl;
143145
import com.github.dockerjava.core.command.RemoveVolumeCmdImpl;
144146
import com.github.dockerjava.core.command.RenameContainerCmdImpl;
145147
import com.github.dockerjava.core.command.ResizeContainerCmdImpl;
@@ -616,6 +618,11 @@ public UpdateSwarmNodeCmd updateSwarmNodeCmd() {
616618
return new UpdateSwarmNodeCmdImpl(getDockerCmdExecFactory().updateSwarmNodeCmdExec());
617619
}
618620

621+
@Override
622+
public RemoveSwarmNodeCmd removeSwarmNodeCmd(String swarmNodeId) {
623+
return new RemoveSwarmNodeCmdImpl(getDockerCmdExecFactory().removeSwarmNodeCmdExec(), swarmNodeId);
624+
}
625+
619626
@Override
620627
public ListSwarmNodesCmd listSwarmNodesCmd() {
621628
return new ListSwarmNodesCmdImpl(getDockerCmdExecFactory().listSwarmNodeCmdExec());
Collapse file

‎docker-java-core/src/main/java/com/github/dockerjava/core/command/RemoveSwarmNodeCmdImpl.java‎

Copy file name to clipboardExpand all lines: docker-java-core/src/main/java/com/github/dockerjava/core/command/RemoveSwarmNodeCmdImpl.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class RemoveSwarmNodeCmdImpl extends AbstrDockerCmd<RemoveSwarmNodeCmd, V
1717

1818
private Boolean force;
1919

20-
public RemoveSwarmNodeCmdImpl(RemoveSwarmNodeCmd.Exec exec, String containerId) {
20+
public RemoveSwarmNodeCmdImpl(RemoveSwarmNodeCmd.Exec exec, String swarmNodeId) {
2121
super(exec);
22-
withContainerId(containerId);
22+
withSwarmNodeId(swarmNodeId);
2323
}
2424

2525
@Override
@@ -35,7 +35,7 @@ public Boolean hasForceEnabled() {
3535
}
3636

3737
@Override
38-
public RemoveSwarmNodeCmd withContainerId(@Nonnull String swarmNodeId) {
38+
public RemoveSwarmNodeCmd withSwarmNodeId(@Nonnull String swarmNodeId) {
3939
checkNotNull(swarmNodeId, "swarmNodeId was not specified");
4040
this.swarmNodeId = swarmNodeId;
4141
return this;
Collapse file
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.github.dockerjava.cmd.swarm;
2+
3+
import com.github.dockerjava.api.DockerClient;
4+
import com.github.dockerjava.api.model.Swarm;
5+
import com.github.dockerjava.api.model.SwarmNode;
6+
import com.github.dockerjava.api.model.SwarmNodeRole;
7+
import com.google.common.collect.Lists;
8+
import org.junit.Test;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
import java.util.List;
13+
import java.util.Optional;
14+
15+
import static org.hamcrest.MatcherAssert.assertThat;
16+
import static org.hamcrest.Matchers.is;
17+
18+
public class RemoveSwarmNodeCmdExecIT extends SwarmCmdIT {
19+
20+
private static final Logger LOGGER = LoggerFactory.getLogger(RemoveSwarmNodeCmdExecIT.class);
21+
22+
@Test
23+
public void testRemoveSwarmNode() throws Exception {
24+
DockerClient dockerClient = startSwarm();
25+
Swarm swarm = dockerClient.inspectSwarmCmd().exec();
26+
27+
DockerClient docker2 = startDockerInDocker();
28+
docker2.joinSwarmCmd()
29+
.withRemoteAddrs(Lists.newArrayList("docker1"))
30+
.withJoinToken(swarm.getJoinTokens().getWorker())
31+
.exec();
32+
LOGGER.info("docker2 joined docker's swarm");
33+
34+
List<SwarmNode> nodes = dockerClient.listSwarmNodesCmd().exec();
35+
assertThat(2, is(nodes.size()));
36+
Optional<SwarmNode> firstWorkNode = nodes.stream().filter(node -> node.getSpec().getRole() == SwarmNodeRole.WORKER)
37+
.findFirst();
38+
dockerClient.removeSwarmNodeCmd(firstWorkNode.get().getId())
39+
.withForce(true)
40+
.exec();
41+
nodes = dockerClient.listSwarmNodesCmd().exec();
42+
assertThat(nodes.size(), is(1));
43+
}
44+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.