You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2019/06/06 16:24:08 UTC

[GitHub] [hadoop] sodonnel commented on a change in pull request #918: HDDS-1622 Use picocli for StorageContainerManager

sodonnel commented on a change in pull request #918: HDDS-1622 Use picocli for StorageContainerManager
URL: https://github.com/apache/hadoop/pull/918#discussion_r291266687
 
 

 ##########
 File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManagerStarter.java
 ##########
 @@ -0,0 +1,155 @@
+/**
+ * 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
+ *
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>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.hadoop.hdds.scm.server;
+
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.tracing.TracingUtil;
+import org.apache.hadoop.ozone.common.StorageInfo;
+import org.apache.hadoop.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+
+import java.io.IOException;
+
+import static org.apache.hadoop.util.ExitUtil.terminate;
+
+/**
+ * This class provides a command line interface to start the SCM
+ * using Picocli.
+ */
+
+@Command(name = "ozone scm",
+    hidden = true, description = "Start or initialize the scm server.",
+    versionProvider = HddsVersionProvider.class,
+    mixinStandardHelpOptions = true)
+public class StorageContainerManagerStarter extends GenericCli {
+
+  private OzoneConfiguration conf;
+  private SCMStarterInterface receiver;
+  private static final Logger LOG =
+      LoggerFactory.getLogger(StorageContainerManagerStarter.class);
+
+  public static void main(String[] args) throws Exception {
+    TracingUtil.initTracing("StorageContainerManager");
+    new StorageContainerManagerStarter(
+        new StorageContainerManagerStarter.SCMStarterHelper()).run(args);
+  }
+
+  public StorageContainerManagerStarter(SCMStarterInterface receiverObj) {
+    super();
+    receiver = receiverObj;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    commonInit();
+    startScm();
+    return null;
+  }
+
+  /**
+   * This function implements a sub-command to generate a new
+   * cluster ID from the command line.
+   */
+  @CommandLine.Command(name = "--genclusterid",
+      customSynopsis = "ozone scm [global options] --genclusterid [options]",
+      hidden = false,
+      description = "Generate a new Cluster ID",
+      mixinStandardHelpOptions = true,
+      versionProvider = HddsVersionProvider.class)
+  public void generateClusterId() {
+    commonInit();
+    System.out.println("Generating new cluster id:");
+    System.out.println(receiver.generateClusterId());
+  }
+
+  /**
+   * This function implements a sub-command to allow the SCM to be
+   * initialized from the command line.
+   *
+   * @param clusterId - Cluster ID to use when initializing. If null,
+   *                  a random ID will be generated and used.
+   */
+  @CommandLine.Command(name = "--init",
+      customSynopsis = "ozone scm [global options] --init [options]",
+      hidden = false,
+      description = "Initialize / format the SCM",
+      mixinStandardHelpOptions = true,
+      versionProvider = HddsVersionProvider.class)
+  public void initScm(@CommandLine.Option(names = { "--clusterid" },
+      description = "Optional: The cluster id to use when formatting SCM",
+      paramLabel = "id") String clusterId)
+      throws Exception {
+    commonInit();
+    boolean result = receiver.init(conf, clusterId);
+    if (!result) {
+      throw new IOException("SCM Init failed. Check the log for more details");
 
 Review comment:
   The method StorageContainerManager.init() which actually does the init(), looks like this:
   
   ```
     /**
      * Routine to set up the Version info for StorageContainerManager.
      *
      * @param conf OzoneConfiguration
      * @return true if SCM initialization is successful, false otherwise.
      * @throws IOException if init fails due to I/O error
      */
     public static boolean scmInit(OzoneConfiguration conf,
         String clusterId) throws IOException {
       SCMStorageConfig scmStorageConfig = new SCMStorageConfig(conf);
       StorageState state = scmStorageConfig.getState();
       if (state != StorageState.INITIALIZED) {
         try {
           if (clusterId != null && !clusterId.isEmpty()) {
             scmStorageConfig.setClusterId(clusterId);
           }
           scmStorageConfig.initialize();
           ...
           return true;
         } catch (IOException ioe) {
           LOG.error("Could not initialize SCM version file", ioe);
           return false;
         }
       } else {
         System.out.println(
             "SCM already initialized. Reusing existing"
                 + " cluster id for sd="
                 + scmStorageConfig.getStorageDir()
                 + ";cid="
                 + scmStorageConfig.getClusterID());
         return true;
       }
     }
   ```
   Note the Java doc states it throws IOException, but it doesn't really (at least in some circumstances) as IOE is caught and then false is returned rather than propagating the exception to the caller. I think it would be better if this init() method throws the exception, rather than returning false and this would let us print the exception on the CLI rather than this message. What do you think?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org