-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12559][SPARK SUBMIT] fix --packages for stand-alone cluster mode #18630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * 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 java.io.File | ||
| import java.nio.file.Files | ||
|
|
||
| import scala.collection.mutable.HashMap | ||
|
|
||
| import org.apache.commons.io.FileUtils | ||
| import org.apache.commons.lang3.StringUtils | ||
| import org.apache.hadoop.conf.Configuration | ||
|
|
||
| import org.apache.spark.util.MutableURLClassLoader | ||
|
|
||
| private[deploy] object DependencyUtils { | ||
|
|
||
| def resolveMavenDependencies( | ||
| packagesExclusions: String, | ||
| packages: String, | ||
| repositories: String, | ||
| ivyRepoPath: String): String = { | ||
| val exclusions: Seq[String] = | ||
| if (!StringUtils.isBlank(packagesExclusions)) { | ||
| packagesExclusions.split(",") | ||
| } else { | ||
| Nil | ||
| } | ||
| // Create the IvySettings, either load from file or build defaults | ||
| val ivySettings = sys.props.get("spark.jars.ivySettings").map { ivySettingsFile => | ||
| SparkSubmitUtils.loadIvySettings(ivySettingsFile, Option(repositories), | ||
| Option(ivyRepoPath)) | ||
|
||
| }.getOrElse { | ||
| SparkSubmitUtils.buildIvySettings(Option(repositories), Option(ivyRepoPath)) | ||
| } | ||
|
|
||
| SparkSubmitUtils.resolveMavenCoordinates(packages, ivySettings, exclusions = exclusions) | ||
| } | ||
|
|
||
| def createTempDir(): File = { | ||
|
||
| val targetDir = Files.createTempDirectory("tmp").toFile | ||
| // scalastyle:off runtimeaddshutdownhook | ||
|
||
| Runtime.getRuntime.addShutdownHook(new Thread() { | ||
| override def run(): Unit = { | ||
| FileUtils.deleteQuietly(targetDir) | ||
| } | ||
| }) | ||
| // scalastyle:on runtimeaddshutdownhook | ||
| targetDir | ||
| } | ||
|
|
||
| def resolveAndDownloadJars(jars: String, userJar: String): String = { | ||
| val targetDir = DependencyUtils.createTempDir() | ||
| val hadoopConf = new Configuration() | ||
| val sparkProperties = new HashMap[String, String]() | ||
| val securityProperties = List("spark.ssl.fs.trustStore", "spark.ssl.trustStore", | ||
| "spark.ssl.fs.trustStorePassword", "spark.ssl.trustStorePassword", | ||
| "spark.ssl.fs.protocol", "spark.ssl.protocol") | ||
|
|
||
| securityProperties.foreach { pName => | ||
| sys.props.get(pName).foreach { pValue => | ||
| sparkProperties.put(pName, pValue) | ||
| } | ||
| } | ||
|
|
||
| Option(jars) | ||
| .map { | ||
| SparkSubmit.resolveGlobPaths(_, hadoopConf) | ||
| .split(",") | ||
| .filterNot(_.contains(userJar.split("/").last)) | ||
| .mkString(",") | ||
| } | ||
| .filterNot(_ == "") | ||
| .map(SparkSubmit.downloadFileList(_, targetDir, sparkProperties, hadoopConf)) | ||
| .orNull | ||
| } | ||
|
|
||
| def addJarsToClassPath(jars: String, loader: MutableURLClassLoader): Unit = { | ||
| if (jars != null) { | ||
| for (jar <- jars.split(",")) { | ||
| SparkSubmit.addJarToClasspath(jar, loader) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,10 @@ package org.apache.spark.deploy.worker | |
|
|
||
| import java.io.File | ||
|
|
||
| import org.apache.commons.lang3.StringUtils | ||
|
|
||
| import org.apache.spark.{SecurityManager, SparkConf} | ||
| import org.apache.spark.deploy.{DependencyUtils, SparkSubmit} | ||
| import org.apache.spark.rpc.RpcEnv | ||
| import org.apache.spark.util.{ChildFirstURLClassLoader, MutableURLClassLoader, Utils} | ||
|
|
||
|
|
@@ -51,6 +54,7 @@ object DriverWrapper { | |
| new MutableURLClassLoader(Array(userJarUrl), currentLoader) | ||
| } | ||
| Thread.currentThread.setContextClassLoader(loader) | ||
| setupDependencies(loader, userJar) | ||
|
|
||
| // Delegate to supplied main class | ||
| val clazz = Utils.classForName(mainClass) | ||
|
|
@@ -66,4 +70,23 @@ object DriverWrapper { | |
| System.exit(-1) | ||
| } | ||
| } | ||
|
|
||
| private def setupDependencies(loader: MutableURLClassLoader, userJar: String): Unit = { | ||
| val Seq(packagesExclusions, packages, repositories, ivyRepoPath) = | ||
| Seq("spark.jars.excludes", "spark.jars.packages", "spark.jars.repositories", "spark.jars.ivy") | ||
| .map(sys.props.get(_).orNull) | ||
|
|
||
| val resolvedMavenCoordinates = DependencyUtils.resolveMavenDependencies(packagesExclusions, | ||
| packages, repositories, ivyRepoPath) | ||
| val jars = { | ||
| val jarsProp = sys.props.get("spark.jars").orNull | ||
| if (!StringUtils.isBlank(resolvedMavenCoordinates)) { | ||
| SparkSubmit.mergeFileLists(jarsProp, resolvedMavenCoordinates) | ||
|
||
| } else { | ||
| jarsProp | ||
| } | ||
| } | ||
| val localJars = DependencyUtils.resolveAndDownloadJars(jars, userJar) | ||
| DependencyUtils.addJarsToClassPath(localJars, loader) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this new object? It make the order of calls confusing. For instance SparkSubmit calls DependencyUtils which makes calls to SparkSubmitUtils. Can we just move this to SparkSubmitUtils?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked for this change, because
SparkSubmitUtilsis kind of a bad place to keep this code if things other thanSparkSubmitstart using it. The calls intoSparkSubmitUtilsare not optimal but those can be refactored separately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's fine if you are thinking the calls back to
SparkSubmitUtilscan be moved here eventually.