Search in sources :

Example 1 with WorkflowAction

use of co.cask.cdap.api.workflow.WorkflowAction in project cdap by caskdata.

the class CustomActionExecutor method createAction.

@SuppressWarnings("unchecked")
@Deprecated
private WorkflowAction createAction(BasicWorkflowContext context, InstantiatorFactory instantiator, ClassLoader classLoader) throws Exception {
    Class<?> clz = Class.forName(context.getSpecification().getClassName(), true, classLoader);
    Preconditions.checkArgument(WorkflowAction.class.isAssignableFrom(clz), "%s is not a WorkflowAction.", clz);
    WorkflowAction action = instantiator.get(TypeToken.of((Class<? extends WorkflowAction>) clz)).create();
    Metrics metrics = new ProgramUserMetrics(context.getProgramMetrics().childContext(Constants.Metrics.Tag.NODE, context.getSpecification().getName()));
    Reflections.visit(action, action.getClass(), new PropertyFieldSetter(context.getSpecification().getProperties()), new DataSetFieldSetter(context), new MetricsFieldSetter(metrics));
    return action;
}
Also used : ProgramUserMetrics(co.cask.cdap.app.metrics.ProgramUserMetrics) Metrics(co.cask.cdap.api.metrics.Metrics) PropertyFieldSetter(co.cask.cdap.common.lang.PropertyFieldSetter) MetricsFieldSetter(co.cask.cdap.internal.app.runtime.MetricsFieldSetter) WorkflowAction(co.cask.cdap.api.workflow.WorkflowAction) ProgramUserMetrics(co.cask.cdap.app.metrics.ProgramUserMetrics) DataSetFieldSetter(co.cask.cdap.internal.app.runtime.DataSetFieldSetter)

Example 2 with WorkflowAction

use of co.cask.cdap.api.workflow.WorkflowAction in project cdap by caskdata.

the class WorkflowDriver method executeAction.

private void executeAction(WorkflowActionNode node, WorkflowToken token) throws Exception {
    WorkflowActionSpecification actionSpec = getActionSpecification(node, node.getProgram().getProgramType());
    status.put(node.getNodeId(), node);
    BasicWorkflowContext workflowContext = createWorkflowContext(actionSpec, token);
    ProgramWorkflowRunner programWorkflowRunner = workflowProgramRunnerFactory.getProgramWorkflowRunner(actionSpec, token, node.getNodeId(), nodeStates);
    final WorkflowAction action = new ProgramWorkflowAction(node.getProgram().getProgramName(), node.getProgram().getProgramType(), programWorkflowRunner);
    action.initialize(workflowContext);
    CountDownLatch executorTerminateLatch = new CountDownLatch(1);
    ExecutorService executorService = createExecutor(1, executorTerminateLatch, "action-" + node.getNodeId() + "-%d");
    try {
        // Run the action in new thread
        Future<?> future = executorService.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                action.run();
                return null;
            }
        });
        future.get();
    } catch (Throwable t) {
        Throwables.propagateIfPossible(t, Exception.class);
        throw Throwables.propagate(t);
    } finally {
        executorService.shutdownNow();
        executorTerminateLatch.await();
        status.remove(node.getNodeId());
    }
    runtimeStore.updateWorkflowToken(workflowRunId, token);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) WorkflowActionSpecification(co.cask.cdap.api.workflow.WorkflowActionSpecification) WorkflowAction(co.cask.cdap.api.workflow.WorkflowAction) ExecutorService(java.util.concurrent.ExecutorService) BasicThrowable(co.cask.cdap.proto.BasicThrowable)

Aggregations

WorkflowAction (co.cask.cdap.api.workflow.WorkflowAction)2 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)1 Metrics (co.cask.cdap.api.metrics.Metrics)1 WorkflowActionSpecification (co.cask.cdap.api.workflow.WorkflowActionSpecification)1 ProgramUserMetrics (co.cask.cdap.app.metrics.ProgramUserMetrics)1 PropertyFieldSetter (co.cask.cdap.common.lang.PropertyFieldSetter)1 DataSetFieldSetter (co.cask.cdap.internal.app.runtime.DataSetFieldSetter)1 MetricsFieldSetter (co.cask.cdap.internal.app.runtime.MetricsFieldSetter)1 BasicThrowable (co.cask.cdap.proto.BasicThrowable)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1