codings-dan commented on a change in pull request #603:
URL: https://github.com/apache/ratis/pull/603#discussion_r812859588



##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/ResumeCommand.java
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.shell.cli.sh.election;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.protocol.RaftPeerId;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+
+import java.io.IOException;
+import java.util.Optional;
+
+/**
+ * Command for resuming leader election on specific server
+ */
+public class ResumeCommand extends AbstractRatisCommand {
+
+  public static final String ADDRESS_OPTION_NAME = "address";
+  /**
+   * @param context command context
+   */
+  public ResumeCommand(Context context) {
+    super(context);
+  }
+
+  @Override
+  public String getCommandName() {
+    return "resume";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    super.run(cl);
+
+    String strAddr = cl.getOptionValue(ADDRESS_OPTION_NAME);
+    final RaftPeerId peerId;
+    Optional<RaftPeer> peer =
+        getRaftGroup().getPeers().stream().filter(p -> 
p.getAddress().equals(strAddr)).findAny();
+    if (peer.isPresent()) {
+      peerId = peer.get().getId();
+    } else {

Review comment:
       done

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/PauseCommand.java
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.shell.cli.sh.election;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.protocol.RaftPeerId;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+
+import java.io.IOException;
+import java.util.Optional;
+
+/**
+ * Command for pause leader election on specific server
+ */
+public class PauseCommand extends AbstractRatisCommand {
+
+  public static final String ADDRESS_OPTION_NAME = "address";
+  /**
+   * @param context command context
+   */
+  public PauseCommand(Context context) {
+    super(context);
+  }
+
+  @Override
+  public String getCommandName() {
+    return "pause";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    super.run(cl);
+
+    String strAddr = cl.getOptionValue(ADDRESS_OPTION_NAME);
+    final RaftPeerId peerId;
+    Optional<RaftPeer> peer =
+        getRaftGroup().getPeers().stream().filter(p -> 
p.getAddress().equals(strAddr)).findAny();
+    if (peer.isPresent()) {
+      peerId = peer.get().getId();
+    } else {
+      printf("Can't find a sever with the address:%s", strAddr);
+      return -1;
+    }

Review comment:
       done

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/ElectionCommand.java
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.shell.cli.sh.command;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.shell.cli.Command;
+import org.apache.ratis.shell.cli.sh.election.PauseCommand;
+import org.apache.ratis.shell.cli.sh.election.ResumeCommand;
+import org.apache.ratis.shell.cli.sh.election.TransferCommand;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class ElectionCommand extends AbstractRatisCommand{
+
+  private static final List<Function<Context, AbstractRatisCommand>> 
SUB_COMMAND_CONSTRUCTORS
+      = Collections.unmodifiableList(Arrays.asList(
+      TransferCommand::new, PauseCommand::new, ResumeCommand::new));
+
+  private final Map<String, Command> subs;
+  public static final String ADDRESS_OPTION_NAME = "address";
+
+  /**
+   * @param context command context
+   */
+  public ElectionCommand(Context context) {
+    super(context);
+    this.subs = Collections.unmodifiableMap(SUB_COMMAND_CONSTRUCTORS.stream()
+        .map(constructor -> constructor.apply(context))
+        .collect(Collectors.toMap(Command::getCommandName, 
Function.identity())));
+  }
+
+  @Override
+  public String getCommandName() {
+    return "election";
+  }
+
+  @Override
+  public String getUsage() {
+
+    StringBuilder usage = new StringBuilder(getCommandName());
+    for (String cmd : subs.keySet()) {
+      usage.append(" [").append(cmd).append("]");
+    }
+    return usage.toString();
+  }
+
+  @Override
+  public String getDescription() {
+    return description();
+  }
+
+  @Override
+  public Map<String, Command> getSubCommands() {
+    return subs;
+  }
+
+  @Override
+  public Options getOptions() {

Review comment:
       done

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/ElectionCommand.java
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.shell.cli.sh.command;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.shell.cli.Command;
+import org.apache.ratis.shell.cli.sh.election.PauseCommand;
+import org.apache.ratis.shell.cli.sh.election.ResumeCommand;
+import org.apache.ratis.shell.cli.sh.election.TransferCommand;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class ElectionCommand extends AbstractRatisCommand{
+
+  private static final List<Function<Context, AbstractRatisCommand>> 
SUB_COMMAND_CONSTRUCTORS
+      = Collections.unmodifiableList(Arrays.asList(
+      TransferCommand::new, PauseCommand::new, ResumeCommand::new));
+
+  private final Map<String, Command> subs;
+  public static final String ADDRESS_OPTION_NAME = "address";

Review comment:
       done

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/ElectionCommand.java
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.shell.cli.sh.command;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.shell.cli.Command;
+import org.apache.ratis.shell.cli.sh.election.PauseCommand;
+import org.apache.ratis.shell.cli.sh.election.ResumeCommand;
+import org.apache.ratis.shell.cli.sh.election.TransferCommand;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class ElectionCommand extends AbstractRatisCommand{
+
+  private static final List<Function<Context, AbstractRatisCommand>> 
SUB_COMMAND_CONSTRUCTORS
+      = Collections.unmodifiableList(Arrays.asList(
+      TransferCommand::new, PauseCommand::new, ResumeCommand::new));
+
+  private final Map<String, Command> subs;

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to