Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class SparkSubmitCommandBuilder extends AbstractCommandBuilder {

case RUN_EXAMPLE:
isExample = true;
appResource = SparkLauncher.NO_RESOURCE;
appResource = findExamplesAppJar();
submitArgs = args.subList(1, args.size());
}

Expand Down Expand Up @@ -241,9 +241,11 @@ List<String> buildSparkSubmitArgs() {
}

args.addAll(parsedArgs);

if (appResource != null) {
args.add(appResource);
}

args.addAll(appArgs);

return args;
Expand Down Expand Up @@ -401,6 +403,15 @@ private boolean isThriftServer(String mainClass) {
mainClass.equals("org.apache.spark.sql.hive.thriftserver.HiveThriftServer2"));
}

private String findExamplesAppJar() {
for (String exampleJar : findExamplesJars()) {
if (new File(exampleJar).getName().startsWith("spark-examples")) {
return exampleJar;
}
}
throw new IllegalStateException("Failed to find examples' main app jar.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koertkuipers I think you can fix it like:

if (isTesting) {
  SparkLauncher.NO_RESOURCE
} else {
  throw new IllegalStateException("Failed to find examples' main app jar.");
}

Are you interested in fixing it as a followup pr via testing as you did?

}

private List<String> findExamplesJars() {
boolean isTesting = "1".equals(getenv("SPARK_TESTING"));
List<String> examplesJars = new ArrayList<>();
Expand Down Expand Up @@ -513,7 +524,7 @@ protected boolean handleUnknown(String opt) {
className = EXAMPLE_CLASS_PREFIX + className;
}
mainClass = className;
appResource = SparkLauncher.NO_RESOURCE;
appResource = findExamplesAppJar();
return false;
} else if (errorOnUnknownArgs) {
checkArgument(!opt.startsWith("-"), "Unrecognized option: %s", opt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,24 @@ public void testExamplesRunner() throws Exception {
assertEquals("42", cmd.get(cmd.size() - 1));
}

@Test
public void testExamplesRunnerPrimaryResource() throws Exception {
List<String> sparkSubmitArgs = Arrays.asList(
SparkSubmitCommandBuilder.RUN_EXAMPLE,
parser.MASTER + "=foo",
parser.DEPLOY_MODE + "=cluster",
"SparkPi",
"100");

List<String> cmd = newCommandBuilder(sparkSubmitArgs).buildSparkSubmitArgs();
assertEquals(SparkSubmitCommandBuilder.EXAMPLE_CLASS_PREFIX + "SparkPi",
findArgValue(cmd, parser.CLASS));
assertEquals("cluster", findArgValue(cmd, parser.DEPLOY_MODE));
String primaryResource = cmd.get(cmd.size() - 2);
assertTrue(new File(primaryResource).getName().startsWith("spark-examples"));
assertFalse(cmd.contains(SparkLauncher.NO_RESOURCE));
}

@Test(expected = IllegalArgumentException.class)
public void testMissingAppResource() {
new SparkSubmitCommandBuilder().buildSparkSubmitArgs();
Expand Down