Search in sources :

Example 21 with XException

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

the class SLAEventsXCommand method execute.

@Override
protected List<SLAEventBean> execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        List<SLAEventBean> slaEventList = null;
        long[] lastSeqId = new long[1];
        if (jpaService != null) {
            slaEventList = jpaService.execute(new SLAEventsGetForFilterJPAExecutor(seqId, maxNoEvents, filter, lastSeqId));
        } else {
            LOG.error(ErrorCode.E0610);
        }
        setLastSeqId(lastSeqId[0]);
        return slaEventList;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) SLAEventsGetForFilterJPAExecutor(org.apache.oozie.executor.jpa.SLAEventsGetForFilterJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) SLAEventBean(org.apache.oozie.SLAEventBean)

Example 22 with XException

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

the class TestBundleJobInfoGetJPAExecutor method testGetJobInfoForText.

public void testGetJobInfoForText() throws Exception {
    BundleJobBean bundleJob1 = addRecordToBundleJobTable(BundleJob.Status.RUNNING, false);
    BundleJobBean bundleJob2 = addRecordToBundleJobTable(BundleJob.Status.KILLED, false);
    bundleJob1.setAppName("oozie-bundle1");
    bundleJob2.setAppName("oozie-bundle2");
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob1);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob2);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Map<String, List<String>> filter = new HashMap<String, List<String>>();
    BundleJobInfoGetJPAExecutor bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    BundleJobInfo ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(2, ret.getBundleJobs().size());
    filter.clear();
    ArrayList<String> textList = new ArrayList<String>();
    textList.add("tes");
    filter.put(OozieClient.FILTER_TEXT, textList);
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getBundleJobs().size(), 2);
    textList.clear();
    textList.add("oozie-bundle1");
    filter.put(OozieClient.FILTER_TEXT, textList);
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getBundleJobs().size(), 1);
    textList.clear();
    textList.add("random");
    filter.put(OozieClient.FILTER_TEXT, textList);
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getBundleJobs().size(), 0);
    textList.clear();
    textList.add("oozie-bundle");
    filter.put(OozieClient.FILTER_TEXT, textList);
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getBundleJobs().size(), 2);
    textList.add("tes");
    filter.put(OozieClient.FILTER_TEXT, textList);
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    try {
        jpaService.execute(bundleInfoGetCmd);
        fail("BundleJobInfoGetJPAExecutor should have thrown E0302 exception.");
    } catch (XException e) {
        assertEquals(ErrorCode.E0302, e.getErrorCode());
        assertEquals(e.getMessage(), "E0302: Invalid parameter [cannot specify multiple strings to search]");
    }
    // Update bundle appName, user and validate text filter
    bundleJob1.setAppName("updated-app-name1");
    bundleJob2.setAppName("updated-app-name2");
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob1);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQueryExecutor.BundleJobQuery.UPDATE_BUNDLE_JOB, bundleJob2);
    textList.clear();
    textList.add("oozie-bundle");
    filter.put(OozieClient.FILTER_TEXT, textList);
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getBundleJobs().size(), 0);
    textList.clear();
    textList.add("updated-app");
    filter.put(OozieClient.FILTER_TEXT, textList);
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getBundleJobs().size(), 2);
    textList.clear();
    textList.add("updated-app-name1");
    bundleInfoGetCmd = new BundleJobInfoGetJPAExecutor(filter, 1, 20);
    ret = jpaService.execute(bundleInfoGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getBundleJobs().size(), 1);
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) XException(org.apache.oozie.XException) BundleJobInfo(org.apache.oozie.BundleJobInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 23 with XException

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

the class BundleJobXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected BundleJobBean execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        BundleJobBean bundleJob = null;
        if (jpaService != null) {
            bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(id));
            List<CoordinatorJobBean> coordinators = jpaService.execute(new BundleJobGetCoordinatorsJPAExecutor(id));
            bundleJob.setCoordJobs(coordinators);
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return bundleJob;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) BundleJobGetCoordinatorsJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetCoordinatorsJPAExecutor)

Example 24 with XException

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

the class BundleKillXCommand method loadState.

@Override
public void loadState() throws CommandException {
    try {
        this.bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB, jobId);
        this.bundleActions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
        LogUtils.setLogInfo(bundleJob);
        super.setJob(bundleJob);
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException)

Example 25 with XException

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

the class CoordResumeXCommand method resumeChildren.

@Override
public void resumeChildren() throws CommandException {
    try {
        // Get all suspended actions to resume them
        List<CoordinatorActionBean> actionList = jpaService.execute(new CoordJobGetActionsSuspendedJPAExecutor(jobId));
        for (CoordinatorActionBean action : actionList) {
            if (action.getExternalId() != null) {
                // queue a ResumeXCommand
                queue(new ResumeXCommand(action.getExternalId()));
                updateCoordAction(action);
                LOG.debug("Resume coord action = [{0}], new status = [{1}], pending = [{2}] and queue ResumeXCommand for [{3}]", action.getId(), action.getStatus(), action.getPending(), action.getExternalId());
            } else {
                updateCoordAction(action);
                LOG.debug("Resume coord action = [{0}], new status = [{1}], pending = [{2}] and external id is null", action.getId(), action.getStatus(), action.getPending());
            }
        }
    } catch (XException ex) {
        exceptionOccured = true;
        throw new CommandException(ex);
    } finally {
        if (exceptionOccured) {
            coordJob.setStatus(CoordinatorJob.Status.FAILED);
            coordJob.resetPending();
            LOG.warn("Resume children failed so fail coordinator, coordinator job id = " + jobId + ", status = " + coordJob.getStatus());
            updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
        }
    }
}
Also used : CoordJobGetActionsSuspendedJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionsSuspendedJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) XException(org.apache.oozie.XException) ResumeXCommand(org.apache.oozie.command.wf.ResumeXCommand) CommandException(org.apache.oozie.command.CommandException) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)

Aggregations

XException (org.apache.oozie.XException)45 CommandException (org.apache.oozie.command.CommandException)32 JPAService (org.apache.oozie.service.JPAService)25 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)8 HashMap (java.util.HashMap)7 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)7 List (java.util.List)6 ParseException (java.text.ParseException)4 BundleJobBean (org.apache.oozie.BundleJobBean)4 SLAEventBean (org.apache.oozie.SLAEventBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 Configuration (org.apache.hadoop.conf.Configuration)3 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)3 PreconditionException (org.apache.oozie.command.PreconditionException)3 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)3 Map (java.util.Map)2 BundleJobInfo (org.apache.oozie.BundleJobInfo)2 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)2