-
Notifications
You must be signed in to change notification settings - Fork 407
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
RATIS-1436.Add ratis-shell GroupInfo command #540
Conversation
@maobaolong Can you help me review the code, thx! |
How about add a new "info" option to the existing group command? |
@szetszwo I think the objects targeted by these two commands are different. The group command operates on peers, and the operation in this pr is groups. I want to add sub option to delete and add groups to specific peers in this command. Therefore, can we consider changing the name of the group command to a name related to Peer. Thx! |
You are right. The existing GroupCommand should be renamed to PeerCommand. The new command in this change should be called GroupCommand. The GroupCommand should correspond to GroupManagementApi. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codings-dan , Thanks for the update.
This is actually a "list" command instead of "info". We should combine this with the InfoCommand (rename it go "group"). Then, use the subcommands
- "group -info";
- "group -list".
Later on, we may add
- "group -add";
- "group -remove".
These are all 4 methods in GroupManagementApi.
/** | ||
* Command for querying the group information of a ratis server. | ||
*/ | ||
public class GroupInfoCommand extends AbstractRatisCommand{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use GroupCommand.
|
||
@Override | ||
public String getCommandName() { | ||
return "groupInfo"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use "group" for the main command and "group -list" for the sub command.
@szetszwo Sorry, due to a lot of things this week, this patch update is late. The code has been updated, I have tested the function, and can be used normally. Can you help review the code, thx! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codings-dan thanks for the update. A few comments inlined; see also https://issues.apache.org/jira/secure/attachment/13036937/540_review.patch
BTW, please include the JIRA number in the title of this pull request.
private static final Map<String, Function<Context, ? extends Command>> | ||
SUB_COMMANDS = new HashMap<>(); | ||
|
||
static { | ||
SUB_COMMANDS.put("info", GroupInfoCommand::new); | ||
SUB_COMMANDS.put("list", GroupListCommand::new); | ||
} | ||
|
||
private Map<String, Command> mSubCommands = new HashMap<>(); | ||
|
||
/** | ||
* @param context command context | ||
*/ | ||
public GroupCommand(Context context) { | ||
super(context); | ||
SUB_COMMANDS.forEach((name, constructor) -> { | ||
mSubCommands.put(name, constructor.apply(context)); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified as below:
private static final List<Function<Context, AbstractRatisCommand>> SUB_COMMAND_CONSTRUCTORS
= Collections.unmodifiableList(Arrays.asList(
GroupInfoCommand::new, GroupListCommand::new));
private final Map<String, Command> subs;
/**
* @param context command context
*/
public GroupCommand(Context context) {
super(context);
this.subs = Collections.unmodifiableMap(SUB_COMMAND_CONSTRUCTORS.stream()
.map(constructor -> constructor.apply(context))
.collect(Collectors.toMap(Command::getCommandName, Function.identity())));
}
getCommandName(), PEER_OPTION_NAME, GROUPID_OPTION_NAME, | ||
REMOVE_OPTION_NAME, ADD_OPTION_NAME); | ||
public boolean hasSubCommand() { | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change the default to below. Then, we don't have to override it anymore.
return Optional.ofNullable(getSubCommands()).filter(subs -> !subs.isEmpty()).isPresent();
String[] str = strAddr.split(":"); | ||
if(str.length < 2) { | ||
throw new IllegalArgumentException("Failed to parse the server address parameter \"" + strAddr + "\"."); | ||
} | ||
final InetSocketAddress serverAddress = InetSocketAddress.createUnresolved(str[0], Integer.parseInt(str[1])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a utility method so that it can be used here and also in other commands.
public static InetSocketAddress parseInetSocketAddress(String address) {
try {
final String[] hostPortPair = address.split(":");
if (hostPortPair.length < 2) {
throw new IllegalArgumentException("Unexpected address format <HOST:PORT>.");
}
return new InetSocketAddress(hostPortPair[0], Integer.parseInt(hostPortPair[1]));
} catch (Exception e) {
throw new IllegalArgumentException("Failed to parse the server address parameter \"" + address + "\".", e);
}
}
} | ||
|
||
/** | ||
* @return command's description | ||
*/ | ||
public static String description() { | ||
return "Remove or Add peers of a ratis group"; | ||
return "Manage the ratis gropu, See sub-commands' descriptions for more details."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a typo. Let's change the message to
return "Manage ratis groups; see the sub-commands for the details.";
@szetszwo Thank you for reviewing the code, I updated the code according to the comment and patch you left, please see if it needs to be updated again, thx! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a typo in GroupCommand.description(); see the comment inlined. The change look good other than that.
I have fixed the typo, PTAL, thx! |
public boolean hasSubCommand() { | ||
return Optional.ofNullable(getSubCommands()).filter(sub -> !subs.isEmpty()).isPresent(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codings-dan , We don't have to override hasSubCommand() anymore since the default will always work. Please remove this. Sorry that I did not see this last time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have delete the code, PTAL again, thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 the change looks good.
What changes were proposed in this pull request?
Add a sub command to show the group information of a ratis server
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/RATIS-1436
How was this patch tested?