Skip to content

Commit 737cc87

Browse files
committed
Merge pull request spark-jobserver#239 from spark-jobserver/velvia/java-job-support
JavaSparkJob
2 parents c86caa8 + 3ae356c commit 737cc87

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package spark.jobserver
2+
3+
import com.typesafe.config.Config
4+
import org.apache.spark.api.java.JavaSparkContext
5+
import org.apache.spark.SparkContext
6+
7+
/**
8+
* A class to make Java jobs easier to write. In Java:
9+
* public class MySparkJob extends JavaSparkJob {
10+
* @override
11+
* public Object runJob(JavaSparkContext jsc, Config jobConfig) { ... }
12+
* }
13+
*/
14+
class JavaSparkJob extends SparkJob {
15+
16+
def runJob(sc: SparkContext, jobConfig: Config): Any = {
17+
runJob(new JavaSparkContext(sc), jobConfig);
18+
}
19+
20+
def validate(sc: SparkContext, config: Config): SparkJobValidation = {
21+
Option(invalidate(new JavaSparkContext(sc), config))
22+
.map(err => SparkJobInvalid(err))
23+
.getOrElse(SparkJobValid)
24+
}
25+
26+
/**
27+
* The main class that carries out the Spark job. The results will be converted to JSON
28+
* and emitted (but NOT persisted).
29+
*/
30+
def runJob(jsc: JavaSparkContext, jobConfig: Config): Any = {}
31+
32+
/**
33+
* Checks the config and returns an error message, or null if the config is fine.
34+
* The error message will be returned to the user as a 404 HTTP error code.
35+
*/
36+
def invalidate(jsc: JavaSparkContext, config: Config): String = { null }
37+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package spark.jobserver;
2+
3+
import com.typesafe.config.Config;
4+
import org.apache.spark.api.java.JavaSparkContext;
5+
import spark.jobserver.JavaSparkJob;
6+
7+
public class JavaHelloWorldJob extends JavaSparkJob {
8+
@Override
9+
public Object runJob(JavaSparkContext jsc, Config jobConfig) {
10+
return("Hello World!");
11+
}
12+
}

0 commit comments

Comments
 (0)