You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/08/09 16:31:09 UTC

[GitHub] [accumulo] milleruntime commented on a diff in pull request #2815: Adding DeleteZooInstance utility to accumulo admin command

milleruntime commented on code in PR #2815:
URL: https://github.com/apache/accumulo/pull/2815#discussion_r941558056


##########
server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java:
##########
@@ -52,35 +53,40 @@ static void deleteRetry(ZooReaderWriter zk, String path) throws Exception {
     }
   }
 
-  /**
-   * @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);
+  }
+

Review Comment:
   You shouldn't need the main method anymore if running through the Admin command. These utility classes could now be POJOs and you could just pass in the parameters you need. This also applies to #2816 



-- 
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-unsubscribe@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org