This is an automated email from the ASF dual-hosted git repository.
dlmarion pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new a49971af14 Refactored ResourceGroupCommand into create, list, and
delete cmds (#5860)
a49971af14 is described below
commit a49971af14aaf52805bf8475b8be2643744b0f0f
Author: Dave Marion <[email protected]>
AuthorDate: Wed Sep 17 09:20:07 2025 -0400
Refactored ResourceGroupCommand into create, list, and delete cmds (#5860)
Related to #5859
---
.../clientImpl/ResourceGroupOperationsImpl.java | 4 +-
.../org/apache/accumulo/server/util/Admin.java | 3 +-
.../main/java/org/apache/accumulo/shell/Shell.java | 7 ++-
...ommand.java => CreateResourceGroupCommand.java} | 65 ++++++++++++----------
.../shell/commands/DeleteResourceGroupCommand.java | 58 +++++++++++++++++++
...Command.java => ListResourceGroupsCommand.java} | 46 +++------------
.../org/apache/accumulo/test/DumpConfigIT.java | 2 +-
.../apache/accumulo/test/shell/ShellServerIT.java | 58 +++++++++++++++++--
8 files changed, 166 insertions(+), 77 deletions(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ResourceGroupOperationsImpl.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ResourceGroupOperationsImpl.java
index 1cd50cd32a..68ed1ac1d9 100644
---
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ResourceGroupOperationsImpl.java
+++
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ResourceGroupOperationsImpl.java
@@ -109,7 +109,7 @@ public class ResourceGroupOperationsImpl implements
ResourceGroupOperations {
TVersionedProperties rgProps = ThriftClientTypes.CLIENT.execute(context,
client ->
client.getVersionedResourceGroupProperties(TraceUtil.traceInfo(),
context.rpcCreds(), group.canonical()),
- ResourceGroupPredicate.exact(group));
+ ResourceGroupPredicate.ANY);
if (rgProps != null && rgProps.getPropertiesSize() > 0) {
return Map.copyOf(rgProps.getProperties());
} else {
@@ -160,7 +160,7 @@ public class ResourceGroupOperationsImpl implements
ResourceGroupOperations {
vProperties = ThriftClientTypes.CLIENT.execute(context,
client ->
client.getVersionedResourceGroupProperties(TraceUtil.traceInfo(),
context.rpcCreds(), group.canonical()),
- ResourceGroupPredicate.exact(group));
+ ResourceGroupPredicate.ANY);
} catch (AccumuloException | AccumuloSecurityException e) {
Throwable t = e.getCause();
if (t instanceof ThriftResourceGroupNotExistsException te) {
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
index 86c7d0d0e0..64a2d4896b 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
@@ -816,7 +816,8 @@ public class Admin implements KeywordExecutable {
private static final MessageFormat createNsFormat = new
MessageFormat("createnamespace {0}\n");
private static final MessageFormat createTableFormat = new
MessageFormat("createtable {0}\n");
private static final MessageFormat createUserFormat = new
MessageFormat("createuser {0}\n");
- private static final MessageFormat createRGFormat = new
MessageFormat("resourcegroup -c {0}\n");
+ private static final MessageFormat createRGFormat =
+ new MessageFormat("createresourcegroup {0}\n");
private static final MessageFormat nsConfigFormat = new
MessageFormat("config -ns {0} -s {1}\n");
private static final MessageFormat rgConfigFormat = new
MessageFormat("config -rg {0} -s {1}\n");
private static final MessageFormat sysPermFormat =
diff --git a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
index 3420329b43..18ab478206 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
@@ -91,6 +91,7 @@ import org.apache.accumulo.shell.commands.CompactCommand;
import org.apache.accumulo.shell.commands.ConfigCommand;
import org.apache.accumulo.shell.commands.ConstraintCommand;
import org.apache.accumulo.shell.commands.CreateNamespaceCommand;
+import org.apache.accumulo.shell.commands.CreateResourceGroupCommand;
import org.apache.accumulo.shell.commands.CreateTableCommand;
import org.apache.accumulo.shell.commands.CreateUserCommand;
import org.apache.accumulo.shell.commands.DUCommand;
@@ -99,6 +100,7 @@ import org.apache.accumulo.shell.commands.DeleteCommand;
import org.apache.accumulo.shell.commands.DeleteIterCommand;
import org.apache.accumulo.shell.commands.DeleteManyCommand;
import org.apache.accumulo.shell.commands.DeleteNamespaceCommand;
+import org.apache.accumulo.shell.commands.DeleteResourceGroupCommand;
import org.apache.accumulo.shell.commands.DeleteRowsCommand;
import org.apache.accumulo.shell.commands.DeleteShellIterCommand;
import org.apache.accumulo.shell.commands.DeleteTableCommand;
@@ -128,6 +130,7 @@ import org.apache.accumulo.shell.commands.InsertCommand;
import org.apache.accumulo.shell.commands.ListBulkCommand;
import org.apache.accumulo.shell.commands.ListCompactionsCommand;
import org.apache.accumulo.shell.commands.ListIterCommand;
+import org.apache.accumulo.shell.commands.ListResourceGroupsCommand;
import org.apache.accumulo.shell.commands.ListScansCommand;
import org.apache.accumulo.shell.commands.ListShellIterCommand;
import org.apache.accumulo.shell.commands.ListTabletsCommand;
@@ -146,7 +149,6 @@ import org.apache.accumulo.shell.commands.QuitCommand;
import org.apache.accumulo.shell.commands.QuotedStringTokenizer;
import org.apache.accumulo.shell.commands.RenameNamespaceCommand;
import org.apache.accumulo.shell.commands.RenameTableCommand;
-import org.apache.accumulo.shell.commands.ResourceGroupCommand;
import org.apache.accumulo.shell.commands.RevokeCommand;
import org.apache.accumulo.shell.commands.ScanCommand;
import org.apache.accumulo.shell.commands.SetAuthsCommand;
@@ -422,7 +424,8 @@ public class Shell extends ShellOptions implements
KeywordExecutable {
Command[] permissionsCommands = {new GrantCommand(), new RevokeCommand(),
new SystemPermissionsCommand(), new TablePermissionsCommand(), new
UserPermissionsCommand(),
new NamespacePermissionsCommand()};
- Command[] resourceGroupCommands = {new ResourceGroupCommand()};
+ Command[] resourceGroupCommands = {new CreateResourceGroupCommand(),
+ new DeleteResourceGroupCommand(), new ListResourceGroupsCommand()};
Command[] stateCommands =
{new AuthenticateCommand(), new ClsCommand(), new ClearCommand(), new
NoTableCommand(),
new SleepCommand(), new TableCommand(), new UserCommand(), new
WhoAmICommand()};
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/ResourceGroupCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/CreateResourceGroupCommand.java
similarity index 50%
copy from
shell/src/main/java/org/apache/accumulo/shell/commands/ResourceGroupCommand.java
copy to
shell/src/main/java/org/apache/accumulo/shell/commands/CreateResourceGroupCommand.java
index 634376f041..96fbf91590 100644
---
a/shell/src/main/java/org/apache/accumulo/shell/commands/ResourceGroupCommand.java
+++
b/shell/src/main/java/org/apache/accumulo/shell/commands/CreateResourceGroupCommand.java
@@ -18,9 +18,13 @@
*/
package org.apache.accumulo.shell.commands;
-import java.util.Set;
-import java.util.TreeSet;
+import static org.apache.accumulo.shell.ShellUtil.readPropertiesFromFile;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.ResourceGroupNotFoundException;
import org.apache.accumulo.core.client.admin.ResourceGroupOperations;
import org.apache.accumulo.core.data.ResourceGroupId;
import org.apache.accumulo.shell.Shell;
@@ -29,55 +33,60 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
-public class ResourceGroupCommand extends Command {
+public class CreateResourceGroupCommand extends Command {
- private Option createOpt;
- private Option listOpt;
- private Option deleteOpt;
+ private Option createRGPropFileOpt;
@Override
public int execute(String fullCommand, CommandLine cl, Shell shellState)
throws Exception {
-
+ final String resourceGroup = cl.getArgs()[0];
+ final ResourceGroupId rgid = ResourceGroupId.of(resourceGroup);
final ResourceGroupOperations ops =
shellState.getAccumuloClient().resourceGroupOperations();
+ try {
+ ops.create(rgid);
+ } catch (AccumuloException | AccumuloSecurityException e) {
+ Shell.log.error("Error creating resource group {}", resourceGroup, e);
+ return 1;
+ }
- 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);
+ String filename = cl.getOptionValue(createRGPropFileOpt.getOpt());
+ if (filename != null) {
+ final Map<String,String> initProperties =
readPropertiesFromFile(filename);
+ try {
+ ops.modifyProperties(rgid, c -> c.putAll(initProperties));
+ } catch (IllegalArgumentException | AccumuloException |
AccumuloSecurityException
+ | ResourceGroupNotFoundException e) {
+ Shell.log.error("Error setting initial resource group properties for
{}", rgid, e);
+ return 1;
+ }
}
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);
+ createRGPropFileOpt = new Option("f", "file", true, "user-defined initial
properties file");
+ createRGPropFileOpt.setArgName("properties-file");
+ final Options o = new Options();
+ o.addOption(createRGPropFileOpt);
return o;
}
@Override
public String description() {
- return "create, list, or remove resource groups";
+ return "creates a resource group";
+ }
+
+ @Override
+ public String usage() {
+ return getName() + "[-f <initial-properties-file>] <ResourceGroup name>";
}
@Override
public int numArgs() {
- return 0;
+ return Shell.NO_FIXED_ARG_LENGTH_CHECK;
}
}
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteResourceGroupCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteResourceGroupCommand.java
new file mode 100644
index 0000000000..0fd91744a1
--- /dev/null
+++
b/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteResourceGroupCommand.java
@@ -0,0 +1,58 @@
+/*
+ * 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 org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.ResourceGroupNotFoundException;
+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;
+
+public class DeleteResourceGroupCommand extends Command {
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState)
throws Exception {
+ String resourceGroup = cl.getArgs()[0];
+ try {
+ shellState.getAccumuloClient().resourceGroupOperations()
+ .remove(ResourceGroupId.of(resourceGroup));
+ } catch (AccumuloException | AccumuloSecurityException |
ResourceGroupNotFoundException e) {
+ Shell.log.error("Error deleting resource group {}", resourceGroup, e);
+ return 1;
+ }
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "deletes a resource group";
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " <ResourceGroup name>";
+ }
+
+ @Override
+ public int numArgs() {
+ return 1;
+ }
+}
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/ResourceGroupCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/ListResourceGroupsCommand.java
similarity index 51%
rename from
shell/src/main/java/org/apache/accumulo/shell/commands/ResourceGroupCommand.java
rename to
shell/src/main/java/org/apache/accumulo/shell/commands/ListResourceGroupsCommand.java
index 634376f041..6083f5f5bd 100644
---
a/shell/src/main/java/org/apache/accumulo/shell/commands/ResourceGroupCommand.java
+++
b/shell/src/main/java/org/apache/accumulo/shell/commands/ListResourceGroupsCommand.java
@@ -18,61 +18,33 @@
*/
package org.apache.accumulo.shell.commands;
+import java.io.IOException;
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;
+public class ListResourceGroupsCommand extends Command {
@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())) {
+ try {
Set<String> sorted = new TreeSet<>();
- ops.list().forEach(rg -> sorted.add(rg.canonical()));
+ shellState.getAccumuloClient().resourceGroupOperations().list()
+ .forEach(rg -> sorted.add(rg.canonical()));
shellState.printLines(sorted.iterator(), false);
+ } catch (IOException e) {
+ Shell.log.error("Error listing resource groups", e);
+ return 1;
}
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";
+ return "list resource groups";
}
@Override
diff --git a/test/src/main/java/org/apache/accumulo/test/DumpConfigIT.java
b/test/src/main/java/org/apache/accumulo/test/DumpConfigIT.java
index 50e531f6c3..39b51d8451 100644
--- a/test/src/main/java/org/apache/accumulo/test/DumpConfigIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/DumpConfigIT.java
@@ -90,7 +90,7 @@ public class DumpConfigIT extends ConfigurableMacBase {
assertFalse(systemPerm
.contains("grant Table.DROP -t " + SystemTables.METADATA.tableName() +
" -u root"));
String rg =
FunctionalTestUtils.readAll(Files.newInputStream(folder.resolve("test_rg.cfg")));
- assertTrue(rg.contains("resourcegroup -c test"));
+ assertTrue(rg.contains("createresourcegroup test"));
assertTrue(rg.contains("config -rg test -s " +
Property.COMPACTION_WARN_TIME.getKey() + "=3m"));
}
diff --git
a/test/src/main/java/org/apache/accumulo/test/shell/ShellServerIT.java
b/test/src/main/java/org/apache/accumulo/test/shell/ShellServerIT.java
index 19a590e3b5..af45bee4ff 100644
--- a/test/src/main/java/org/apache/accumulo/test/shell/ShellServerIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/shell/ShellServerIT.java
@@ -2462,24 +2462,52 @@ public class ShellServerIT extends
SharedMiniClusterBase {
@Test
public void resourceGroups() throws AccumuloException,
AccumuloSecurityException, IOException,
- ResourceGroupNotFoundException {
+ ResourceGroupNotFoundException, InterruptedException {
try (AccumuloClient client =
Accumulo.newClient().from(getClientProps()).build()) {
ResourceGroupOperations ops = client.resourceGroupOperations();
String badRG = "test-RG";
String goodRG = "testRG";
+ String goodFileRG = "testFileRG";
+ String badFileRG = "testBadFileRG";
ResourceGroupId goodRgid = ResourceGroupId.of(goodRG);
+ ResourceGroupId goodFileRgid = ResourceGroupId.of(goodFileRG);
+ ResourceGroupId badFileRgid = ResourceGroupId.of(badFileRG);
+ String propsFile = System.getProperty("user.dir") +
"/target/resourceGroupInitPropsFile";
+ java.nio.file.Path propsFilePath = java.nio.file.Path.of(propsFile);
+ try (BufferedWriter writer = Files.newBufferedWriter(propsFilePath,
UTF_8)) {
+ writer.write(Property.SSERV_WAL_SORT_MAX_CONCURRENT.getKey() + "=4\n");
+ }
+
+ String badPropsFile =
+ System.getProperty("user.dir") +
"/target/resourceGroupBadInitPropsFile";
+ java.nio.file.Path badPropsFilePath =
java.nio.file.Path.of(badPropsFile);
+ try (BufferedWriter writer = Files.newBufferedWriter(badPropsFilePath,
UTF_8)) {
+ writer.write(Property.TABLE_BLOOM_ENABLED.getKey() + "=true\n");
+ }
assertEquals(1, ops.list().size());
assertEquals(ResourceGroupId.DEFAULT, ops.list().iterator().next());
- ts.exec("resourcegroup -c " + badRG, false, "contains invalid
characters");
- ts.exec("resourcegroup -c " + goodRG, true);
+ ts.exec("createresourcegroup " + badRG, false, "contains invalid
characters");
+ ts.exec("createresourcegroup " + goodRG, true);
+ ts.exec("createresourcegroup -f " + propsFilePath.toAbsolutePath() + " "
+ goodFileRG, true);
+ ts.exec("createresourcegroup -f " + badPropsFilePath.toAbsolutePath() +
" " + badFileRG,
+ false);
+
+ // createresourcegroup command above goes to the Manager
+ // ops.list() below uses the clients ZooCache
+ // Wait a bit so that ZooCache updates.
+ Thread.sleep(100);
- assertEquals(2, ops.list().size());
+ assertEquals(4, ops.list().size());
assertTrue(ops.list().contains(ResourceGroupId.DEFAULT));
assertTrue(ops.list().contains(goodRgid));
+ assertTrue(ops.list().contains(goodFileRgid));
+ assertTrue(ops.list().contains(badFileRgid));
+
+ ts.exec("listresourcegroups", true, goodRG);
ts.exec("config -rg " + badRG + " -s " +
Property.COMPACTION_WARN_TIME.getKey() + "=3m",
false, "contains invalid characters");
@@ -2487,6 +2515,8 @@ public class ShellServerIT extends SharedMiniClusterBase {
true);
getCluster().getConfig().getClusterServerConfiguration().addCompactorResourceGroup(goodRG,
1);
+
getCluster().getConfig().getClusterServerConfiguration().addCompactorResourceGroup(goodFileRG,
+ 1);
getCluster().getClusterControl().start(ServerType.COMPACTOR);
Wait.waitFor(() -> getCluster().getServerContext().getServerPaths()
.getCompactor(ResourceGroupPredicate.exact(goodRgid),
AddressSelector.all(), true).size()
@@ -2496,8 +2526,24 @@ public class ShellServerIT extends SharedMiniClusterBase
{
assertTrue(props.containsKey(Property.COMPACTION_WARN_TIME.getKey()));
assertEquals("3m", props.get(Property.COMPACTION_WARN_TIME.getKey()));
- ts.exec("resourcegroup -d " + badRG, false, "contains invalid
characters");
- ts.exec("resourcegroup -d " + goodRG, true);
+ Wait.waitFor(() -> getCluster().getServerContext().getServerPaths()
+ .getCompactor(ResourceGroupPredicate.exact(goodFileRgid),
AddressSelector.all(), true)
+ .size() == 1);
+ Map<String,String> fileProps = ops.getProperties(goodFileRgid);
+ assertEquals(1, fileProps.size());
+
assertTrue(fileProps.containsKey(Property.SSERV_WAL_SORT_MAX_CONCURRENT.getKey()));
+ assertEquals("4",
fileProps.get(Property.SSERV_WAL_SORT_MAX_CONCURRENT.getKey()));
+
+ ts.exec("deleteresourcegroup " + badRG, false, "contains invalid
characters");
+ ts.exec("deleteresourcegroup " + goodRG, true);
+ ts.exec("deleteresourcegroup " + goodFileRG, true);
+ ts.exec("deleteresourcegroup " + badFileRG, true);
+
+ // deleteresourcegroup command above goes to the Manager
+ // ops.list() below uses the clients ZooCache
+ // Wait a bit so that ZooCache updates.
+ Thread.sleep(100);
+
assertEquals(1, ops.list().size());
assertEquals(ResourceGroupId.DEFAULT, ops.list().iterator().next());