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 java.io.DataInput; 022 import java.io.IOException; 023 024 import org.apache.hadoop.classification.InterfaceAudience; 025 import org.apache.hadoop.classification.InterfaceStability; 026 import org.apache.hadoop.mapreduce.TaskType; 027 028 /** 029 * TaskID represents the immutable and unique identifier for 030 * a Map or Reduce Task. Each TaskID encompasses multiple attempts made to 031 * execute the Map or Reduce Task, each of which are uniquely indentified by 032 * their TaskAttemptID. 033 * 034 * TaskID consists of 3 parts. First part is the {@link JobID}, that this 035 * TaskInProgress belongs to. Second part of the TaskID is either 'm' or 'r' 036 * representing whether the task is a map task or a reduce task. 037 * And the third part is the task number. <br> 038 * An example TaskID is : 039 * <code>task_200707121733_0003_m_000005</code> , which represents the 040 * fifth map task in the third job running at the jobtracker 041 * started at <code>200707121733</code>. 042 * <p> 043 * Applications should never construct or parse TaskID strings 044 * , but rather use appropriate constructors or {@link #forName(String)} 045 * method. 046 * 047 * @see JobID 048 * @see TaskAttemptID 049 */ 050 @Deprecated 051 @InterfaceAudience.Public 052 @InterfaceStability.Stable 053 public class TaskID extends org.apache.hadoop.mapreduce.TaskID { 054 055 /** 056 * Constructs a TaskID object from given {@link JobID}. 057 * @param jobId JobID that this tip belongs to 058 * @param isMap whether the tip is a map 059 * @param id the tip number 060 * @deprecated Use {@link #TaskID(String, int, TaskType, int)} 061 */ 062 @Deprecated 063 public TaskID(org.apache.hadoop.mapreduce.JobID jobId, boolean isMap,int id) { 064 this(jobId, isMap ? TaskType.MAP : TaskType.REDUCE, id); 065 } 066 067 /** 068 * Constructs a TaskInProgressId object from given parts. 069 * @param jtIdentifier jobTracker identifier 070 * @param jobId job number 071 * @param isMap whether the tip is a map 072 * @param id the tip number 073 * @deprecated Use {@link #TaskID(org.apache.hadoop.mapreduce.JobID, TaskType, 074 * int)} 075 */ 076 @Deprecated 077 public TaskID(String jtIdentifier, int jobId, boolean isMap, int id) { 078 this(jtIdentifier, jobId, isMap ? TaskType.MAP : TaskType.REDUCE, id); 079 } 080 081 /** 082 * Constructs a TaskID object from given {@link JobID}. 083 * @param jobId JobID that this tip belongs to 084 * @param type the {@link TaskType} 085 * @param id the tip number 086 */ 087 public TaskID(org.apache.hadoop.mapreduce.JobID jobId, TaskType type,int id) { 088 super(jobId, type, id); 089 } 090 091 /** 092 * Constructs a TaskInProgressId object from given parts. 093 * @param jtIdentifier jobTracker identifier 094 * @param jobId job number 095 * @param type the {@link TaskType} 096 * @param id the tip number 097 */ 098 public TaskID(String jtIdentifier, int jobId, TaskType type, int id) { 099 this(new JobID(jtIdentifier, jobId), type, id); 100 } 101 102 public TaskID() { 103 super(new JobID(), TaskType.REDUCE, 0); 104 } 105 106 /** 107 * Downgrade a new TaskID to an old one 108 * @param old a new or old TaskID 109 * @return either old or a new TaskID build to match old 110 */ 111 public static TaskID downgrade(org.apache.hadoop.mapreduce.TaskID old) { 112 if (old instanceof TaskID) { 113 return (TaskID) old; 114 } else { 115 return new TaskID(JobID.downgrade(old.getJobID()), old.getTaskType(), 116 old.getId()); 117 } 118 } 119 120 @Deprecated 121 public static TaskID read(DataInput in) throws IOException { 122 TaskID tipId = new TaskID(); 123 tipId.readFields(in); 124 return tipId; 125 } 126 127 public JobID getJobID() { 128 return (JobID) super.getJobID(); 129 } 130 131 /** 132 * Returns a regex pattern which matches task IDs. Arguments can 133 * be given null, in which case that part of the regex will be generic. 134 * For example to obtain a regex matching <i>the first map task</i> 135 * of <i>any jobtracker</i>, of <i>any job</i>, we would use : 136 * <pre> 137 * TaskID.getTaskIDsPattern(null, null, true, 1); 138 * </pre> 139 * which will return : 140 * <pre> "task_[^_]*_[0-9]*_m_000001*" </pre> 141 * @param jtIdentifier jobTracker identifier, or null 142 * @param jobId job number, or null 143 * @param isMap whether the tip is a map, or null 144 * @param taskId taskId number, or null 145 * @return a regex pattern matching TaskIDs 146 * @deprecated Use {@link TaskID#getTaskIDsPattern(String, Integer, TaskType, 147 * Integer)} 148 */ 149 @Deprecated 150 public static String getTaskIDsPattern(String jtIdentifier, Integer jobId 151 , Boolean isMap, Integer taskId) { 152 return getTaskIDsPattern(jtIdentifier, jobId, 153 isMap ? TaskType.MAP : TaskType.REDUCE, taskId); 154 } 155 156 /** 157 * Returns a regex pattern which matches task IDs. Arguments can 158 * be given null, in which case that part of the regex will be generic. 159 * For example to obtain a regex matching <i>the first map task</i> 160 * of <i>any jobtracker</i>, of <i>any job</i>, we would use : 161 * <pre> 162 * TaskID.getTaskIDsPattern(null, null, true, 1); 163 * </pre> 164 * which will return : 165 * <pre> "task_[^_]*_[0-9]*_m_000001*" </pre> 166 * @param jtIdentifier jobTracker identifier, or null 167 * @param jobId job number, or null 168 * @param type the {@link TaskType}, or null 169 * @param taskId taskId number, or null 170 * @return a regex pattern matching TaskIDs 171 */ 172 @Deprecated 173 public static String getTaskIDsPattern(String jtIdentifier, Integer jobId 174 , TaskType type, Integer taskId) { 175 StringBuilder builder = new StringBuilder(TASK).append(SEPARATOR) 176 .append(getTaskIDsPatternWOPrefix(jtIdentifier, jobId, type, taskId)); 177 return builder.toString(); 178 } 179 180 @Deprecated 181 static StringBuilder getTaskIDsPatternWOPrefix(String jtIdentifier 182 , Integer jobId, TaskType type, Integer taskId) { 183 StringBuilder builder = new StringBuilder(); 184 builder.append(JobID.getJobIDsPatternWOPrefix(jtIdentifier, jobId)) 185 .append(SEPARATOR) 186 .append(type != null ? 187 (org.apache.hadoop.mapreduce.TaskID.getRepresentingCharacter(type)) : 188 org.apache.hadoop.mapreduce.TaskID.getAllTaskTypes()). 189 append(SEPARATOR) 190 .append(taskId != null ? idFormat.format(taskId) : "[0-9]*"); 191 return builder; 192 } 193 194 public static TaskID forName(String str 195 ) throws IllegalArgumentException { 196 return (TaskID) org.apache.hadoop.mapreduce.TaskID.forName(str); 197 } 198 199 }