use of io.cdap.cdap.api.ProgramState in project cdap by caskdata.
the class WorkflowDriver method executeAll.
private void executeAll(Iterator<WorkflowNode> iterator, ApplicationSpecification appSpec, InstantiatorFactory instantiator, ClassLoader classLoader, WorkflowToken token) throws Exception {
while (iterator.hasNext() && runningThread != null) {
try {
blockIfSuspended();
WorkflowNode node = iterator.next();
executeNode(appSpec, node, instantiator, classLoader, token);
} catch (Throwable t) {
Throwable rootCause = Throwables.getRootCause(t);
if (rootCause instanceof InterruptedException) {
LOG.debug("Workflow '{}' with run id '{}' aborted", workflowSpec.getName(), workflowRunId.getRun());
workflowContext.setState(new ProgramState(ProgramStatus.KILLED, rootCause.getMessage()));
break;
}
workflowContext.setState(new ProgramState(ProgramStatus.FAILED, Exceptions.condenseThrowableMessage(t)));
throw t;
}
}
}
use of io.cdap.cdap.api.ProgramState in project cdap by caskdata.
the class WorkflowDriver method run.
@Override
protected void run() throws Exception {
LOG.info("Starting workflow execution for '{}' with Run id '{}'", workflowSpec.getName(), workflowRunId.getRun());
LOG.trace("Workflow specification is {}", workflowSpec);
workflowContext.setState(new ProgramState(ProgramStatus.RUNNING, null));
executeAll(workflowSpec.getNodes().iterator(), program.getApplicationSpecification(), new InstantiatorFactory(false), program.getClassLoader(), basicWorkflowToken);
if (runningThread != null) {
workflowContext.setState(new ProgramState(ProgramStatus.COMPLETED, null));
}
LOG.info("Workflow '{}' with run id '{}' completed", workflowSpec.getName(), workflowRunId.getRun());
}
use of io.cdap.cdap.api.ProgramState in project cdap by caskdata.
the class SparkRuntimeService method shutDown.
@Override
protected void shutDown() throws Exception {
// Try to get from the submission future to see if the job completed successfully.
ListenableFuture<RunId> jobCompletion = completion.get();
ProgramState state = new ProgramState(ProgramStatus.COMPLETED, null);
try {
jobCompletion.get();
} catch (Exception e) {
if (jobCompletion.isCancelled()) {
state = new ProgramState(ProgramStatus.KILLED, null);
} else {
state = new ProgramState(ProgramStatus.FAILED, Throwables.getRootCause(e).getMessage());
}
}
try {
destroy(state);
} finally {
cleanupTask.run();
LOG.debug("Spark program completed: {}", runtimeContext);
}
}
use of io.cdap.cdap.api.ProgramState in project cdap by caskdata.
the class CustomActionExecutor method execute.
void execute() throws Exception {
TransactionControl defaultTxControl = customActionContext.getDefaultTxControl();
try {
customActionContext.setState(new ProgramState(ProgramStatus.INITIALIZING, null));
// AbstractCustomAction implements final initialize(context) and requires subclass to
// implement initialize(), whereas programs that directly implement CustomAction can
// override initialize(context)
TransactionControl txControl = customAction instanceof AbstractCustomAction ? Transactions.getTransactionControl(defaultTxControl, AbstractCustomAction.class, customAction, "initialize") : Transactions.getTransactionControl(defaultTxControl, CustomAction.class, customAction, "initialize", CustomActionContext.class);
customActionContext.initializeProgram(customAction, txControl, false);
customActionContext.setState(new ProgramState(ProgramStatus.RUNNING, null));
customActionContext.execute(customAction::run);
customActionContext.setState(new ProgramState(ProgramStatus.COMPLETED, null));
} catch (Throwable t) {
customActionContext.setState(new ProgramState(ProgramStatus.FAILED, Exceptions.condenseThrowableMessage(t)));
Throwables.propagateIfPossible(t, Exception.class);
throw Throwables.propagate(t);
} finally {
TransactionControl txControl = Transactions.getTransactionControl(defaultTxControl, CustomAction.class, customAction, "destroy");
customActionContext.destroyProgram(customAction, txControl, false);
}
}
use of io.cdap.cdap.api.ProgramState in project cdap by caskdata.
the class WorkflowDriver method initializeWorkflow.
@SuppressWarnings("unchecked")
private Workflow initializeWorkflow() throws Exception {
Class<?> clz = Class.forName(workflowSpec.getClassName(), true, program.getClassLoader());
if (!Workflow.class.isAssignableFrom(clz)) {
throw new IllegalStateException(String.format("%s is not Workflow.", clz));
}
Class<? extends Workflow> workflowClass = (Class<? extends Workflow>) clz;
final Workflow workflow = new InstantiatorFactory(false).get(TypeToken.of(workflowClass)).create();
// set metrics
Reflections.visit(workflow, workflow.getClass(), new MetricsFieldSetter(workflowContext.getMetrics()));
if (!(workflow instanceof ProgramLifecycle)) {
return workflow;
}
final TransactionControl txControl = Transactions.getTransactionControl(workflowContext.getDefaultTxControl(), Workflow.class, workflow, "initialize", WorkflowContext.class);
basicWorkflowToken.setCurrentNode(workflowSpec.getName());
workflowContext.setState(new ProgramState(ProgramStatus.INITIALIZING, null));
workflowContext.initializeProgram((ProgramLifecycle) workflow, txControl, false);
workflowStateWriter.setWorkflowToken(workflowRunId, basicWorkflowToken);
return workflow;
}
Aggregations