Search in sources :

Example 11 with ApplicationType

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

the class JobTypeConfiguration method parseJobTypeConfiguration.

private void parseJobTypeConfiguration(Element configuration) {
    Map<ApplicationType, JobType> defaultMap = new HashMap<ApplicationType, JobType>();
    NodeList nodes = configuration.getChildNodes();
    int n = 0;
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            n++;
            Element jobTypeNode = (Element) node;
            String jobTypeName;
            Node jobTypeNameNode = jobTypeNode.getElementsByTagName("name").item(0);
            if (jobTypeNameNode == null) {
                throw new RuntimeException("No tag 'jobtype' in jobtype " + n);
            }
            jobTypeName = jobTypeNameNode.getTextContent();
            if (jobTypeName.equals("")) {
                throw new RuntimeException("Empty tag 'jobtype' in jobtype " + n);
            }
            // Truncate jobtype length for db constraint
            if (jobTypeName.length() > TYPE_LEN_LIMIT) {
                logger.info("Truncate type " + jobTypeName.length());
                jobTypeName = jobTypeName.substring(0, TYPE_LEN_LIMIT);
            }
            String jobConfName;
            Node jobConfNameNode = jobTypeNode.getElementsByTagName("conf").item(0);
            if (jobConfNameNode == null) {
                throw new RuntimeException("No tag 'conf' in jobtype " + jobTypeName);
            }
            jobConfName = jobConfNameNode.getTextContent();
            if (jobConfName.equals("")) {
                throw new RuntimeException("Empty tag 'conf' in jobtype " + jobTypeName);
            }
            String jobConfValue;
            Node jobConfValueNode = jobTypeNode.getElementsByTagName("value").item(0);
            if (jobConfValueNode == null) {
                // Default regex. match any char one or more times
                jobConfValue = ".*";
            } else {
                jobConfValue = jobConfValueNode.getTextContent();
                if (jobConfValue.equals("")) {
                    jobConfValue = ".*";
                }
            }
            String appTypeName;
            Node appTypeNameNode = jobTypeNode.getElementsByTagName("applicationtype").item(0);
            if (appTypeNameNode == null) {
                throw new RuntimeException("No tag 'applicationtype' in jobtype " + jobTypeName);
            }
            appTypeName = appTypeNameNode.getTextContent();
            ApplicationType appType = new ApplicationType(appTypeName);
            boolean isDefault = jobTypeNode.getElementsByTagName("isDefault").item(0) != null;
            JobType newJobType = null;
            try {
                newJobType = new JobType(jobTypeName, jobConfName, jobConfValue);
            } catch (PatternSyntaxException e) {
                throw new RuntimeException("Error processing this pattern.  Pattern:" + jobConfValue + " jobtype:" + jobTypeName);
            }
            String newJobTypeStr = String.format("jobType:%s, for application type:%s, isDefault:%s, confName:%s, confValue:%s.", jobTypeName, appTypeName, isDefault, jobConfName, jobConfValue);
            logger.info("Loaded " + newJobTypeStr);
            if (isDefault) {
                if (defaultMap.containsKey(appType)) {
                    throw new RuntimeException("Each application type should have one and only one default job type. Duplicate default job type: " + newJobTypeStr + " for application type: " + appType.getName());
                } else {
                    defaultMap.put(appType, newJobType);
                }
            } else {
                List<JobType> jobTypes = getJobTypeList(appType);
                jobTypes.add(newJobType);
            }
        }
    }
    // Append default maps to the end of each job type list
    for (Map.Entry<ApplicationType, JobType> entry : defaultMap.entrySet()) {
        ApplicationType appType = entry.getKey();
        JobType jobType = entry.getValue();
        List<JobType> jobTypes = getJobTypeList(appType);
        jobTypes.add(jobType);
    }
    // Sanity check
    for (ApplicationType appType : _appTypeToJobTypeList.keySet()) {
        if (!defaultMap.containsKey(appType)) {
            throw new RuntimeException("Each application type should have one and only one default job type, there is" + " none for application type: " + appType.getName() + ". Use <isDefault/> to tag one.");
        }
    }
    Integer jobTypesSize = 0;
    for (List<JobType> jobTypes : _appTypeToJobTypeList.values()) {
        jobTypesSize += jobTypes.size();
    }
    logger.info("Loaded total " + jobTypesSize + " job types for " + _appTypeToJobTypeList.size() + " app types");
}
Also used : HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ApplicationType(com.linkedin.drelephant.analysis.ApplicationType) JobType(com.linkedin.drelephant.analysis.JobType) HashMap(java.util.HashMap) Map(java.util.Map) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)11 Heuristic (com.linkedin.drelephant.analysis.Heuristic)4 Element (org.w3c.dom.Element)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 JobType (com.linkedin.drelephant.analysis.JobType)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ArrayList (java.util.ArrayList)3 Document (org.w3c.dom.Document)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)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 ElephantFetcher (com.linkedin.drelephant.analysis.ElephantFetcher)1 HadoopApplicationData (com.linkedin.drelephant.analysis.HadoopApplicationData)1 HadoopMetricsAggregator (com.linkedin.drelephant.analysis.HadoopMetricsAggregator)1