Search in sources :

Example 1 with AggregatorConfiguration

use of com.linkedin.drelephant.configurations.aggregator.AggregatorConfiguration in project dr-elephant by linkedin.

the class ElephantContext method loadAggregators.

private void loadAggregators() {
    Document document = Utils.loadXMLDoc(AGGREGATORS_CONF);
    _aggregatorConfData = new AggregatorConfiguration(document.getDocumentElement()).getAggregatorsConfigurationData();
    for (AggregatorConfigurationData data : _aggregatorConfData) {
        try {
            Class<?> aggregatorClass = Class.forName(data.getClassName());
            Object instance = aggregatorClass.getConstructor(AggregatorConfigurationData.class).newInstance(data);
            if (!(instance instanceof HadoopMetricsAggregator)) {
                throw new IllegalArgumentException("Class " + aggregatorClass.getName() + " is not an implementation of " + HadoopMetricsAggregator.class.getName());
            }
            ApplicationType type = data.getAppType();
            if (_typeToAggregator.get(type) == null) {
                _typeToAggregator.put(type, (HadoopMetricsAggregator) instance);
            }
            logger.info("Load Aggregator : " + data.getClassName());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Could not find class " + data.getClassName(), e);
        } catch (InstantiationException e) {
            throw new RuntimeException("Could not instantiate class " + data.getClassName(), e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Could not access constructor for class" + data.getClassName(), e);
        } catch (RuntimeException e) {
            throw new RuntimeException(data.getClassName() + " is not a valid Aggregator class.", e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException("Could not invoke class " + data.getClassName(), e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Could not find constructor for class " + data.getClassName(), e);
        }
    }
}
Also used : Document(org.w3c.dom.Document) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) AggregatorConfiguration(com.linkedin.drelephant.configurations.aggregator.AggregatorConfiguration) AggregatorConfigurationData(com.linkedin.drelephant.configurations.aggregator.AggregatorConfigurationData) HadoopMetricsAggregator(com.linkedin.drelephant.analysis.HadoopMetricsAggregator)

Aggregations

ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)1 HadoopMetricsAggregator (com.linkedin.drelephant.analysis.HadoopMetricsAggregator)1 AggregatorConfiguration (com.linkedin.drelephant.configurations.aggregator.AggregatorConfiguration)1 AggregatorConfigurationData (com.linkedin.drelephant.configurations.aggregator.AggregatorConfigurationData)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Document (org.w3c.dom.Document)1