Search in sources :

Example 1 with Function0

use of org.apache.spark.api.java.function.Function0 in project cdap by caskdata.

the class SparkStreamingPipelineDriver method run.

private JavaStreamingContext run(final DataStreamsPipelineSpec pipelineSpec, final PipelinePhase pipelinePhase, final JavaSparkExecutionContext sec, @Nullable final String checkpointDir) throws Exception {
    Function0<JavaStreamingContext> contextFunction = new Function0<JavaStreamingContext>() {

        @Override
        public JavaStreamingContext call() throws Exception {
            JavaStreamingContext jssc = new JavaStreamingContext(new JavaSparkContext(), Durations.milliseconds(pipelineSpec.getBatchIntervalMillis()));
            SparkStreamingPipelineRunner runner = new SparkStreamingPipelineRunner(sec, jssc, pipelineSpec, false);
            PipelinePluginContext pluginContext = new PipelinePluginContext(sec.getPluginContext(), sec.getMetrics(), pipelineSpec.isStageLoggingEnabled(), pipelineSpec.isProcessTimingEnabled());
            // Seems like they should be set at configure time instead of runtime? but that requires an API change.
            try {
                runner.runPipeline(pipelinePhase, StreamingSource.PLUGIN_TYPE, sec, new HashMap<String, Integer>(), pluginContext, new HashMap<String, StageStatisticsCollector>());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (checkpointDir != null) {
                jssc.checkpoint(checkpointDir);
            }
            return jssc;
        }
    };
    return checkpointDir == null ? contextFunction.call() : StreamingCompat.getOrCreate(checkpointDir, contextFunction);
}
Also used : Function0(org.apache.spark.api.java.function.Function0) JavaStreamingContext(org.apache.spark.streaming.api.java.JavaStreamingContext) StageStatisticsCollector(co.cask.cdap.etl.common.StageStatisticsCollector) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) PipelinePluginContext(co.cask.cdap.etl.common.plugin.PipelinePluginContext)

Aggregations

StageStatisticsCollector (co.cask.cdap.etl.common.StageStatisticsCollector)1 PipelinePluginContext (co.cask.cdap.etl.common.plugin.PipelinePluginContext)1 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)1 Function0 (org.apache.spark.api.java.function.Function0)1 JavaStreamingContext (org.apache.spark.streaming.api.java.JavaStreamingContext)1