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 package org.apache.hadoop.mapred; 019 020 import java.util.Map; 021 022 import org.apache.hadoop.classification.InterfaceAudience; 023 import org.apache.hadoop.classification.InterfaceStability; 024 import org.apache.hadoop.mapreduce.JobACL; 025 import 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 035 public 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 @Deprecated 082 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 083 float cleanupProgress, int runState) { 084 this(jobid, mapProgress, reduceProgress, cleanupProgress, runState, null, 085 null, null, null); 086 } 087 088 /** 089 * Create a job status object for a given jobid. 090 * @param jobid The jobid of the job 091 * @param mapProgress The progress made on the maps 092 * @param reduceProgress The progress made on the reduces 093 * @param runState The current state of the job 094 */ 095 @Deprecated 096 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 097 int runState) { 098 this (jobid, mapProgress, reduceProgress, runState, null, null, null, null); 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 jp Priority of the job. 108 */ 109 @Deprecated 110 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 111 float cleanupProgress, int runState, JobPriority jp) { 112 this(jobid, mapProgress, reduceProgress, cleanupProgress, runState, jp, 113 null, null, null, null); 114 } 115 116 /** 117 * Create a job status object for a given jobid. 118 * @param jobid The jobid of the job 119 * @param setupProgress The progress made on the setup 120 * @param mapProgress The progress made on the maps 121 * @param reduceProgress The progress made on the reduces 122 * @param cleanupProgress The progress made on the cleanup 123 * @param runState The current state of the job 124 * @param jp Priority of the job. 125 */ 126 @Deprecated 127 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 128 float reduceProgress, float cleanupProgress, 129 int runState, JobPriority jp) { 130 this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 131 runState, jp, null, null, null, null); 132 } 133 134 /** 135 * Create a job status object for a given jobid. 136 * @param jobid The jobid of the job 137 * @param mapProgress The progress made on the maps 138 * @param reduceProgress The progress made on the reduces 139 * @param cleanupProgress The progress made on cleanup 140 * @param runState The current state of the job 141 * @param user userid of the person who submitted the job. 142 * @param jobName user-specified job name. 143 * @param jobFile job configuration file. 144 * @param trackingUrl link to the web-ui for details of the job. 145 */ 146 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 147 float cleanupProgress, int runState, 148 String user, String jobName, 149 String jobFile, String trackingUrl) { 150 this(jobid, mapProgress, reduceProgress, cleanupProgress, runState, 151 JobPriority.NORMAL, user, jobName, jobFile, trackingUrl); 152 } 153 154 /** 155 * Create a job status object for a given jobid. 156 * @param jobid The jobid of the job 157 * @param mapProgress The progress made on the maps 158 * @param reduceProgress The progress made on the reduces 159 * @param runState The current state of the job 160 * @param user userid of the person who submitted the job. 161 * @param jobName user-specified job name. 162 * @param jobFile job configuration file. 163 * @param trackingUrl link to the web-ui for details of the job. 164 */ 165 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 166 int runState, String user, String jobName, 167 String jobFile, String trackingUrl) { 168 this(jobid, mapProgress, reduceProgress, 0.0f, runState, user, jobName, 169 jobFile, trackingUrl); 170 } 171 172 /** 173 * Create a job status object for a given jobid. 174 * @param jobid The jobid of the job 175 * @param mapProgress The progress made on the maps 176 * @param reduceProgress The progress made on the reduces 177 * @param runState The current state of the job 178 * @param jp Priority of the job. 179 * @param user userid of the person who submitted the job. 180 * @param jobName user-specified job name. 181 * @param jobFile job configuration file. 182 * @param trackingUrl link to the web-ui for details of the job. 183 */ 184 public JobStatus(JobID jobid, float mapProgress, float reduceProgress, 185 float cleanupProgress, int runState, JobPriority jp, 186 String user, String jobName, String jobFile, 187 String trackingUrl) { 188 this(jobid, 0.0f, mapProgress, reduceProgress, 189 cleanupProgress, runState, jp, user, jobName, jobFile, 190 trackingUrl); 191 } 192 193 /** 194 * Create a job status object for a given jobid. 195 * @param jobid The jobid of the job 196 * @param setupProgress The progress made on the setup 197 * @param mapProgress The progress made on the maps 198 * @param reduceProgress The progress made on the reduces 199 * @param cleanupProgress The progress made on the cleanup 200 * @param runState The current state of the job 201 * @param jp Priority of the job. 202 * @param user userid of the person who submitted the job. 203 * @param jobName user-specified job name. 204 * @param jobFile job configuration file. 205 * @param trackingUrl link to the web-ui for details of the job. 206 */ 207 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 208 float reduceProgress, float cleanupProgress, 209 int runState, JobPriority jp, String user, String jobName, 210 String jobFile, String trackingUrl) { 211 this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 212 runState, jp, user, jobName, "default", jobFile, trackingUrl); 213 } 214 215 /** 216 * Create a job status object for a given jobid. 217 * @param jobid The jobid of the job 218 * @param setupProgress The progress made on the setup 219 * @param mapProgress The progress made on the maps 220 * @param reduceProgress The progress made on the reduces 221 * @param cleanupProgress The progress made on the cleanup 222 * @param runState The current state of the job 223 * @param jp Priority of the job. 224 * @param user userid of the person who submitted the job. 225 * @param jobName user-specified job name. 226 * @param jobFile job configuration file. 227 * @param trackingUrl link to the web-ui for details of the job. 228 * @param isUber Whether job running in uber mode 229 */ 230 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 231 float reduceProgress, float cleanupProgress, 232 int runState, JobPriority jp, String user, String jobName, 233 String jobFile, String trackingUrl, boolean isUber) { 234 this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 235 runState, jp, user, jobName, "default", jobFile, trackingUrl, isUber); 236 } 237 238 /** 239 * Create a job status object for a given jobid. 240 * @param jobid The jobid of the job 241 * @param setupProgress The progress made on the setup 242 * @param mapProgress The progress made on the maps 243 * @param reduceProgress The progress made on the reduces 244 * @param cleanupProgress The progress made on the cleanup 245 * @param runState The current state of the job 246 * @param jp Priority of the job. 247 * @param user userid of the person who submitted the job. 248 * @param jobName user-specified job name. 249 * @param queue job queue name. 250 * @param jobFile job configuration file. 251 * @param trackingUrl link to the web-ui for details of the job. 252 */ 253 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 254 float reduceProgress, float cleanupProgress, 255 int runState, JobPriority jp, 256 String user, String jobName, String queue, 257 String jobFile, String trackingUrl) { 258 this(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 259 runState, jp, 260 user, jobName, queue, jobFile, trackingUrl, false); 261 } 262 263 /** 264 * Create a job status object for a given jobid. 265 * @param jobid The jobid of the job 266 * @param setupProgress The progress made on the setup 267 * @param mapProgress The progress made on the maps 268 * @param reduceProgress The progress made on the reduces 269 * @param cleanupProgress The progress made on the cleanup 270 * @param runState The current state of the job 271 * @param jp Priority of the job. 272 * @param user userid of the person who submitted the job. 273 * @param jobName user-specified job name. 274 * @param queue job queue name. 275 * @param jobFile job configuration file. 276 * @param trackingUrl link to the web-ui for details of the job. 277 * @param isUber Whether job running in uber mode 278 */ 279 public JobStatus(JobID jobid, float setupProgress, float mapProgress, 280 float reduceProgress, float cleanupProgress, 281 int runState, JobPriority jp, 282 String user, String jobName, String queue, 283 String jobFile, String trackingUrl, boolean isUber) { 284 super(jobid, setupProgress, mapProgress, reduceProgress, cleanupProgress, 285 getEnum(runState), org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name()), 286 user, jobName, queue, jobFile, trackingUrl, isUber); 287 } 288 289 public static JobStatus downgrade(org.apache.hadoop.mapreduce.JobStatus stat){ 290 JobStatus old = new JobStatus(JobID.downgrade(stat.getJobID()), 291 stat.getSetupProgress(), stat.getMapProgress(), stat.getReduceProgress(), 292 stat.getCleanupProgress(), stat.getState().getValue(), 293 JobPriority.valueOf(stat.getPriority().name()), 294 stat.getUsername(), stat.getJobName(), stat.getQueue(), stat.getJobFile(), 295 stat.getTrackingUrl(), stat.isUber()); 296 old.setStartTime(stat.getStartTime()); 297 old.setFinishTime(stat.getFinishTime()); 298 old.setSchedulingInfo(stat.getSchedulingInfo()); 299 old.setHistoryFile(stat.getHistoryFile()); 300 return old; 301 } 302 /** 303 * @deprecated use getJobID instead 304 */ 305 @Deprecated 306 public String getJobId() { return getJobID().toString(); } 307 308 /** 309 * @return The jobid of the Job 310 */ 311 public JobID getJobID() { return JobID.downgrade(super.getJobID()); } 312 313 /** 314 * Return the priority of the job 315 * @return job priority 316 */ 317 public synchronized JobPriority getJobPriority() { 318 return JobPriority.valueOf(super.getPriority().name()); 319 } 320 321 /** 322 * Sets the map progress of this job 323 * @param p The value of map progress to set to 324 */ 325 protected synchronized void setMapProgress(float p) { 326 super.setMapProgress(p); 327 } 328 329 /** 330 * Sets the cleanup progress of this job 331 * @param p The value of cleanup progress to set to 332 */ 333 protected synchronized void setCleanupProgress(float p) { 334 super.setCleanupProgress(p); 335 } 336 337 /** 338 * Sets the setup progress of this job 339 * @param p The value of setup progress to set to 340 */ 341 protected synchronized void setSetupProgress(float p) { 342 super.setSetupProgress(p); 343 } 344 345 /** 346 * Sets the reduce progress of this Job 347 * @param p The value of reduce progress to set to 348 */ 349 protected synchronized void setReduceProgress(float p) { 350 super.setReduceProgress(p); 351 } 352 353 /** 354 * Set the finish time of the job 355 * @param finishTime The finishTime of the job 356 */ 357 protected synchronized void setFinishTime(long finishTime) { 358 super.setFinishTime(finishTime); 359 } 360 361 /** 362 * Set the job history file url for a completed job 363 */ 364 protected synchronized void setHistoryFile(String historyFile) { 365 super.setHistoryFile(historyFile); 366 } 367 368 /** 369 * Set the link to the web-ui for details of the job. 370 */ 371 protected synchronized void setTrackingUrl(String trackingUrl) { 372 super.setTrackingUrl(trackingUrl); 373 } 374 375 /** 376 * Set the job retire flag to true. 377 */ 378 protected synchronized void setRetired() { 379 super.setRetired(); 380 } 381 382 /** 383 * Change the current run state of the job. 384 * 385 * The setter is public to be compatible with M/R 1.x, however, it should be 386 * used internally. 387 * 388 * @param state the state of the job 389 */ 390 @InterfaceAudience.Private 391 public synchronized void setRunState(int state) { 392 super.setState(getEnum(state)); 393 } 394 395 /** 396 * @return running state of the job 397 */ 398 public synchronized int getRunState() { return super.getState().getValue(); } 399 400 401 /** 402 * Set the start time of the job 403 * @param startTime The startTime of the job 404 */ 405 protected synchronized void setStartTime(long startTime) { 406 super.setStartTime(startTime); 407 } 408 409 /** 410 * @param userName The username of the job 411 */ 412 protected synchronized void setUsername(String userName) { 413 super.setUsername(userName); 414 } 415 416 /** 417 * Used to set the scheduling information associated to a particular Job. 418 * 419 * The setter is public to be compatible with M/R 1.x, however, it should be 420 * used internally. 421 * 422 * @param schedulingInfo Scheduling information of the job 423 */ 424 @InterfaceAudience.Private 425 public synchronized void setSchedulingInfo(String schedulingInfo) { 426 super.setSchedulingInfo(schedulingInfo); 427 } 428 429 protected synchronized void setJobACLs(Map<JobACL, AccessControlList> acls) { 430 super.setJobACLs(acls); 431 } 432 433 public synchronized void setFailureInfo(String failureInfo) { 434 super.setFailureInfo(failureInfo); 435 } 436 437 /** 438 * Set the priority of the job, defaulting to NORMAL. 439 * @param jp new job priority 440 */ 441 public synchronized void setJobPriority(JobPriority jp) { 442 super.setPriority( 443 org.apache.hadoop.mapreduce.JobPriority.valueOf(jp.name())); 444 } 445 446 /** 447 * @return Percentage of progress in maps 448 */ 449 public synchronized float mapProgress() { return super.getMapProgress(); } 450 451 /** 452 * @return Percentage of progress in cleanup 453 */ 454 public synchronized float cleanupProgress() { 455 return super.getCleanupProgress(); 456 } 457 458 /** 459 * @return Percentage of progress in setup 460 */ 461 public synchronized float setupProgress() { 462 return super.getSetupProgress(); 463 } 464 465 /** 466 * @return Percentage of progress in reduce 467 */ 468 public synchronized float reduceProgress() { 469 return super.getReduceProgress(); 470 } 471 472 // A utility to convert new job runstates to the old ones. 473 static int getOldNewJobRunState( 474 org.apache.hadoop.mapreduce.JobStatus.State state) { 475 return state.getValue(); 476 } 477 }