From c7a85545ba73e93e4a55ef8886362badaa2e2147 Mon Sep 17 00:00:00 2001 From: Maximilian Michels Date: Mon, 1 Aug 2016 15:19:15 +0200 Subject: [PATCH] [FLINK-4297] [yarn] Decode URL encoded fat jar path This solves problems with spaces and special characters in the automatically determined fat jar path which is returned URL encoded. This closes #2320 --- .../src/main/flink-bin/yarn-bin/yarn-session.sh | 2 +- .../flink/yarn/cli/FlinkYarnSessionCli.java | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/flink-dist/src/main/flink-bin/yarn-bin/yarn-session.sh b/flink-dist/src/main/flink-bin/yarn-bin/yarn-session.sh index 7c92680bc5adb..502df3d08e588 100755 --- a/flink-dist/src/main/flink-bin/yarn-bin/yarn-session.sh +++ b/flink-dist/src/main/flink-bin/yarn-bin/yarn-session.sh @@ -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 "$@" diff --git a/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java b/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java index 3e3b6406465a2..bee6a7ac80c3b 100644 --- a/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java +++ b/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java @@ -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; @@ -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);