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 027 /** 028 * JobID represents the immutable and unique identifier for 029 * the job. JobID consists of two parts. First part 030 * represents the jobtracker identifier, so that jobID to jobtracker map 031 * is defined. For cluster setup this string is the jobtracker 032 * start time, for local setting, it is "local". 033 * Second part of the JobID is the job number. <br> 034 * An example JobID is : 035 * <code>job_200707121733_0003</code> , which represents the third job 036 * running at the jobtracker started at <code>200707121733</code>. 037 * <p> 038 * Applications should never construct or parse JobID strings, but rather 039 * use appropriate constructors or {@link #forName(String)} method. 040 * 041 * @see TaskID 042 * @see TaskAttemptID 043 */ 044 @Deprecated 045 @InterfaceAudience.Public 046 @InterfaceStability.Stable 047 public class JobID extends org.apache.hadoop.mapreduce.JobID { 048 /** 049 * Constructs a JobID object 050 * @param jtIdentifier jobTracker identifier 051 * @param id job number 052 */ 053 public JobID(String jtIdentifier, int id) { 054 super(jtIdentifier, id); 055 } 056 057 public JobID() { } 058 059 /** 060 * Downgrade a new JobID to an old one 061 * @param old a new or old JobID 062 * @return either old or a new JobID build to match old 063 */ 064 public static JobID downgrade(org.apache.hadoop.mapreduce.JobID old) { 065 if (old instanceof JobID) { 066 return (JobID) old; 067 } else { 068 return new JobID(old.getJtIdentifier(), old.getId()); 069 } 070 } 071 072 @Deprecated 073 public static JobID read(DataInput in) throws IOException { 074 JobID jobId = new JobID(); 075 jobId.readFields(in); 076 return jobId; 077 } 078 079 /** Construct a JobId object from given string 080 * @return constructed JobId object or null if the given String is null 081 * @throws IllegalArgumentException if the given string is malformed 082 */ 083 public static JobID forName(String str) throws IllegalArgumentException { 084 return (JobID) org.apache.hadoop.mapreduce.JobID.forName(str); 085 } 086 087 /** 088 * Returns a regex pattern which matches task IDs. Arguments can 089 * be given null, in which case that part of the regex will be generic. 090 * For example to obtain a regex matching <i>any job</i> 091 * run on the jobtracker started at <i>200707121733</i>, we would use : 092 * <pre> 093 * JobID.getTaskIDsPattern("200707121733", null); 094 * </pre> 095 * which will return : 096 * <pre> "job_200707121733_[0-9]*" </pre> 097 * @param jtIdentifier jobTracker identifier, or null 098 * @param jobId job number, or null 099 * @return a regex pattern matching JobIDs 100 */ 101 @Deprecated 102 public static String getJobIDsPattern(String jtIdentifier, Integer jobId) { 103 StringBuilder builder = new StringBuilder(JOB).append(SEPARATOR); 104 builder.append(getJobIDsPatternWOPrefix(jtIdentifier, jobId)); 105 return builder.toString(); 106 } 107 108 @Deprecated 109 static StringBuilder getJobIDsPatternWOPrefix(String jtIdentifier, 110 Integer jobId) { 111 StringBuilder builder = new StringBuilder(); 112 if (jtIdentifier != null) { 113 builder.append(jtIdentifier); 114 } else { 115 builder.append("[^").append(SEPARATOR).append("]*"); 116 } 117 builder.append(SEPARATOR) 118 .append(jobId != null ? idFormat.format(jobId) : "[0-9]*"); 119 return builder; 120 } 121 122 }