[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


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/c7a85545
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/c7a85545
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/c7a85545

Branch: refs/heads/master
Commit: c7a85545ba73e93e4a55ef8886362badaa2e2147
Parents: e629b2e
Author: Maximilian Michels <m...@apache.org>
Authored: Mon Aug 1 15:19:15 2016 +0200
Committer: Stephan Ewen <se...@apache.org>
Committed: Fri Aug 5 16:03:58 2016 +0200

----------------------------------------------------------------------
 .../src/main/flink-bin/yarn-bin/yarn-session.sh    |  2 +-
 .../apache/flink/yarn/cli/FlinkYarnSessionCli.java | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/c7a85545/flink-dist/src/main/flink-bin/yarn-bin/yarn-session.sh
----------------------------------------------------------------------
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 7c92680..502df3d 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 "$@"
 

http://git-wip-us.apache.org/repos/asf/flink/blob/c7a85545/flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java
----------------------------------------------------------------------
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 3e3b640..bee6a7a 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.IOException;
 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 class FlinkYarnSessionCli implements 
CustomCommandLine<YarnClusterClient>
                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);

Reply via email to