TorqueTimerTask torqueTimerTask = new TorqueTimerTask(p, command);
timeout.schedule(torqueTimerTask, TorqueTimerTask.timeoutInterval * 1000);
BufferedReader result = new BufferedReader(new InputStreamReader(p
.getInputStream()));
ErStreamHandler errorHandler = new ErStreamHandler(p.getErrorStream(),
command, false);
errorHandler.start();
String line = null;
String exit_status = null;
String hosts = null;
long timeQueued = -1;
long startTimeValue = -1;
long endTimeValue = -1;
boolean findResult = false;
while ((line = result.readLine()) != null && !findResult) {
if (line.indexOf("end") >= 0 && line.indexOf("Exit_status") >= 0
&& line.indexOf("qtime") >= 0) {
TreeMap<String, String> jobData = new TreeMap<String, String>();
String[] items = line.split("\\s+");
for (int i = 0; i < items.length; i++) {
String[] items2 = items[i].split("=");
if (items2.length >= 2) {
jobData.put(items2[0], items2[1]);
}
}
String startTime = jobData.get("ctime");
startTimeValue = Long.valueOf(startTime);
startTimeValue = startTimeValue - startTimeValue % (60);
Timestamp startTimedb = new Timestamp(startTimeValue * 1000);
String queueTime = jobData.get("qtime");
long queueTimeValue = Long.valueOf(queueTime);
String sTime = jobData.get("start");
long sTimeValue = Long.valueOf(sTime);
timeQueued = sTimeValue - queueTimeValue;
String endTime = jobData.get("end");
endTimeValue = Long.valueOf(endTime);
endTimeValue = endTimeValue - endTimeValue % (60);
Timestamp endTimedb = new Timestamp(endTimeValue * 1000);
exit_status = jobData.get("Exit_status");
hosts = jobData.get("exec_host");
String[] items2 = hosts.split("[+]");
int num = 0;
for (int i = 0; i < items2.length; i++) {
String machinetemp = items2[i];
if (machinetemp.length() >= 3) {
String machine = items2[i].substring(0, items2[i].length() - 2);
StringBuffer data = new StringBuffer();
data.append("HodId=").append(hodId);
data.append(", Machine=").append(machine);
if (domain != null) {
data.append(".").append(domain);
}
log.info(data.toString());
num++;
}
}
StringBuffer data = new StringBuffer();
data.append("HodID=").append(hodId);
data.append(", UserId=").append(userId);
data.append(", Status=").append(exit_status);
data.append(", TimeQueued=").append(timeQueued);
data.append(", StartTime=").append(startTimedb);
data.append(", EndTime=").append(endTimedb);
data.append(", NumOfMachines=").append(num);
log.info(data.toString());
findResult = true;
log.debug(" hod info for job " + hodId + " has been loaded ");
}// if
}// while
try {
errorHandler.join();
} catch (InterruptedException ie) {
log.error(ie.getMessage());
}
timeout.cancel();