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