use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.
the class CoordChangeXCommand method execute.
/* (non-Javadoc)
* @see org.apache.oozie.command.XCommand#execute()
*/
@Override
protected Void execute() throws CommandException {
LOG.info("STARTED CoordChangeXCommand for jobId=" + jobId);
try {
oldConcurrency = this.coordJob.getConcurrency();
if (newEndTime != null) {
// during coord materialization, nextMaterializedTime is set to
// startTime + n(actions materialized) * frequency and this can be AFTER endTime,
// while doneMaterialization is true. Hence the following checks
// for newEndTime being in the middle of endTime and nextMatdTime.
// Since job is already done materialization so no need to change
boolean dontChange = coordJob.getEndTime().before(newEndTime) && coordJob.getNextMaterializedTime() != null && coordJob.getNextMaterializedTime().after(newEndTime);
if (!dontChange) {
coordJob.setEndTime(newEndTime);
// OOZIE-1703, we should SUCCEEDED the coord, if it's in PREP and new endtime is before start time
if (coordJob.getStartTime().compareTo(newEndTime) >= 0) {
if (coordJob.getStatus() != CoordinatorJob.Status.PREP) {
processLookaheadActions(coordJob, newEndTime);
}
if (coordJob.getStatus() == CoordinatorJob.Status.PREP || coordJob.getStatus() == CoordinatorJob.Status.RUNNING) {
LOG.info("Changing coord status to SUCCEEDED, because it's in " + coordJob.getStatus() + " and new end time is before start time. Startime is " + coordJob.getStartTime() + " and new end time is " + newEndTime);
coordJob.setStatus(CoordinatorJob.Status.SUCCEEDED);
coordJob.resetPending();
}
coordJob.setDoneMaterialization();
} else {
// move it to running iff new end time is after starttime.
if (coordJob.getStatus() == CoordinatorJob.Status.SUCCEEDED) {
coordJob.setStatus(CoordinatorJob.Status.RUNNING);
}
if (coordJob.getStatus() == CoordinatorJob.Status.DONEWITHERROR || coordJob.getStatus() == CoordinatorJob.Status.FAILED) {
// Check for backward compatibility for Oozie versions (3.2 and before)
// when RUNNINGWITHERROR, SUSPENDEDWITHERROR and
// PAUSEDWITHERROR is not supported
coordJob.setStatus(StatusUtils.getStatusIfBackwardSupportTrue(CoordinatorJob.Status.RUNNINGWITHERROR));
}
coordJob.setPending();
coordJob.resetDoneMaterialization();
processLookaheadActions(coordJob, newEndTime);
}
} else {
LOG.info("Didn't change endtime. Endtime is in between coord end time and next materialization time." + "Coord endTime = " + DateUtils.formatDateOozieTZ(newEndTime) + " next materialization time =" + DateUtils.formatDateOozieTZ(coordJob.getNextMaterializedTime()));
}
}
if (newConcurrency != null) {
this.coordJob.setConcurrency(newConcurrency);
}
if (newPauseTime != null || resetPauseTime == true) {
this.coordJob.setPauseTime(newPauseTime);
if (oldPauseTime != null && newPauseTime != null) {
if (oldPauseTime.before(newPauseTime)) {
if (this.coordJob.getStatus() == Job.Status.PAUSED) {
this.coordJob.setStatus(Job.Status.RUNNING);
} else if (this.coordJob.getStatus() == Job.Status.PAUSEDWITHERROR) {
this.coordJob.setStatus(Job.Status.RUNNINGWITHERROR);
}
}
} else if (oldPauseTime != null && newPauseTime == null) {
if (this.coordJob.getStatus() == Job.Status.PAUSED) {
this.coordJob.setStatus(Job.Status.RUNNING);
} else if (this.coordJob.getStatus() == Job.Status.PAUSEDWITHERROR) {
this.coordJob.setStatus(Job.Status.RUNNINGWITHERROR);
}
}
if (!resetPauseTime) {
processLookaheadActions(coordJob, newPauseTime);
}
}
if (jobStatus != null) {
coordJob.setStatus(jobStatus);
LOG.info("Coord status is changed to " + jobStatus + " from " + prevStatus);
if (jobStatus.equals(CoordinatorJob.Status.RUNNING)) {
coordJob.setPending();
if (coordJob.getNextMaterializedTime() == null || coordJob.getEndTime().after(coordJob.getNextMaterializedTime())) {
coordJob.resetDoneMaterialization();
}
} else if (jobStatus.equals(CoordinatorJob.Status.IGNORED)) {
coordJob.resetPending();
coordJob.setDoneMaterialization();
}
}
if (coordJob.getNextMaterializedTime() != null && coordJob.getEndTime().compareTo(coordJob.getNextMaterializedTime()) <= 0) {
LOG.info("[" + coordJob.getId() + "]: all actions have been materialized, job status = " + coordJob.getStatus() + ", set pending to true");
// set doneMaterialization to true when materialization is done
coordJob.setDoneMaterialization();
}
coordJob.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_CHANGE, coordJob));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, deleteList);
if (newConcurrency != null && newConcurrency > oldConcurrency) {
queue(new CoordActionReadyXCommand(jobId));
}
return null;
} catch (XException ex) {
throw new CommandException(ex);
} finally {
LOG.info("ENDED CoordChangeXCommand for jobId=" + jobId);
// update bundle action
if (coordJob.getBundleId() != null) {
// ignore pending as it'sync command
BundleStatusUpdateXCommand bundleStatusUpdate = new BundleStatusUpdateXCommand(coordJob, prevStatus, true);
bundleStatusUpdate.call();
}
}
}
use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.
the class CoordResumeXCommand method updateJob.
@Override
public void updateJob() {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
coordJob.setSuspendedTime(null);
coordJob.setLastModifiedTime(new Date());
LOG.debug("Resume coordinator job id = " + jobId + ", status = " + coordJob.getStatus() + ", pending = " + coordJob.isPending());
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
}
use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.
the class CoordSuspendXCommand method updateJob.
@Override
public void updateJob() {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
coordJob.setLastModifiedTime(new Date());
coordJob.setSuspendedTime(new Date());
LOG.debug("Suspend coordinator job id = " + jobId + ", status = " + coordJob.getStatus() + ", pending = " + coordJob.isPending());
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
}
use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.
the class CoordSuspendXCommand method suspendChildren.
@Override
public void suspendChildren() throws CommandException {
try {
// Get all running actions of a job to suspend them
List<CoordinatorActionBean> actionList = jpaService.execute(new CoordJobGetActionsRunningJPAExecutor(jobId));
for (CoordinatorActionBean action : actionList) {
// queue a SuspendXCommand
if (action.getExternalId() != null) {
queue(new SuspendXCommand(action.getExternalId()));
updateCoordAction(action);
LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and queue SuspendXCommand for [{3}]", action.getId(), action.getStatus(), action.getPending(), action.getExternalId());
} else {
updateCoordAction(action);
LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and external id is null", action.getId(), action.getStatus(), action.getPending());
}
}
LOG.debug("Suspended coordinator actions for the coordinator=[{0}]", jobId);
} catch (XException ex) {
exceptionOccured = true;
throw new CommandException(ex);
} finally {
if (exceptionOccured) {
coordJob.setStatus(CoordinatorJob.Status.FAILED);
coordJob.resetPending();
LOG.debug("Exception happened, fail coordinator job id = " + jobId + ", status = " + coordJob.getStatus());
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
}
}
}
use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.
the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDelete.
public void testExecuteBatchUpdateInsertDelete() throws Exception {
BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
// for update
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
// for insert
CoordinatorActionBean coordAction = new CoordinatorActionBean();
coordAction.setId("testCoordAction1");
JPAService jpaService = Services.get().get(JPAService.class);
// update the status
coordJob.setStatus(CoordinatorJob.Status.RUNNING);
wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
// update the list for doing bulk writes
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_MODTIME, coordJob));
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wfJob));
// insert beans
Collection<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(coordAction);
// delete beans
Collection<JsonBean> deleteList = new ArrayList<JsonBean>();
deleteList.add(wfAction);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, deleteList);
// check update after running ExecuteBatchUpdateInsertDelete
coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coordJob.getId());
assertEquals("RUNNING", coordJob.getStatusStr());
wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, wfJob.getId());
assertEquals("SUCCEEDED", wfJob.getStatusStr());
coordAction = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordAction.getId());
assertEquals("testCoordAction1", coordAction.getId());
try {
wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, wfJob.getId());
fail();
} catch (JPAExecutorException ex) {
assertEquals(ex.getErrorCode().toString(), "E0605");
}
}
Aggregations