From 207523915dde46bc27b7c8320c258876ed050b48 Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Fri, 1 Dec 2017 12:14:08 -0800 Subject: [PATCH] HDFS-12588. Use GenericOptionsParser for scm and ksm daemon. Contributed by Elek, Marton. --- .../hadoop/ozone/ksm/KeySpaceManager.java | 15 +++++++++- .../ozone/scm/StorageContainerManager.java | 28 ++++++++++++++----- .../apache/hadoop/ozone/scm/cli/SCMCLI.java | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java index dd142f70e6c..385d5f6eeaa 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java @@ -48,6 +48,7 @@ import org.apache.hadoop.scm.protocol.ScmBlockLocationProtocol; import org.apache.hadoop.scm.protocolPB.ScmBlockLocationProtocolClientSideTranslatorPB; import org.apache.hadoop.scm.protocolPB.ScmBlockLocationProtocolPB; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,6 +90,7 @@ public class KeySpaceManager extends ServiceRuntimeInfoImpl private final KSMMetrics metrics; private final KeySpaceManagerHttpServer httpServer; private ObjectName ksmInfoBeanName; + private static final String USAGE = "hdfs ksm [genericOptions]"; public KeySpaceManager(OzoneConfiguration conf) throws IOException { final int handlerCount = conf.getInt(OZONE_KSM_HANDLER_COUNT_KEY, @@ -191,14 +193,25 @@ public class KeySpaceManager extends ServiceRuntimeInfoImpl * @throws IOException if startup fails due to I/O error */ public static void main(String[] argv) throws IOException { - StringUtils.startupShutdownMessage(KeySpaceManager.class, argv, LOG); + if (DFSUtil.parseHelpArgument(argv, USAGE, + System.out, true)) { + System.exit(0); + } try { OzoneConfiguration conf = new OzoneConfiguration(); + GenericOptionsParser hParser = new GenericOptionsParser(conf, argv); + if (!hParser.isParseSuccessful() + || hParser.getRemainingArgs().length > 0) { + System.err.println("USAGE: " + USAGE + " \n"); + hParser.printGenericCommandUsage(System.err); + System.exit(1); + } if (!DFSUtil.isOzoneEnabled(conf)) { System.out.println("KSM cannot be started in secure mode or when " + OZONE_ENABLED + " is set to false"); System.exit(1); } + StringUtils.startupShutdownMessage(KeySpaceManager.class, argv, LOG); KeySpaceManager ksm = new KeySpaceManager(conf); ksm.start(); ksm.join(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java index b351c846bbf..bae4cffd303 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java @@ -91,6 +91,7 @@ import org.apache.hadoop.scm.protocolPB.StorageContainerLocationProtocolPB; import org.apache.hadoop.ozone.common.Storage.StorageState; import org.apache.hadoop.ozone.scm.exceptions.SCMException.ResultCodes; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -216,9 +217,12 @@ public class StorageContainerManager extends ServiceRuntimeInfoImpl private static final String USAGE = - "Usage: \n hdfs scm [ " + StartupOption.INIT.getName() + " [ " - + StartupOption.CLUSTERID.getName() + " ] ]\n " + "hdfs scm [ " - + StartupOption.GENCLUSTERID.getName() + " ]\n " + "hdfs scm [ " + "Usage: \n hdfs scm [genericOptions] " + + "[ " + StartupOption.INIT.getName() + " [ " + + StartupOption.CLUSTERID.getName() + " ] ]\n " + + "hdfs scm [genericOptions] [ " + + StartupOption.GENCLUSTERID.getName() + " ]\n " + + "hdfs scm [ " + StartupOption.HELP.getName() + " ]\n"; /** * Creates a new StorageContainerManager. Configuration will be updated with @@ -401,11 +405,21 @@ public class StorageContainerManager extends ServiceRuntimeInfoImpl * @throws IOException if startup fails due to I/O error */ public static void main(String[] argv) throws IOException { - StringUtils.startupShutdownMessage(StorageContainerManager.class, - argv, LOG); - OzoneConfiguration conf = new OzoneConfiguration(); + if (DFSUtil.parseHelpArgument(argv, USAGE, + System.out, true)) { + System.exit(0); + } try { - StorageContainerManager scm = createSCM(argv, conf); + OzoneConfiguration conf = new OzoneConfiguration(); + GenericOptionsParser hParser = new GenericOptionsParser(conf, argv); + if (!hParser.isParseSuccessful()) { + System.err.println("USAGE: " + USAGE + "\n"); + hParser.printGenericCommandUsage(System.err); + System.exit(1); + } + StringUtils.startupShutdownMessage(StorageContainerManager.class, + argv, LOG); + StorageContainerManager scm = createSCM(hParser.getRemainingArgs(), conf); if (scm != null) { scm.start(); scm.join(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SCMCLI.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SCMCLI.java index b9bd89fcd3e..fb22d05fef7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SCMCLI.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/SCMCLI.java @@ -162,7 +162,7 @@ public class SCMCLI extends OzoneBaseCLI { HelpFormatter helpFormatter = new HelpFormatter(); Options topLevelOptions = new Options(); addTopLevelOptions(topLevelOptions); - helpFormatter.printHelp(CMD_WIDTH, "hdfs scm []", + helpFormatter.printHelp(CMD_WIDTH, "hdfs scmcli []", "where can be one of the following", topLevelOptions, ""); }