String jobID = "";
matcher = jobPattern.matcher(capp);
if(matcher.matches()) {
jobID=matcher.group(2);
}
ChukwaRecord record = new ChukwaRecord();
ChukwaRecord jobConfRecord = new ChukwaRecord();
DocumentBuilderFactory docBuilderFactory
= DocumentBuilderFactory.newInstance();
//ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
try {
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = null;
String fileName = "test_"+randomNumber.nextInt();
File tmp = new File(fileName);
FileOutputStream out = new FileOutputStream(tmp);
out.write(recordEntry.getBytes());
out.close();
doc = builder.parse(fileName);
Element root = doc.getDocumentElement();
if (!"configuration".equals(root.getTagName()))
log.fatal("bad conf file: top-level element not <configuration>");
NodeList props = root.getChildNodes();
JSONObject json = new JSONObject();
String queue = "default";
for (int i = 0; i < props.getLength(); i++) {
Node propNode = props.item(i);
if (!(propNode instanceof Element))
continue;
Element prop = (Element)propNode;
if (!"property".equals(prop.getTagName()))
log.warn("bad conf file: element not <property>");
NodeList fields = prop.getChildNodes();
String attr = null;
String value = null;
boolean finalParameter = false;
for (int j = 0; j < fields.getLength(); j++) {
Node fieldNode = fields.item(j);
if (!(fieldNode instanceof Element))
continue;
Element field = (Element)fieldNode;
if ("name".equals(field.getTagName()) && field.hasChildNodes())
attr = ((Text)field.getFirstChild()).getData().trim();
if ("value".equals(field.getTagName()) && field.hasChildNodes())
value = ((Text)field.getFirstChild()).getData();
if ("final".equals(field.getTagName()) && field.hasChildNodes())
finalParameter = "true".equals(((Text)field.getFirstChild()).getData());
}
// Ignore this parameter if it has already been marked as 'final'
if (attr != null && value != null) {
json.put(attr, value);
if(attr.intern()=="mapred.job.queue.name".intern()) {
queue=value;
}
jobConfRecord.add("job_conf." + attr, value);
}
}
record.add("JOBCONF-JSON", json.toString());
record.add("mapred.job.queue.name", queue);
record.add("JOBID", "job_" + jobID);
buildGenericRecord(record, null, time, "JobData");
calendar.setTimeInMillis(time);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
key.setKey("" + calendar.getTimeInMillis() + "/job_" + jobID + "/" + time);
output.collect(key, record);
jobConfRecord.add("JOBID", "job_" + jobID);
buildGenericRecord(jobConfRecord, null, time, "JobConfData");
output.collect(key, jobConfRecord);
tmp.delete();
} catch(Exception e) {