Search in sources :

Example 1 with BasicArguments

use of co.cask.cdap.etl.common.BasicArguments 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 BasicArguments

use of co.cask.cdap.etl.common.BasicArguments in project cdap by caskdata.

the class PipelineAction method run.

@Override
public void run() throws Exception {
    CustomActionContext context = getContext();
    Map<String, String> properties = context.getSpecification().getProperties();
    BatchPhaseSpec phaseSpec = GSON.fromJson(properties.get(Constants.PIPELINEID), BatchPhaseSpec.class);
    PipelinePhase phase = phaseSpec.getPhase();
    StageInfo stageInfo = phase.iterator().next();
    PluginContext pluginContext = new PipelinePluginContext(context, metrics, phaseSpec.isStageLoggingEnabled(), phaseSpec.isProcessTimingEnabled());
    Action action = pluginContext.newPluginInstance(stageInfo.getName(), new DefaultMacroEvaluator(context.getWorkflowToken(), context.getRuntimeArguments(), context.getLogicalStartTime(), context, context.getNamespace()));
    BasicArguments arguments = new BasicArguments(context);
    ActionContext actionContext = new BasicActionContext(context, metrics, stageInfo.getName(), arguments);
    if (!context.getDataTracer(stageInfo.getName()).isEnabled()) {
        action.run(actionContext);
    }
    WorkflowToken token = context.getWorkflowToken();
    if (token == null) {
        throw new IllegalStateException("WorkflowToken cannot be null when action is executed through Workflow.");
    }
    for (Map.Entry<String, String> entry : arguments.getAddedArguments().entrySet()) {
        token.put(entry.getKey(), entry.getValue());
    }
}
Also used : Action(co.cask.cdap.etl.api.action.Action) CustomAction(co.cask.cdap.api.customaction.CustomAction) AbstractCustomAction(co.cask.cdap.api.customaction.AbstractCustomAction) PipelinePluginContext(co.cask.cdap.etl.common.plugin.PipelinePluginContext) PluginContext(co.cask.cdap.api.plugin.PluginContext) StageInfo(co.cask.cdap.etl.planner.StageInfo) WorkflowToken(co.cask.cdap.api.workflow.WorkflowToken) CustomActionContext(co.cask.cdap.api.customaction.CustomActionContext) ActionContext(co.cask.cdap.etl.api.action.ActionContext) PipelinePhase(co.cask.cdap.etl.common.PipelinePhase) DefaultMacroEvaluator(co.cask.cdap.etl.common.DefaultMacroEvaluator) CustomActionContext(co.cask.cdap.api.customaction.CustomActionContext) BatchPhaseSpec(co.cask.cdap.etl.batch.BatchPhaseSpec) BasicArguments(co.cask.cdap.etl.common.BasicArguments) HashMap(java.util.HashMap) Map(java.util.Map) PipelinePluginContext(co.cask.cdap.etl.common.plugin.PipelinePluginContext)

Example 3 with BasicArguments

use of co.cask.cdap.etl.common.BasicArguments 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

BasicArguments (co.cask.cdap.etl.common.BasicArguments)3 StageInfo (co.cask.cdap.etl.planner.StageInfo)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 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 LinkedHashMap (java.util.LinkedHashMap)2 ProgramStatus (co.cask.cdap.api.ProgramStatus)1 AbstractCustomAction (co.cask.cdap.api.customaction.AbstractCustomAction)1 CustomAction (co.cask.cdap.api.customaction.CustomAction)1 CustomActionContext (co.cask.cdap.api.customaction.CustomActionContext)1 PluginContext (co.cask.cdap.api.plugin.PluginContext)1 WorkflowToken (co.cask.cdap.api.workflow.WorkflowToken)1 Action (co.cask.cdap.etl.api.action.Action)1 ActionContext (co.cask.cdap.etl.api.action.ActionContext)1 BatchPhaseSpec (co.cask.cdap.etl.batch.BatchPhaseSpec)1 WorkflowBackedActionContext (co.cask.cdap.etl.batch.WorkflowBackedActionContext)1 DefaultMacroEvaluator (co.cask.cdap.etl.common.DefaultMacroEvaluator)1 PipelinePhase (co.cask.cdap.etl.common.PipelinePhase)1