HDFS-12588. Use GenericOptionsParser for scm and ksm daemon. Contributed by Elek, Marton.

This commit is contained in:
Anu Engineer 2017-12-01 12:14:08 -08:00 committed by Owen O'Malley
parent 7bba3943f0
commit 207523915d
3 changed files with 36 additions and 9 deletions

View File

@ -48,6 +48,7 @@
import org.apache.hadoop.scm.protocolPB.ScmBlockLocationProtocolClientSideTranslatorPB; import org.apache.hadoop.scm.protocolPB.ScmBlockLocationProtocolClientSideTranslatorPB;
import org.apache.hadoop.scm.protocolPB.ScmBlockLocationProtocolPB; import org.apache.hadoop.scm.protocolPB.ScmBlockLocationProtocolPB;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -89,6 +90,7 @@ public class KeySpaceManager extends ServiceRuntimeInfoImpl
private final KSMMetrics metrics; private final KSMMetrics metrics;
private final KeySpaceManagerHttpServer httpServer; private final KeySpaceManagerHttpServer httpServer;
private ObjectName ksmInfoBeanName; private ObjectName ksmInfoBeanName;
private static final String USAGE = "hdfs ksm [genericOptions]";
public KeySpaceManager(OzoneConfiguration conf) throws IOException { public KeySpaceManager(OzoneConfiguration conf) throws IOException {
final int handlerCount = conf.getInt(OZONE_KSM_HANDLER_COUNT_KEY, final int handlerCount = conf.getInt(OZONE_KSM_HANDLER_COUNT_KEY,
@ -191,14 +193,25 @@ public KSMMetrics getMetrics() {
* @throws IOException if startup fails due to I/O error * @throws IOException if startup fails due to I/O error
*/ */
public static void main(String[] argv) throws IOException { 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 { try {
OzoneConfiguration conf = new OzoneConfiguration(); 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)) { if (!DFSUtil.isOzoneEnabled(conf)) {
System.out.println("KSM cannot be started in secure mode or when " + System.out.println("KSM cannot be started in secure mode or when " +
OZONE_ENABLED + " is set to false"); OZONE_ENABLED + " is set to false");
System.exit(1); System.exit(1);
} }
StringUtils.startupShutdownMessage(KeySpaceManager.class, argv, LOG);
KeySpaceManager ksm = new KeySpaceManager(conf); KeySpaceManager ksm = new KeySpaceManager(conf);
ksm.start(); ksm.start();
ksm.join(); ksm.join();

View File

@ -91,6 +91,7 @@
import org.apache.hadoop.ozone.common.Storage.StorageState; import org.apache.hadoop.ozone.common.Storage.StorageState;
import org.apache.hadoop.ozone.scm.exceptions.SCMException.ResultCodes; import org.apache.hadoop.ozone.scm.exceptions.SCMException.ResultCodes;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -216,9 +217,12 @@ public String getName() {
private static final String USAGE = private static final String USAGE =
"Usage: \n hdfs scm [ " + StartupOption.INIT.getName() + " [ " "Usage: \n hdfs scm [genericOptions] "
+ StartupOption.CLUSTERID.getName() + " <cid> ] ]\n " + "hdfs scm [ " + "[ " + StartupOption.INIT.getName() + " [ "
+ StartupOption.GENCLUSTERID.getName() + " ]\n " + "hdfs scm [ " + StartupOption.CLUSTERID.getName() + " <cid> ] ]\n "
+ "hdfs scm [genericOptions] [ "
+ StartupOption.GENCLUSTERID.getName() + " ]\n " +
"hdfs scm [ "
+ StartupOption.HELP.getName() + " ]\n"; + StartupOption.HELP.getName() + " ]\n";
/** /**
* Creates a new StorageContainerManager. Configuration will be updated with * Creates a new StorageContainerManager. Configuration will be updated with
@ -401,11 +405,21 @@ private void unregisterMXBean() {
* @throws IOException if startup fails due to I/O error * @throws IOException if startup fails due to I/O error
*/ */
public static void main(String[] argv) throws IOException { public static void main(String[] argv) throws IOException {
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()) {
System.err.println("USAGE: " + USAGE + "\n");
hParser.printGenericCommandUsage(System.err);
System.exit(1);
}
StringUtils.startupShutdownMessage(StorageContainerManager.class, StringUtils.startupShutdownMessage(StorageContainerManager.class,
argv, LOG); argv, LOG);
OzoneConfiguration conf = new OzoneConfiguration(); StorageContainerManager scm = createSCM(hParser.getRemainingArgs(), conf);
try {
StorageContainerManager scm = createSCM(argv, conf);
if (scm != null) { if (scm != null) {
scm.start(); scm.start();
scm.join(); scm.join();

View File

@ -162,7 +162,7 @@ protected void displayHelp() {
HelpFormatter helpFormatter = new HelpFormatter(); HelpFormatter helpFormatter = new HelpFormatter();
Options topLevelOptions = new Options(); Options topLevelOptions = new Options();
addTopLevelOptions(topLevelOptions); addTopLevelOptions(topLevelOptions);
helpFormatter.printHelp(CMD_WIDTH, "hdfs scm <commands> [<options>]", helpFormatter.printHelp(CMD_WIDTH, "hdfs scmcli <commands> [<options>]",
"where <commands> can be one of the following", "where <commands> can be one of the following",
topLevelOptions, ""); topLevelOptions, "");
} }