sodonnel commented on a change in pull request #918: HDDS-1622 Use picocli for StorageContainerManager URL: https://github.com/apache/hadoop/pull/918#discussion_r291288026
########## 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: Looking at this a bit more, is it valid to assume that when "ozone scm --init" is called, the log will go to the console, rather than hidden in a log file? The way we have Pico CLI configured, is that if you throw an exception in a command, it causes the process to have a non-zero exit status. If the exception has a cause, it prints just the cause to stder and if it has no cause, it prints the entire stack trace to stderr. So the output from the current implementation would be: ``` ... 2019-06-06 18:13:52,696 INFO server.StorageContainerManagerStarter (LogAdapter.java:info(51)) - registered UNIX signal handlers for [TERM, HUP, INT] 2019-06-06 18:13:52,827 WARN server.ServerUtils (ServerUtils.java:getScmDbDir(145)) - ozone.scm.db.dirs is not configured. We recommend adding this setting. Falling back to ozone.metadata.dirs instead. SCM initialization succeeded.Current cluster id for sd=/tmp/metadata/scm;cid=CID-6786a617-9e83-4135-996f-749c3e07dd8a 2019-06-06 18:13:52,868 ERROR server.StorageContainerManager (StorageContainerManager.java:scmInit(608)) - Could not initialize SCM version file java.io.IOException at org.apache.hadoop.hdds.scm.server.StorageContainerManager.scmInit(StorageContainerManager.java:606) at org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter$SCMStarterHelper.init(StorageContainerManagerStarter.java:146) at org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter.initScm(StorageContainerManagerStarter.java:105) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at picocli.CommandLine.execute(CommandLine.java:1189) at picocli.CommandLine.access$800(CommandLine.java:141) at picocli.CommandLine$RunLast.handle(CommandLine.java:1367) <snipped> org.apache.hadoop.hdds.scm.server.StorageContainerManagerStarter.main(StorageContainerManagerStarter.java:56) SCM Init failed. Check the log for more details 2019-06-06 18:13:52,875 INFO server.StorageContainerManagerStarter (LogAdapter.java:info(51)) - SHUTDOWN_MSG: /************************************************************ SHUTDOWN_MSG: Shutting down StorageContainerManager at SOdonnell-MBP15.local/192.168.0.20 ************************************************************/ ``` So perhaps I should just change the IOE cause to "SCM Init failed." and leave the rest as is based on the above output? Otherwise, we will get the same stack printed to the console twice. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
