Skip to content

Commit 95ddfa8

Browse files
author
Marcelo Vanzin
committed
Fix handling of --help for spark-class command builder.
1 parent 72da7ec commit 95ddfa8

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

launcher/src/main/java/org/apache/spark/launcher/SparkClassCommandBuilder.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,48 @@ public List<String> buildCommand(Map<String, String> env) throws IOException {
109109
}
110110

111111
private List<String> createSparkSubmitCommand(Map<String, String> env) throws IOException {
112-
List<String> sparkSubmitArgs = new ArrayList<String>(classArgs);
112+
final List<String> sparkSubmitArgs = new ArrayList<String>();
113+
final List<String> appArgs = new ArrayList<String>();
113114

114-
// This is a workaround for the fact that the constants in SparkSubmitOptionParser are not
115-
// static. The parser itself is never used, we just don't want to hardcode the value of that
116-
// option here.
115+
// This parser exists for two reasons:
116+
// - to expose the command line args constants, since they're not static
117+
// - to special-case the HELP command line argument, and allow it to be propagated to
118+
// the app being launched.
117119
SparkSubmitOptionParser parser = new SparkSubmitOptionParser() {
118120

119121
@Override
120122
protected boolean handle(String opt, String value) {
121-
throw new UnsupportedOperationException();
123+
if (opt.equals(HELP)) {
124+
appArgs.add(opt);
125+
} else {
126+
sparkSubmitArgs.add(opt);
127+
sparkSubmitArgs.add(value);
128+
}
129+
return true;
122130
}
123131

124132
@Override
125133
protected boolean handleUnknown(String opt) {
126-
throw new UnsupportedOperationException();
134+
appArgs.add(opt);
135+
return true;
127136
}
128137

129138
@Override
130139
protected void handleExtraArgs(List<String> extra) {
131-
throw new UnsupportedOperationException();
140+
appArgs.addAll(extra);
132141
}
133142

134143
};
135144

145+
parser.parse(classArgs);
136146
sparkSubmitArgs.add(parser.CLASS);
137147
sparkSubmitArgs.add(className);
138148

139149
SparkSubmitCommandBuilder builder = new SparkSubmitCommandBuilder(true, sparkSubmitArgs);
140150
builder.setAppResource("spark-internal");
151+
for (String arg: appArgs) {
152+
builder.addAppArgs(arg);
153+
}
141154
return builder.buildCommand(env);
142155
}
143156

0 commit comments

Comments
 (0)