Search in sources :

Example 1 with BasicCustomActionContext

use of co.cask.cdap.internal.app.runtime.customaction.BasicCustomActionContext in project cdap by caskdata.

the class WorkflowDriver method executeCustomAction.

private void executeCustomAction(final WorkflowActionNode node, InstantiatorFactory instantiator, final ClassLoader classLoader, WorkflowToken token) throws Exception {
    CustomActionExecutor customActionExecutor;
    // Node has CustomActionSpecification, so it must represent the CustomAction added in 3.5.0
    // Create instance of the CustomActionExecutor using CustomActionContext
    WorkflowProgramInfo info = new WorkflowProgramInfo(workflowSpec.getName(), node.getNodeId(), workflowRunId.getRun(), node.getNodeId(), (BasicWorkflowToken) token);
    ProgramOptions actionOptions = new SimpleProgramOptions(programOptions.getProgramId(), programOptions.getArguments(), new BasicArguments(RuntimeArguments.extractScope(ACTION_SCOPE, node.getNodeId(), programOptions.getUserArguments().asMap())));
    BasicCustomActionContext context = new BasicCustomActionContext(program, actionOptions, cConf, node.getCustomActionSpecification(), info, metricsCollectionService, datasetFramework, txClient, discoveryServiceClient, pluginInstantiator, secureStore, secureStoreManager, messagingService);
    customActionExecutor = new CustomActionExecutor(context, instantiator, classLoader);
    status.put(node.getNodeId(), node);
    runtimeStore.addWorkflowNodeState(workflowRunId, new WorkflowNodeStateDetail(node.getNodeId(), NodeStatus.RUNNING));
    Throwable failureCause = null;
    try {
        customActionExecutor.execute();
    } catch (Throwable t) {
        failureCause = t;
        throw t;
    } finally {
        status.remove(node.getNodeId());
        runtimeStore.updateWorkflowToken(workflowRunId, token);
        NodeStatus status = failureCause == null ? NodeStatus.COMPLETED : NodeStatus.FAILED;
        nodeStates.put(node.getNodeId(), new WorkflowNodeState(node.getNodeId(), status, null, failureCause));
        BasicThrowable defaultThrowable = failureCause == null ? null : new BasicThrowable(failureCause);
        runtimeStore.addWorkflowNodeState(workflowRunId, new WorkflowNodeStateDetail(node.getNodeId(), status, null, defaultThrowable));
    }
}
Also used : WorkflowNodeState(co.cask.cdap.api.workflow.WorkflowNodeState) BasicCustomActionContext(co.cask.cdap.internal.app.runtime.customaction.BasicCustomActionContext) BasicThrowable(co.cask.cdap.proto.BasicThrowable) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(co.cask.cdap.internal.app.runtime.BasicArguments) BasicThrowable(co.cask.cdap.proto.BasicThrowable) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(co.cask.cdap.app.runtime.ProgramOptions) NodeStatus(co.cask.cdap.api.workflow.NodeStatus) WorkflowNodeStateDetail(co.cask.cdap.proto.WorkflowNodeStateDetail)

Aggregations

NodeStatus (co.cask.cdap.api.workflow.NodeStatus)1 WorkflowNodeState (co.cask.cdap.api.workflow.WorkflowNodeState)1 ProgramOptions (co.cask.cdap.app.runtime.ProgramOptions)1 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)1 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)1 BasicCustomActionContext (co.cask.cdap.internal.app.runtime.customaction.BasicCustomActionContext)1 BasicThrowable (co.cask.cdap.proto.BasicThrowable)1 WorkflowNodeStateDetail (co.cask.cdap.proto.WorkflowNodeStateDetail)1