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
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,11 @@ private[spark] class Client(
try {
jarsStream.setLevel(0)
jarsDir.listFiles().foreach { f =>
if (f.isFile && f.getName.toLowerCase(Locale.ROOT).endsWith(".jar") && f.canRead) {
if (f.isFile
&& f.getName.toLowerCase(Locale.ROOT).endsWith(".jar")
&& f.canRead
&& !f.getName.matches(sparkConf.get("spark.yarn.jars.exclusionRegex", "")))
{
jarsStream.putNextEntry(new ZipEntry(f.getName))
Files.copy(f, jarsStream)
jarsStream.closeEntry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.deploy.yarn
import java.io.{File, FileInputStream, FileOutputStream}
import java.net.URI
import java.util.Properties
import java.util.zip.ZipFile

import scala.collection.JavaConverters._
import scala.collection.mutable.{HashMap => MutableHashMap}
Expand Down Expand Up @@ -331,6 +332,32 @@ class ClientSuite extends SparkFunSuite with Matchers {
classpath(client) should contain (buildPath(PWD, LOCALIZED_LIB_DIR, "*"))
}

test("exclude local spark jars when specified") {
val temp = Utils.createTempDir()
val jarsDir = new File(temp, "jars")
assert(jarsDir.mkdir())

val jarInclude = new File(jarsDir, "include.jar")
val jarExclude = new File(jarsDir, "exclude.jar")
new FileOutputStream(jarInclude).close()
new FileOutputStream(jarExclude).close()

val sparkConf = new SparkConfWithEnv(Map("SPARK_HOME" -> temp.getAbsolutePath()))
sparkConf.set("spark.yarn.jars.exclusionRegex", ".*exclude.*")

val client = createClient(sparkConf)
client.prepareLocalResources(new Path(temp.getAbsolutePath()), Nil)

val outputZipFile = new ZipFile(
temp
.listFiles()
.filter(fl => fl.getName.matches("__spark_libs__.*zip"))(0)
)

outputZipFile.getEntry(jarInclude.getName) should not be (null)
outputZipFile.getEntry(jarExclude.getName) should be (null)
}

test("ignore same name jars") {
val libs = Utils.createTempDir()
val jarsDir = new File(libs, "jars")
Expand Down