Search in sources :

Example 11 with ProgramLifecycle

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

the class SparkRuntimeService method destroy.

/**
   * Calls the destroy or onFinish method of {@link ProgramLifecycle}.
   */
private void destroy(final ProgramState state) throws Exception {
    final TransactionControl txControl = spark instanceof ProgramLifecycle ? Transactions.getTransactionControl(TransactionControl.IMPLICIT, Spark.class, spark, "destroy") : TransactionControl.IMPLICIT;
    TxRunnable runnable = new TxRunnable() {

        @Override
        public void run(DatasetContext ctxt) throws Exception {
            Cancellable cancellable = SparkRuntimeUtils.setContextClassLoader(new SparkClassLoader(runtimeContext));
            try {
                context.setState(state);
                if (spark instanceof ProgramLifecycle) {
                    ((ProgramLifecycle) spark).destroy();
                } else {
                    spark.onFinish(state.getStatus() == ProgramStatus.COMPLETED, context);
                }
            } finally {
                cancellable.cancel();
            }
        }
    };
    if (TransactionControl.IMPLICIT == txControl) {
        context.execute(runnable);
    } else {
        runnable.run(context);
    }
}
Also used : ProgramLifecycle(co.cask.cdap.api.ProgramLifecycle) TxRunnable(co.cask.cdap.api.TxRunnable) Cancellable(org.apache.twill.common.Cancellable) TransactionControl(co.cask.cdap.api.annotation.TransactionControl) AbstractSpark(co.cask.cdap.api.spark.AbstractSpark) Spark(co.cask.cdap.api.spark.Spark) DatasetContext(co.cask.cdap.api.data.DatasetContext)

Aggregations

ProgramLifecycle (co.cask.cdap.api.ProgramLifecycle)11 TransactionControl (co.cask.cdap.api.annotation.TransactionControl)6 WeakReferenceDelegatorClassLoader (co.cask.cdap.common.lang.WeakReferenceDelegatorClassLoader)5 TxRunnable (co.cask.cdap.api.TxRunnable)4 DatasetContext (co.cask.cdap.api.data.DatasetContext)4 IOException (java.io.IOException)4 ProgramState (co.cask.cdap.api.ProgramState)3 CombineClassLoader (co.cask.cdap.common.lang.CombineClassLoader)3 MetricsFieldSetter (co.cask.cdap.internal.app.runtime.MetricsFieldSetter)3 RuntimeContext (co.cask.cdap.api.RuntimeContext)2 AbstractMapReduce (co.cask.cdap.api.mapreduce.AbstractMapReduce)2 AbstractSpark (co.cask.cdap.api.spark.AbstractSpark)2 PropertyFieldSetter (co.cask.cdap.common.lang.PropertyFieldSetter)2 DataSetFieldSetter (co.cask.cdap.internal.app.runtime.DataSetFieldSetter)2 ProvisionException (com.google.inject.ProvisionException)2 URISyntaxException (java.net.URISyntaxException)2 TransactionConflictException (org.apache.tephra.TransactionConflictException)2 TransactionFailureException (org.apache.tephra.TransactionFailureException)2 Cancellable (org.apache.twill.common.Cancellable)2 MapReduce (co.cask.cdap.api.mapreduce.MapReduce)1