-
Notifications
You must be signed in to change notification settings - Fork 15
/
DemoPlugin.scala
46 lines (35 loc) · 1.19 KB
/
DemoPlugin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package ch.cern
import java.util.{Map => JMap}
import scala.collection.JavaConverters._
import org.apache.spark.api.plugin.{DriverPlugin, ExecutorPlugin, PluginContext, SparkPlugin}
import org.apache.spark.SparkContext
// Basic example of Spark Executor Plugin in Scala
class DemoPlugin extends SparkPlugin {
// Return the plugin's driver-side component.
override def driverPlugin(): DriverPlugin = {
new DriverPlugin() {
override def init(sc: SparkContext, myContext: PluginContext): JMap[String, String] = {
DemoPlugin.numSuccessfulPlugins += 1
Map.empty[String, String].asJava
}
override def shutdown(): Unit = {
DemoPlugin.numSuccessfulTerminations += 1
}
}
}
// Return the plugin's executor-side component.
override def executorPlugin(): ExecutorPlugin = {
new ExecutorPlugin() {
override def init(myContext: PluginContext, extraConf: JMap[String, String]): Unit = {
DemoPlugin.numSuccessfulPlugins += 1
}
override def shutdown(): Unit = {
DemoPlugin.numSuccessfulTerminations += 1
}
}
}
}
object DemoPlugin {
var numSuccessfulPlugins : Int = 0
var numSuccessfulTerminations: Int = 0
}