Skip to content

Commit

Permalink
SPARK-1111: URL Validation Throws Error for HDFS URL's
Browse files Browse the repository at this point in the history
Fixes an error where HDFS URL's cause an exception. Should be merged into master and 0.9.

Author: Patrick Wendell <pwendell@gmail.com>

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

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

(cherry picked from commit 45b15e2)
Signed-off-by: Aaron Davidson <aaron@databricks.com>
  • Loading branch information
pwendell authored and James Z.M. Gao committed Mar 10, 2014
1 parent f0caee3 commit 8f302e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.spark.deploy

import java.net.URL

import scala.collection.mutable.ListBuffer

import org.apache.log4j.Level
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -115,3 +110,7 @@ private[spark] class ClientArguments(args: Array[String]) {
System.exit(exitCode)
}
}

object ClientArguments {
def isValidJarUrl(s: String) = s.matches("(.+):(.+)jar")
}
34 changes: 34 additions & 0 deletions core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala
Original file line number Diff line number Diff line change
@@ -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)
}

}

0 comments on commit 8f302e0

Please sign in to comment.