Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix comments.
  • Loading branch information
Sun Rui committed Jul 13, 2015
commit 2ca5048dfe9b4132b95cefb64b91b97041d3046b
2 changes: 1 addition & 1 deletion core/src/main/scala/org/apache/spark/api/r/RRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private[r] object RRDD {
private def createRProcess(port: Int, script: String): BufferedStreamThread = {
val rCommand = SparkEnv.get.conf.get("spark.sparkr.r.command", "Rscript")
val rOptions = "--vanilla"
val rLibDir = RUtils.sparkRPackagePath(false)
val rLibDir = RUtils.sparkRPackagePath(driver = false)
val rExecScript = rLibDir + "/SparkR/worker/" + script
val pb = new ProcessBuilder(List(rCommand, rOptions, rExecScript))
// Unset the R_TESTS environment variable for workers.
Expand Down
23 changes: 17 additions & 6 deletions core/src/main/scala/org/apache/spark/api/r/RUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,39 @@

package org.apache.spark.api.r

import java.io.{File}
import java.io.File

import org.apache.spark.SparkException

private[spark] object RUtils {
/**
* Get the SparkR package path in the local spark distribution.
*/
def localSparkRPackagePath: Option[String] = {
val sparkHome = sys.env.get("SPARK_HOME")
sparkHome.map(
Seq(_, "R", "lib").mkString(File.separator)
)
}

/**
* Get the SparkR package path in various deployment modes.
*/
def sparkRPackagePath(driver: Boolean): String = {
val yarnMode = sys.env.get("SPARK_YARN_MODE")
if (!yarnMode.isEmpty && yarnMode.get == "true" &&
!(driver && System.getProperty("spark.master") == "yarn-client")) {
// The SparkR package distributed as an archive resource should be pointed to
// For workers in YARN modes and driver in yarn cluster mode,
// the SparkR package distributed as an archive resource should be pointed to
// by a symbol link "sparkr" in the current directory.
new File("sparkr").getAbsolutePath
} else {
// TBD: add support for MESOS
val sparkHome = sys.env.get("SPARK_HOME")
if (sparkHome.isEmpty) {
val rPackagePath = localSparkRPackagePath
if (rPackagePath.isEmpty) {
throw new SparkException("SPARK_HOME not set. Can't locate SparkR package.")
}
Seq(sparkHome, "R", "lib").mkString(File.separator)
}
rPackagePath.get
}
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/org/apache/spark/deploy/RRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object RRunner {
val builder = new ProcessBuilder(Seq(rCommand, rFileNormalized) ++ otherArgs)
val env = builder.environment()
env.put("EXISTING_SPARKR_BACKEND_PORT", sparkRBackendPort.toString)
val rPackageDir = RUtils.sparkRPackagePath(true)
val rPackageDir = RUtils.sparkRPackagePath(driver = true)
env.put("SPARKR_PACKAGE_DIR", rPackageDir)
env.put("R_PROFILE_USER",
Seq(rPackageDir, "SparkR", "profile", "general.R").mkString(File.separator))
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.apache.ivy.core.settings.IvySettings
import org.apache.ivy.plugins.matcher.GlobPatternMatcher
import org.apache.ivy.plugins.repository.file.FileRepository
import org.apache.ivy.plugins.resolver.{FileSystemResolver, ChainResolver, IBiblioResolver}
import org.apache.spark.api.r.RUtils
import org.apache.spark.SPARK_VERSION
import org.apache.spark.deploy.rest._
import org.apache.spark.util.{ChildFirstURLClassLoader, MutableURLClassLoader, Utils}
Expand Down Expand Up @@ -351,12 +352,11 @@ object SparkSubmit {
// In yarn mode for an R app, add the SparkR package archive to archives
// that can be distributed with the job
if (args.isR && clusterManager == YARN) {
val sparkHome = sys.env.get("SPARK_HOME")
if (sparkHome.isEmpty) {
val rPackagePath = RUtils.localSparkRPackagePath
if (rPackagePath.isEmpty) {
printErrorAndExit("SPARK_HOME does not exist for R application in yarn mode.")
}
val rPackagePath = Seq(sparkHome.get, "R", "lib").mkString(File.separator)
val rPackageFile = new File(rPackagePath, SPARKR_PACKAGE_ARCHIVE)
val rPackageFile = new File(rPackagePath.get, SPARKR_PACKAGE_ARCHIVE)
if (!rPackageFile.exists()) {
printErrorAndExit(s"$SPARKR_PACKAGE_ARCHIVE does not exist for R application in yarn mode.")
}
Expand Down