This is an automated email from the ASF dual-hosted git repository. mmiller 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 469fe9f681 Adding DeleteZooInstance utility to accumulo admin command (#2815) 469fe9f681 is described below commit 469fe9f6815912507bc2e3d5c6d69d38475a67d9 Author: Christopher L. Shannon <christopher.l.shan...@gmail.com> AuthorDate: Fri Aug 12 08:24:24 2022 -0400 Adding DeleteZooInstance utility to accumulo admin command (#2815) Issue #2807 --- .../org/apache/accumulo/server/util/Admin.java | 11 +++++++ .../accumulo/server/util/DeleteZooInstance.java | 34 +++++++++++++--------- 2 files changed, 31 insertions(+), 14 deletions(-) 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 053e0c197b..168530b9ee 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 @@ -176,6 +176,12 @@ public class Admin implements KeywordExecutable { commandDescription = "Changes the unique secret given to the instance that all servers must know.") static class ChangeSecretCommand {} + @Parameters(commandDescription = "Deletes instance name or id from zookeeper.") + static class DeleteZooInstanceCommand { + @Parameter(names = {"-i", "--instance"}, description = "the instance name or id to delete") + String instance; + } + public static void main(String[] args) { new Admin().execute(args); } @@ -210,6 +216,9 @@ public class Admin implements KeywordExecutable { ChangeSecretCommand changeSecretCommand = new ChangeSecretCommand(); cl.addCommand("changeSecret", changeSecretCommand); + DeleteZooInstanceCommand deleteZooInstanceOpts = new DeleteZooInstanceCommand(); + cl.addCommand("deleteZooInstance", deleteZooInstanceOpts); + ListInstancesCommand listIntancesOpts = new ListInstancesCommand(); cl.addCommand("listInstances", listIntancesOpts); @@ -291,6 +300,8 @@ public class Admin implements KeywordExecutable { verifyTabletAssignmentsOpts.verbose); } else if (cl.getParsedCommand().equals("changeSecret")) { ChangeSecret.changeSecret(context, conf); + } else if (cl.getParsedCommand().equals("deleteZooInstance")) { + DeleteZooInstance.deleteZooInstance(deleteZooInstanceOpts.instance); } else { everything = cl.getParsedCommand().equals("stopAll"); diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java b/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java index 4c673ec1f1..d92a9245d4 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java @@ -21,6 +21,7 @@ package org.apache.accumulo.server.util; import static java.nio.charset.StandardCharsets.UTF_8; import java.util.HashSet; +import java.util.Objects; import java.util.Set; import org.apache.accumulo.core.Constants; @@ -52,35 +53,40 @@ public class DeleteZooInstance { } } - /** - * @param args - * : the name or UUID of the instance to be deleted - */ - public static void main(String[] args) throws Exception { - Opts opts = new Opts(); - opts.parseArgs(DeleteZooInstance.class.getName(), args); + public static void deleteZooInstance(final String instance) throws Exception { + Objects.requireNonNull(instance, "Instance must not be null"); var zk = new ZooReaderWriter(SiteConfiguration.auto()); // try instance name: Set<String> instances = new HashSet<>(zk.getChildren(Constants.ZROOT + Constants.ZINSTANCES)); Set<String> uuids = new HashSet<>(zk.getChildren(Constants.ZROOT)); uuids.remove("instances"); - if (instances.contains(opts.instance)) { - String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + opts.instance; + if (instances.contains(instance)) { + String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + instance; byte[] data = zk.getData(path); deleteRetry(zk, path); deleteRetry(zk, Constants.ZROOT + "/" + new String(data, UTF_8)); - } else if (uuids.contains(opts.instance)) { + } else if (uuids.contains(instance)) { // look for the real instance name - for (String instance : instances) { - String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + instance; + for (String zkInstance : instances) { + String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + zkInstance; byte[] data = zk.getData(path); - if (opts.instance.equals(new String(data, UTF_8))) { + if (instance.equals(new String(data, UTF_8))) { deleteRetry(zk, path); } } - deleteRetry(zk, Constants.ZROOT + "/" + opts.instance); + deleteRetry(zk, Constants.ZROOT + "/" + instance); } } + /** + * @param args + * : the name or UUID of the instance to be deleted + */ + public static void main(String[] args) throws Exception { + Opts opts = new Opts(); + opts.parseArgs(DeleteZooInstance.class.getName(), args); + deleteZooInstance(opts.instance); + } + }