Search in sources :

Example 41 with CoordinatorJobBean

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

the class TestCoordActionStartXCommand method testActionStartWithEscapeStrings.

/**
 * Test : configuration contains url string which should be escaped before put into the evaluator.
 * If not escape, the error 'SAXParseException' will be thrown and workflow job will not be submitted.
 *
 * @throws Exception
 */
public void testActionStartWithEscapeStrings() throws Exception {
    Date start = DateUtils.parseDateOozieTZ("2009-12-15T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-12-16T01:00Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    CoordinatorActionBean action = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUBMITTED, "coord-action-start-escape-strings.xml", 0);
    String actionId = action.getId();
    new CoordActionStartXCommand(actionId, getTestUser(), "myapp", "myjob").call();
    final JPAService jpaService = Services.get().get(JPAService.class);
    action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
    }
    final String wfId = action.getExternalId();
    waitFor(3000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> wfActions = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
            return wfActions.size() > 0;
        }
    });
    List<WorkflowActionBean> wfActions = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
    assertTrue(wfActions.size() > 0);
    final String wfActionId = wfActions.get(0).getId();
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId));
            return wfAction.getExternalId() != null;
        }
    });
    WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId));
    assertNotNull(wfAction.getExternalId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 42 with CoordinatorJobBean

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

the class TestCoordActionsIgnoreXCommand method createDBRecords.

private void createDBRecords() throws Exception {
    JPAService jpaService = services.get(JPAService.class);
    coordJobs = new ArrayList<CoordinatorJobBean>();
    coordActions = new ArrayList<CoordinatorActionBean>();
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T23:59Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-02T23:59Z");
    CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.KILLED, startTime, endTime, false, true, 0);
    CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, true, 0);
    coordJobs.add(job1);
    coordJobs.add(job2);
    CoordinatorActionBean action1_1 = addRecordToCoordActionTable(job1.getId(), 1, CoordinatorAction.Status.FAILED, "coord-action-get.xml", 0);
    CoordinatorActionBean action1_2 = addRecordToCoordActionTable(job1.getId(), 2, CoordinatorAction.Status.FAILED, "coord-action-get.xml", 0);
    CoordinatorActionBean action1_3 = addRecordToCoordActionTable(job1.getId(), 3, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
    CoordinatorActionBean action1_4 = addRecordToCoordActionTable(job1.getId(), 4, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
    CoordinatorActionBean action1_5 = addRecordToCoordActionTable(job1.getId(), 5, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    coordActions.add(action1_1);
    coordActions.add(action1_2);
    coordActions.add(action1_3);
    coordActions.add(action1_4);
    coordActions.add(action1_5);
    action1_1.setNominalTime(DateUtils.parseDateOozieTZ("2009-12-15T02:00Z"));
    action1_1.setExternalId(null);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action1_1);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 43 with CoordinatorJobBean

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

the class TestCoordActionsKillXCommand method createDBRecords.

private String[] createDBRecords() throws Exception {
    JPAService jpaService = services.get(JPAService.class);
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T23:59Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-02T23:59Z");
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, true, 0);
    CoordinatorActionBean action1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    CoordinatorActionBean action2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    action2.setNominalTime(DateUtils.parseDateOozieTZ("2009-12-15T02:00Z"));
    action2.setExternalId(null);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action2);
    WorkflowJobBean wf = new WorkflowJobBean();
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    wf.setId(action1.getExternalId());
    wf.setStatus(WorkflowJob.Status.RUNNING);
    WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
    WorkflowInstance wfInstance = workflowLib.createInstance(app, new XConfiguration());
    ((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.RUNNING);
    wf.setWorkflowInstance(wfInstance);
    jpaService.execute(new WorkflowJobInsertJPAExecutor(wf));
    return new String[] { job.getId(), action1.getId(), action2.getId(), wf.getId() };
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) JPAService(org.apache.oozie.service.JPAService)

Example 44 with CoordinatorJobBean

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

the class TestCoordActionsKillXCommand method testActionKillCommandActionNumbers.

/**
 * Test the working of CoordActionKillXCommand by passing range
 * as action ids
 *
 * @throws Exception
 */
public void testActionKillCommandActionNumbers() throws Exception {
    JPAService jpaService = services.get(JPAService.class);
    String[] ids = createDBRecords();
    new CoordActionsKillXCommand(ids[0], "action", "1,3").call();
    CoordinatorActionBean action = jpaService.execute(new CoordActionGetForCheckJPAExecutor(ids[1]));
    assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
    sleep(100);
    WorkflowJobBean wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_FOR_SLA, ids[3]);
    assertEquals(WorkflowJob.Status.KILLED, wf.getStatus());
    CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(ids[0]));
    assertEquals(CoordinatorJob.Status.RUNNING, job.getStatus());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    job = jpaService.execute(new CoordJobGetJPAExecutor(ids[0]));
    assertEquals(CoordinatorJob.Status.RUNNINGWITHERROR, job.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) CoordActionGetForCheckJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForCheckJPAExecutor)

Example 45 with CoordinatorJobBean

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

the class TestCoordChangeXCommand method testCoordChangeEndTime.

/**
 * test end time change : pending should mark false if job is running with
 * pending true
 * Changing the end time to be 40 minutes after the current time
 * Changing the pause time to be 10 minutes after the current time
 *
 * @throws Exception
 */
public void testCoordChangeEndTime() throws Exception {
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + (20 * 60 * 1000));
    final CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, true, true, 0);
    String pauseTime = convertDateToString(startTime.getTime() + 10 * 60 * 1000);
    String newEndTime = convertDateToString(startTime.getTime() + 40 * 60 * 1000);
    new CoordChangeXCommand(job.getId(), "endtime=" + newEndTime + ";pausetime=" + pauseTime).call();
    try {
        checkCoordJobs(job.getId(), DateUtils.parseDateOozieTZ(newEndTime), null, DateUtils.parseDateOozieTZ(pauseTime), true);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Invalid date" + ex);
    }
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    assertFalse(coordJob.isDoneMaterialization());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) StoreException(org.apache.oozie.store.StoreException) CommandException(org.apache.oozie.command.CommandException)

Aggregations

CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)373 Date (java.util.Date)177 JPAService (org.apache.oozie.service.JPAService)153 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)149 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)121 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)114 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 CommandException (org.apache.oozie.command.CommandException)49 BundleJobBean (org.apache.oozie.BundleJobBean)46 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)43 IOException (java.io.IOException)39 XConfiguration (org.apache.oozie.util.XConfiguration)38 ArrayList (java.util.ArrayList)36 BundleActionBean (org.apache.oozie.BundleActionBean)36 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)34 Configuration (org.apache.hadoop.conf.Configuration)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)30 Path (org.apache.hadoop.fs.Path)24