Search in sources :

Example 26 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestReRunXCommand method testRerunDisableForChild.

/**
 * Rerun workflow should run by parent only if configuration has been set to
 * true for oozie.wf.child.disable.rerun , Default it is disabled.
 * @throws Exception
 */
public void testRerunDisableForChild() throws Exception {
    final OozieClient wfClient = LocalOozie.getClient();
    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();
    wfClient.kill(wfId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    Properties newConf = wfClient.createConfiguration();
    newConf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, true);
    try {
        wfClient.reRun(wfId, newConf);
        fail("OozieClientException should have been thrown (" + ErrorCode.E0755 + " Rerun is not allowed through child workflow, please re-run through the parent)");
    } catch (OozieClientException ex) {
        assertEquals(ErrorCode.E0755.toString(), ex.getErrorCode());
    }
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, false);
    wfClient.reRun(wfId, newConf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(wfId).getStatus());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) OozieClientException(org.apache.oozie.client.OozieClientException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionStartXCommand(org.apache.oozie.command.coord.CoordActionStartXCommand) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Properties(java.util.Properties) Date(java.util.Date) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException)

Example 27 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class CoordUtils method getCoordActionsFromIds.

/**
 * Get the list of actions for given id ranges
 *
 * @param jobId coordinator job id
 * @param scope a comma-separated list of action ranges. The action range is specified with two action numbers separated by '-'
 * @return the list of all Coordinator actions for action range
 * @throws CommandException thrown if failed to get coordinator actions by given id range
 */
@VisibleForTesting
public static List<CoordinatorActionBean> getCoordActionsFromIds(String jobId, String scope) throws CommandException {
    JPAService jpaService = Services.get().get(JPAService.class);
    Set<String> actions = getActionsIds(jobId, scope);
    // Retrieve the actions using the corresponding actionIds
    List<CoordinatorActionBean> coordActions = new ArrayList<CoordinatorActionBean>();
    for (String id : actions) {
        CoordinatorActionBean coordAction = null;
        try {
            coordAction = jpaService.execute(new CoordActionGetJPAExecutor(id));
        } catch (JPAExecutorException je) {
            if (je.getErrorCode().equals(ErrorCode.E0605)) {
                // ignore retrieval of non-existent actions in range
                XLog.getLog(XLogService.class).warn("Coord action ID num [{0}] not yet materialized. Hence skipping over it for Kill action", id.substring(id.indexOf("@") + 1));
                continue;
            } else {
                throw new CommandException(je);
            }
        }
        coordActions.add(coordAction);
    }
    return coordActions;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 28 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestCoordKillXCommand method testCoordKillWaiting.

/**
 * Test: Kill a waiting coord action
 * @throws Exception
 */
public void testCoordKillWaiting() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, true, 0);
    // Create a workflow job with RUNNING status
    WorkflowJobBean wfJob1 = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    // Create a coordinator job with RUNNING status
    CoordinatorActionBean action1 = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1.getId(), "RUNNING", 0);
    // Create a coordinator job with WAITING status
    CoordinatorActionBean action2 = addRecordToCoordActionTable(coordJob.getId(), 2, CoordinatorAction.Status.WAITING, "coord-action-get.xml", null, null, 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    CoordActionGetJPAExecutor coordActionGetCmd1 = new CoordActionGetJPAExecutor(action1.getId());
    CoordActionGetJPAExecutor coordActionGetCmd2 = new CoordActionGetJPAExecutor(action2.getId());
    coordJob = jpaService.execute(coordJobGetCmd);
    action1 = jpaService.execute(coordActionGetCmd1);
    action2 = jpaService.execute(coordActionGetCmd2);
    // Make sure the status is updated
    assertEquals(coordJob.getStatus(), CoordinatorJob.Status.RUNNING);
    assertEquals(action1.getStatus(), CoordinatorAction.Status.RUNNING);
    assertEquals(action2.getStatus(), CoordinatorAction.Status.WAITING);
    // Issue the kill command
    new CoordKillXCommand(coordJob.getId()).call();
    coordJob = jpaService.execute(coordJobGetCmd);
    action1 = jpaService.execute(coordActionGetCmd1);
    action2 = jpaService.execute(coordActionGetCmd2);
    // Check the status and pending flag after kill command is issued
    assertEquals(coordJob.getStatus(), CoordinatorJob.Status.KILLED);
    assertEquals(action1.getStatus(), CoordinatorAction.Status.KILLED);
    // The wf job is running and can be killed, so pending for coord action
    // kill should be true
    assertEquals(action1.getPending(), 1);
    assertEquals(action2.getStatus(), CoordinatorAction.Status.KILLED);
    // The coord job is waiting and no wf created yet, so pending for coord
    // action kill should be false
    assertEquals(action2.getPending(), 0);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Example 29 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestCoordKillXCommand method testCoordKillForBackwardSupport.

/**
 * Test : kill SUCCEEDED job successfully when CONF_BACKWARD_SUPPORT_FOR_COORD_STATUS is true and coordinator schema
 * is 0.1
 *
 * @throws Exception
 */
public void testCoordKillForBackwardSupport() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_COORD_STATUS, "true");
    services = new Services();
    setClassesToBeExcluded(services.getConf(), excludedServices);
    services.init();
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, true);
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    job.setAppNamespace(SchemaService.COORDINATOR_NAMESPACE_URI_1);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_APPNAMESPACE, job);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(CoordinatorJob.Status.SUCCEEDED, job.getStatus());
    assertEquals(CoordinatorAction.Status.RUNNING, action.getStatus());
    new CoordKillXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(CoordinatorJob.Status.KILLED, job.getStatus());
    assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
}
Also used : Services(org.apache.oozie.service.Services) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 30 with CoordActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.

the class TestCoordKillXCommand method testCoordKillFailed.

/**
 * Test : kill job failed. Job does not exist.
 *
 * @throws Exception
 */
public void testCoordKillFailed() throws Exception {
    final String testJobId = "0000001-" + new Date().getTime() + "-testCoordKill-C";
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, true);
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.READY, "coord-action-get.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUCCEEDED);
    assertEquals(action.getStatus(), CoordinatorAction.Status.READY);
    try {
        new CoordKillXCommand(testJobId).call();
        fail("Job doesn't exist. Should fail.");
    } catch (CommandException ce) {
    // Job doesn't exist. Exception is expected.
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Aggregations

CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)60 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)60 JPAService (org.apache.oozie.service.JPAService)54 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)43 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)41 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)32 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)25 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)23 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)21 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)21 Date (java.util.Date)19 BundleActionBean (org.apache.oozie.BundleActionBean)9 BundleJobBean (org.apache.oozie.BundleJobBean)9 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)9 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)9 IOException (java.io.IOException)8 CommandException (org.apache.oozie.command.CommandException)7 CoordActionStartXCommand (org.apache.oozie.command.coord.CoordActionStartXCommand)3 Properties (java.util.Properties)2 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)2