Search in sources :

Example 16 with SLAEventBean

use of org.apache.oozie.SLAEventBean 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 17 with SLAEventBean

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

the class TestSLAEventsGetForFilterJPAExecutor method testGetSLAEventsWithRange.

public void testGetSLAEventsWithRange() throws Exception {
    Map<String, List<String>> filterList = new HashMap();
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    long[] lastSeqId = new long[1];
    lastSeqId[0] = -1;
    SLAEventsGetForFilterJPAExecutor slaEventsGetCmd = new SLAEventsGetForFilterJPAExecutor(1, 3, filterList, lastSeqId);
    List<SLAEventBean> list = jpaService.execute(slaEventsGetCmd);
    assertNotNull(list);
    assertEquals(3, list.size());
}
Also used : HashMap(java.util.HashMap) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) SLAEventBean(org.apache.oozie.SLAEventBean)

Example 18 with SLAEventBean

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

the class TestSLAEventsGetForFilterJPAExecutor method testGetSLAEventsForCombinedWithRange.

public void testGetSLAEventsForCombinedWithRange() throws Exception {
    Map<String, List<String>> filterList = createFilterList("jobid", coordId1, coordActionId1, coordId2, coordActionId2);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    long[] lastSeqId = new long[1];
    lastSeqId[0] = -1;
    SLAEventsGetForFilterJPAExecutor slaEventsGetCmd = new SLAEventsGetForFilterJPAExecutor(1, 3, filterList, lastSeqId);
    List<SLAEventBean> list = jpaService.execute(slaEventsGetCmd);
    assertNotNull(list);
    assertEquals(3, list.size());
}
Also used : List(java.util.List) JPAService(org.apache.oozie.service.JPAService) SLAEventBean(org.apache.oozie.SLAEventBean)

Example 19 with SLAEventBean

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

the class CoordActionUpdateXCommand method execute.

@Override
protected Void execute() throws CommandException {
    try {
        LOG.debug("STARTED CoordActionUpdateXCommand for wfId=[{0}]", workflow.getId());
        final CoordinatorAction.Status formerCoordinatorStatus = coordAction.getStatus();
        final int formerCoordinatorPending = coordAction.getPending();
        Status slaStatus = null;
        if (workflow.getStatus() == WorkflowJob.Status.SUCCEEDED) {
            coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
            coordAction.setPending(0);
            slaStatus = Status.SUCCEEDED;
        } else if (workflow.getStatus() == WorkflowJob.Status.FAILED) {
            coordAction.setStatus(CoordinatorAction.Status.FAILED);
            coordAction.setPending(0);
            slaStatus = Status.FAILED;
        } else if (workflow.getStatus() == WorkflowJob.Status.KILLED) {
            coordAction.setStatus(CoordinatorAction.Status.KILLED);
            coordAction.setPending(0);
            slaStatus = Status.KILLED;
        } else if (workflow.getStatus() == WorkflowJob.Status.SUSPENDED) {
            coordAction.setStatus(CoordinatorAction.Status.SUSPENDED);
            coordAction.decrementAndGetPending();
        } else if (workflow.getStatus() == WorkflowJob.Status.RUNNING || workflow.getStatus() == WorkflowJob.Status.PREP) {
            // resume workflow job and update coord action accordingly
            coordAction.setStatus(CoordinatorAction.Status.RUNNING);
            coordAction.decrementAndGetPending();
        } else {
            LOG.warn("Unexpected workflow [{0}] STATUS [{1}]", workflow.getId(), workflow.getStatus());
            // update lastModifiedTime
            coordAction.setLastModifiedTime(new Date());
            CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQueryExecutor.CoordActionQuery.UPDATE_COORD_ACTION_FOR_MODIFIED_DATE, coordAction);
            /* CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordAction.getJobId()));
                if (!coordJob.isPending()) {
                    coordJob.setPending();
                    jpaService.execute(new CoordJobUpdateJPAExecutor(coordJob));
                }*/
            return null;
        }
        LOG.info("Updating Coordinator action id: [{0}] status [{1}] to [{2}] pending [{3}] to [{4}]", coordAction.getId(), formerCoordinatorStatus, coordAction.getStatus(), formerCoordinatorPending, coordAction.getPending());
        coordAction.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
        /*CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordAction.getJobId()));
            if (!coordJob.isPending()) {
                coordJob.setPending();
                jpaService.execute(new CoordJobUpdateJPAExecutor(coordJob));
                LOG.info("Updating Coordinator job "+ coordJob.getId() + "pending to true");
            }*/
        if (slaStatus != null) {
            SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), slaStatus, SlaAppType.COORDINATOR_ACTION, LOG);
            if (slaEvent != null) {
                insertList.add(slaEvent);
            }
        }
        if (workflow.getStatus() != WorkflowJob.Status.SUSPENDED && workflow.getStatus() != WorkflowJob.Status.RUNNING) {
            queue(new CoordActionReadyXCommand(coordAction.getJobId()));
        }
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
        if (EventHandlerService.isEnabled()) {
            generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), workflow.getStartTime());
        }
        LOG.debug("ENDED CoordActionUpdateXCommand for wfId= [{0}]", workflow.getId());
    } catch (XException ex) {
        LOG.warn("CoordActionUpdate Failed [{0}]", ex.getMessage());
        throw new CommandException(ex);
    }
    return null;
}
Also used : Status(org.apache.oozie.client.SLAEvent.Status) XException(org.apache.oozie.XException) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 20 with SLAEventBean

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

the class CoordMaterializeTransitionXCommand method writeActionSlaRegistration.

private void writeActionSlaRegistration(String actionXml, CoordinatorActionBean actionBean, Configuration jobConf) throws Exception {
    Element eAction = XmlUtils.parseXml(actionXml);
    Element eSla = eAction.getChild("action", eAction.getNamespace()).getChild("info", eAction.getNamespace("sla"));
    SLAEventBean slaEvent = SLADbOperations.createSlaRegistrationEvent(eSla, actionBean.getId(), SlaAppType.COORDINATOR_ACTION, coordJob.getUser(), coordJob.getGroup(), LOG);
    if (slaEvent != null) {
        insertList.add(slaEvent);
    }
    // inserting into new table also
    SLAOperations.createSlaRegistrationEvent(eSla, actionBean.getId(), actionBean.getJobId(), AppType.COORDINATOR_ACTION, coordJob.getUser(), coordJob.getAppName(), LOG, false, CoordUtils.isSlaAlertDisabled(actionBean, coordJob.getAppName(), jobConf));
}
Also used : Element(org.jdom.Element) SLAEventBean(org.apache.oozie.SLAEventBean)

Aggregations

SLAEventBean (org.apache.oozie.SLAEventBean)42 Date (java.util.Date)15 JPAService (org.apache.oozie.service.JPAService)14 CommandException (org.apache.oozie.command.CommandException)13 List (java.util.List)12 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)10 Element (org.jdom.Element)7 XException (org.apache.oozie.XException)6 WorkflowActionQuery (org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery)6 ArrayList (java.util.ArrayList)5 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)5 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5 IOException (java.io.IOException)4 Configuration (org.apache.hadoop.conf.Configuration)4 ControlNodeActionExecutor (org.apache.oozie.action.control.ControlNodeActionExecutor)4 Status (org.apache.oozie.client.SLAEvent.Status)4 PreconditionException (org.apache.oozie.command.PreconditionException)4 Query (javax.persistence.Query)3 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)3 CoordActionQuery (org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)3