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 019package org.apache.hadoop.mapred; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import org.apache.hadoop.classification.InterfaceAudience.Private; 023import org.apache.hadoop.classification.InterfaceStability; 024 025/** 026 * This is used to track task completion events on 027 * job tracker. 028 */ 029@InterfaceAudience.Public 030@InterfaceStability.Stable 031public class TaskCompletionEvent 032 extends org.apache.hadoop.mapreduce.TaskCompletionEvent { 033 @InterfaceAudience.Public 034 @InterfaceStability.Stable 035 /** 036 * Task Completion Statuses 037 */ 038 static public enum Status { 039 /** 040 * Task Event Attempt failed but there are attempts remaining. 041 */ 042 FAILED, 043 /** 044 * Task Event was killed. 045 */ 046 KILLED, 047 /** 048 * Task Event was successful. 049 */ 050 SUCCEEDED, 051 /** 052 * Used to Override a previously successful event status. 053 * Example: Map attempt runs and a SUCCEEDED event is sent. Later a task 054 * is retroactively failed due to excessive fetch failure during shuffle 055 * phase. When the retroactive attempt failure occurs, an OBSOLETE event is 056 * sent for the map attempt indicating the prior event is no longer valid. 057 */ 058 OBSOLETE, 059 /** 060 * Task Event attempt failed and no further attempts exist. 061 * reached MAX attempts. When a reducer receives a TIPFAILED event it 062 * gives up trying to shuffle data from that map task. 063 */ 064 TIPFAILED 065 } 066 067 public static final TaskCompletionEvent[] EMPTY_ARRAY = 068 new TaskCompletionEvent[0]; 069 /** 070 * Default constructor for Writable. 071 * 072 */ 073 public TaskCompletionEvent() { 074 super(); 075 } 076 077 /** 078 * Constructor. eventId should be created externally and incremented 079 * per event for each job. 080 * @param eventId event id, event id should be unique and assigned in 081 * incrementally, starting from 0. 082 * @param taskId task id 083 * @param status task's status 084 * @param taskTrackerHttp task tracker's host:port for http. 085 */ 086 public TaskCompletionEvent(int eventId, 087 TaskAttemptID taskId, 088 int idWithinJob, 089 boolean isMap, 090 Status status, 091 String taskTrackerHttp){ 092 super(eventId, taskId, idWithinJob, isMap, org.apache.hadoop.mapreduce. 093 TaskCompletionEvent.Status.valueOf(status.name()), taskTrackerHttp); 094 } 095 096 @Private 097 public static TaskCompletionEvent downgrade( 098 org.apache.hadoop.mapreduce.TaskCompletionEvent event) { 099 return new TaskCompletionEvent(event.getEventId(), 100 TaskAttemptID.downgrade(event.getTaskAttemptId()),event.idWithinJob(), 101 event.isMapTask(), Status.valueOf(event.getStatus().name()), 102 event.getTaskTrackerHttp()); 103 } 104 /** 105 * Returns task id. 106 * @return task id 107 * @deprecated use {@link #getTaskAttemptId()} instead. 108 */ 109 @Deprecated 110 public String getTaskId() { 111 return getTaskAttemptId().toString(); 112 } 113 114 /** 115 * Returns task id. 116 * @return task id 117 */ 118 public TaskAttemptID getTaskAttemptId() { 119 return TaskAttemptID.downgrade(super.getTaskAttemptId()); 120 } 121 122 /** 123 * Returns {@link Status} 124 * @return task completion status 125 */ 126 public Status getTaskStatus() { 127 return Status.valueOf(super.getStatus().name()); 128 } 129 130 /** 131 * Sets task id. 132 * @param taskId 133 * @deprecated use {@link #setTaskAttemptId(TaskAttemptID)} instead. 134 */ 135 @Deprecated 136 public void setTaskId(String taskId) { 137 this.setTaskAttemptId(TaskAttemptID.forName(taskId)); 138 } 139 140 /** 141 * Sets task id. 142 * @param taskId 143 * @deprecated use {@link #setTaskAttemptId(TaskAttemptID)} instead. 144 */ 145 @Deprecated 146 public void setTaskID(TaskAttemptID taskId) { 147 this.setTaskAttemptId(taskId); 148 } 149 150 /** 151 * Sets task id. 152 * @param taskId 153 */ 154 protected void setTaskAttemptId(TaskAttemptID taskId) { 155 super.setTaskAttemptId(taskId); 156 } 157 158 /** 159 * Set task status. 160 * @param status 161 */ 162 @Private 163 public void setTaskStatus(Status status) { 164 super.setTaskStatus(org.apache.hadoop.mapreduce. 165 TaskCompletionEvent.Status.valueOf(status.name())); 166 } 167 168 /** 169 * Set the task completion time 170 * @param taskCompletionTime time (in millisec) the task took to complete 171 */ 172 @Private 173 public void setTaskRunTime(int taskCompletionTime) { 174 super.setTaskRunTime(taskCompletionTime); 175 } 176 177 /** 178 * set event Id. should be assigned incrementally starting from 0. 179 * @param eventId 180 */ 181 @Private 182 public void setEventId(int eventId) { 183 super.setEventId(eventId); 184 } 185 186 /** 187 * Set task tracker http location. 188 * @param taskTrackerHttp 189 */ 190 @Private 191 public void setTaskTrackerHttp(String taskTrackerHttp) { 192 super.setTaskTrackerHttp(taskTrackerHttp); 193 } 194}