Search in sources :

Example 6 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestJMSTopicService method testMixedTopic1.

@Test
public void testMixedTopic1() throws Exception {
    services = setupServicesForTopic();
    services.getConf().set(JMSTopicService.TOPIC_NAME, JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow," + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord, default = " + JMSTopicService.TopicType.JOBID.getValue());
    services.init();
    JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
    WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_JOB, wfj.getUser(), wfj.getId(), null));
    WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
    assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_ACTION, wfj.getUser(), wab.getId(), wab.getWfId()));
    CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
    assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
    assertEquals("coord", jmsTopicService.getTopic(AppType.COORDINATOR_JOB, cjb.getUser(), cjb.getId(), null));
    CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-for-action-input-check.xml", 0);
    assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
    assertEquals("coord", jmsTopicService.getTopic(AppType.COORDINATOR_ACTION, cjb.getUser(), cab.getId(), cab.getJobId()));
    BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
    assertEquals(bjb.getId(), jmsTopicService.getTopic(bjb.getId()));
    assertEquals(bjb.getId(), jmsTopicService.getTopic(AppType.BUNDLE_JOB, bjb.getUser(), bjb.getId(), null));
    BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
    assertEquals(bjb.getId(), jmsTopicService.getTopic(bab.getBundleActionId()));
    assertEquals(bjb.getId(), jmsTopicService.getTopic(AppType.BUNDLE_ACTION, bjb.getUser(), bab.getBundleActionId(), bab.getBundleId()));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobBean(org.apache.oozie.BundleJobBean) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) BundleActionBean(org.apache.oozie.BundleActionBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Test(org.junit.Test)

Example 7 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestJMSTopicService method testMixedTopic2.

@Test
public void testMixedTopic2() throws Exception {
    services = setupServicesForTopic();
    services.getConf().set(JMSTopicService.TOPIC_NAME, JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow," + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord");
    services.init();
    JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
    WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_JOB, wfj.getUser(), wfj.getId(), null));
    WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
    assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_ACTION, wfj.getUser(), wab.getId(), wab.getWfId()));
    CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
    assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
    CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-for-action-input-check.xml", 0);
    assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
    assertEquals("coord", jmsTopicService.getTopic(AppType.COORDINATOR_ACTION, cjb.getUser(), cab.getId(), cab.getJobId()));
    BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
    // As no default is specified, user will be considered as topic
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(bjb.getId()));
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(AppType.BUNDLE_JOB, bjb.getUser(), bjb.getId(), null));
    BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(bab.getBundleActionId()));
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(AppType.BUNDLE_ACTION, bjb.getUser(), bab.getBundleActionId(), bab.getBundleId()));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobBean(org.apache.oozie.BundleJobBean) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) BundleActionBean(org.apache.oozie.BundleActionBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Test(org.junit.Test)

Example 8 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestPauseTransitService method testUnpauseBundleAndCoordinator.

/**
 * Test : Unpause a PAUSED bundle, then check bundle action has been updated to RUNNING by BundleStatusUpdateXCommand
 *
 * @throws Exception
 */
public void testUnpauseBundleAndCoordinator() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PAUSED, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    job.setPauseTime(null);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_PAUSE_KICKOFF, job);
    BundleActionBean bundleAction1 = this.addRecordToBundleActionTable(job.getId(), "action1", 0, Job.Status.PAUSED);
    BundleActionBean bundleAction2 = this.addRecordToBundleActionTable(job.getId(), "action2", 0, Job.Status.PAUSED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob1 = addRecordToCoordJobTable("action1", CoordinatorJob.Status.PAUSED, start, end, false);
    CoordinatorJobBean coordJob2 = addRecordToCoordJobTable("action2", CoordinatorJob.Status.PAUSED, start, end, false);
    coordJob1.setPauseTime(null);
    coordJob1.setBundleId(job.getId());
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob1);
    coordJob2.setPauseTime(null);
    coordJob2.setBundleId(job.getId());
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob2);
    BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(Job.Status.PAUSED, job.getStatus());
    Runnable pauseStartRunnable = new PauseTransitRunnable();
    pauseStartRunnable.run();
    final String jobId = job.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bJob1 = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
            return bJob1.getStatus() == Job.Status.RUNNING;
        }
    });
    final String coordJobId1 = coordJob1.getId();
    final String coordJobId2 = coordJob2.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean cJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
            CoordinatorJobBean cJob2 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId2));
            return cJob1.getStatus() == Job.Status.RUNNING && cJob2.getStatus() == Job.Status.RUNNING;
        }
    });
    job = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
    assertEquals(Job.Status.RUNNING, job.getStatus());
    coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
    assertEquals(Job.Status.RUNNING, coordJob1.getStatus());
    coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId2));
    assertEquals(Job.Status.RUNNING, coordJob2.getStatus());
    bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(job.getId(), "action1"));
    assertEquals(Job.Status.RUNNING, bundleAction1.getStatus());
    bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(job.getId(), "action2"));
    assertEquals(Job.Status.RUNNING, bundleAction2.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 9 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class BundleJobChangeXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected Void execute() throws CommandException {
    StringBuffer changeReport = new StringBuffer();
    try {
        if (isChangePauseTime || isChangeEndTime) {
            if (isChangePauseTime) {
                bundleJob.setPauseTime(newPauseTime);
            } else if (isChangeEndTime) {
                bundleJob.setEndTime(newEndTime);
                if (bundleJob.getStatus() == Job.Status.SUCCEEDED) {
                    bundleJob.setStatus(Job.Status.RUNNING);
                }
                if (bundleJob.getStatus() == Job.Status.DONEWITHERROR || bundleJob.getStatus() == Job.Status.FAILED) {
                    bundleJob.setStatus(StatusUtils.getStatusIfBackwardSupportTrue(Job.Status.RUNNINGWITHERROR));
                }
            }
            for (BundleActionBean action : this.bundleActions) {
                // queue coord change commands;
                if (action.getStatus() != Job.Status.KILLED && action.getCoordId() != null) {
                    try {
                        new CoordChangeXCommand(action.getCoordId(), changeValue).call();
                    } catch (Exception e) {
                        String errorMsg = action.getCoordId() + " : " + e.getMessage();
                        LOG.info("Change command failed " + errorMsg);
                        changeReport.append("[ ").append(errorMsg).append(" ]");
                    }
                } else {
                    String errorMsg = action.getCoordId() + " : Coord is in killed state";
                    LOG.info("Change command failed " + errorMsg);
                    changeReport.append("[ ").append(errorMsg).append(" ]");
                }
            }
            updateList.add(new UpdateEntry<BundleJobQuery>(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PAUSE_ENDTIME, bundleJob));
            BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, null);
        }
        if (!changeReport.toString().isEmpty()) {
            throw new CommandException(ErrorCode.E1320, changeReport.toString());
        }
        return null;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) BundleActionBean(org.apache.oozie.BundleActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) CoordChangeXCommand(org.apache.oozie.command.coord.CoordChangeXCommand)

Example 10 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class BundleKillXCommand method killChildren.

@Override
public void killChildren() throws CommandException {
    if (bundleActions != null) {
        for (BundleActionBean action : bundleActions) {
            if (action.getCoordId() != null) {
                queue(new CoordKillXCommand(action.getCoordId()));
                updateBundleAction(action);
                LOG.debug("Killed bundle action = [{0}], new status = [{1}], " + "pending = [{2}] and queue CoordKillXCommand for [{3}]", action.getBundleActionId(), action.getStatus(), action.getPending(), action.getCoordId());
            } else {
                updateBundleAction(action);
                LOG.debug("Killed bundle action = [{0}], current status = [{1}]," + "pending = [{2}]", action.getBundleActionId(), action.getStatus(), action.getPending());
            }
        }
    }
    LOG.debug("Killed coord jobs for the bundle=[{0}]", jobId);
}
Also used : CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

BundleActionBean (org.apache.oozie.BundleActionBean)76 BundleJobBean (org.apache.oozie.BundleJobBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAService (org.apache.oozie.service.JPAService)35 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)33 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)30 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)20 Date (java.util.Date)19 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)19 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)13 IOException (java.io.IOException)10 CommandException (org.apache.oozie.command.CommandException)10 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)10 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)9 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 XConfiguration (org.apache.oozie.util.XConfiguration)8 ArrayList (java.util.ArrayList)6