Search in sources :

Example 1 with PostAction

use of co.cask.cdap.etl.api.batch.PostAction in project cdap by caskdata.

the class ETLWorkflow method destroy.

@Override
public void destroy() {
    WorkflowContext workflowContext = getContext();
    if (workflowContext.getDataTracer(PostAction.PLUGIN_TYPE).isEnabled()) {
        return;
    }
    BasicArguments arguments = new BasicArguments(workflowContext.getToken(), workflowContext.getRuntimeArguments());
    for (Map.Entry<String, PostAction> endingActionEntry : postActions.entrySet()) {
        String name = endingActionEntry.getKey();
        PostAction action = endingActionEntry.getValue();
        StageInfo stageInfo = StageInfo.builder(name, PostAction.PLUGIN_TYPE).setStageLoggingEnabled(spec.isStageLoggingEnabled()).setProcessTimingEnabled(spec.isProcessTimingEnabled()).build();
        BatchActionContext context = new WorkflowBackedActionContext(workflowContext, workflowMetrics, stageInfo, arguments);
        try {
            action.run(context);
        } catch (Throwable t) {
            LOG.error("Error while running ending action {}.", name, t);
        }
    }
}
Also used : BatchActionContext(co.cask.cdap.etl.api.batch.BatchActionContext) StageInfo(co.cask.cdap.etl.planner.StageInfo) WorkflowContext(co.cask.cdap.api.workflow.WorkflowContext) BasicArguments(co.cask.cdap.etl.common.BasicArguments) PostAction(co.cask.cdap.etl.api.batch.PostAction) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with PostAction

use of co.cask.cdap.etl.api.batch.PostAction in project cdap by caskdata.

the class SmartWorkflow method destroy.

@Override
public void destroy() {
    WorkflowContext workflowContext = getContext();
    // Execute the post actions only if pipeline is not running in preview mode.
    if (!workflowContext.getDataTracer(PostAction.PLUGIN_TYPE).isEnabled()) {
        BasicArguments arguments = new BasicArguments(workflowContext.getToken(), workflowContext.getRuntimeArguments());
        for (Map.Entry<String, PostAction> endingActionEntry : postActions.entrySet()) {
            String name = endingActionEntry.getKey();
            PostAction action = endingActionEntry.getValue();
            StageInfo stageInfo = StageInfo.builder(name, PostAction.PLUGIN_TYPE).setStageLoggingEnabled(spec.isStageLoggingEnabled()).setProcessTimingEnabled(spec.isProcessTimingEnabled()).build();
            BatchActionContext context = new WorkflowBackedActionContext(workflowContext, workflowMetrics, stageInfo, arguments);
            try {
                action.run(context);
            } catch (Throwable t) {
                LOG.error("Error while running post action {}.", name, t);
            }
        }
    }
    ProgramStatus status = getContext().getState().getStatus();
    if (status == ProgramStatus.FAILED) {
        WRAPPERLOGGER.error("Pipeline '{}' failed.", getContext().getApplicationSpecification().getName());
    } else {
        WRAPPERLOGGER.info("Pipeline '{}' {}.", getContext().getApplicationSpecification().getName(), status == ProgramStatus.COMPLETED ? "succeeded" : status.name().toLowerCase());
    }
}
Also used : BatchActionContext(co.cask.cdap.etl.api.batch.BatchActionContext) WorkflowBackedActionContext(co.cask.cdap.etl.batch.WorkflowBackedActionContext) StageInfo(co.cask.cdap.etl.planner.StageInfo) WorkflowContext(co.cask.cdap.api.workflow.WorkflowContext) BasicArguments(co.cask.cdap.etl.common.BasicArguments) PostAction(co.cask.cdap.etl.api.batch.PostAction) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProgramStatus(co.cask.cdap.api.ProgramStatus)

Aggregations

WorkflowContext (co.cask.cdap.api.workflow.WorkflowContext)2 BatchActionContext (co.cask.cdap.etl.api.batch.BatchActionContext)2 PostAction (co.cask.cdap.etl.api.batch.PostAction)2 BasicArguments (co.cask.cdap.etl.common.BasicArguments)2 StageInfo (co.cask.cdap.etl.planner.StageInfo)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ProgramStatus (co.cask.cdap.api.ProgramStatus)1 WorkflowBackedActionContext (co.cask.cdap.etl.batch.WorkflowBackedActionContext)1