{
// merge together the entries for each task attempt
Map<String,Attempt> taskAttemptIdToAttempt = new HashMap<String,Attempt>();
for (Attempt attempt : attemptEntries)
{
Attempt mergedAttempt;
if (!taskAttemptIdToAttempt.containsKey(attempt.getTaskAttemptId().toString()))
{
mergedAttempt = new Attempt();
mergedAttempt.setCounters(new HashMap<CharSequence,Long>());
mergedAttempt.setDerived(new DerivedAttemptData());
taskAttemptIdToAttempt.put(attempt.getTaskAttemptId().toString(),mergedAttempt);
}
else
{
mergedAttempt = taskAttemptIdToAttempt.get(attempt.getTaskAttemptId().toString());
}
if (attempt.getType() != null)
{
mergedAttempt.setType(attempt.getType());
}
if (attempt.getJobId() != null)
{
mergedAttempt.setJobId(attempt.getJobId());
}
if (attempt.getTaskId() != null)
{
mergedAttempt.setTaskId(attempt.getTaskId());
}
if (attempt.getTaskAttemptId() != null)
{
mergedAttempt.setTaskAttemptId(attempt.getTaskAttemptId());
}
if (attempt.getStartTime() != null)
{
// take the later start time in case there are multiple
if (mergedAttempt.getStartTime() == null || mergedAttempt.getStartTime() < attempt.getStartTime())
{
mergedAttempt.setStartTime(attempt.getStartTime());
}
}
if (attempt.getFinishTime() != null)
{
// take the later finish time in case there are multiple
if (mergedAttempt.getFinishTime() == null || mergedAttempt.getFinishTime() < attempt.getFinishTime())
{
mergedAttempt.setFinishTime(attempt.getFinishTime());
}
}
if (attempt.getShuffleFinished() != null)
{
// take the later finish time in case there are multiple
if (mergedAttempt.getShuffleFinished() == null || mergedAttempt.getShuffleFinished() < attempt.getShuffleFinished())
{
mergedAttempt.setShuffleFinished(attempt.getShuffleFinished());
}
}
if (attempt.getSortFinished() != null)
{
// take the later finish time in case there are multiple
if (mergedAttempt.getSortFinished() == null || mergedAttempt.getSortFinished() < attempt.getSortFinished())
{
mergedAttempt.setSortFinished(attempt.getSortFinished());
}
}
if (attempt.getTaskStatus() != null)
{
mergedAttempt.setTaskStatus(attempt.getTaskStatus());
}
if (attempt.getCounters() != null && attempt.getCounters().size() > 0)
{
mergedAttempt.setCounters(attempt.getCounters());
}
}
// filter out bad data
Collection<Attempt> filteredAttempts = Collections2.filter(taskAttemptIdToAttempt.values(), new Predicate<Attempt>() {