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 @InterfaceAudience.Public
045 @InterfaceStability.Stable
046 public class JobID extends org.apache.hadoop.mapreduce.JobID {
047 /**
048 * Constructs a JobID object
049 * @param jtIdentifier jobTracker identifier
050 * @param id job number
051 */
052 public JobID(String jtIdentifier, int id) {
053 super(jtIdentifier, id);
054 }
055
056 public JobID() { }
057
058 /**
059 * Downgrade a new JobID to an old one
060 * @param old a new or old JobID
061 * @return either old or a new JobID build to match old
062 */
063 public static JobID downgrade(org.apache.hadoop.mapreduce.JobID old) {
064 if (old instanceof JobID) {
065 return (JobID) old;
066 } else {
067 return new JobID(old.getJtIdentifier(), old.getId());
068 }
069 }
070
071 @Deprecated
072 public static JobID read(DataInput in) throws IOException {
073 JobID jobId = new JobID();
074 jobId.readFields(in);
075 return jobId;
076 }
077
078 /** Construct a JobId object from given string
079 * @return constructed JobId object or null if the given String is null
080 * @throws IllegalArgumentException if the given string is malformed
081 */
082 public static JobID forName(String str) throws IllegalArgumentException {
083 return (JobID) org.apache.hadoop.mapreduce.JobID.forName(str);
084 }
085
086 /**
087 * Returns a regex pattern which matches task IDs. Arguments can
088 * be given null, in which case that part of the regex will be generic.
089 * For example to obtain a regex matching <i>any job</i>
090 * run on the jobtracker started at <i>200707121733</i>, we would use :
091 * <pre>
092 * JobID.getTaskIDsPattern("200707121733", null);
093 * </pre>
094 * which will return :
095 * <pre> "job_200707121733_[0-9]*" </pre>
096 * @param jtIdentifier jobTracker identifier, or null
097 * @param jobId job number, or null
098 * @return a regex pattern matching JobIDs
099 */
100 @Deprecated
101 public static String getJobIDsPattern(String jtIdentifier, Integer jobId) {
102 StringBuilder builder = new StringBuilder(JOB).append(SEPARATOR);
103 builder.append(getJobIDsPatternWOPrefix(jtIdentifier, jobId));
104 return builder.toString();
105 }
106
107 @Deprecated
108 static StringBuilder getJobIDsPatternWOPrefix(String jtIdentifier,
109 Integer jobId) {
110 StringBuilder builder = new StringBuilder();
111 if (jtIdentifier != null) {
112 builder.append(jtIdentifier);
113 } else {
114 builder.append("[^").append(SEPARATOR).append("]*");
115 }
116 builder.append(SEPARATOR)
117 .append(jobId != null ? idFormat.format(jobId) : "[0-9]*");
118 return builder;
119 }
120
121 }