001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.hadoop.mapred; 019 020 import java.util.ArrayList; 021 import java.util.Collection; 022 import java.util.List; 023 024 import org.apache.hadoop.classification.InterfaceAudience; 025 import org.apache.hadoop.classification.InterfaceStability; 026 027 /** 028 * A report on the state of a task. 029 */ 030 @InterfaceAudience.Public 031 @InterfaceStability.Stable 032 public class TaskReport extends org.apache.hadoop.mapreduce.TaskReport { 033 034 public TaskReport() { 035 super(); 036 } 037 038 /** 039 * Creates a new TaskReport object 040 * @param taskid 041 * @param progress 042 * @param state 043 * @param diagnostics 044 * @param startTime 045 * @param finishTime 046 * @param counters 047 * @deprecated 048 */ 049 @Deprecated 050 TaskReport(TaskID taskid, float progress, String state, 051 String[] diagnostics, long startTime, long finishTime, 052 Counters counters) { 053 this(taskid, progress, state, diagnostics, null, startTime, finishTime, 054 counters); 055 } 056 057 /** 058 * Creates a new TaskReport object 059 * @param taskid 060 * @param progress 061 * @param state 062 * @param diagnostics 063 * @param currentStatus 064 * @param startTime 065 * @param finishTime 066 * @param counters 067 */ 068 TaskReport(TaskID taskid, float progress, String state, 069 String[] diagnostics, TIPStatus currentStatus, 070 long startTime, long finishTime, 071 Counters counters) { 072 super(taskid, progress, state, diagnostics, currentStatus, startTime, 073 finishTime, new org.apache.hadoop.mapreduce.Counters(counters)); 074 } 075 076 static TaskReport downgrade( 077 org.apache.hadoop.mapreduce.TaskReport report) { 078 return new TaskReport(TaskID.downgrade(report.getTaskID()), 079 report.getProgress(), report.getState(), report.getDiagnostics(), 080 report.getCurrentStatus(), report.getStartTime(), report.getFinishTime(), 081 Counters.downgrade(report.getTaskCounters())); 082 } 083 084 static TaskReport[] downgradeArray(org.apache.hadoop. 085 mapreduce.TaskReport[] reports) { 086 List<TaskReport> ret = new ArrayList<TaskReport>(); 087 for (org.apache.hadoop.mapreduce.TaskReport report : reports) { 088 ret.add(downgrade(report)); 089 } 090 return ret.toArray(new TaskReport[0]); 091 } 092 093 /** The string of the task id. */ 094 public String getTaskId() { 095 return TaskID.downgrade(super.getTaskID()).toString(); 096 } 097 098 /** The id of the task. */ 099 public TaskID getTaskID() { 100 return TaskID.downgrade(super.getTaskID()); 101 } 102 103 public Counters getCounters() { 104 return Counters.downgrade(super.getTaskCounters()); 105 } 106 107 /** 108 * set successful attempt ID of the task. 109 */ 110 public void setSuccessfulAttempt(TaskAttemptID t) { 111 super.setSuccessfulAttemptId(t); 112 } 113 /** 114 * Get the attempt ID that took this task to completion 115 */ 116 public TaskAttemptID getSuccessfulTaskAttempt() { 117 return TaskAttemptID.downgrade(super.getSuccessfulTaskAttemptId()); 118 } 119 /** 120 * set running attempt(s) of the task. 121 */ 122 public void setRunningTaskAttempts( 123 Collection<TaskAttemptID> runningAttempts) { 124 Collection<org.apache.hadoop.mapreduce.TaskAttemptID> attempts = 125 new ArrayList<org.apache.hadoop.mapreduce.TaskAttemptID>(); 126 for (TaskAttemptID id : runningAttempts) { 127 attempts.add(id); 128 } 129 super.setRunningTaskAttemptIds(attempts); 130 } 131 /** 132 * Get the running task attempt IDs for this task 133 */ 134 public Collection<TaskAttemptID> getRunningTaskAttempts() { 135 Collection<TaskAttemptID> attempts = new ArrayList<TaskAttemptID>(); 136 for (org.apache.hadoop.mapreduce.TaskAttemptID id : 137 super.getRunningTaskAttemptIds()) { 138 attempts.add(TaskAttemptID.downgrade(id)); 139 } 140 return attempts; 141 } 142 143 /** 144 * set finish time of task. 145 * @param finishTime finish time of task. 146 */ 147 protected void setFinishTime(long finishTime) { 148 super.setFinishTime(finishTime); 149 } 150 151 /** 152 * set start time of the task. 153 */ 154 protected void setStartTime(long startTime) { 155 super.setStartTime(startTime); 156 } 157 158 }