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 static TaskCompletionEvent downgrade( 067 org.apache.hadoop.mapreduce.TaskCompletionEvent event) { 068 return new TaskCompletionEvent(event.getEventId(), 069 TaskAttemptID.downgrade(event.getTaskAttemptId()),event.idWithinJob(), 070 event.isMapTask(), Status.valueOf(event.getStatus().name()), 071 event.getTaskTrackerHttp()); 072 } 073 /** 074 * Returns task id. 075 * @return task id 076 * @deprecated use {@link #getTaskAttemptId()} instead. 077 */ 078 @Deprecated 079 public String getTaskId() { 080 return getTaskAttemptId().toString(); 081 } 082 083 /** 084 * Returns task id. 085 * @return task id 086 */ 087 public TaskAttemptID getTaskAttemptId() { 088 return TaskAttemptID.downgrade(super.getTaskAttemptId()); 089 } 090 091 /** 092 * Returns enum Status.SUCESS or Status.FAILURE. 093 * @return task tracker status 094 */ 095 public Status getTaskStatus() { 096 return Status.valueOf(super.getStatus().name()); 097 } 098 099 /** 100 * Sets task id. 101 * @param taskId 102 * @deprecated use {@link #setTaskAttemptId(TaskAttemptID)} instead. 103 */ 104 @Deprecated 105 public void setTaskId(String taskId) { 106 this.setTaskAttemptId(TaskAttemptID.forName(taskId)); 107 } 108 109 /** 110 * Sets task id. 111 * @param taskId 112 */ 113 protected void setTaskAttemptId(TaskAttemptID taskId) { 114 super.setTaskAttemptId(taskId); 115 } 116 117 /** 118 * Set task status. 119 * @param status 120 */ 121 @Private 122 public void setTaskStatus(Status status) { 123 super.setTaskStatus(org.apache.hadoop.mapreduce. 124 TaskCompletionEvent.Status.valueOf(status.name())); 125 } 126 127 /** 128 * Set the task completion time 129 * @param taskCompletionTime time (in millisec) the task took to complete 130 */ 131 @Private 132 public void setTaskRunTime(int taskCompletionTime) { 133 super.setTaskRunTime(taskCompletionTime); 134 } 135 136 /** 137 * set event Id. should be assigned incrementally starting from 0. 138 * @param eventId 139 */ 140 @Private 141 public void setEventId(int eventId) { 142 super.setEventId(eventId); 143 } 144 145 /** 146 * Set task tracker http location. 147 * @param taskTrackerHttp 148 */ 149 @Private 150 public void setTaskTrackerHttp(String taskTrackerHttp) { 151 super.setTaskTrackerHttp(taskTrackerHttp); 152 } 153 }