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 */ 018package org.apache.hadoop.mapred; 019 020import java.util.Map; 021 022import org.apache.hadoop.classification.InterfaceAudience; 023import org.apache.hadoop.classification.InterfaceStability; 024import org.apache.hadoop.mapreduce.JobACL; 025import org.apache.hadoop.security.authorize.AccessControlList; 026 027/************************************************** 028 * Describes the current status of a job. This is 029 * not intended to be a comprehensive piece of data. 030 * For that, look at JobProfile. 031 ************************************************* 032 **/ 033@InterfaceAudience.Public 034@InterfaceStability.Stable 035public class JobStatus extends org.apache.hadoop.mapreduce.JobStatus { 036 037 public static final int RUNNING = 038 org.apache.hadoop.mapreduce.JobStatus.State.RUNNING.getValue(); 039 public static final int SUCCEEDED = 040 org.apache.hadoop.mapreduce.JobStatus.State.SUCCEEDED.getValue(); 041 public static final int FAILED = 042 org.apache.hadoop.mapreduce.JobStatus.State.FAILED.getValue(); 043 public static final int PREP = 044 org.apache.hadoop.mapreduce.JobStatus.State.PREP.getValue(); 045 public static final int KILLED = 046 org.apache.hadoop.mapreduce.JobStatus.State.KILLED.getValue(); 047 048 private static final String UNKNOWN = "UNKNOWN"; 049 050 private static final String[] runStates = 051 {UNKNOWN, "RUNNING", "SUCCEEDED", "FAILED", "PREP", "KILLED"}; 052 053 /** 054 * Helper method to get human-readable state of the job. 055 * @param state job state 056 * @return human-readable state of the job 057 */ 058 public static String getJobRunState(int state) { 059 if (state < 1 || state >= runStates.length) { 060 return UNKNOWN; 061 } 062 return runStates[state]; 063 } 064 065 static org.apache.hadoop.mapreduce.JobStatus.State getEnum(int state) { 066 switch (state) { 067 case 1: return org.apache.hadoop.mapreduce.JobStatus.State.RUNNING; 068 case 2: return org.apache.hadoop.mapreduce.JobStatus.State.SUCCEEDED; 069 case 3: return org.apache.hadoop.mapreduce.JobStatus.State.FAILED; 070 case 4: return org.apache.hadoop.mapreduce.JobStatus.State.PREP; 071 case 5: return org.apache.hadoop.mapreduce.JobStatus.State.KILLED; 072 } 073 return null; 074 } 075 076 /** 077 */ 078 public JobStatus() { 079 } 080 081 /** 082 * Create a job status object for a given jobid. 083 * @param jobid The jobid of the job 084 * @param mapProgress The progress made on the maps 085 * @param reduceProgress The progress made on the reduces 086 * @param cleanupProgress The progress made on cleanup 087 * @param runState The current state of the job 088 * @param user userid of the person who submitted the job. 089 * @param jobName user-specified job name. 090 * @param jobFile job configuration file. 091 * @param trackingUrl link to the web-ui for details of the job. 092 */ 093 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 094 float cleanupProgress, int runState, 095 String user, String jobName, 096 String jobFile, String trackingUrl) { 097 this(jobid, mapProgress, reduceProgress, cleanupProgress, runState, 098 JobPriority.NORMAL, user, jobName, jobFile, trackingUrl); 099 } 100 101 /** 102 * Create a job status object for a given jobid. 103 * @param jobid The jobid of the job 104 * @param mapProgress The progress made on the maps 105 * @param reduceProgress The progress made on the reduces 106 * @param runState The current state of the job 107 * @param user userid of the person who submitted the job. 108 * @param jobName user-specified job name. 109 * @param jobFile job configuration file. 110 * @param trackingUrl link to the web-ui for details of the job. 111 */ 112 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 113 int runState, String user, String jobName, 114 String jobFile, String trackingUrl) { 115 this(jobid, mapProgress, reduceProgress, 0.0f, runState, user, jobName, 116 jobFile, trackingUrl); 117 } 118 119 /** 120 * Create a job status object for a given jobid. 121 * @param jobid The jobid of the job 122 * @param mapProgress The progress made on the maps 123 * @param reduceProgress The progress made on the reduces 124 * @param runState The current state of the job 125 * @param jp Priority of the job. 126 * @param user userid of the person who submitted the job. 127 * @param jobName user-specified job name. 128 * @param jobFile job configuration file. 129 * @param trackingUrl link to the web-ui for details of the job. 130 */ 131 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 132 float cleanupProgress, int runState, JobPriority jp, 133 String user, String jobName, String jobFile, 134 String trackingUrl) { 135 this(jobid, 0.0f, mapProgress, reduceProgress, 136 cleanupProgress, runState, jp, user, jobName, jobFile, 137 trackingUrl); 138 } 139 140 /** 141 * Create a job status object for a given jobid. 142 * @param jobid The jobid of the job 143 * @param setupProgress The progress made on the setup 144 * @param mapProgress The progress made on the maps 145 * @param reduceProgress The progress made on the reduces 146 * @param cleanupProgress The progress made on the cleanup 147 * @param runState The current state of the job 148 * @param jp Priority of the job. 149 * @param user userid of the person who submitted the job. 150 * @param jobName user-specified job name. 151 * @param jobFile job configuration file. 152 * @param trackingUrl link to the web-ui for details of the job. 153 */ 154 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 155 float reduceProgress, float cleanupProgress, 156 int runState, JobPriority jp, String user, String jobName, 157 String jobFile, String trackingUrl) { 158 this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 159 runState, jp, user, jobName, "default", jobFile, trackingUrl); 160 } 161 162 /** 163 * Create a job status object for a given jobid. 164 * @param jobid The jobid of the job 165 * @param setupProgress The progress made on the setup 166 * @param mapProgress The progress made on the maps 167 * @param reduceProgress The progress made on the reduces 168 * @param cleanupProgress The progress made on the cleanup 169 * @param runState The current state of the job 170 * @param jp Priority of the job. 171 * @param user userid of the person who submitted the job. 172 * @param jobName user-specified job name. 173 * @param jobFile job configuration file. 174 * @param trackingUrl link to the web-ui for details of the job. 175 * @param isUber Whether job running in uber mode 176 */ 177 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 178 float reduceProgress, float cleanupProgress, 179 int runState, JobPriority jp, String user, String jobName, 180 String jobFile, String trackingUrl, boolean isUber) { 181 this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 182 runState, jp, user, jobName, "default", jobFile, trackingUrl, isUber); 183 } 184 185 /** 186 * Create a job status object for a given jobid. 187 * @param jobid The jobid of the job 188 * @param setupProgress The progress made on the setup 189 * @param mapProgress The progress made on the maps 190 * @param reduceProgress The progress made on the reduces 191 * @param cleanupProgress The progress made on the cleanup 192 * @param runState The current state of the job 193 * @param jp Priority of the job. 194 * @param user userid of the person who submitted the job. 195 * @param jobName user-specified job name. 196 * @param queue job queue name. 197 * @param jobFile job configuration file. 198 * @param trackingUrl link to the web-ui for details of the job. 199 */ 200 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 201 float reduceProgress, float cleanupProgress, 202 int runState, JobPriority jp, 203 String user, String jobName, String queue, 204 String jobFile, String trackingUrl) { 205 this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 206 runState, jp, 207 user, jobName, queue, jobFile, trackingUrl, false); 208 } 209 210 /** 211 * Create a job status object for a given jobid. 212 * @param jobid The jobid of the job 213 * @param setupProgress The progress made on the setup 214 * @param mapProgress The progress made on the maps 215 * @param reduceProgress The progress made on the reduces 216 * @param cleanupProgress The progress made on the cleanup 217 * @param runState The current state of the job 218 * @param jp Priority of the job. 219 * @param user userid of the person who submitted the job. 220 * @param jobName user-specified job name. 221 * @param queue job queue name. 222 * @param jobFile job configuration file. 223 * @param trackingUrl link to the web-ui for details of the job. 224 * @param isUber Whether job running in uber mode 225 */ 226 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 227 float reduceProgress, float cleanupProgress, 228 int runState, JobPriority jp, 229 String user, String jobName, String queue, 230 String jobFile, String trackingUrl, boolean isUber) { 231 super(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 232 getEnum(runState), org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name()), 233 user, jobName, queue, jobFile, trackingUrl, isUber); 234 } 235 236 public static JobStatus downgrade(org.apache.hadoop.mapreduce.JobStatus stat){ 237 JobStatus old = new JobStatus(JobID.downgrade(stat.getJobID()), 238 stat.getSetupProgress(), stat.getMapProgress(), stat.getReduceProgress(), 239 stat.getCleanupProgress(), stat.getState().getValue(), 240 JobPriority.valueOf(stat.getPriority().name()), 241 stat.getUsername(), stat.getJobName(), stat.getQueue(), stat.getJobFile(), 242 stat.getTrackingUrl(), stat.isUber()); 243 old.setStartTime(stat.getStartTime()); 244 old.setFinishTime(stat.getFinishTime()); 245 old.setSchedulingInfo(stat.getSchedulingInfo()); 246 old.setHistoryFile(stat.getHistoryFile()); 247 return old; 248 } 249 /** 250 * @deprecated use getJobID instead 251 */ 252 @Deprecated 253 public String getJobId() { return getJobID().toString(); } 254 255 /** 256 * @return The jobid of the Job 257 */ 258 public JobID getJobID() { return JobID.downgrade(super.getJobID()); } 259 260 /** 261 * Return the priority of the job 262 * @return job priority 263 */ 264 public synchronized JobPriority getJobPriority() { 265 return JobPriority.valueOf(super.getPriority().name()); 266 } 267 268 /** 269 * Sets the map progress of this job 270 * @param p The value of map progress to set to 271 */ 272 protected synchronized void setMapProgress(float p) { 273 super.setMapProgress(p); 274 } 275 276 /** 277 * Sets the cleanup progress of this job 278 * @param p The value of cleanup progress to set to 279 */ 280 protected synchronized void setCleanupProgress(float p) { 281 super.setCleanupProgress(p); 282 } 283 284 /** 285 * Sets the setup progress of this job 286 * @param p The value of setup progress to set to 287 */ 288 protected synchronized void setSetupProgress(float p) { 289 super.setSetupProgress(p); 290 } 291 292 /** 293 * Sets the reduce progress of this Job 294 * @param p The value of reduce progress to set to 295 */ 296 protected synchronized void setReduceProgress(float p) { 297 super.setReduceProgress(p); 298 } 299 300 /** 301 * Set the finish time of the job 302 * @param finishTime The finishTime of the job 303 */ 304 protected synchronized void setFinishTime(long finishTime) { 305 super.setFinishTime(finishTime); 306 } 307 308 /** 309 * Set the job history file url for a completed job 310 */ 311 protected synchronized void setHistoryFile(String historyFile) { 312 super.setHistoryFile(historyFile); 313 } 314 315 /** 316 * Set the link to the web-ui for details of the job. 317 */ 318 protected synchronized void setTrackingUrl(String trackingUrl) { 319 super.setTrackingUrl(trackingUrl); 320 } 321 322 /** 323 * Set the job retire flag to true. 324 */ 325 protected synchronized void setRetired() { 326 super.setRetired(); 327 } 328 329 /** 330 * Change the current run state of the job. 331 */ 332 protected synchronized void setRunState(int state) { 333 super.setState(getEnum(state)); 334 } 335 336 /** 337 * @return running state of the job 338 */ 339 public synchronized int getRunState() { return super.getState().getValue(); } 340 341 342 /** 343 * Set the start time of the job 344 * @param startTime The startTime of the job 345 */ 346 protected synchronized void setStartTime(long startTime) { 347 super.setStartTime(startTime); 348 } 349 350 /** 351 * @param userName The username of the job 352 */ 353 protected synchronized void setUsername(String userName) { 354 super.setUsername(userName); 355 } 356 357 /** 358 * Used to set the scheduling information associated to a particular Job. 359 * 360 * @param schedulingInfo Scheduling information of the job 361 */ 362 protected synchronized void setSchedulingInfo(String schedulingInfo) { 363 super.setSchedulingInfo(schedulingInfo); 364 } 365 366 protected synchronized void setJobACLs(Map<JobACL, AccessControlList> acls) { 367 super.setJobACLs(acls); 368 } 369 370 public synchronized void setFailureInfo(String failureInfo) { 371 super.setFailureInfo(failureInfo); 372 } 373 374 /** 375 * Set the priority of the job, defaulting to NORMAL. 376 * @param jp new job priority 377 */ 378 public synchronized void setJobPriority(JobPriority jp) { 379 super.setPriority( 380 org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name())); 381 } 382 383 /** 384 * @return Percentage of progress in maps 385 */ 386 public synchronized float mapProgress() { return super.getMapProgress(); } 387 388 /** 389 * @return Percentage of progress in cleanup 390 */ 391 public synchronized float cleanupProgress() { 392 return super.getCleanupProgress(); 393 } 394 395 /** 396 * @return Percentage of progress in setup 397 */ 398 public synchronized float setupProgress() { 399 return super.getSetupProgress(); 400 } 401 402 /** 403 * @return Percentage of progress in reduce 404 */ 405 public synchronized float reduceProgress() { 406 return super.getReduceProgress(); 407 } 408 409 // A utility to convert new job runstates to the old ones. 410 static int getOldNewJobRunState( 411 org.apache.hadoop.mapreduce.JobStatus.State state) { 412 return state.getValue(); 413 } 414}