Skip to content

add missing cmd RemoveSwarmNodeCmd in client #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.github.dockerjava.api.command.RemoveNetworkCmd;
import com.github.dockerjava.api.command.RemoveSecretCmd;
import com.github.dockerjava.api.command.RemoveServiceCmd;
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
import com.github.dockerjava.api.command.RemoveVolumeCmd;
import com.github.dockerjava.api.command.RenameContainerCmd;
import com.github.dockerjava.api.command.ResizeContainerCmd;
Expand Down Expand Up @@ -342,6 +343,15 @@ public interface DockerClient extends Closeable {
*/
UpdateSwarmNodeCmd updateSwarmNodeCmd();

/**
* Remove the swarm node
*
* @param swarmNodeId swarmNodeId
* @return the command
* @since 1.24
*/
RemoveSwarmNodeCmd removeSwarmNodeCmd(String swarmNodeId);

/**
* List nodes in swarm
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.github.dockerjava.api.command.RemoveNetworkCmd;
import com.github.dockerjava.api.command.RemoveSecretCmd;
import com.github.dockerjava.api.command.RemoveServiceCmd;
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
import com.github.dockerjava.api.command.RemoveVolumeCmd;
import com.github.dockerjava.api.command.RenameContainerCmd;
import com.github.dockerjava.api.command.ResizeContainerCmd;
Expand Down Expand Up @@ -423,6 +424,11 @@ public UpdateSwarmNodeCmd updateSwarmNodeCmd() {
return getDockerClient().updateSwarmNodeCmd();
}

@Override
public RemoveSwarmNodeCmd removeSwarmNodeCmd(String swarmNodeId) {
return getDockerClient().removeSwarmNodeCmd(swarmNodeId);
}

@Override
public ListSwarmNodesCmd listSwarmNodesCmd() {
return getDockerClient().listSwarmNodesCmd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface RemoveSwarmNodeCmd extends SyncDockerCmd<Void> {
@CheckForNull
Boolean hasForceEnabled();

RemoveSwarmNodeCmd withContainerId(@Nonnull String containerId);
RemoveSwarmNodeCmd withSwarmNodeId(@Nonnull String swarmNodeId);

RemoveSwarmNodeCmd withForce(Boolean force);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.github.dockerjava.api.command.RemoveNetworkCmd;
import com.github.dockerjava.api.command.RemoveSecretCmd;
import com.github.dockerjava.api.command.RemoveServiceCmd;
import com.github.dockerjava.api.command.RemoveSwarmNodeCmd;
import com.github.dockerjava.api.command.RemoveVolumeCmd;
import com.github.dockerjava.api.command.RenameContainerCmd;
import com.github.dockerjava.api.command.ResizeContainerCmd;
Expand Down Expand Up @@ -140,6 +141,7 @@
import com.github.dockerjava.core.command.RemoveNetworkCmdImpl;
import com.github.dockerjava.core.command.RemoveSecretCmdImpl;
import com.github.dockerjava.core.command.RemoveServiceCmdImpl;
import com.github.dockerjava.core.command.RemoveSwarmNodeCmdImpl;
import com.github.dockerjava.core.command.RemoveVolumeCmdImpl;
import com.github.dockerjava.core.command.RenameContainerCmdImpl;
import com.github.dockerjava.core.command.ResizeContainerCmdImpl;
Expand Down Expand Up @@ -616,6 +618,11 @@ public UpdateSwarmNodeCmd updateSwarmNodeCmd() {
return new UpdateSwarmNodeCmdImpl(getDockerCmdExecFactory().updateSwarmNodeCmdExec());
}

@Override
public RemoveSwarmNodeCmd removeSwarmNodeCmd(String swarmNodeId) {
return new RemoveSwarmNodeCmdImpl(getDockerCmdExecFactory().removeSwarmNodeCmdExec(), swarmNodeId);
}

@Override
public ListSwarmNodesCmd listSwarmNodesCmd() {
return new ListSwarmNodesCmdImpl(getDockerCmdExecFactory().listSwarmNodeCmdExec());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class RemoveSwarmNodeCmdImpl extends AbstrDockerCmd<RemoveSwarmNodeCmd, V

private Boolean force;

public RemoveSwarmNodeCmdImpl(RemoveSwarmNodeCmd.Exec exec, String containerId) {
public RemoveSwarmNodeCmdImpl(RemoveSwarmNodeCmd.Exec exec, String swarmNodeId) {
super(exec);
withContainerId(containerId);
withSwarmNodeId(swarmNodeId);
}

@Override
Expand All @@ -35,7 +35,7 @@ public Boolean hasForceEnabled() {
}

@Override
public RemoveSwarmNodeCmd withContainerId(@Nonnull String swarmNodeId) {
public RemoveSwarmNodeCmd withSwarmNodeId(@Nonnull String swarmNodeId) {
checkNotNull(swarmNodeId, "swarmNodeId was not specified");
this.swarmNodeId = swarmNodeId;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.dockerjava.cmd.swarm;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Swarm;
import com.github.dockerjava.api.model.SwarmNode;
import com.github.dockerjava.api.model.SwarmNodeRole;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Optional;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class RemoveSwarmNodeCmdExecIT extends SwarmCmdIT {

private static final Logger LOGGER = LoggerFactory.getLogger(RemoveSwarmNodeCmdExecIT.class);

@Test
public void testRemoveSwarmNode() throws Exception {
DockerClient dockerClient = startSwarm();
Swarm swarm = dockerClient.inspectSwarmCmd().exec();

DockerClient docker2 = startDockerInDocker();
docker2.joinSwarmCmd()
.withRemoteAddrs(Lists.newArrayList("docker1"))
.withJoinToken(swarm.getJoinTokens().getWorker())
.exec();
LOGGER.info("docker2 joined docker's swarm");

List<SwarmNode> nodes = dockerClient.listSwarmNodesCmd().exec();
assertThat(2, is(nodes.size()));
Optional<SwarmNode> firstWorkNode = nodes.stream().filter(node -> node.getSpec().getRole() == SwarmNodeRole.WORKER)
.findFirst();
dockerClient.removeSwarmNodeCmd(firstWorkNode.get().getId())
.withForce(true)
.exec();
nodes = dockerClient.listSwarmNodesCmd().exec();
assertThat(nodes.size(), is(1));
}
}