Skip to content

Commit

Permalink
[FLINK-4297] [yarn] Decode URL encoded fat jar path
Browse files Browse the repository at this point in the history
This solves problems with spaces and special characters in the
automatically determined fat jar path which is returned URL encoded.

This closes apache#2320
  • Loading branch information
mxm authored and StephanEwen committed Aug 5, 2016
1 parent e629b2e commit c7a8554
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion flink-dist/src/main/flink-bin/yarn-bin/yarn-session.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ log_setting="-Dlog.file="$log" -Dlog4j.configuration=file:"$FLINK_CONF_DIR"/log4

export FLINK_CONF_DIR

$JAVA_RUN $JVM_ARGS -classpath $CC_CLASSPATH:$HADOOP_CLASSPATH:$HADOOP_CONF_DIR:$YARN_CONF_DIR $log_setting org.apache.flink.yarn.cli.FlinkYarnSessionCli -j $FLINK_LIB_DIR/flink-dist*.jar "$@"
$JAVA_RUN $JVM_ARGS -classpath "$CC_CLASSPATH:$HADOOP_CLASSPATH:$HADOOP_CONF_DIR:$YARN_CONF_DIR" $log_setting org.apache.flink.yarn.cli.FlinkYarnSessionCli -j "$FLINK_LIB_DIR"/flink-dist*.jar "$@"

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -253,15 +256,23 @@ public AbstractYarnClusterDescriptor createDescriptor(String defaultApplicationN
Path localJarPath;
if (cmd.hasOption(FLINK_JAR.getOpt())) {
String userPath = cmd.getOptionValue(FLINK_JAR.getOpt());
if(!userPath.startsWith("file://")) {
if (!userPath.startsWith("file://")) {
userPath = "file://" + userPath;
}
localJarPath = new Path(userPath);
} else {
LOG.info("No path for the flink jar passed. Using the location of "
+ yarnClusterDescriptor.getClass() + " to locate the jar");
localJarPath = new Path("file://" +
yarnClusterDescriptor.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
String encodedJarPath =
yarnClusterDescriptor.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
try {
// we have to decode the url encoded parts of the path
String decodedPath = URLDecoder.decode(encodedJarPath, Charset.defaultCharset().name());
localJarPath = new Path(new File(decodedPath).toURI());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Couldn't decode the encoded Flink dist jar path: " + encodedJarPath +
" Please supply a path manually via the -" + FLINK_JAR.getOpt() + " option.");
}
}

yarnClusterDescriptor.setLocalJarPath(localJarPath);
Expand Down

0 comments on commit c7a8554

Please sign in to comment.