From e9ce2df1f21e61350acb7b65d55ab6ee3ad38bca Mon Sep 17 00:00:00 2001 From: Naganarasimha Date: Tue, 20 Dec 2016 06:36:25 +0530 Subject: [PATCH] YARN-5524. Yarn live log aggregation does not throw if command line arg is wrong. Contributed by Xuan Gong. (cherry picked from commit 358341398adfe8f59bb2165472b50751de3ffb98) --- .../apache/hadoop/yarn/client/cli/LogsCLI.java | 2 +- .../hadoop/yarn/client/cli/TestLogsCLI.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java index 8963d34e3cb..2cbe8208558 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java @@ -138,7 +138,7 @@ public class LogsCLI extends Configured implements Tool { String localDir = null; long bytes = Long.MAX_VALUE; try { - CommandLine commandLine = parser.parse(opts, args, true); + CommandLine commandLine = parser.parse(opts, args, false); appIdStr = commandLine.getOptionValue(APPLICATION_ID_OPTION); containerIdStr = commandLine.getOptionValue(CONTAINER_ID_OPTION); nodeAddress = commandLine.getOptionValue(NODE_ADDRESS_OPTION); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java index ec8e000233e..eef92b102e3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java @@ -125,6 +125,21 @@ public class TestLogsCLI { assertTrue("Should return an error code", exitCode != 0); } + @Test(timeout = 1000l) + public void testInvalidOpts() throws Exception { + Configuration conf = new YarnConfiguration(); + YarnClient mockYarnClient = createMockYarnClient( + YarnApplicationState.FINISHED, + UserGroupInformation.getCurrentUser().getShortUserName()); + LogsCLI cli = new LogsCLIForTest(mockYarnClient); + cli.setConf(conf); + + int exitCode = cli.run( new String[] { "-InvalidOpts"}); + assertTrue(exitCode == -1); + assertTrue(sysErrStream.toString().contains( + "options parsing failed: Unrecognized option: -InvalidOpts")); + } + @Test(timeout = 5000l) public void testInvalidApplicationId() throws Exception { Configuration conf = new YarnConfiguration();