keith-turner commented on code in PR #5749: URL: https://github.com/apache/accumulo/pull/5749#discussion_r2231819665
########## shell/src/main/java/org/apache/accumulo/shell/commands/ResourceGroupCommand.java: ########## @@ -0,0 +1,83 @@ +/* + * 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 + * + * https://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.accumulo.shell.commands; + +import java.util.Set; +import java.util.TreeSet; + +import org.apache.accumulo.core.client.admin.ResourceGroupOperations; +import org.apache.accumulo.core.data.ResourceGroupId; +import org.apache.accumulo.shell.Shell; +import org.apache.accumulo.shell.Shell.Command; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; + +public class ResourceGroupCommand extends Command { + + private Option createOpt; + private Option listOpt; + private Option deleteOpt; + + @Override + public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception { + + final ResourceGroupOperations ops = shellState.getAccumuloClient().resourceGroupOperations(); + + if (cl.hasOption(createOpt.getOpt())) { + ops.create(ResourceGroupId.of(cl.getOptionValue(createOpt))); + } else if (cl.hasOption(deleteOpt.getOpt())) { + ops.remove(ResourceGroupId.of(cl.getOptionValue(deleteOpt))); + } else if (cl.hasOption(listOpt.getOpt())) { + Set<String> sorted = new TreeSet<>(); + ops.list().forEach(rg -> sorted.add(rg.canonical())); + shellState.printLines(sorted.iterator(), false); + } + return 0; + } + + @Override + public Options getOptions() { + final Options o = new Options(); + + createOpt = new Option("c", "create", true, "create a resource group"); + createOpt.setArgName("group"); + o.addOption(createOpt); + + listOpt = new Option("l", "list", false, "display resource group names"); + o.addOption(listOpt); + + deleteOpt = new Option("d", "delete", true, "delete a resource group"); + deleteOpt.setArgName("group"); + o.addOption(deleteOpt); + + return o; + } + + @Override + public String description() { + return "create, list, or remove resource groups"; Review Comment: > do we need separate createresourcegroup and deleteresourcegroup commands? That would follow the pattern of some other shell command. I like the pattern you have here though. Not sure if its possible in the shell, a nicer pattern would be subcommands that could have their own options. Like`resourcegroup create -propsFile <initial props file> <rg name>` where only the create sub command has the -propFile option. If sub commands are not possible in the shell code then that leads to multiple top level commands for having per command options OR just having options that cause runtime failures when used together. -- 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: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org