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 3db970ca73b923d1f60b574085938cf07f0f65fe..00f5cd54ad6505636565482ff7948ac18dd2e2ef 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") +} 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 0000000000000000000000000000000000000000..d6b93f5fedd3b8c8cc79c0400757192b830d38c5 --- /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) + } + +}