Search in sources :

Example 1 with HeuristicConfigurationData

use of com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData in project dr-elephant by linkedin.

the class AnalyticJobTest method loadHeuristics.

private List<Heuristic> loadHeuristics() {
    List<Heuristic> heuristics = new ArrayList<Heuristic>();
    // dummy hash map
    Map<String, String> paramsMap = new HashMap<String, String>();
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Mapper Skew", "com.linkedin.drelephant.mapreduce.heuristics.MapperSkewHeuristic", "views.html.help.mapreduce.helpMapperSkew", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Mapper GC", "com.linkedin.drelephant.mapreduce.heuristics.MapperGCHeuristic", "views.html.help.mapreduce.helpGC", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Mapper Time", "com.linkedin.drelephant.mapreduce.heuristics.MapperTimeHeuristic", "views.html.help.mapreduce.helpMapperTime", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Mapper Speed", "com.linkedin.drelephant.mapreduce.heuristics.MapperSpeedHeuristic", "views.html.help.mapreduce.helpMapperSpeed", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Mapper Spill", "com.linkedin.drelephant.mapreduce.heuristics.MapperSpillHeuristic", "views.html.help.mapreduce.helpMapperSpill", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Mapper Memory", "com.linkedin.drelephant.mapreduce.heuristics.MapperMemoryHeuristic", "views.html.help.mapreduce.helpMapperMemory", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Reducer Skew", "com.linkedin.drelephant.mapreduce.heuristics.ReducerSkewHeuristic", "views.html.help.mapreduce.helpReducerSkew", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Reducer GC", "com.linkedin.drelephant.mapreduce.heuristics.ReducerGCHeuristic", "views.html.help.mapreduce.helpGC", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Reducer Time", "com.linkedin.drelephant.mapreduce.heuristics.ReducerTimeHeuristic", "views.html.help.mapreduce.helpReducerTime", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Reducer Memory", "com.linkedin.drelephant.mapreduce.heuristics.ReducerMemoryHeuristic", "views.html.help.mapreduce.helpReducerMemory", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Shuffle &#38; Sort", "com.linkedin.drelephant.mapreduce.heuristics.ShuffleSortHeuristic", "views.html.help.mapreduce.helpShuffleSort", new ApplicationType("mapreduce"), paramsMap)));
    heuristics.add(new MapperSkewHeuristic(new HeuristicConfigurationData("Exception", "com.linkedin.drelephant.mapreduce.heuristics.ExceptionHeuristic", "views.html.help.mapreduce.helpException", new ApplicationType("mapreduce"), paramsMap)));
    return heuristics;
}
Also used : HeuristicConfigurationData(com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData) MapperSkewHeuristic(com.linkedin.drelephant.mapreduce.heuristics.MapperSkewHeuristic) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapperSkewHeuristic(com.linkedin.drelephant.mapreduce.heuristics.MapperSkewHeuristic)

Example 2 with HeuristicConfigurationData

use of com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData in project dr-elephant by linkedin.

the class ElephantContext method loadHeuristics.

/**
 * Load all the heuristics and their views configured in HeuristicConf.xml
 */
private void loadHeuristics() {
    Document document = Utils.loadXMLDoc(HEURISTICS_CONF);
    _heuristicsConfData = new HeuristicConfiguration(document.getDocumentElement()).getHeuristicsConfigurationData();
    for (HeuristicConfigurationData data : _heuristicsConfData) {
        // Load all the heuristic classes
        try {
            Class<?> heuristicClass = Class.forName(data.getClassName());
            Object instance = heuristicClass.getConstructor(HeuristicConfigurationData.class).newInstance(data);
            if (!(instance instanceof Heuristic)) {
                throw new IllegalArgumentException("Class " + heuristicClass.getName() + " is not an implementation of " + Heuristic.class.getName());
            }
            ApplicationType type = data.getAppType();
            List<Heuristic> heuristics = _typeToHeuristics.get(type);
            if (heuristics == null) {
                heuristics = new ArrayList<Heuristic>();
                _typeToHeuristics.put(type, heuristics);
            }
            heuristics.add((Heuristic) instance);
            logger.info("Load Heuristic : " + 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) {
            // More descriptive on other runtime exception such as ClassCastException
            throw new RuntimeException(data.getClassName() + " is not a valid Heuristic 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);
        }
        // Load all the heuristic views
        try {
            Class<?> viewClass = Class.forName(data.getViewName());
            Method render = viewClass.getDeclaredMethod("render");
            Html page = (Html) render.invoke(null);
            _heuristicToView.put(data.getHeuristicName(), page);
            logger.info("Load View : " + data.getViewName());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Could not find view " + data.getViewName(), e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Could not access render on view" + data.getViewName(), e);
        } catch (RuntimeException e) {
            // More descriptive on other runtime exception such as ClassCastException
            throw new RuntimeException(data.getViewName() + " is not a valid view class.", e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException("Could not invoke view " + data.getViewName(), e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Could not find method render for view " + data.getViewName(), e);
        }
    }
    // Bind No_DATA heuristic to its helper pages, no need to add any real configurations
    _heuristicsConfData.add(new HeuristicConfigurationData(HeuristicResult.NO_DATA.getHeuristicName(), HeuristicResult.NO_DATA.getHeuristicClassName(), "views.html.help.helpNoData", null, null));
}
Also used : HeuristicConfigurationData(com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData) Html(play.api.templates.Html) Method(java.lang.reflect.Method) Document(org.w3c.dom.Document) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) HeuristicConfiguration(com.linkedin.drelephant.configurations.heuristic.HeuristicConfiguration) Heuristic(com.linkedin.drelephant.analysis.Heuristic)

Aggregations

HeuristicConfigurationData (com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData)2 ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)1 Heuristic (com.linkedin.drelephant.analysis.Heuristic)1 HeuristicConfiguration (com.linkedin.drelephant.configurations.heuristic.HeuristicConfiguration)1 MapperSkewHeuristic (com.linkedin.drelephant.mapreduce.heuristics.MapperSkewHeuristic)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Document (org.w3c.dom.Document)1 Html (play.api.templates.Html)1