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 <pwendell@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
This commit is contained in:
Patrick Wendell 2014-02-21 11:11:55 -08:00 committed by Aaron Davidson
parent 59b1379594
commit 45b15e27a8
2 changed files with 42 additions and 9 deletions

View file

@ -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")
}

View file

@ -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)
}
}