}
// collect each of the attempts and add to the corresponding task
for (Attempt attempt : filteredAttempts)
{
Task task = taskIdToTask.get(attempt.getTaskId().toString());
if (task == null)
{
throw new RuntimeException("Could not find task");
}
if (task.getAttempts() == null)
{
task.setAttempts(new ArrayList<Attempt>());
}
task.getAttempts().add(attempt);
}
for (Task task : job.getTasks())
{
if (task.getAttempts().size() > 0)
{
// sort attempts by start time
Collections.sort(task.getAttempts(),new Comparator<Attempt>() {
@Override
public int compare(Attempt o1, Attempt o2)
{
return o1.getStartTime().compareTo(o2.getStartTime());
}
});
boolean foundSuccess = false;
// For simplicity we'll say that all attempts which are not successful are excess.
// In reality there could be some overlapping successful attempts, but we'll ignore this
// because it should be rare.
for (Attempt attempt : task.getAttempts())
{
if (attempt.getStartTime() == 0 || attempt.getFinishTime() == 0)
{
attempt.setStartTime(null);
attempt.setFinishTime(null);
//context.getCounter("Job Parsing", "startTime or finishTime zero").increment(1);
}
else
{
((DerivedAttemptData)attempt.getDerived()).setMinutes((attempt.getFinishTime() - attempt.getStartTime())/1000.0/60.0);
}
if (attempt.getCounters().containsKey(CPU_MILLISECONDS))
{
attempt.getDerived().setCpuMinutes(attempt.getCounters().get(CPU_MILLISECONDS)/1000.0/60.0);
}
if (attempt.getTaskStatus().equals("SUCCESS"))
{
((DerivedAttemptData)attempt.getDerived()).setExcess(false);
foundSuccess = true;
}
else
{
((DerivedAttemptData)attempt.getDerived()).setExcess(true);
}
}
// If none were successful then mark the first attempt as the non-excess one.
if (task.getAttempts().size() > 0 && !foundSuccess)
{
((DerivedAttemptData)task.getAttempts().get(0).getDerived()).setExcess(false);
}
// sort by task attempt id
Collections.sort(task.getAttempts(),new Comparator<Attempt>() {
@Override
public int compare(Attempt o1, Attempt o2)
{
return o1.getTaskAttemptId().toString().compareTo(o2.getTaskAttemptId().toString());
}