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 019 package org.apache.hadoop.mapred; 020 021 import org.apache.hadoop.classification.InterfaceAudience; 022 import org.apache.hadoop.classification.InterfaceAudience.Private; 023 import 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 031 public class TaskCompletionEvent 032 extends org.apache.hadoop.mapreduce.TaskCompletionEvent { 033 @InterfaceAudience.Public 034 @InterfaceStability.Stable 035 static public enum Status {FAILED, KILLED, SUCCEEDED, OBSOLETE, TIPFAILED}; 036 037 public static final TaskCompletionEvent[] EMPTY_ARRAY = 038 new TaskCompletionEvent[0]; 039 /** 040 * Default constructor for Writable. 041 * 042 */ 043 public TaskCompletionEvent() { 044 super(); 045 } 046 047 /** 048 * Constructor. eventId should be created externally and incremented 049 * per event for each job. 050 * @param eventId event id, event id should be unique and assigned in 051 * incrementally, starting from 0. 052 * @param taskId task id 053 * @param status task's status 054 * @param taskTrackerHttp task tracker's host:port for http. 055 */ 056 public TaskCompletionEvent(int eventId, 057 TaskAttemptID taskId, 058 int idWithinJob, 059 boolean isMap, 060 Status status, 061 String taskTrackerHttp){ 062 super(eventId, taskId, idWithinJob, isMap, org.apache.hadoop.mapreduce. 063 TaskCompletionEvent.Status.valueOf(status.name()), taskTrackerHttp); 064 } 065 066 @Private 067 public static TaskCompletionEvent downgrade( 068 org.apache.hadoop.mapreduce.TaskCompletionEvent event) { 069 return new TaskCompletionEvent(event.getEventId(), 070 TaskAttemptID.downgrade(event.getTaskAttemptId()),event.idWithinJob(), 071 event.isMapTask(), Status.valueOf(event.getStatus().name()), 072 event.getTaskTrackerHttp()); 073 } 074 /** 075 * Returns task id. 076 * @return task id 077 * @deprecated use {@link #getTaskAttemptId()} instead. 078 */ 079 @Deprecated 080 public String getTaskId() { 081 return getTaskAttemptId().toString(); 082 } 083 084 /** 085 * Returns task id. 086 * @return task id 087 */ 088 public TaskAttemptID getTaskAttemptId() { 089 return TaskAttemptID.downgrade(super.getTaskAttemptId()); 090 } 091 092 /** 093 * Returns enum Status.SUCESS or Status.FAILURE. 094 * @return task tracker status 095 */ 096 public Status getTaskStatus() { 097 return Status.valueOf(super.getStatus().name()); 098 } 099 100 /** 101 * Sets task id. 102 * @param taskId 103 * @deprecated use {@link #setTaskAttemptId(TaskAttemptID)} instead. 104 */ 105 @Deprecated 106 public void setTaskId(String taskId) { 107 this.setTaskAttemptId(TaskAttemptID.forName(taskId)); 108 } 109 110 /** 111 * Sets task id. 112 * @param taskId 113 * @deprecated use {@link #setTaskAttemptId(TaskAttemptID)} instead. 114 */ 115 @Deprecated 116 public void setTaskID(TaskAttemptID taskId) { 117 this.setTaskAttemptId(taskId); 118 } 119 120 /** 121 * Sets task id. 122 * @param taskId 123 */ 124 protected void setTaskAttemptId(TaskAttemptID taskId) { 125 super.setTaskAttemptId(taskId); 126 } 127 128 /** 129 * Set task status. 130 * @param status 131 */ 132 @Private 133 public void setTaskStatus(Status status) { 134 super.setTaskStatus(org.apache.hadoop.mapreduce. 135 TaskCompletionEvent.Status.valueOf(status.name())); 136 } 137 138 /** 139 * Set the task completion time 140 * @param taskCompletionTime time (in millisec) the task took to complete 141 */ 142 @Private 143 public void setTaskRunTime(int taskCompletionTime) { 144 super.setTaskRunTime(taskCompletionTime); 145 } 146 147 /** 148 * set event Id. should be assigned incrementally starting from 0. 149 * @param eventId 150 */ 151 @Private 152 public void setEventId(int eventId) { 153 super.setEventId(eventId); 154 } 155 156 /** 157 * Set task tracker http location. 158 * @param taskTrackerHttp 159 */ 160 @Private 161 public void setTaskTrackerHttp(String taskTrackerHttp) { 162 super.setTaskTrackerHttp(taskTrackerHttp); 163 } 164 }