score:1
If you want to test your Spark program locally, you don't even need to spin up the single-node standalone Spark. Just set your master url to local[*]
like this
val sc = new SparkContext("local[*]", "Simple Application", sparkConf)
Then in sbt, type > run
to run your program (this should be the same as running from IntelliJ, but I used to run the program from terminal using sbt).
Since you may not want to change your master url in code between local[*]
and spark://...
many times, you can leave them blank
val sc = new SparkContext(new SparkConf())
and set your java properties when running, for example, in build.sbt
, you can add
javaOptions := Seq("-Dspark.master=local[*]", "-Dspark.app.name=my-app")
and run it using run
in sbt.
To make a more comprehensive local-mode experience, you may want to add the following lines in your build.sbt
run in Compile <<= Defaults.runTask(fullClasspath in Compile, mainClass in (Compile, run), runner in (Compile, run))
runMain in Compile <<= Defaults.runTask(fullClasspath in Compile, mainClass in (Compile, run), runner in (Compile, run))
fork := true
javaOptions := Seq("-Dspark.master=local[*]", s"-Dspark.app.name=my-app")
outputStrategy := Some(StdoutOutput)
We have created a sbt plugin which can add these settings for you, it can also help you deploy a standalone Spark cluster on cloud system like aws ec2, give a look at spark-deployer if you are interested.
score:1
You are missing a crucial step:
org.apache.spark.deploy.SparkSubmit
which actually submits a job to the cluster. Unfortunately there is not presently a solid working wrapper for it except for spark-submit
. So there presently is not a reliable way to programatically submit spark jobs. There is a jira for it that was partially addressed in Feb 2015: but it lacks documentation.
https://github.com/apache/spark/pull/3916/files
The difficulty lies in the complexity of the environmental machinations provided by spark-submit
. It has not been found possible to replicate them solely within scala/java code.
score:1
Here is the Class.
https://spark.apache.org/docs/1.4.0/api/java/org/apache/spark/launcher/package-summary.html
import org.apache.spark.launcher.SparkLauncher;
public class MyLauncher {
public static void main(String[] args) throws Exception {
Process spark = new SparkLauncher()
.setAppResource("/my/app.jar")
.setMainClass("my.spark.app.Main")
.setMaster("local")
.setConf(SparkLauncher.DRIVER_MEMORY, "2g")
.launch();
spark.waitFor();
}
}
Source: stackoverflow.com
Related Query
- How do you submit a job to Spark from code?
- How to get the details of user who submitted the spark job from within the job context?
- Launch spark job on-demand from code
- How to view the source code in spark job in .jar file
- How to submit a Spark scala job over Yarn, Hadoop
- How to redirect Apache Spark logs from the driver and the slaves to the console of the machine that launchs the Spark job using log4j?
- How to submit spark job Remotely
- How should you end a Spark job inside an if statement?
- How can you use scalacheck to verify if some generated code from a function is correct?
- how to filter out a null value from spark dataframe
- Spark : how to run spark file from spark shell
- How do you remove the _<scala-version> postfix from artifacts built+published with simple-build-tool?
- How to use scala.None from Java code
- How do you call a Scala singleton method from Java?
- How to create a DataFrame from a text file in Spark
- How to use Scala varargs from Java code
- How to create a Spark Dataset from an RDD
- How to create hive table from Spark data frame, using its schema?
- How do you call Scala objects from Java?
- How do you impose scala code coverage specifically for integration tests?
- Scala - How to compile code from an external file at runtime?
- How to extract a value from a Vector in a column of a Spark Dataframe
- How to create Spark Dataset or Dataframe from case classes that contains Enums
- How to create a Row from a List or Array in Spark using Scala
- how to create DataFrame from multiple arrays in Spark Scala?
- How to use the programmatic spark submit capability
- java.lang.NoClassDefFoundError: Could not initialize class when launching spark job via spark-submit in scala code
- How to run Spark Scala code on Amazon EMR
- How to run tests on every code change in IntelliJ IDEA from Scala sbt project?
- How to run simple Spark app from Eclipse/Intellij IDE?
More Query from same tag
- How to translate the Java double colon operator (::) to Scala?
- Inject all implementations of a certain trait/class in play using guice
- Writing scala enum into database and reading from it
- Slick with Hikari don't use more connections when needed
- Modify a column in Spark dataframe based on certain conditions
- Succint syntax of converting to Map and accessing element
- Method signature clashes when class and its parameters extends from the same trait
- in scala how to convert the result in sql query row to double
- Get list of elements that are divisible by 3 or 5 from 1 - 1000
- value unsafePerformSync is not a member of scalaz.concurrent.Task[String]
- foreach in Scala parallel collections
- Final keyword benefits for vals and case classes
- Spark Scala - converting Dataframe with one record and one column into Double
- quill - can't tokenize a non-scalar lifting
- How to access members of container class with same name? scala
- How to convert multiples arrays into multiple columns Spark in Scala
- How to pass text file as argument scala
- Scala: Reuse Function Value
- How to update List of objects in scala
- Why the value cannot be found for Scala form?
- Specifying Future[Done] as materialized value when creating a source
- error in attribute extended from trait in scala
- How send response in Scala Play 2.0?
- Parsing an array of json objects to scala objects with pickling
- a right-associative triple colon operator
- How to make classes from a Scala jar library of mine accessible in Scala console and Scala scripts?
- Adding "extends AnyVal" causes a "type arguments do no conform" error
- Scala Akka system actorRef wrapper
- How to transform disjunction of Future to Future of disjunction
- Update concurrent map inside a stream map on flink