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 019package org.apache.oozie.command.coord; 020 021import org.apache.hadoop.conf.Configuration; 022import org.apache.oozie.AppType; 023import org.apache.oozie.CoordinatorActionBean; 024import org.apache.oozie.CoordinatorJobBean; 025import org.apache.oozie.ErrorCode; 026import org.apache.oozie.SLAEventBean; 027import org.apache.oozie.client.CoordinatorJob; 028import org.apache.oozie.client.Job; 029import org.apache.oozie.client.SLAEvent.SlaAppType; 030import org.apache.oozie.client.rest.JsonBean; 031import org.apache.oozie.command.CommandException; 032import org.apache.oozie.command.MaterializeTransitionXCommand; 033import org.apache.oozie.command.PreconditionException; 034import org.apache.oozie.command.bundle.BundleStatusUpdateXCommand; 035import org.apache.oozie.coord.TimeUnit; 036import org.apache.oozie.executor.jpa.BatchQueryExecutor; 037import org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry; 038import org.apache.oozie.executor.jpa.CoordActionsActiveCountJPAExecutor; 039import org.apache.oozie.executor.jpa.CoordJobQueryExecutor; 040import org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery; 041import org.apache.oozie.executor.jpa.JPAExecutorException; 042import org.apache.oozie.service.ConfigurationService; 043import org.apache.oozie.service.CoordMaterializeTriggerService; 044import org.apache.oozie.service.EventHandlerService; 045import org.apache.oozie.service.JPAService; 046import org.apache.oozie.service.Service; 047import org.apache.oozie.service.Services; 048import org.apache.oozie.sla.SLAOperations; 049import org.apache.oozie.util.DateUtils; 050import org.apache.oozie.util.Instrumentation; 051import org.apache.oozie.util.LogUtils; 052import org.apache.oozie.util.ParamChecker; 053import org.apache.oozie.util.StatusUtils; 054import org.apache.oozie.util.XConfiguration; 055import org.apache.oozie.util.XmlUtils; 056import org.apache.oozie.util.db.SLADbOperations; 057import org.jdom.Element; 058import org.jdom.JDOMException; 059 060import java.io.IOException; 061import java.io.StringReader; 062import java.sql.Timestamp; 063import java.util.Calendar; 064import java.util.Date; 065import java.util.TimeZone; 066 067/** 068 * Materialize actions for specified start and end time for coordinator job. 069 */ 070@SuppressWarnings("deprecation") 071public class CoordMaterializeTransitionXCommand extends MaterializeTransitionXCommand { 072 073 private JPAService jpaService = null; 074 private CoordinatorJobBean coordJob = null; 075 private String jobId = null; 076 private Date startMatdTime = null; 077 private Date endMatdTime = null; 078 private final int materializationWindow; 079 private int lastActionNumber = 1; // over-ride by DB value 080 private CoordinatorJob.Status prevStatus = null; 081 082 static final private int lookAheadWindow = ConfigurationService.getInt(CoordMaterializeTriggerService 083 .CONF_LOOKUP_INTERVAL); 084 085 /** 086 * Default MAX timeout in minutes, after which coordinator input check will timeout 087 */ 088 public static final String CONF_DEFAULT_MAX_TIMEOUT = Service.CONF_PREFIX + "coord.default.max.timeout"; 089 090 /** 091 * The constructor for class {@link CoordMaterializeTransitionXCommand} 092 * 093 * @param jobId coordinator job id 094 * @param materializationWindow materialization window to calculate end time 095 */ 096 public CoordMaterializeTransitionXCommand(String jobId, int materializationWindow) { 097 super("coord_mater", "coord_mater", 1); 098 this.jobId = ParamChecker.notEmpty(jobId, "jobId"); 099 this.materializationWindow = materializationWindow; 100 } 101 102 public CoordMaterializeTransitionXCommand(CoordinatorJobBean coordJob, int materializationWindow, Date startTime, 103 Date endTime) { 104 super("coord_mater", "coord_mater", 1); 105 this.jobId = ParamChecker.notEmpty(coordJob.getId(), "jobId"); 106 this.materializationWindow = materializationWindow; 107 this.coordJob = coordJob; 108 this.startMatdTime = startTime; 109 this.endMatdTime = endTime; 110 } 111 112 /* (non-Javadoc) 113 * @see org.apache.oozie.command.MaterializeTransitionXCommand#transitToNext() 114 */ 115 @Override 116 public void transitToNext() throws CommandException { 117 } 118 119 /* (non-Javadoc) 120 * @see org.apache.oozie.command.TransitionXCommand#updateJob() 121 */ 122 @Override 123 public void updateJob() throws CommandException { 124 updateList.add(new UpdateEntry(CoordJobQuery.UPDATE_COORD_JOB_MATERIALIZE,coordJob)); 125 } 126 127 /* (non-Javadoc) 128 * @see org.apache.oozie.command.MaterializeTransitionXCommand#performWrites() 129 */ 130 @Override 131 public void performWrites() throws CommandException { 132 try { 133 BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null); 134 // register the partition related dependencies of actions 135 for (JsonBean actionBean : insertList) { 136 if (actionBean instanceof CoordinatorActionBean) { 137 CoordinatorActionBean coordAction = (CoordinatorActionBean) actionBean; 138 if (EventHandlerService.isEnabled()) { 139 CoordinatorXCommand.generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), null); 140 } 141 142 // TODO: time 100s should be configurable 143 queue(new CoordActionNotificationXCommand(coordAction), 100); 144 145 //Delay for input check = (nominal time - now) 146 long checkDelay = coordAction.getNominalTime().getTime() - new Date().getTime(); 147 queue(new CoordActionInputCheckXCommand(coordAction.getId(), coordAction.getJobId()), 148 Math.max(checkDelay, 0)); 149 150 if (coordAction.getPushMissingDependencies() != null) { 151 // TODO: Delay in catchup mode? 152 queue(new CoordPushDependencyCheckXCommand(coordAction.getId(), true), 100); 153 } 154 } 155 } 156 } 157 catch (JPAExecutorException jex) { 158 throw new CommandException(jex); 159 } 160 } 161 162 /* (non-Javadoc) 163 * @see org.apache.oozie.command.XCommand#getEntityKey() 164 */ 165 @Override 166 public String getEntityKey() { 167 return this.jobId; 168 } 169 170 @Override 171 protected boolean isLockRequired() { 172 return true; 173 } 174 175 /* (non-Javadoc) 176 * @see org.apache.oozie.command.XCommand#loadState() 177 */ 178 @Override 179 protected void loadState() throws CommandException { 180 jpaService = Services.get().get(JPAService.class); 181 if (jpaService == null) { 182 LOG.error(ErrorCode.E0610); 183 } 184 185 try { 186 coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB_MATERIALIZE, jobId); 187 prevStatus = coordJob.getStatus(); 188 } 189 catch (JPAExecutorException jex) { 190 throw new CommandException(jex); 191 } 192 193 // calculate start materialize and end materialize time 194 calcMatdTime(); 195 196 LogUtils.setLogInfo(coordJob); 197 } 198 199 /** 200 * Calculate startMatdTime and endMatdTime from job's start time if next materialized time is null 201 * 202 * @throws CommandException thrown if failed to calculate startMatdTime and endMatdTime 203 */ 204 protected void calcMatdTime() throws CommandException { 205 Timestamp startTime = coordJob.getNextMaterializedTimestamp(); 206 if (startTime == null) { 207 startTime = coordJob.getStartTimestamp(); 208 } 209 // calculate end time by adding materializationWindow to start time. 210 // need to convert materializationWindow from secs to milliseconds 211 long startTimeMilli = startTime.getTime(); 212 long endTimeMilli = startTimeMilli + (materializationWindow * 1000); 213 214 startMatdTime = DateUtils.toDate(new Timestamp(startTimeMilli)); 215 endMatdTime = DateUtils.toDate(new Timestamp(endTimeMilli)); 216 endMatdTime = getMaterializationTimeForCatchUp(endMatdTime); 217 // if MaterializationWindow end time is greater than endTime 218 // for job, then set it to endTime of job 219 Date jobEndTime = coordJob.getEndTime(); 220 if (endMatdTime.compareTo(jobEndTime) > 0) { 221 endMatdTime = jobEndTime; 222 } 223 224 LOG.debug("Materializing coord job id=" + jobId + ", start=" + DateUtils.formatDateOozieTZ(startMatdTime) + ", end=" + DateUtils.formatDateOozieTZ(endMatdTime) 225 + ", window=" + materializationWindow); 226 } 227 228 /** 229 * Get materialization for window for catch-up jobs. for current jobs,it reruns currentMatdate, For catch-up, end 230 * Mataterilized Time = startMatdTime + MatThrottling * frequency; unless LAST_ONLY execution order is set, in which 231 * case it returns now (to materialize all actions in the past) 232 * 233 * @param currentMatTime 234 * @return 235 * @throws CommandException 236 * @throws JDOMException 237 */ 238 private Date getMaterializationTimeForCatchUp(Date currentMatTime) throws CommandException { 239 if (currentMatTime.after(new Date())) { 240 return currentMatTime; 241 } 242 if (coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.LAST_ONLY) || 243 coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.NONE)) { 244 return new Date(); 245 } 246 int frequency = 0; 247 try { 248 frequency = Integer.parseInt(coordJob.getFrequency()); 249 } 250 catch (NumberFormatException e) { 251 return currentMatTime; 252 } 253 254 TimeZone appTz = DateUtils.getTimeZone(coordJob.getTimeZone()); 255 TimeUnit freqTU = TimeUnit.valueOf(coordJob.getTimeUnitStr()); 256 Calendar startInstance = Calendar.getInstance(appTz); 257 startInstance.setTime(startMatdTime); 258 Calendar endMatInstance = null; 259 Calendar previousInstance = startInstance; 260 for (int i = 1; i <= coordJob.getMatThrottling(); i++) { 261 endMatInstance = (Calendar) startInstance.clone(); 262 endMatInstance.add(freqTU.getCalendarUnit(), i * frequency); 263 if (endMatInstance.getTime().compareTo(new Date()) >= 0) { 264 if (previousInstance.getTime().after(currentMatTime)) { 265 return previousInstance.getTime(); 266 } 267 else { 268 return currentMatTime; 269 } 270 } 271 previousInstance = endMatInstance; 272 } 273 if (endMatInstance == null) { 274 return currentMatTime; 275 } 276 else { 277 return endMatInstance.getTime(); 278 } 279 } 280 281 /* (non-Javadoc) 282 * @see org.apache.oozie.command.XCommand#verifyPrecondition() 283 */ 284 @Override 285 protected void verifyPrecondition() throws CommandException, PreconditionException { 286 if (!(coordJob.getStatus() == CoordinatorJobBean.Status.PREP || coordJob.getStatus() == CoordinatorJobBean.Status.RUNNING 287 || coordJob.getStatus() == CoordinatorJobBean.Status.RUNNINGWITHERROR)) { 288 throw new PreconditionException(ErrorCode.E1100, "CoordMaterializeTransitionXCommand for jobId=" + jobId 289 + " job is not in PREP or RUNNING but in " + coordJob.getStatus()); 290 } 291 292 if (coordJob.isDoneMaterialization()) { 293 throw new PreconditionException(ErrorCode.E1100, "CoordMaterializeTransitionXCommand for jobId =" + jobId 294 + " job is already materialized"); 295 } 296 297 if (coordJob.getNextMaterializedTimestamp() != null 298 && coordJob.getNextMaterializedTimestamp().compareTo(coordJob.getEndTimestamp()) >= 0) { 299 throw new PreconditionException(ErrorCode.E1100, "CoordMaterializeTransitionXCommand for jobId=" + jobId 300 + " job is already materialized"); 301 } 302 303 Timestamp startTime = coordJob.getNextMaterializedTimestamp(); 304 if (startTime == null) { 305 startTime = coordJob.getStartTimestamp(); 306 307 if (startTime.after(new Timestamp(System.currentTimeMillis() + lookAheadWindow * 1000))) { 308 throw new PreconditionException(ErrorCode.E1100, "CoordMaterializeTransitionXCommand for jobId=" 309 + jobId + " job's start time is not reached yet - nothing to materialize"); 310 } 311 } 312 313 if (coordJob.getNextMaterializedTimestamp() != null 314 && coordJob.getNextMaterializedTimestamp().after( 315 new Timestamp(System.currentTimeMillis() + lookAheadWindow * 1000))) { 316 throw new PreconditionException(ErrorCode.E1100, "CoordMaterializeTransitionXCommand for jobId=" + jobId 317 + " Request is for future time. Lookup time is " 318 + new Timestamp(System.currentTimeMillis() + lookAheadWindow * 1000) + " mat time is " 319 + coordJob.getNextMaterializedTimestamp()); 320 } 321 322 if (coordJob.getLastActionTime() != null && coordJob.getLastActionTime().compareTo(coordJob.getEndTime()) >= 0) { 323 throw new PreconditionException(ErrorCode.E1100, "ENDED Coordinator materialization for jobId = " + jobId 324 + ", all actions have been materialized from start time = " + coordJob.getStartTime() 325 + " to end time = " + coordJob.getEndTime() + ", job status = " + coordJob.getStatusStr()); 326 } 327 328 if (coordJob.getLastActionTime() != null && coordJob.getLastActionTime().compareTo(endMatdTime) >= 0) { 329 throw new PreconditionException(ErrorCode.E1100, "ENDED Coordinator materialization for jobId = " + jobId 330 + ", action is *already* materialized for Materialization start time = " + startMatdTime 331 + ", materialization end time = " + endMatdTime + ", job status = " + coordJob.getStatusStr()); 332 } 333 334 if (endMatdTime.after(coordJob.getEndTime())) { 335 throw new PreconditionException(ErrorCode.E1100, "ENDED Coordinator materialization for jobId = " + jobId 336 + " materialization end time = " + endMatdTime + " surpasses coordinator job's end time = " 337 + coordJob.getEndTime() + " job status = " + coordJob.getStatusStr()); 338 } 339 340 if (coordJob.getPauseTime() != null && !startMatdTime.before(coordJob.getPauseTime())) { 341 throw new PreconditionException(ErrorCode.E1100, "ENDED Coordinator materialization for jobId = " + jobId 342 + ", materialization start time = " + startMatdTime 343 + " is after or equal to coordinator job's pause time = " + coordJob.getPauseTime() 344 + ", job status = " + coordJob.getStatusStr()); 345 } 346 347 } 348 349 /* (non-Javadoc) 350 * @see org.apache.oozie.command.MaterializeTransitionXCommand#materialize() 351 */ 352 @Override 353 protected void materialize() throws CommandException { 354 Instrumentation.Cron cron = new Instrumentation.Cron(); 355 cron.start(); 356 try { 357 materializeActions(false); 358 updateJobMaterializeInfo(coordJob); 359 } 360 catch (CommandException ex) { 361 LOG.warn("Exception occurred:" + ex.getMessage() + " Making the job failed ", ex); 362 coordJob.setStatus(Job.Status.FAILED); 363 coordJob.resetPending(); 364 // remove any materialized actions and slaEvents 365 insertList.clear(); 366 } 367 catch (Exception e) { 368 LOG.error("Exception occurred:" + e.getMessage() + " Making the job failed ", e); 369 coordJob.setStatus(Job.Status.FAILED); 370 try { 371 CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_MATERIALIZE, coordJob); 372 } 373 catch (JPAExecutorException jex) { 374 throw new CommandException(ErrorCode.E1011, jex); 375 } 376 throw new CommandException(ErrorCode.E1012, e.getMessage(), e); 377 } finally { 378 cron.stop(); 379 instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".materialize", cron); 380 } 381 } 382 383 /** 384 * Create action instances starting from "startMatdTime" to "endMatdTime" and store them into coord action table. 385 * 386 * @param dryrun if this is a dry run 387 * @throws Exception thrown if failed to materialize actions 388 */ 389 protected String materializeActions(boolean dryrun) throws Exception { 390 391 Configuration jobConf = null; 392 try { 393 jobConf = new XConfiguration(new StringReader(coordJob.getConf())); 394 } 395 catch (IOException ioe) { 396 LOG.warn("Configuration parse error. read from DB :" + coordJob.getConf(), ioe); 397 throw new CommandException(ErrorCode.E1005, ioe.getMessage(), ioe); 398 } 399 400 String jobXml = coordJob.getJobXml(); 401 Element eJob = XmlUtils.parseXml(jobXml); 402 TimeZone appTz = DateUtils.getTimeZone(coordJob.getTimeZone()); 403 404 String frequency = coordJob.getFrequency(); 405 TimeUnit freqTU = TimeUnit.valueOf(coordJob.getTimeUnitStr()); 406 TimeUnit endOfFlag = TimeUnit.valueOf(eJob.getAttributeValue("end_of_duration")); 407 Calendar start = Calendar.getInstance(appTz); 408 start.setTime(startMatdTime); 409 DateUtils.moveToEnd(start, endOfFlag); 410 Calendar end = Calendar.getInstance(appTz); 411 end.setTime(endMatdTime); 412 lastActionNumber = coordJob.getLastActionNumber(); 413 //Intentionally printing dates in their own timezone, not Oozie timezone 414 LOG.info("materialize actions for tz=" + appTz.getDisplayName() + ",\n start=" + start.getTime() + ", end=" 415 + end.getTime() + ",\n timeUnit " + freqTU.getCalendarUnit() + ",\n frequency :" + frequency + ":" 416 + freqTU + ",\n lastActionNumber " + lastActionNumber); 417 // Keep the actual start time 418 Calendar origStart = Calendar.getInstance(appTz); 419 origStart.setTime(coordJob.getStartTimestamp()); 420 // Move to the End of duration, if needed. 421 DateUtils.moveToEnd(origStart, endOfFlag); 422 423 StringBuilder actionStrings = new StringBuilder(); 424 Date jobPauseTime = coordJob.getPauseTime(); 425 Calendar pause = null; 426 if (jobPauseTime != null) { 427 pause = Calendar.getInstance(appTz); 428 pause.setTime(DateUtils.convertDateToTimestamp(jobPauseTime)); 429 } 430 431 String action = null; 432 int numWaitingActions = dryrun ? 0 : jpaService.execute(new CoordActionsActiveCountJPAExecutor(coordJob.getId())); 433 int maxActionToBeCreated = coordJob.getMatThrottling() - numWaitingActions; 434 // If LAST_ONLY and all materialization is in the past, ignore maxActionsToBeCreated 435 boolean ignoreMaxActions = 436 (coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.LAST_ONLY) || 437 coordJob.getExecutionOrder().equals(CoordinatorJob.Execution.NONE)) 438 && endMatdTime.before(new Date()); 439 LOG.debug("Coordinator job :" + coordJob.getId() + ", maxActionToBeCreated :" + maxActionToBeCreated 440 + ", Mat_Throttle :" + coordJob.getMatThrottling() + ", numWaitingActions :" + numWaitingActions); 441 442 boolean isCronFrequency = false; 443 444 Calendar effStart = (Calendar) start.clone(); 445 try { 446 int intFrequency = Integer.parseInt(coordJob.getFrequency()); 447 effStart = (Calendar) origStart.clone(); 448 effStart.add(freqTU.getCalendarUnit(), lastActionNumber * intFrequency); 449 } 450 catch (NumberFormatException e) { 451 isCronFrequency = true; 452 } 453 454 boolean firstMater = true; 455 while (effStart.compareTo(end) < 0 && (ignoreMaxActions || maxActionToBeCreated-- > 0)) { 456 if (pause != null && effStart.compareTo(pause) >= 0) { 457 break; 458 } 459 460 Date nextTime = effStart.getTime(); 461 462 if (isCronFrequency) { 463 if (effStart.getTime().compareTo(startMatdTime) == 0 && firstMater) { 464 effStart.add(Calendar.MINUTE, -1); 465 firstMater = false; 466 } 467 468 nextTime = CoordCommandUtils.getNextValidActionTimeForCronFrequency(effStart.getTime(), coordJob); 469 effStart.setTime(nextTime); 470 } 471 472 if (effStart.compareTo(end) < 0) { 473 474 if (pause != null && effStart.compareTo(pause) >= 0) { 475 break; 476 } 477 CoordinatorActionBean actionBean = new CoordinatorActionBean(); 478 lastActionNumber++; 479 480 int timeout = coordJob.getTimeout(); 481 LOG.debug("Materializing action for time=" + DateUtils.formatDateOozieTZ(effStart.getTime()) 482 + ", lastactionnumber=" + lastActionNumber + " timeout=" + timeout + " minutes"); 483 Date actualTime = new Date(); 484 action = CoordCommandUtils.materializeOneInstance(jobId, dryrun, (Element) eJob.clone(), 485 nextTime, actualTime, lastActionNumber, jobConf, actionBean); 486 actionBean.setTimeOut(timeout); 487 488 if (!dryrun) { 489 storeToDB(actionBean, action); // Storing to table 490 491 } 492 else { 493 actionStrings.append("action for new instance"); 494 actionStrings.append(action); 495 } 496 } 497 else { 498 break; 499 } 500 501 if (!isCronFrequency) { 502 effStart = (Calendar) origStart.clone(); 503 effStart.add(freqTU.getCalendarUnit(), lastActionNumber * Integer.parseInt(coordJob.getFrequency())); 504 } 505 } 506 507 if (isCronFrequency) { 508 if (effStart.compareTo(end) < 0 && !(ignoreMaxActions || maxActionToBeCreated-- > 0)) { 509 //Since we exceed the throttle, we need to move the nextMadtime forward 510 //to avoid creating duplicate actions 511 if (!firstMater) { 512 effStart.setTime(CoordCommandUtils.getNextValidActionTimeForCronFrequency(effStart.getTime(), coordJob)); 513 } 514 } 515 } 516 517 endMatdTime = effStart.getTime(); 518 519 if (!dryrun) { 520 return action; 521 } 522 else { 523 return actionStrings.toString(); 524 } 525 } 526 527 private void storeToDB(CoordinatorActionBean actionBean, String actionXml) throws Exception { 528 LOG.debug("In storeToDB() coord action id = " + actionBean.getId() + ", size of actionXml = " 529 + actionXml.length()); 530 actionBean.setActionXml(actionXml); 531 532 insertList.add(actionBean); 533 writeActionSlaRegistration(actionXml, actionBean); 534 } 535 536 private void writeActionSlaRegistration(String actionXml, CoordinatorActionBean actionBean) throws Exception { 537 Element eAction = XmlUtils.parseXml(actionXml); 538 Element eSla = eAction.getChild("action", eAction.getNamespace()).getChild("info", eAction.getNamespace("sla")); 539 SLAEventBean slaEvent = SLADbOperations.createSlaRegistrationEvent(eSla, actionBean.getId(), SlaAppType.COORDINATOR_ACTION, coordJob 540 .getUser(), coordJob.getGroup(), LOG); 541 if(slaEvent != null) { 542 insertList.add(slaEvent); 543 } 544 // inserting into new table also 545 SLAOperations.createSlaRegistrationEvent(eSla, actionBean.getId(), actionBean.getJobId(), 546 AppType.COORDINATOR_ACTION, coordJob.getUser(), coordJob.getAppName(), LOG, false); 547 } 548 549 private void updateJobMaterializeInfo(CoordinatorJobBean job) throws CommandException { 550 job.setLastActionTime(endMatdTime); 551 job.setLastActionNumber(lastActionNumber); 552 // if the job endtime == action endtime, we don't need to materialize this job anymore 553 Date jobEndTime = job.getEndTime(); 554 555 556 if (job.getStatus() == CoordinatorJob.Status.PREP){ 557 LOG.info("[" + job.getId() + "]: Update status from " + job.getStatus() + " to RUNNING"); 558 job.setStatus(Job.Status.RUNNING); 559 } 560 job.setPending(); 561 562 if (jobEndTime.compareTo(endMatdTime) <= 0) { 563 LOG.info("[" + job.getId() + "]: all actions have been materialized, set pending to true"); 564 // set doneMaterialization to true when materialization is done 565 job.setDoneMaterialization(); 566 } 567 job.setStatus(StatusUtils.getStatus(job)); 568 LOG.info("Coord Job status updated to = " + job.getStatus()); 569 job.setNextMaterializedTime(endMatdTime); 570 } 571 572 /* (non-Javadoc) 573 * @see org.apache.oozie.command.XCommand#getKey() 574 */ 575 @Override 576 public String getKey() { 577 return getName() + "_" + jobId; 578 } 579 580 /* (non-Javadoc) 581 * @see org.apache.oozie.command.TransitionXCommand#notifyParent() 582 */ 583 @Override 584 public void notifyParent() throws CommandException { 585 // update bundle action only when status changes in coord job 586 if (this.coordJob.getBundleId() != null) { 587 if (!prevStatus.equals(coordJob.getStatus())) { 588 BundleStatusUpdateXCommand bundleStatusUpdate = new BundleStatusUpdateXCommand(coordJob, prevStatus); 589 bundleStatusUpdate.call(); 590 } 591 } 592 } 593}