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;
}
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);
}
Aggregations