Example usage for org.apache.hadoop.conf Configuration getClass

List of usage examples for org.apache.hadoop.conf Configuration getClass

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration getClass.

Prototype

public <U> Class<? extends U> getClass(String name, Class<? extends U> defaultValue, Class<U> xface) 

Source Link

Document

Get the value of the name property as a Class implementing the interface specified by xface.

Usage

From source file:org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil.java

License:Apache License

public static ImportPreUpsertKeyValueProcessor loadPreUpsertProcessor(Configuration conf) {
    Class<? extends ImportPreUpsertKeyValueProcessor> processorClass = null;
    try {//from   ww w  .  j av a  2s  .co m
        processorClass = conf.getClass(UPSERT_HOOK_CLASS_CONFKEY,
                FormatToBytesWritableMapper.DefaultImportPreUpsertKeyValueProcessor.class,
                ImportPreUpsertKeyValueProcessor.class);
    } catch (Exception e) {
        throw new IllegalStateException("Couldn't load upsert hook class", e);
    }

    return ReflectionUtils.newInstance(processorClass, conf);
}

From source file:org.apache.rya.indexing.accumulo.ConfigUtils.java

License:Apache License

public static Tokenizer getFreeTextTokenizer(final Configuration conf) {
    final Class<? extends Tokenizer> c = conf.getClass(TOKENIZER_CLASS, LuceneTokenizer.class, Tokenizer.class);
    return ReflectionUtils.newInstance(c, conf);
}

From source file:org.apache.slider.providers.SliderProviderFactory.java

License:Apache License

/**
 * Create a provider for a specific application
 * @param application app//from w ww . java2  s .co  m
 * @return app instance
 * @throws SliderException on any instantiation problem
 */
public static SliderProviderFactory createSliderProviderFactory(String application) throws SliderException {
    Configuration conf = loadSliderConfiguration();
    if (application == null) {
        application = DEFAULT_CLUSTER_TYPE;
    }
    String providerKey = String.format(SliderXmlConfKeys.KEY_PROVIDER, application);
    if (application.contains(".")) {
        log.debug("Treating {} as a classname", application);
        String name = "classname.key";
        conf.set(name, application);
        providerKey = name;
    }

    Class<? extends SliderProviderFactory> providerClass;
    try {
        providerClass = conf.getClass(providerKey, null, SliderProviderFactory.class);
    } catch (RuntimeException e) {
        throw new BadClusterStateException(e, "Failed to load provider %s: %s", application, e);
    }
    if (providerClass == null) {
        throw new BadClusterStateException(PROVIDER_NOT_FOUND, application);
    }

    Exception ex;
    try {
        SliderProviderFactory providerFactory = providerClass.newInstance();
        providerFactory.setConf(conf);
        return providerFactory;
    } catch (Exception e) {
        ex = e;
    }
    //by here the operation failed and ex is set to the value 
    throw new BadClusterStateException(ex, "Failed to create an instance of %s : %s", providerClass, ex);
}

From source file:org.apache.tajo.master.FragmentScheduleAlgorithmFactory.java

License:Apache License

public static Class<? extends FragmentScheduleAlgorithm> getScheduleAlgorithmClass(Configuration conf)
        throws IOException {
    if (CACHED_ALGORITHM_CLASS != null) {
        return CACHED_ALGORITHM_CLASS;
    } else {/*w  w w  .  j a  va  2s .  c  o m*/
        CACHED_ALGORITHM_CLASS = conf.getClass("tajo.querymaster.lazy-task-scheduler.algorithm", null,
                FragmentScheduleAlgorithm.class);
    }

    if (CACHED_ALGORITHM_CLASS == null) {
        throw new IOException("Scheduler algorithm is null");
    }
    return CACHED_ALGORITHM_CLASS;
}

From source file:org.apache.tajo.master.TaskSchedulerFactory.java

License:Apache License

public static Class<? extends AbstractTaskScheduler> getTaskSchedulerClass(Configuration conf)
        throws IOException {
    if (CACHED_ALGORITHM_CLASS != null) {
        return CACHED_ALGORITHM_CLASS;
    } else {//from  ww w . j  a  va 2  s  .  co  m
        CACHED_ALGORITHM_CLASS = conf.getClass("tajo.querymaster.task-scheduler", null,
                AbstractTaskScheduler.class);
    }

    if (CACHED_ALGORITHM_CLASS == null) {
        throw new IOException("Task scheduler is null");
    }
    return CACHED_ALGORITHM_CLASS;
}

From source file:org.apache.tajo.storage.fragment.FragmentConvertor.java

License:Apache License

public static Class<? extends Fragment> getFragmentClass(Configuration conf, String storeType)
        throws IOException {
    Class<? extends Fragment> fragmentClass = CACHED_FRAGMENT_CLASSES.get(storeType.toLowerCase());
    if (fragmentClass == null) {
        fragmentClass = conf.getClass(String.format("tajo.storage.fragment.%s.class", storeType.toLowerCase()),
                null, Fragment.class);
        CACHED_FRAGMENT_CLASSES.put(storeType.toLowerCase(), fragmentClass);
    }// w w  w . j  a  v  a  2  s  .  c o  m

    if (fragmentClass == null) {
        throw new IOException("No such a fragment for " + storeType.toLowerCase());
    }

    return fragmentClass;
}

From source file:org.apache.tez.dag.app.speculate.DefaultSpeculator.java

License:Apache License

static private TaskRuntimeEstimator getEstimator(Configuration conf, AppContext context) {
    TaskRuntimeEstimator estimator;/*w  w w  .  j  av a 2  s  .  c  o  m*/

    try {
        // "yarn.mapreduce.job.task.runtime.estimator.class"
        Class<? extends TaskRuntimeEstimator> estimatorClass = conf.getClass(MRJobConfig.MR_AM_TASK_ESTIMATOR,
                LegacyTaskRuntimeEstimator.class, TaskRuntimeEstimator.class);

        Constructor<? extends TaskRuntimeEstimator> estimatorConstructor = estimatorClass.getConstructor();

        estimator = estimatorConstructor.newInstance();

        estimator.contextualize(conf, context);
    } catch (InstantiationException ex) {
        LOG.error("Can't make a speculation runtime extimator", ex);
        throw new TezUncheckedException(ex);
    } catch (IllegalAccessException ex) {
        LOG.error("Can't make a speculation runtime extimator", ex);
        throw new TezUncheckedException(ex);
    } catch (InvocationTargetException ex) {
        LOG.error("Can't make a speculation runtime extimator", ex);
        throw new TezUncheckedException(ex);
    } catch (NoSuchMethodException ex) {
        LOG.error("Can't make a speculation runtime extimator", ex);
        throw new TezUncheckedException(ex);
    }

    return estimator;
}

From source file:org.apache.tez.engine.common.ConfigUtils.java

License:Apache License

public static <V> Class<V> getIntermediateOutputValueClass(Configuration conf) {
    Class<V> retv = (Class<V>) conf.getClass(TezJobConfig.TEZ_ENGINE_INTERMEDIATE_OUTPUT_VALUE_CLASS, null,
            Object.class);
    return retv;/*w ww .j  a  va  2s .c o  m*/
}

From source file:org.apache.tez.engine.common.ConfigUtils.java

License:Apache License

public static <V> Class<V> getIntermediateInputValueClass(Configuration conf) {
    Class<V> retv = (Class<V>) conf.getClass(TezJobConfig.TEZ_ENGINE_INTERMEDIATE_INPUT_VALUE_CLASS, null,
            Object.class);
    return retv;/*from  ww w .ja v a  2 s.  c om*/
}

From source file:org.apache.tez.engine.common.ConfigUtils.java

License:Apache License

public static <K> Class<K> getIntermediateOutputKeyClass(Configuration conf) {
    Class<K> retv = (Class<K>) conf.getClass(TezJobConfig.TEZ_ENGINE_INTERMEDIATE_OUTPUT_KEY_CLASS, null,
            Object.class);
    return retv;/*from  ww w . j av  a2  s.  c o m*/
}