Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions core/src/main/scala/org/apache/spark/deploy/ClientArguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.deploy

import java.net.{URI, URISyntaxException}

import scala.collection.mutable.ListBuffer

import org.apache.log4j.Level
Expand Down Expand Up @@ -73,7 +75,8 @@ private[spark] class ClientArguments(args: Array[String]) {

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)")
println(s"Must be a jar file path in URL format " +
"(e.g. hdfs://host:port/XX.jar, file:///XX.jar)")
printUsageAndExit(-1)
}

Expand Down Expand Up @@ -114,5 +117,12 @@ private[spark] class ClientArguments(args: Array[String]) {
}

object ClientArguments {
def isValidJarUrl(s: String): Boolean = s.matches("(.+):(.+)jar")
def isValidJarUrl(s: String): Boolean = {
try {
val uri = new URI(s)
uri.getScheme != null && uri.getPath != null && uri.getPath.endsWith(".jar")
} catch {
case _: URISyntaxException => false
}
}
}
17 changes: 16 additions & 1 deletion core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,27 @@ import org.scalatest.Matchers
class ClientSuite extends FunSuite with Matchers {
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)

// file scheme with authority and path is valid.
ClientArguments.isValidJarUrl("file://somehost/path/to/a/jarFile.jar") should be (true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why is this valid?


// file scheme without path is not valid.
// In this case, jarFile.jar is recognized as authority.
ClientArguments.isValidJarUrl("file://jarFile.jar") should be (false)

// file scheme without authority but with triple slash is valid.
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)

// This URI doesn't have authority and path.
ClientArguments.isValidJarUrl("hdfs:someHost:1234/jarfile.jar") should be (false)

// Invalid syntax.
ClientArguments.isValidJarUrl("hdfs:") should be (false)
}

}