Search in sources :

Example 1 with BasicCustomActionContext

use of io.cdap.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, workflowContext.fieldLineageConsolidationEnabled());
    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, metadataReader, metadataPublisher, namespaceQueryAdmin, fieldLineageWriter, remoteClientFactory);
    customActionExecutor = new CustomActionExecutor(context, instantiator, classLoader);
    status.put(node.getNodeId(), node);
    workflowStateWriter.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());
        workflowStateWriter.setWorkflowToken(workflowRunId, token);
        NodeStatus status = failureCause == null ? NodeStatus.COMPLETED : NodeStatus.FAILED;
        if (failureCause == null) {
            writeFieldLineage(context);
        }
        nodeStates.put(node.getNodeId(), new WorkflowNodeState(node.getNodeId(), status, null, failureCause));
        BasicThrowable defaultThrowable = failureCause == null ? null : new BasicThrowable(failureCause);
        workflowStateWriter.addWorkflowNodeState(workflowRunId, new WorkflowNodeStateDetail(node.getNodeId(), status, null, defaultThrowable));
    }
}
Also used : WorkflowNodeState(io.cdap.cdap.api.workflow.WorkflowNodeState) BasicCustomActionContext(io.cdap.cdap.internal.app.runtime.customaction.BasicCustomActionContext) BasicThrowable(io.cdap.cdap.proto.BasicThrowable) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) BasicThrowable(io.cdap.cdap.proto.BasicThrowable) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) NodeStatus(io.cdap.cdap.api.workflow.NodeStatus) WorkflowNodeStateDetail(io.cdap.cdap.proto.WorkflowNodeStateDetail)

Aggregations

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