Search in sources :

Example 1 with PreconditionException

use of org.apache.oozie.command.PreconditionException in project oozie by apache.

the class TestCallableQueueService method testRemoveUniqueCallables.

public void testRemoveUniqueCallables() throws Exception {
    XCommand command = new XCommand("Test", "type", 100) {

        @Override
        protected boolean isLockRequired() {
            return false;
        }

        @Override
        public String getEntityKey() {
            return "TEST";
        }

        @Override
        protected void loadState() throws CommandException {
        }

        @Override
        protected void verifyPrecondition() throws CommandException, PreconditionException {
        }

        @Override
        protected Object execute() throws CommandException {
            return null;
        }
    };
    Services.get().destroy();
    setSystemProperty(CallableQueueService.CONF_THREADS, "1");
    new Services().init();
    CallableQueueService queueservice = Services.get().get(CallableQueueService.class);
    List<String> uniquesBefore = queueservice.getUniqueDump();
    try {
        queueservice.queue(command);
        fail("Expected illegal argument exception: priority = 100");
    } catch (Exception e) {
        assertTrue(e.getCause() != null && e.getCause() instanceof IllegalArgumentException);
    }
    List<String> uniquesAfter = queueservice.getUniqueDump();
    uniquesAfter.removeAll(uniquesBefore);
    assertTrue(uniquesAfter.toString(), uniquesAfter.isEmpty());
}
Also used : XCommand(org.apache.oozie.command.XCommand) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 2 with PreconditionException

use of org.apache.oozie.command.PreconditionException in project oozie by apache.

the class TestCoordActionSkipXCommand method testVerifyPrecondition.

public void testVerifyPrecondition() throws Exception {
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + 1 * 60 * 1000);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, true, 0);
    int actionNum = 1;
    for (CoordinatorAction.Status actionStatus : CoordinatorAction.Status.values()) {
        CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), actionNum, actionStatus, "coord-action-get.xml", 0);
        try {
            new CoordActionSkipXCommand(action, getTestUser(), "my-app-name").verifyPrecondition();
            if (!(actionStatus.equals(CoordinatorAction.Status.WAITING) || actionStatus.equals(CoordinatorAction.Status.READY))) {
                fail();
            }
        } catch (PreconditionException pe) {
            assertEquals(ErrorCode.E1100, pe.getErrorCode());
            assertTrue(pe.getMessage().endsWith("[" + actionStatus + "]]"));
        }
        actionNum++;
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) Date(java.util.Date) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 3 with PreconditionException

use of org.apache.oozie.command.PreconditionException in project oozie by apache.

the class TestCoordKillXCommand method testCoordKillSuccess1.

/**
 * Test : kill job and action (READY) successfully
 *
 * @throws Exception
 */
public void testCoordKillSuccess1() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 0);
    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.RUNNING);
    assertEquals(action.getStatus(), CoordinatorAction.Status.READY);
    assertFalse(job.isDoneMaterialization());
    new CoordKillXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
    assertTrue(job.isDoneMaterialization());
    assertNotNull(job.getLastModifiedTime());
    assertEquals(action.getStatus(), CoordinatorAction.Status.KILLED);
    // Change job status to RUNNINGWITHERROR to simulate StatusTransitService changing it to
    // RUNNINGWITHERROR if it had loaded status and had it as RUNNING in memory when CoordKill
    // executes and updates status to KILLED in database.
    job.setStatus(CoordinatorJob.Status.RUNNINGWITHERROR);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_STATUS, job);
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNINGWITHERROR);
    final CoordMaterializeTransitionXCommand transitionCmd = new CoordMaterializeTransitionXCommand(job.getId(), 3600);
    try {
        transitionCmd.loadState();
        transitionCmd.verifyPrecondition();
        fail();
    } catch (PreconditionException e) {
    // Materialization should not happen as done materialization is set to true by coord kill
    }
    StatusTransitService.StatusTransitRunnable statusTransit = new StatusTransitService.StatusTransitRunnable();
    statusTransit.run();
    // StatusTransitService should change the job back to KILLED
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
    assertTrue(job.isDoneMaterialization());
    assertNotNull(job.getLastModifiedTime());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) Date(java.util.Date) PreconditionException(org.apache.oozie.command.PreconditionException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitService(org.apache.oozie.service.StatusTransitService) JPAService(org.apache.oozie.service.JPAService)

Example 4 with PreconditionException

use of org.apache.oozie.command.PreconditionException in project oozie by apache.

the class CoordActionCheckXCommand method verifyPrecondition.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#verifyPrecondition()
     */
@Override
protected void verifyPrecondition() throws CommandException, PreconditionException {
    // if the action has been updated, quit this command
    Timestamp actionCheckTs = new Timestamp(System.currentTimeMillis() - actionCheckDelay * 1000);
    Timestamp cactionLmt = coordAction.getLastModifiedTimestamp();
    if (cactionLmt.after(actionCheckTs)) {
        throw new PreconditionException(ErrorCode.E1100, "The coord action :" + actionId + " has been updated. Ignore CoordActionCheckCommand!");
    }
    if (coordAction.getStatus().equals(CoordinatorAction.Status.SUCCEEDED) || coordAction.getStatus().equals(CoordinatorAction.Status.FAILED) || coordAction.getStatus().equals(CoordinatorAction.Status.KILLED)) {
        throw new PreconditionException(ErrorCode.E1100, "The coord action [" + actionId + "] must not have status " + CoordinatorAction.Status.SUCCEEDED.name() + ", " + CoordinatorAction.Status.FAILED.name() + ", or " + CoordinatorAction.Status.KILLED.name() + " but has status [" + coordAction.getStatus().name() + "]");
    }
}
Also used : Timestamp(java.sql.Timestamp) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 5 with PreconditionException

use of org.apache.oozie.command.PreconditionException in project oozie by apache.

the class ActionCheckXCommand method eagerVerifyPrecondition.

@Override
protected void eagerVerifyPrecondition() throws CommandException, PreconditionException {
    if (wfJob == null) {
        throw new PreconditionException(ErrorCode.E0604, jobId);
    }
    if (wfAction == null) {
        throw new PreconditionException(ErrorCode.E0605, actionId);
    }
    // if the action has been updated, quit this command
    if (actionCheckDelay > 0) {
        Timestamp actionCheckTs = new Timestamp(System.currentTimeMillis() - actionCheckDelay * 1000);
        Timestamp actionLmt = wfAction.getLastCheckTimestamp();
        if (actionLmt.after(actionCheckTs)) {
            throw new PreconditionException(ErrorCode.E0817, actionId);
        }
    }
    executor = Services.get().get(ActionService.class).getExecutor(wfAction.getType());
    if (executor == null) {
        throw new CommandException(ErrorCode.E0802, wfAction.getType());
    }
}
Also used : CommandException(org.apache.oozie.command.CommandException) Timestamp(java.sql.Timestamp) PreconditionException(org.apache.oozie.command.PreconditionException)

Aggregations

PreconditionException (org.apache.oozie.command.PreconditionException)7 CommandException (org.apache.oozie.command.CommandException)4 Date (java.util.Date)3 Timestamp (java.sql.Timestamp)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)1 XCommand (org.apache.oozie.command.XCommand)1 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)1 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)1 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)1 JPAService (org.apache.oozie.service.JPAService)1 StatusTransitService (org.apache.oozie.service.StatusTransitService)1 JDOMException (org.jdom.JDOMException)1 SAXException (org.xml.sax.SAXException)1