use of io.cdap.cdap.etl.common.PhaseSpec in project cdap by caskdata.
the class SparkStreamingPipelineDriver method run.
private JavaStreamingContext run(DataStreamsPipelineSpec pipelineSpec, PipelinePhase pipelinePhase, JavaSparkExecutionContext sec, @Nullable String checkpointDir, @Nullable JavaSparkContext context) throws Exception {
PipelinePluginContext pluginContext = new PipelinePluginContext(sec.getPluginContext(), sec.getMetrics(), pipelineSpec.isStageLoggingEnabled(), pipelineSpec.isProcessTimingEnabled());
PipelineRuntime pipelineRuntime = new SparkPipelineRuntime(sec);
MacroEvaluator evaluator = new DefaultMacroEvaluator(pipelineRuntime.getArguments(), sec.getLogicalStartTime(), sec.getSecureStore(), sec.getServiceDiscoverer(), sec.getNamespace());
SparkStreamingPreparer preparer = new SparkStreamingPreparer(pluginContext, sec.getMetrics(), evaluator, pipelineRuntime, sec);
try {
SparkFieldLineageRecorder recorder = new SparkFieldLineageRecorder(sec, pipelinePhase, pipelineSpec, preparer);
recorder.record();
} catch (Exception e) {
LOG.warn("Failed to emit field lineage operations for streaming pipeline", e);
}
Set<String> uncombinableSinks = preparer.getUncombinableSinks();
// the content in the function might not run due to spark checkpointing, currently just have the lineage logic
// before anything is run
Function0<JavaStreamingContext> contextFunction = (Function0<JavaStreamingContext>) () -> {
JavaSparkContext javaSparkContext = context == null ? new JavaSparkContext() : context;
JavaStreamingContext jssc = new JavaStreamingContext(javaSparkContext, Durations.milliseconds(pipelineSpec.getBatchIntervalMillis()));
SparkStreamingPipelineRunner runner = new SparkStreamingPipelineRunner(sec, jssc, pipelineSpec, pipelineSpec.isCheckpointsDisabled());
// Seems like they should be set at configure time instead of runtime? but that requires an API change.
try {
PhaseSpec phaseSpec = new PhaseSpec(sec.getApplicationSpecification().getName(), pipelinePhase, Collections.emptyMap(), pipelineSpec.isStageLoggingEnabled(), pipelineSpec.isProcessTimingEnabled());
boolean shouldConsolidateStages = Boolean.parseBoolean(sec.getRuntimeArguments().getOrDefault(Constants.CONSOLIDATE_STAGES, Boolean.TRUE.toString()));
boolean shouldCacheFunctions = Boolean.parseBoolean(sec.getRuntimeArguments().getOrDefault(Constants.CACHE_FUNCTIONS, Boolean.TRUE.toString()));
runner.runPipeline(phaseSpec, StreamingSource.PLUGIN_TYPE, sec, Collections.emptyMap(), pluginContext, Collections.emptyMap(), uncombinableSinks, shouldConsolidateStages, shouldCacheFunctions);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (checkpointDir != null) {
jssc.checkpoint(checkpointDir);
jssc.sparkContext().hadoopConfiguration().set("fs.defaultFS", checkpointDir);
}
return jssc;
};
return checkpointDir == null ? contextFunction.call() : JavaStreamingContext.getOrCreate(checkpointDir, contextFunction, context.hadoopConfiguration());
}
use of io.cdap.cdap.etl.common.PhaseSpec in project cdap by caskdata.
the class SparkFieldLineageRecorder method generateOperations.
private void generateOperations() throws Exception {
preparer.prepare(new PhaseSpec(DataStreamsSparkLauncher.NAME, pipelinePhase, Collections.emptyMap(), pipelineSpec.isStageLoggingEnabled(), pipelineSpec.isProcessTimingEnabled()));
operations = preparer.getFieldOperations();
}
Aggregations