From 45b15e27a84527abeaa8588b0eb1ade7e831e6ef Mon Sep 17 00:00:00 2001 From: Patrick Wendell <pwendell@gmail.com> Date: Fri, 21 Feb 2014 11:11:55 -0800 Subject: [PATCH] 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 --- .../apache/spark/deploy/ClientArguments.scala | 17 +++++----- .../org/apache/spark/deploy/ClientSuite.scala | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 core/src/test/scala/org/apache/spark/deploy/ClientSuite.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 3db970ca73..00f5cd54ad 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 0000000000..d6b93f5fed --- /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) + } + +} -- GitLab