Search in sources :

Example 6 with ProgramState

use of co.cask.cdap.api.ProgramState in project cdap by caskdata.

the class MapReduceRuntimeService method doInitialize.

private void doInitialize(Job job) throws Exception {
    context.setState(new ProgramState(ProgramStatus.INITIALIZING, null));
    ClassLoader oldClassLoader = ClassLoaders.setContextClassLoader(job.getConfiguration().getClassLoader());
    try {
        if (mapReduce instanceof ProgramLifecycle) {
            //noinspection unchecked
            ((ProgramLifecycle) mapReduce).initialize(context);
        } else {
            mapReduce.beforeSubmit(context);
        }
    } finally {
        ClassLoaders.setContextClassLoader(oldClassLoader);
    }
    // once the initialize method is executed, set the status of the MapReduce to RUNNING
    context.setState(new ProgramState(ProgramStatus.RUNNING, null));
}
Also used : ProgramLifecycle(co.cask.cdap.api.ProgramLifecycle) WeakReferenceDelegatorClassLoader(co.cask.cdap.common.lang.WeakReferenceDelegatorClassLoader) CombineClassLoader(co.cask.cdap.common.lang.CombineClassLoader) ProgramState(co.cask.cdap.api.ProgramState)

Example 7 with ProgramState

use of co.cask.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(co.cask.cdap.api.ProgramState) RunId(org.apache.twill.api.RunId) URISyntaxException(java.net.URISyntaxException) UnsupportedTypeException(co.cask.common.internal.io.UnsupportedTypeException) IOException(java.io.IOException)

Aggregations

ProgramState (co.cask.cdap.api.ProgramState)7 ProgramLifecycle (co.cask.cdap.api.ProgramLifecycle)3 TransactionControl (co.cask.cdap.api.annotation.TransactionControl)3 InstantiatorFactory (co.cask.cdap.common.lang.InstantiatorFactory)2 TxRunnable (co.cask.cdap.api.TxRunnable)1 AbstractCustomAction (co.cask.cdap.api.customaction.AbstractCustomAction)1 CustomAction (co.cask.cdap.api.customaction.CustomAction)1 CustomActionContext (co.cask.cdap.api.customaction.CustomActionContext)1 DatasetContext (co.cask.cdap.api.data.DatasetContext)1 AbstractSpark (co.cask.cdap.api.spark.AbstractSpark)1 Workflow (co.cask.cdap.api.workflow.Workflow)1 WorkflowNode (co.cask.cdap.api.workflow.WorkflowNode)1 CombineClassLoader (co.cask.cdap.common.lang.CombineClassLoader)1 WeakReferenceDelegatorClassLoader (co.cask.cdap.common.lang.WeakReferenceDelegatorClassLoader)1 AbstractContext (co.cask.cdap.internal.app.runtime.AbstractContext)1 MetricsFieldSetter (co.cask.cdap.internal.app.runtime.MetricsFieldSetter)1 BasicCustomActionContext (co.cask.cdap.internal.app.runtime.customaction.BasicCustomActionContext)1 BasicThrowable (co.cask.cdap.proto.BasicThrowable)1 UnsupportedTypeException (co.cask.common.internal.io.UnsupportedTypeException)1 IOException (java.io.IOException)1