Skip to content
Snippets Groups Projects
Commit efd3b11a authored by Devaraj K's avatar Devaraj K Committed by Marcelo Vanzin
Browse files

[SPARK-15665][CORE] spark-submit --kill and --status are not working

## What changes were proposed in this pull request?
--kill and --status were not considered while handling in OptionParser and due to that it was failing. Now handling the --kill and --status options as part of OptionParser.handle.

## How was this patch tested?
Added a test org.apache.spark.launcher.SparkSubmitCommandBuilderSuite.testCliKillAndStatus() and also I have verified these manually by running --kill and --status commands.

Author: Devaraj K <devaraj@apache.org>

Closes #13407 from devaraj-kavali/SPARK-15665.
parent 9e2eb13c
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder { ...@@ -89,7 +89,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {
} }
final List<String> sparkArgs; final List<String> sparkArgs;
private final boolean printInfo; private final boolean isAppResourceReq;
private final boolean isExample; private final boolean isExample;
/** /**
...@@ -101,7 +101,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder { ...@@ -101,7 +101,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {
SparkSubmitCommandBuilder() { SparkSubmitCommandBuilder() {
this.sparkArgs = new ArrayList<>(); this.sparkArgs = new ArrayList<>();
this.printInfo = false; this.isAppResourceReq = true;
this.isExample = false; this.isExample = false;
} }
...@@ -133,19 +133,19 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder { ...@@ -133,19 +133,19 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {
this.isExample = isExample; this.isExample = isExample;
OptionParser parser = new OptionParser(); OptionParser parser = new OptionParser();
parser.parse(submitArgs); parser.parse(submitArgs);
this.printInfo = parser.infoRequested; this.isAppResourceReq = parser.isAppResourceReq;
} else { } else {
this.isExample = isExample; this.isExample = isExample;
this.printInfo = true; this.isAppResourceReq = false;
} }
} }
@Override @Override
public List<String> buildCommand(Map<String, String> env) public List<String> buildCommand(Map<String, String> env)
throws IOException, IllegalArgumentException { throws IOException, IllegalArgumentException {
if (PYSPARK_SHELL.equals(appResource) && !printInfo) { if (PYSPARK_SHELL.equals(appResource) && isAppResourceReq) {
return buildPySparkShellCommand(env); return buildPySparkShellCommand(env);
} else if (SPARKR_SHELL.equals(appResource) && !printInfo) { } else if (SPARKR_SHELL.equals(appResource) && isAppResourceReq) {
return buildSparkRCommand(env); return buildSparkRCommand(env);
} else { } else {
return buildSparkSubmitCommand(env); return buildSparkSubmitCommand(env);
...@@ -156,7 +156,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder { ...@@ -156,7 +156,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {
List<String> args = new ArrayList<>(); List<String> args = new ArrayList<>();
SparkSubmitOptionParser parser = new SparkSubmitOptionParser(); SparkSubmitOptionParser parser = new SparkSubmitOptionParser();
if (!allowsMixedArguments && !printInfo) { if (!allowsMixedArguments && isAppResourceReq) {
checkArgument(appResource != null, "Missing application resource."); checkArgument(appResource != null, "Missing application resource.");
} }
...@@ -208,7 +208,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder { ...@@ -208,7 +208,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {
args.add(join(",", pyFiles)); args.add(join(",", pyFiles));
} }
if (!printInfo) { if (isAppResourceReq) {
checkArgument(!isExample || mainClass != null, "Missing example class name."); checkArgument(!isExample || mainClass != null, "Missing example class name.");
} }
if (mainClass != null) { if (mainClass != null) {
...@@ -388,7 +388,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder { ...@@ -388,7 +388,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {
private class OptionParser extends SparkSubmitOptionParser { private class OptionParser extends SparkSubmitOptionParser {
boolean infoRequested = false; boolean isAppResourceReq = true;
@Override @Override
protected boolean handle(String opt, String value) { protected boolean handle(String opt, String value) {
...@@ -420,11 +420,15 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder { ...@@ -420,11 +420,15 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {
allowsMixedArguments = true; allowsMixedArguments = true;
appResource = specialClasses.get(value); appResource = specialClasses.get(value);
} }
} else if (opt.equals(KILL_SUBMISSION) || opt.equals(STATUS)) {
isAppResourceReq = false;
sparkArgs.add(opt);
sparkArgs.add(value);
} else if (opt.equals(HELP) || opt.equals(USAGE_ERROR)) { } else if (opt.equals(HELP) || opt.equals(USAGE_ERROR)) {
infoRequested = true; isAppResourceReq = false;
sparkArgs.add(opt); sparkArgs.add(opt);
} else if (opt.equals(VERSION)) { } else if (opt.equals(VERSION)) {
infoRequested = true; isAppResourceReq = false;
sparkArgs.add(opt); sparkArgs.add(opt);
} else { } else {
sparkArgs.add(opt); sparkArgs.add(opt);
......
...@@ -72,6 +72,12 @@ public class SparkSubmitCommandBuilderSuite extends BaseSuite { ...@@ -72,6 +72,12 @@ public class SparkSubmitCommandBuilderSuite extends BaseSuite {
cmd.contains("org.apache.spark.deploy.SparkSubmit")); cmd.contains("org.apache.spark.deploy.SparkSubmit"));
} }
@Test
public void testCliKillAndStatus() throws Exception {
testCLIOpts(parser.STATUS);
testCLIOpts(parser.KILL_SUBMISSION);
}
@Test @Test
public void testCliParser() throws Exception { public void testCliParser() throws Exception {
List<String> sparkSubmitArgs = Arrays.asList( List<String> sparkSubmitArgs = Arrays.asList(
...@@ -326,4 +332,12 @@ public class SparkSubmitCommandBuilderSuite extends BaseSuite { ...@@ -326,4 +332,12 @@ public class SparkSubmitCommandBuilderSuite extends BaseSuite {
return newCommandBuilder(args).buildCommand(env); return newCommandBuilder(args).buildCommand(env);
} }
private void testCLIOpts(String opt) throws Exception {
List<String> helpArgs = Arrays.asList(opt, "driver-20160531171222-0000");
Map<String, String> env = new HashMap<>();
List<String> cmd = buildCommand(helpArgs, env);
assertTrue(opt + " should be contained in the final cmd.",
cmd.contains(opt));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment