├── README.md ├── project ├── build.properties └── plugins.sbt ├── .gitignore └── src └── main └── scala └── com └── knoldus └── sprayservices ├── boot.scala └── SparkServices.scala /README.md: -------------------------------------------------------------------------------- 1 | # spark-spray-starter 2 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.5 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0" ) 2 | 3 | //SBT Plugin for assembly 4 | addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0") 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | 4 | # sbt specific 5 | .cache 6 | .history 7 | .lib/ 8 | dist/* 9 | target/ 10 | lib_managed/ 11 | src_managed/ 12 | project/boot/ 13 | project/plugins/project/ 14 | 15 | # Scala-IDE specific 16 | .scala_dependencies 17 | .worksheet 18 | 19 | logs 20 | project/project 21 | project/target 22 | target 23 | tmp 24 | .history 25 | dist 26 | /.idea 27 | /*.iml 28 | /out 29 | /.idea_modules 30 | /.classpath 31 | /.project 32 | /RUNNING_PID 33 | /.settings 34 | -------------------------------------------------------------------------------- /src/main/scala/com/knoldus/sprayservices/boot.scala: -------------------------------------------------------------------------------- 1 | package com.knoldus.sprayservices 2 | 3 | import akka.actor.{ ActorSystem, Props } 4 | import akka.event.Logging 5 | import akka.io.IO 6 | import spray.can.Http 7 | import com.typesafe.config.ConfigFactory 8 | import scala.concurrent.duration.DurationInt 9 | 10 | object StartSpark extends App { 11 | 12 | // we need an ActorSystem to host our application in 13 | implicit val actorSystem = ActorSystem("spark-services") 14 | implicit val timeout = 30 seconds 15 | 16 | // create and start our service actor 17 | val service = actorSystem.actorOf(Props[SparkServices], "spark-services") 18 | 19 | // start a new HTTP server on port 8080 with our service actor as the handler 20 | IO(Http) ! Http.Bind(service, interface = "localhost", port = 8000) 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/scala/com/knoldus/sprayservices/SparkServices.scala: -------------------------------------------------------------------------------- 1 | package com.knoldus.sprayservices 2 | 3 | import scala.concurrent.ExecutionContext.Implicits.global 4 | import scala.concurrent.Future 5 | import scala.util.Failure 6 | import scala.util.Success 7 | import org.apache.spark.SparkConf 8 | import org.apache.spark.SparkContext 9 | import akka.actor.Actor 10 | import akka.actor.ActorContext 11 | import spray.http.MediaTypes._ 12 | import spray.routing.Directive.pimpApply 13 | import spray.routing.HttpService 14 | import spray.routing.RequestContext 15 | import spray.http.HttpResponse 16 | import spray.http.StatusCodes.OK 17 | 18 | trait SparkService extends HttpService { 19 | 20 | val sparkConf: SparkConf = new SparkConf().setAppName("spark-spray-starter").setMaster("local") 21 | val sc: SparkContext = new SparkContext(sparkConf) 22 | 23 | val sparkRoutes = 24 | path("spark" / "version") { 25 | get { 26 | complete { 27 | HttpResponse(OK, "Spark version in this template is: " + sc.version) 28 | } 29 | } 30 | } 31 | 32 | } 33 | 34 | class SparkServices extends Actor with SparkService { 35 | def actorRefFactory: ActorContext = context 36 | def receive: Actor.Receive = runRoute(sparkRoutes) 37 | } 38 | --------------------------------------------------------------------------------