HADOOP-13697. LogLevel#main should not throw exception if no arguments. Contributed by Mingliang Liu

(cherry picked from commit 2fb392a587)
This commit is contained in:
Mingliang Liu 2016-10-07 14:05:40 -07:00
parent 28bd08798d
commit 21fcb5726a
1 changed files with 6 additions and 3 deletions

View File

@ -47,15 +47,17 @@ import org.apache.hadoop.http.HttpServer2;
import org.apache.hadoop.security.authentication.client.AuthenticatedURL; import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
import org.apache.hadoop.security.authentication.client.KerberosAuthenticator; import org.apache.hadoop.security.authentication.client.KerberosAuthenticator;
import org.apache.hadoop.security.ssl.SSLFactory; import org.apache.hadoop.security.ssl.SSLFactory;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.ServletUtil; import org.apache.hadoop.util.ServletUtil;
import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
/** /**
* Change log level in runtime. * Change log level in runtime.
*/ */
@InterfaceStability.Evolving @InterfaceStability.Evolving
public class LogLevel { public class LogLevel {
public static final String USAGES = "\nUsage: General options are:\n" public static final String USAGES = "\nUsage: Command options are:\n"
+ "\t[-getlevel <host:port> <classname> [-protocol (http|https)]\n" + "\t[-getlevel <host:port> <classname> [-protocol (http|https)]\n"
+ "\t[-setlevel <host:port> <classname> <level> " + "\t[-setlevel <host:port> <classname> <level> "
+ "[-protocol (http|https)]\n"; + "[-protocol (http|https)]\n";
@ -67,7 +69,7 @@ public class LogLevel {
*/ */
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
CLI cli = new CLI(new Configuration()); CLI cli = new CLI(new Configuration());
System.exit(cli.run(args)); System.exit(ToolRunner.run(cli, args));
} }
/** /**
@ -81,6 +83,7 @@ public class LogLevel {
private static void printUsage() { private static void printUsage() {
System.err.println(USAGES); System.err.println(USAGES);
GenericOptionsParser.printGenericCommandUsage(System.err);
} }
public static boolean isValidProtocol(String protocol) { public static boolean isValidProtocol(String protocol) {
@ -107,7 +110,7 @@ public class LogLevel {
sendLogLevelRequest(); sendLogLevelRequest();
} catch (HadoopIllegalArgumentException e) { } catch (HadoopIllegalArgumentException e) {
printUsage(); printUsage();
throw e; return -1;
} }
return 0; return 0;
} }