Skip to content
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

Filter rLibDir by exists so that daemon.R references the correct file #460

Merged
merged 1 commit into from
Dec 13, 2018
Merged
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
12 changes: 8 additions & 4 deletions core/src/main/scala/org/apache/spark/api/r/RRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,14 @@ private[r] object RRunner {
val rConnectionTimeout = sparkConf.getInt(
"spark.r.backendConnectionTimeout", SparkRDefaults.DEFAULT_CONNECTION_TIMEOUT)
val rOptions = "--vanilla"
val rLibDir = condaEnv.map { conda =>
RUtils.sparkRPackagePath(isDriver = false) :+ (conda.condaEnvDir + "/lib/R/library")
}.getOrElse(RUtils.sparkRPackagePath(isDriver = false))
val rExecScript = RUtils.sparkRInstallLocation(rLibDir, "/SparkR/worker/" + script)
val rLibDir = condaEnv.map(conda =>
RUtils.sparkRPackagePath(isDriver = false) :+ (conda.condaEnvDir + "/lib/R/library"))
.getOrElse(RUtils.sparkRPackagePath(isDriver = false))
.filter(dir => new File(dir).exists)
if (rLibDir.isEmpty) {
throw new SparkException("SparkR package is not installed on executor.")
}
val rExecScript = RUtils.getSparkRScript(rLibDir, "/SparkR/worker/" + script)
val pb = new ProcessBuilder(Arrays.asList(rCommand, rOptions, rExecScript))
// Activate the conda environment by setting the right env variables if applicable.
condaEnv.map(_.activatedEnvironment()).map(_.asJava).foreach(pb.environment().putAll)
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/scala/org/apache/spark/api/r/RUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ private[spark] object RUtils {
}
}

/** Finds the rLibDir with SparkR installed on it. */
def sparkRInstallLocation(rLibDir: Seq[String], scriptPath: String): String = {
rLibDir.find(dir => new File(dir + scriptPath).exists)
.getOrElse(throw new SparkException("SparkR package not installed on executor.")) + scriptPath
/** Finds a script in a sequence of possible SparkR installation directories. */
def getSparkRScript(rLibDir: Seq[String], scriptPath: String): String = {
rLibDir.find(dir => new File(dir + scriptPath).exists).getOrElse(
throw new SparkException(
s"Script $scriptPath not found in any SparkR installation directory.")
) + scriptPath
}

/** Check if R is installed before running tests that use R commands. */
Expand Down