Search in sources :

Example 1 with AbstractMapReduce

use of co.cask.cdap.api.mapreduce.AbstractMapReduce in project cdap by caskdata.

the class MapReduceRuntimeService method beforeSubmit.

/**
   * For pre 3.5 MapReduce programs, calls the {@link MapReduce#beforeSubmit(MapReduceContext)} method.
   * For MapReduce programs created after 3.5, calls the initialize method of the {@link ProgramLifecycle}.
   * This method also sets up the Input/Output within the same transaction.
   */
@SuppressWarnings("unchecked")
private void beforeSubmit(final Job job) throws Exception {
    // AbstractMapReduce implements final initialize(context) and requires subclass to
    // implement initialize(), whereas programs that directly implement MapReduce have
    // the option to override initialize(context) (if they implement ProgramLifeCycle)
    final TransactionControl txControl = mapReduce instanceof AbstractMapReduce ? Transactions.getTransactionControl(TransactionControl.IMPLICIT, AbstractMapReduce.class, mapReduce, "initialize") : mapReduce instanceof ProgramLifecycle ? Transactions.getTransactionControl(TransactionControl.IMPLICIT, MapReduce.class, mapReduce, "initialize", MapReduceContext.class) : TransactionControl.IMPLICIT;
    if (TransactionControl.EXPLICIT == txControl) {
        doInitialize(job);
    } else {
        Transactionals.execute(context, new TxRunnable() {

            @Override
            public void run(DatasetContext context) throws Exception {
                doInitialize(job);
            }
        }, Exception.class);
    }
    ClassLoader oldClassLoader = ClassLoaders.setContextClassLoader(job.getConfiguration().getClassLoader());
    try {
        // set input/outputs info, and get one of the configured mapper's TypeToken
        TypeToken<?> mapperTypeToken = setInputsIfNeeded(job);
        setOutputsIfNeeded(job);
        setOutputClassesIfNeeded(job, mapperTypeToken);
        setMapOutputClassesIfNeeded(job, mapperTypeToken);
    } finally {
        ClassLoaders.setContextClassLoader(oldClassLoader);
    }
}
Also used : ProgramLifecycle(co.cask.cdap.api.ProgramLifecycle) AbstractMapReduce(co.cask.cdap.api.mapreduce.AbstractMapReduce) TxRunnable(co.cask.cdap.api.TxRunnable) TransactionControl(co.cask.cdap.api.annotation.TransactionControl) WeakReferenceDelegatorClassLoader(co.cask.cdap.common.lang.WeakReferenceDelegatorClassLoader) CombineClassLoader(co.cask.cdap.common.lang.CombineClassLoader) DatasetContext(co.cask.cdap.api.data.DatasetContext) ProvisionException(com.google.inject.ProvisionException) IOException(java.io.IOException) TransactionFailureException(org.apache.tephra.TransactionFailureException) URISyntaxException(java.net.URISyntaxException) TransactionConflictException(org.apache.tephra.TransactionConflictException)

Aggregations

ProgramLifecycle (co.cask.cdap.api.ProgramLifecycle)1 TxRunnable (co.cask.cdap.api.TxRunnable)1 TransactionControl (co.cask.cdap.api.annotation.TransactionControl)1 DatasetContext (co.cask.cdap.api.data.DatasetContext)1 AbstractMapReduce (co.cask.cdap.api.mapreduce.AbstractMapReduce)1 CombineClassLoader (co.cask.cdap.common.lang.CombineClassLoader)1 WeakReferenceDelegatorClassLoader (co.cask.cdap.common.lang.WeakReferenceDelegatorClassLoader)1 ProvisionException (com.google.inject.ProvisionException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 TransactionConflictException (org.apache.tephra.TransactionConflictException)1 TransactionFailureException (org.apache.tephra.TransactionFailureException)1