Skip to content

Commit

Permalink
Merge pull request #16 from riptano/DSP-15163-dse
Browse files Browse the repository at this point in the history
DSP-15163 use dse script to start context in separate jvm
  • Loading branch information
jtgrabowski authored Feb 25, 2018
2 parents c9836a5 + 813a850 commit 9ce8b09
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
4 changes: 2 additions & 2 deletions bin/manager_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ get_abs_script_path
. $appdir/setenv.sh

# Override logging options to provide per-context logging
LOGGING_OPTS="-Dlog4j.configuration=file:$appdir/log4j-server.properties
LOGGING_OPTS="$LOGGING_OPTS_FILE
-DLOG_DIR=$1"

GC_OPTS="-XX:+UseConcMarkSweepGC
Expand All @@ -40,5 +40,5 @@ else
$appdir/spark-job-server.jar $1 $2 $conffile'
fi

eval $cmd > /dev/null 2>&1 &
eval $cmd > /dev/null 2>&1
# exec java -cp $CLASSPATH $GC_OPTS $JAVA_OPTS $LOGGING_OPTS $CONFIG_OVERRIDES $MAIN $1 $2 $conffile 2>&1 &
6 changes: 4 additions & 2 deletions bin/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ if [ -z "$LOG_DIR" ]; then
fi
mkdir -p $LOG_DIR

LOGGING_OPTS="-Dlogback.configurationFile=file:$appdir/logback-server.xml
-DLOG_DIR=$LOG_DIR"
# used in server_start and in manager_start
LOGGING_OPTS_FILE="-Dlogback.configurationFile=file:$appdir/logback-server.xml"

LOGGING_OPTS="$LOGGING_OPTS_FILE -DLOG_DIR=$LOG_DIR"

# For Mesos
CONFIG_OVERRIDES="-Dspark.executor.uri=$SPARK_EXECUTOR_URI "
Expand Down
5 changes: 5 additions & 0 deletions job-server/config/dse.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ spark {

# Note that you can use this file to define settings not only for job server,
# but for your Spark jobs as well. Spark job configuration merges with this configuration file as defaults.


deploy {
manager-start-cmd = "dse spark-jobserver context-per-jvm-managed-start"
}
55 changes: 33 additions & 22 deletions job-server/src/spark.jobserver/AkkaClusterSupervisorActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package spark.jobserver
import java.io.IOException
import java.nio.file.{Files, Paths}
import java.nio.charset.Charset
import java.util.concurrent.TimeUnit
import java.util.concurrent.{ExecutorService, Executors, TimeUnit}

import akka.actor._
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{MemberUp, MemberEvent, InitialStateAsEvents}
import akka.util.Timeout
import com.google.common.util.concurrent.ThreadFactoryBuilder
import com.typesafe.config.{Config, ConfigFactory, ConfigRenderOptions}
import ooyala.common.akka.InstrumentedActor
import spark.jobserver.util.SparkJobUtils

import scala.collection.mutable
import scala.util.{Try, Success, Failure}
import scala.sys.process._

import scala.collection.concurrent.TrieMap

/**
* The AkkaClusterSupervisorActor launches Spark Contexts as external processes
* that connect back with the master node via Akka Cluster.
Expand Down Expand Up @@ -50,8 +54,10 @@ class AkkaClusterSupervisorActor(daoActor: ActorRef) extends InstrumentedActor {
//TODO: try to pass this state to the jobManager at start instead of having to track
//extra state. What happens if the WebApi process dies before the forked process
//starts up? Then it never gets initialized, and this state disappears.
private val contextInitInfos = mutable.HashMap.empty[String, (Boolean, ActorRef => Unit, Throwable => Unit)]

private val contextInitInfos = TrieMap.empty[String, (Boolean, ActorRef => Unit, Throwable => Unit)]
private val contextInitExecutorService = Executors.newCachedThreadPool(
new ThreadFactoryBuilder().setDaemon(true).setNameFormat("job-server-context-init-thread -% d").build
)
// actor name -> (JobManagerActor ref, ResultActor ref)
private val contexts = mutable.HashMap.empty[String, (ActorRef, ActorRef)]

Expand Down Expand Up @@ -212,26 +218,31 @@ class AkkaClusterSupervisorActor(daoActor: ActorRef) extends InstrumentedActor {
cmdString = cmdString + s" ${contextConfig.getString("spark.proxy.user")}"
}

val pb = Process(cmdString)
val pio = new ProcessIO(_ => (),
stdout => scala.io.Source.fromInputStream(stdout)
.getLines.foreach(println),
stderr => scala.io.Source.fromInputStream(stderr).getLines().foreach(println))
logger.info("Starting to execute sub process {}", pb)
val processStart = Try {
val process = pb.run(pio)
val exitVal = process.exitValue()
if (exitVal != 0) {
throw new IOException("Failed to launch context process, got exit code " + exitVal)
}
}

if (processStart.isSuccess) {
contextInitInfos(contextActorName) = (isAdHoc, successFunc, failureFunc)
} else {
failureFunc(processStart.failed.get)
}
contextInitInfos(contextActorName) = (isAdHoc, successFunc, failureFunc)

contextInitExecutorService.submit(new Runnable {
override def run(): Unit = {
val pb = Process(cmdString)
val pio = new ProcessIO(_ => (),
stdout => scala.io.Source.fromInputStream(stdout)
.getLines.foreach(println),
stderr => scala.io.Source.fromInputStream(stderr).getLines().foreach(println))

logger.info("Starting to execute sub process {}", pb)
val processStart = Try {
val process = pb.run(pio)
val exitVal = process.exitValue()
if (exitVal != 0) {
throw new IOException("Failed to launch context process, got exit code " + exitVal)
}
}

if (processStart.isFailure) {
failureFunc(processStart.failed.get)
contextInitInfos.remove(contextActorName)
}
}
})
}

private def createContextDir(name: String,
Expand Down

0 comments on commit 9ce8b09

Please sign in to comment.