Search in sources :

Example 1 with ProgramState

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;
        }
    }
}
Also used : BasicThrowable(io.cdap.cdap.proto.BasicThrowable) ProgramState(io.cdap.cdap.api.ProgramState) WorkflowNode(io.cdap.cdap.api.workflow.WorkflowNode)

Example 2 with ProgramState

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());
}
Also used : InstantiatorFactory(io.cdap.cdap.common.lang.InstantiatorFactory) ProgramState(io.cdap.cdap.api.ProgramState)

Example 3 with ProgramState

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);
    }
}
Also used : ProgramState(io.cdap.cdap.api.ProgramState) RunId(org.apache.twill.api.RunId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 4 with ProgramState

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);
    }
}
Also used : AbstractCustomAction(io.cdap.cdap.api.customaction.AbstractCustomAction) CustomAction(io.cdap.cdap.api.customaction.CustomAction) TransactionControl(io.cdap.cdap.api.annotation.TransactionControl) AbstractCustomAction(io.cdap.cdap.api.customaction.AbstractCustomAction) CustomActionContext(io.cdap.cdap.api.customaction.CustomActionContext) BasicCustomActionContext(io.cdap.cdap.internal.app.runtime.customaction.BasicCustomActionContext) ProgramState(io.cdap.cdap.api.ProgramState)

Example 5 with ProgramState

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;
}
Also used : InstantiatorFactory(io.cdap.cdap.common.lang.InstantiatorFactory) MetricsFieldSetter(io.cdap.cdap.internal.app.runtime.MetricsFieldSetter) ProgramLifecycle(io.cdap.cdap.api.ProgramLifecycle) TransactionControl(io.cdap.cdap.api.annotation.TransactionControl) Workflow(io.cdap.cdap.api.workflow.Workflow) ProgramState(io.cdap.cdap.api.ProgramState)

Aggregations

ProgramState (io.cdap.cdap.api.ProgramState)7 TransactionControl (io.cdap.cdap.api.annotation.TransactionControl)4 ProgramLifecycle (io.cdap.cdap.api.ProgramLifecycle)3 InstantiatorFactory (io.cdap.cdap.common.lang.InstantiatorFactory)2 AbstractCustomAction (io.cdap.cdap.api.customaction.AbstractCustomAction)1 CustomAction (io.cdap.cdap.api.customaction.CustomAction)1 CustomActionContext (io.cdap.cdap.api.customaction.CustomActionContext)1 AbstractMapReduce (io.cdap.cdap.api.mapreduce.AbstractMapReduce)1 AbstractSpark (io.cdap.cdap.api.spark.AbstractSpark)1 Workflow (io.cdap.cdap.api.workflow.Workflow)1 WorkflowNode (io.cdap.cdap.api.workflow.WorkflowNode)1 MetricsFieldSetter (io.cdap.cdap.internal.app.runtime.MetricsFieldSetter)1 BasicCustomActionContext (io.cdap.cdap.internal.app.runtime.customaction.BasicCustomActionContext)1 BasicThrowable (io.cdap.cdap.proto.BasicThrowable)1 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 RunId (org.apache.twill.api.RunId)1