Skip to content

Commit

Permalink
Use LocalCommand as the parent of RaftMetaConfCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
idellzheng committed Aug 18, 2023
1 parent f3c9be2 commit 1d56bcc
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
22 changes: 14 additions & 8 deletions ratis-docs/src/site/markdown/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ The following command can be invoked in order to get the basic usage:
$ ratis sh
Usage: ratis sh [generic options]
[election [transfer] [stepDown] [pause] [resume]]
[group [info] [list] [raftMetaConf]]
[group [info] [list]]
[peer [add] [remove] [setPriority]]
[snapshot [create]]
[local [raftMetaConf]]
```
## generic options
Expand Down Expand Up @@ -125,7 +126,7 @@ $ ratis sh election resume -peers <P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PO
## group
The `group` command manages ratis groups.
It has the following subcommands:
`info`, `list`, `raftMetaConf`
`info`, `list`
### group info
Display the information of a specific raft group.
Expand All @@ -139,12 +140,6 @@ Display the group information of a specific raft server
$ ratis sh group list -peers <P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT> [-groupid <RAFT_GROUP_ID>] <[-serverAddress <P0_HOST:P0_PORT>]|[-peerId <peerId0>]>
```
### group raftMetaConf
Generate a new raft-meta.conf file, which is used to move a raft node to a new node
```
$ ratis sh group raftMetaConf -peers <P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT> -path <PARENT_PATH_OF_RAFT_META_CONF>
```
## peer
The `peer` command manages ratis cluster peers.
It has the following subcommands:
Expand Down Expand Up @@ -178,3 +173,14 @@ Trigger the specified server take snapshot.
```
$ ratis sh snapshot create -peers <P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT> -peerId <peerId0> [-groupid <RAFT_GROUP_ID>]
```
## local
The `local` command is used to process local operation, which no need to connect to ratis server.
It has the following subcommands:
`raftMetaConf`
### local raftMetaConf
Generate a new raft-meta.conf file based on original raft-meta.conf and new peers, which is used to move a raft node to a new node.
```
$ ratis sh local raftMetaConf -peers <P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT> -path <PARENT_PATH_OF_RAFT_META_CONF>
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.ratis.shell.cli.sh.command;

import org.apache.ratis.shell.cli.sh.group.RaftMetaConfCommand;
import org.apache.ratis.shell.cli.sh.group.GroupInfoCommand;
import org.apache.ratis.shell.cli.sh.group.GroupListCommand;

Expand All @@ -33,7 +32,7 @@ public class GroupCommand extends AbstractParentCommand {

private static final List<Function<Context, AbstractRatisCommand>> SUB_COMMAND_CONSTRUCTORS
= Collections.unmodifiableList(Arrays.asList(
GroupInfoCommand::new, GroupListCommand::new, RaftMetaConfCommand::new));
GroupInfoCommand::new, GroupListCommand::new));
/**
* @param context command context
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.ratis.shell.cli.sh.local.RaftMetaConfCommand;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
* Command for local operation, which no need to connect to ratis server
*/
public class LocalCommand extends AbstractParentCommand {

private static final List<Function<Context, AbstractRatisCommand>> SUB_COMMAND_CONSTRUCTORS
= Collections.unmodifiableList(Arrays.asList(RaftMetaConfCommand::new));

/**
* @param context command context
*/
public LocalCommand(Context context) {
super(context, SUB_COMMAND_CONSTRUCTORS);
}

@Override
public String getCommandName() {
return "local";
}

@Override
public String getDescription() {
return description();
}

/**
* @return command's description
*/
public static String description() {
return "Command for local operation, which no need to connect to ratis server; "
+ "see the sub-commands for the details.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ratis.shell.cli.sh.group;
package org.apache.ratis.shell.cli.sh.local;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
Expand All @@ -37,7 +37,8 @@
import java.util.List;

/**
* Command for generate a new raft-meta.conf file, which is used to move a raft node to a new node.
* Command for generate a new raft-meta.conf file based on original raft-meta.conf and new peers,
* which is used to move a raft node to a new node.
*/
public class RaftMetaConfCommand extends AbstractRatisCommand {
public static final String PATH_OPTION_NAME = "path";
Expand Down Expand Up @@ -122,7 +123,7 @@ public Options getOptions() {
* @return command's description
*/
public static String description() {
return "Generate a new raft-meta.conf file.";
return "Generate a new raft-meta.conf file based on original raft-meta.conf and new peers.";
}
}

0 comments on commit 1d56bcc

Please sign in to comment.