Search in sources :

Example 1 with Heuristic

use of com.linkedin.drelephant.analysis.Heuristic in project dr-elephant by linkedin.

the class Web method restSearchOptions.

/**
 * This returns the rest search options which are filled in the forms for the search page.
 * @return Returns the json object which should be filled in the search form.
 * return object:
 * <pre>
 *  *{
 *  "search-options": {
 *    "jobcategory": [
 *      {
 *        "name": "SPARK",
 *        "jobtypes": [
 *          {
 *            "name": "Spark"
 *          }
 *        ],
 *        "heuristics": [
 *          {
 *            "name": "Spark Configuration Best Practice"
 *          },
 *          {
 *            "name": "Spark Memory Limit"
 *          },
 *          {
 *            "name": "Spark Stage Runtime"
 *          },
 *          {
 *            "name": "Spark Job Runtime"
 *          },
 *          {
 *            "name": "Spark Executor Load Balance"
 *          },
 *          {
 *            "name": "Spark Event Log Limit"
 *          }
 *        ]
 *      },
 *      {
 *        "name": "MAPREDUCE",
 *        "jobtypes": [
 *          {
 *            "name": "Pig"
 *          },
 *          {
 *            "name": "Hive"
 *          },
 *          {
 *            "name": "Cascading"
 *          },
 *          {
 *            "name": "Voldemort"
 *          },
 *          {
 *            "name": "Kafka"
 *          },
 *          {
 *            "name": "HadoopJava"
 *          }
 *        ],
 *        "heuristics": [
 *          {
 *            "name": "Mapper Data Skew"
 *          },
 *          {
 *            "name": "Mapper GC"
 *          },
 *          {
 *            "name": "Mapper Time"
 *          },
 *          {
 *            "name": "Mapper Speed"
 *          },
 *          {
 *            "name": "Mapper Spill"
 *          },
 *          {
 *            "name": "Mapper Memory"
 *          },
 *          {
 *            "name": "Reducer Data Skew"
 *          },
 *          {
 *            "name": "Reducer GC"
 *          },
 *          {
 *            "name": "Reducer Time"
 *          },
 *          {
 *            "name": "Reducer Memory"
 *          },
 *          {
 *            "name": "Shuffle & Sort"
 *          },
 *          {
 *            "name": "Exception"
 *          }
 *        ]
 *      }
 *    ],
 *    "severities": [
 *      {
 *        "name": "Critical",
 *        "value": 4
 *      },
 *      {
 *        "name": "Severe",
 *        "value": 3
 *      },
 *      {
 *        "name": "Moderate",
 *        "value": 2
 *      },
 *      {
 *        "name": "Low",
 *        "value": 1
 *      },
 *      {
 *        "name": "None",
 *        "value": 0
 *      }
 *    ],
 *    "id": "search"
 *  }
 *}
 * </pre>
 */
public static Result restSearchOptions() {
    JsonObject searchOptions = new JsonObject();
    JsonArray jobCategory = new JsonArray();
    JsonArray severities = new JsonArray();
    Map<ApplicationType, List<JobType>> applicationTypeListMap = ElephantContext.instance().getAppTypeToJobTypes();
    for (ApplicationType key : applicationTypeListMap.keySet()) {
        JsonObject applicationType = new JsonObject();
        JsonArray jobTypes = new JsonArray();
        JsonArray heuristics = new JsonArray();
        for (JobType jobtype : applicationTypeListMap.get(key)) {
            JsonObject jobTypeNode = new JsonObject();
            jobTypeNode.addProperty(JsonKeys.NAME, jobtype.getName());
            jobTypes.add(jobTypeNode);
        }
        for (Heuristic heuristic : ElephantContext.instance().getHeuristicsForApplicationType(key)) {
            JsonObject heuristicNode = new JsonObject();
            heuristicNode.addProperty(JsonKeys.NAME, heuristic.getHeuristicConfData().getHeuristicName());
            heuristics.add(heuristicNode);
        }
        applicationType.addProperty(JsonKeys.NAME, key.getName());
        applicationType.add(JsonKeys.JOB_TYPES, jobTypes);
        applicationType.add(JsonKeys.HEURISTICS, heuristics);
        jobCategory.add(applicationType);
    }
    for (Severity severity : Severity.values()) {
        JsonObject severityObject = new JsonObject();
        severityObject.addProperty(JsonKeys.NAME, severity.getText());
        severityObject.addProperty(JsonKeys.VALUE, severity.getValue());
        severities.add(severityObject);
    }
    searchOptions.add(JsonKeys.JOB_CATEGORY, jobCategory);
    searchOptions.add(JsonKeys.SEVERITIES, severities);
    searchOptions.addProperty(JsonKeys.ID, "search");
    JsonObject parent = new JsonObject();
    parent.add(JsonKeys.SEARCH_OPTS, searchOptions);
    return ok(new Gson().toJson(parent));
}
Also used : JsonArray(com.google.gson.JsonArray) ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) JobType(com.linkedin.drelephant.analysis.JobType) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionList(com.avaje.ebean.ExpressionList) Severity(com.linkedin.drelephant.analysis.Severity) Heuristic(com.linkedin.drelephant.analysis.Heuristic)

Example 2 with Heuristic

use of com.linkedin.drelephant.analysis.Heuristic in project dr-elephant by linkedin.

the class ElephantContext method configureSupportedApplicationTypes.

/**
 * Decides what application types can be supported.
 *
 * An application type is supported if all the below are true.
 * 1. A Fetcher is defined in FetcherConf.xml for the application type.
 * 2. At least one Heuristic is configured in HeuristicConf.xml for the application type.
 * 3. At least one job type is configured in JobTypeConf.xml for the application type.
 */
private void configureSupportedApplicationTypes() {
    Set<ApplicationType> supportedTypes = Sets.intersection(_typeToFetcher.keySet(), _typeToHeuristics.keySet());
    supportedTypes = Sets.intersection(supportedTypes, _appTypeToJobTypes.keySet());
    supportedTypes = Sets.intersection(supportedTypes, _typeToAggregator.keySet());
    _typeToAggregator.keySet().retainAll(supportedTypes);
    _typeToFetcher.keySet().retainAll(supportedTypes);
    _typeToHeuristics.keySet().retainAll(supportedTypes);
    _appTypeToJobTypes.keySet().retainAll(supportedTypes);
    logger.info("Configuring ElephantContext...");
    for (ApplicationType type : supportedTypes) {
        _nameToType.put(type.getName(), type);
        List<String> classes = new ArrayList<String>();
        List<Heuristic> heuristics = _typeToHeuristics.get(type);
        for (Heuristic heuristic : heuristics) {
            classes.add(heuristic.getClass().getName());
        }
        List<JobType> jobTypes = _appTypeToJobTypes.get(type);
        logger.info("Supports " + type.getName() + " application type, using " + _typeToFetcher.get(type).toString() + " fetcher class with Heuristics [" + StringUtils.join(classes, ", ") + "] and following JobTypes [" + StringUtils.join(jobTypes, ", ") + "].");
    }
}
Also used : ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) JobType(com.linkedin.drelephant.analysis.JobType) ArrayList(java.util.ArrayList) Heuristic(com.linkedin.drelephant.analysis.Heuristic)

Example 3 with Heuristic

use of com.linkedin.drelephant.analysis.Heuristic in project dr-elephant by linkedin.

the class ElephantContext method getAllHeuristicNames.

/**
 * Return the heuristic names available grouped by application type.
 *
 * @return A map of application type name -> a list of heuristic names
 */
public Map<String, List<String>> getAllHeuristicNames() {
    if (_heuristicGroupedNames.isEmpty()) {
        for (Map.Entry<ApplicationType, List<Heuristic>> entry : _typeToHeuristics.entrySet()) {
            ApplicationType type = entry.getKey();
            List<Heuristic> list = entry.getValue();
            List<String> nameList = new ArrayList<String>();
            for (Heuristic heuristic : list) {
                nameList.add(heuristic.getHeuristicConfData().getHeuristicName());
            }
            Collections.sort(nameList);
            _heuristicGroupedNames.put(type.getName(), nameList);
        }
    }
    return _heuristicGroupedNames;
}
Also used : ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Heuristic(com.linkedin.drelephant.analysis.Heuristic)

Example 4 with Heuristic

use of com.linkedin.drelephant.analysis.Heuristic 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

ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)4 Heuristic (com.linkedin.drelephant.analysis.Heuristic)4 ArrayList (java.util.ArrayList)3 JobType (com.linkedin.drelephant.analysis.JobType)2 List (java.util.List)2 ExpressionList (com.avaje.ebean.ExpressionList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Severity (com.linkedin.drelephant.analysis.Severity)1 HeuristicConfiguration (com.linkedin.drelephant.configurations.heuristic.HeuristicConfiguration)1 HeuristicConfigurationData (com.linkedin.drelephant.configurations.heuristic.HeuristicConfigurationData)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Document (org.w3c.dom.Document)1 Html (play.api.templates.Html)1