You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ad...@apache.org on 2014/02/21 20:12:32 UTC

git commit: SPARK-1111: URL Validation Throws Error for HDFS URL's

Repository: incubator-spark
Updated Branches:
  refs/heads/master 59b137959 -> 45b15e27a


SPARK-1111: URL Validation Throws Error for HDFS URL's

Fixes an error where HDFS URL's cause an exception. Should be merged into master and 0.9.

Author: Patrick Wendell <pw...@gmail.com>

Closes #625 from pwendell/url-validation and squashes the following commits:

d14bfe3 [Patrick Wendell] SPARK-1111: URL Validation Throws Error for HDFS URL's


Project: http://git-wip-us.apache.org/repos/asf/incubator-spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spark/commit/45b15e27
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spark/tree/45b15e27
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spark/diff/45b15e27

Branch: refs/heads/master
Commit: 45b15e27a84527abeaa8588b0eb1ade7e831e6ef
Parents: 59b1379
Author: Patrick Wendell <pw...@gmail.com>
Authored: Fri Feb 21 11:11:55 2014 -0800
Committer: Aaron Davidson <aa...@databricks.com>
Committed: Fri Feb 21 11:11:55 2014 -0800

----------------------------------------------------------------------
 .../apache/spark/deploy/ClientArguments.scala   | 17 +++++-----
 .../org/apache/spark/deploy/ClientSuite.scala   | 34 ++++++++++++++++++++
 2 files changed, 42 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/45b15e27/core/src/main/scala/org/apache/spark/deploy/ClientArguments.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/deploy/ClientArguments.scala b/core/src/main/scala/org/apache/spark/deploy/ClientArguments.scala
index 3db970c..00f5cd5 100644
--- a/core/src/main/scala/org/apache/spark/deploy/ClientArguments.scala
+++ b/core/src/main/scala/org/apache/spark/deploy/ClientArguments.scala
@@ -17,8 +17,6 @@
 
 package org.apache.spark.deploy
 
-import java.net.URL
-
 import scala.collection.mutable.ListBuffer
 
 import org.apache.log4j.Level
@@ -71,13 +69,10 @@ private[spark] class ClientArguments(args: Array[String]) {
     case "launch" :: _master :: _jarUrl :: _mainClass :: tail =>
       cmd = "launch"
 
-      try {
-        new URL(_jarUrl)
-      } catch {
-        case e: Exception =>
-          println(s"Jar url '${_jarUrl}' is not a valid URL.")
-          println(s"Jar must be in URL format (e.g. hdfs://XX, file://XX)")
-          printUsageAndExit(-1)
+      if (!ClientArguments.isValidJarUrl(_jarUrl)) {
+        println(s"Jar url '${_jarUrl}' is not in valid format.")
+        println(s"Must be a jar file path in URL format (e.g. hdfs://XX.jar, file://XX.jar)")
+        printUsageAndExit(-1)
       }
 
       jarUrl = _jarUrl
@@ -115,3 +110,7 @@ private[spark] class ClientArguments(args: Array[String]) {
     System.exit(exitCode)
   }
 }
+
+object ClientArguments {
+  def isValidJarUrl(s: String) = s.matches("(.+):(.+)jar")
+}

http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/45b15e27/core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala b/core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala
new file mode 100644
index 0000000..d6b93f5
--- /dev/null
+++ b/core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.deploy
+
+import org.scalatest.FunSuite
+import org.scalatest.matchers.ShouldMatchers
+
+class ClientSuite extends FunSuite with ShouldMatchers {
+  test("correctly validates driver jar URL's") {
+    ClientArguments.isValidJarUrl("http://someHost:8080/foo.jar") should be (true)
+    ClientArguments.isValidJarUrl("file://some/path/to/a/jarFile.jar") should be (true)
+    ClientArguments.isValidJarUrl("hdfs://someHost:1234/foo.jar") should be (true)
+
+    ClientArguments.isValidJarUrl("hdfs://someHost:1234/foo") should be (false)
+    ClientArguments.isValidJarUrl("/missing/a/protocol/jarfile.jar") should be (false)
+    ClientArguments.isValidJarUrl("not-even-a-path.jar") should be (false)
+  }
+
+}