diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/param/RunJobParameters.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/param/RunJobParameters.java index 92a1883f32..d923e0f106 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/param/RunJobParameters.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/param/RunJobParameters.java @@ -62,6 +62,12 @@ public void updateParametersByParsedCommandline(CommandLine parsedCommandLine, if (parsedCommandLine.getOptionValue(CliConstants.N_WORKERS) != null) { nWorkers = Integer.parseInt( parsedCommandLine.getOptionValue(CliConstants.N_WORKERS)); + // Only check null value. + // Training job shouldn't ignore INPUT_PATH option + // But if nWorkers is 0, INPUT_PATH can be ignored because user can only run Tensorboard + if (null == input && 0 != nWorkers) { + throw new ParseException("\"--" + CliConstants.INPUT_PATH + "\" is absent"); + } } int nPS = 0; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java index 295d6a87c9..240de064b2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-submarine/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestRunJobCliParsing.java @@ -19,6 +19,7 @@ package org.apache.hadoop.yarn.submarine.client.cli; +import org.apache.commons.cli.ParseException; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.ResourceInformation; @@ -135,6 +136,44 @@ public void testBasicRunJobForSingleNodeTraining() throws Exception { Assert.assertTrue(jobRunParameters.isWaitJobFinish()); } + @Test + public void testNoInputPathOptionSpecified() throws Exception { + RunJobCli runJobCli = new RunJobCli(getMockClientContext()); + String expectedErrorMessage = "\"--" + CliConstants.INPUT_PATH + "\" is absent"; + String actualMessage = ""; + try { + runJobCli.run( + new String[]{"--name", "my-job", "--docker_image", "tf-docker:1.1.0", + "--checkpoint_path", "hdfs://output", + "--num_workers", "1", "--worker_launch_cmd", "python run-job.py", + "--worker_resources", "memory=4g,vcores=2", "--tensorboard", + "true", "--verbose", "--wait_job_finish"}); + } catch (ParseException e) { + actualMessage = e.getMessage(); + e.printStackTrace(); + } + Assert.assertEquals(expectedErrorMessage, actualMessage); + } + + /** + * when only run tensorboard, input_path is not needed + * */ + @Test + public void testNoInputPathOptionButOnlyRunTensorboard() throws Exception { + RunJobCli runJobCli = new RunJobCli(getMockClientContext()); + boolean success = true; + try { + runJobCli.run( + new String[]{"--name", "my-job", "--docker_image", "tf-docker:1.1.0", + "--num_workers", "0", "--tensorboard", "--verbose", + "--tensorboard_resources", "memory=2G,vcores=2", + "--tensorboard_docker_image", "tb_docker_image:001"}); + } catch (ParseException e) { + success = false; + } + Assert.assertTrue(success); + } + @Test public void testLaunchCommandPatternReplace() throws Exception { RunJobCli runJobCli = new RunJobCli(getMockClientContext());