Search in sources :

Example 6 with SLAEventBean

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

the class SLADbXOperations method createSlaRegistrationEvent.

/**
 * Create SLA registration event
 *
 * @param eSla SLA xml element
 * @param slaId SLA Id
 * @param appType SLA app type
 * @param user user name
 * @param groupName group name
 * @return the event
 * @throws Exception in case of error
 */
public static SLAEventBean createSlaRegistrationEvent(Element eSla, String slaId, SlaAppType appType, String user, String groupName) throws Exception {
    if (eSla == null) {
        return null;
    }
    SLAEventBean sla = new SLAEventBean();
    // sla.setClientId(getTagElement( eSla, "client-id"));
    // sla.setClientId(getClientId());
    sla.setAppName(getTagElement(eSla, "app-name"));
    sla.setParentClientId(getTagElement(eSla, "parent-child-id"));
    sla.setParentSlaId(getTagElement(eSla, "parent-sla-id"));
    String strNominalTime = getTagElement(eSla, "nominal-time");
    if (strNominalTime == null || strNominalTime.length() == 0) {
        throw new CommandException(ErrorCode.E1101);
    }
    Date nominalTime = DateUtils.parseDateOozieTZ(strNominalTime);
    // Setting expected start time
    String strRelExpectedStart = getTagElement(eSla, "should-start");
    if (strRelExpectedStart != null && strRelExpectedStart.length() > 0) {
        int relExpectedStart = Integer.parseInt(strRelExpectedStart);
        if (relExpectedStart < 0) {
            sla.setExpectedStart(null);
        } else {
            Date expectedStart = new Date(nominalTime.getTime() + relExpectedStart * 60 * 1000);
            sla.setExpectedStart(expectedStart);
        }
    } else {
        sla.setExpectedStart(null);
    }
    // Setting expected end time
    String strRelExpectedEnd = getTagElement(eSla, "should-end");
    if (strRelExpectedEnd == null || strRelExpectedEnd.length() == 0) {
        throw new RuntimeException("should-end can't be empty");
    }
    int relExpectedEnd = Integer.parseInt(strRelExpectedEnd);
    if (relExpectedEnd < 0) {
        sla.setExpectedEnd(null);
    } else {
        Date expectedEnd = new Date(nominalTime.getTime() + relExpectedEnd * 60 * 1000);
        sla.setExpectedEnd(expectedEnd);
    }
    sla.setNotificationMsg(getTagElement(eSla, "notification-msg"));
    sla.setAlertContact(getTagElement(eSla, "alert-contact"));
    sla.setDevContact(getTagElement(eSla, "dev-contact"));
    sla.setQaContact(getTagElement(eSla, "qa-contact"));
    sla.setSeContact(getTagElement(eSla, "se-contact"));
    sla.setAlertFrequency(getTagElement(eSla, "alert-frequency"));
    sla.setAlertPercentage(getTagElement(eSla, "alert-percentage"));
    sla.setUpstreamApps(getTagElement(eSla, "upstream-apps"));
    // Oozie defined
    sla.setSlaId(slaId);
    sla.setAppType(appType);
    sla.setUser(user);
    sla.setGroupName(groupName);
    sla.setJobStatus(Status.CREATED);
    sla.setStatusTimestamp(new Date());
    return sla;
}
Also used : CommandException(org.apache.oozie.command.CommandException) SLAEventBean(org.apache.oozie.SLAEventBean) Date(java.util.Date)

Example 7 with SLAEventBean

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

the class TestSLADbOperations method testCreateSlaRegistrationEventMinReqFields.

@SuppressWarnings("deprecation")
public void testCreateSlaRegistrationEventMinReqFields() throws Exception {
    Date nomDate = DateUtils.parseDateOozieTZ("2014-01-01T01:01Z");
    String slaXML = " <sla:info xmlns:sla='uri:oozie:sla:0.2'>" + " <sla:nominal-time>" + DateUtils.formatDateOozieTZ(nomDate) + "</sla:nominal-time>" + " <sla:should-end>5</sla:should-end>" + "</sla:info>";
    Element eSla = XmlUtils.parseXml(slaXML);
    SLAEventBean regEvent = SLADbOperations.createSlaRegistrationEvent(eSla, null, "id1", SLAEvent.SlaAppType.WORKFLOW_JOB, "user1", "group1");
    assertEquals(SLAEvent.SlaAppType.WORKFLOW_JOB, regEvent.getAppType());
    assertEquals(new Date(nomDate.getTime() + 5 * 60 * 1000), regEvent.getExpectedEnd());
    assertEquals("group1", regEvent.getGroupName());
    assertEquals("id1", regEvent.getSlaId());
    assertEquals("user1", regEvent.getUser());
    regEvent = SLADbOperations.createSlaRegistrationEvent(eSla, "id1", SLAEvent.SlaAppType.WORKFLOW_JOB, "user1", "group1", null);
    assertEquals(SLAEvent.SlaAppType.WORKFLOW_JOB, regEvent.getAppType());
    assertEquals(new Date(nomDate.getTime() + 5 * 60 * 1000), regEvent.getExpectedEnd());
    assertEquals("group1", regEvent.getGroupName());
    assertEquals("id1", regEvent.getSlaId());
    assertEquals("user1", regEvent.getUser());
}
Also used : Element(org.jdom.Element) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean)

Example 8 with SLAEventBean

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

the class CoordActionCheckXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected Void execute() throws CommandException {
    try {
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        Status slaStatus = null;
        CoordinatorAction.Status initialStatus = coordAction.getStatus();
        if (workflowJob.getStatus() == WorkflowJob.Status.SUCCEEDED) {
            coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
            // set pending to false as the status is SUCCEEDED
            coordAction.setPending(0);
            slaStatus = Status.SUCCEEDED;
        } else {
            if (workflowJob.getStatus() == WorkflowJob.Status.FAILED) {
                coordAction.setStatus(CoordinatorAction.Status.FAILED);
                slaStatus = Status.FAILED;
                // set pending to false as the status is FAILED
                coordAction.setPending(0);
            } else {
                if (workflowJob.getStatus() == WorkflowJob.Status.KILLED) {
                    coordAction.setStatus(CoordinatorAction.Status.KILLED);
                    slaStatus = Status.KILLED;
                    // set pending to false as the status is KILLED
                    coordAction.setPending(0);
                } else if (workflowJob.getStatus() == WorkflowJob.Status.SUSPENDED) {
                    coordAction.setStatus(CoordinatorAction.Status.SUSPENDED);
                    slaStatus = Status.FAILED;
                    // set pending to false as the status is SUSPENDED
                    coordAction.setPending(0);
                } else {
                    LOG.warn("Unexpected workflow " + workflowJob.getId() + " STATUS " + workflowJob.getStatus());
                    coordAction.setLastModifiedTime(new Date());
                    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQueryExecutor.CoordActionQuery.UPDATE_COORD_ACTION_FOR_MODIFIED_DATE, coordAction);
                    return null;
                }
            }
        }
        LOG.debug("Updating Coordinator actionId :" + coordAction.getId() + "status to =" + coordAction.getStatus());
        coordAction.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
        if (slaStatus != null) {
            SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), slaStatus, SlaAppType.COORDINATOR_ACTION, LOG);
            if (slaEvent != null) {
                insertList.add(slaEvent);
            }
        }
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
        CoordinatorAction.Status endStatus = coordAction.getStatus();
        if (endStatus != initialStatus && EventHandlerService.isEnabled()) {
            generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), workflowJob.getStartTime());
        }
    } catch (XException ex) {
        LOG.warn("CoordActionCheckCommand Failed ", ex);
        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 9 with SLAEventBean

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

the class KillXCommand method execute.

@Override
protected Void execute() throws CommandException {
    LOG.info("STARTED WorkflowKillXCommand for jobId=" + wfId);
    wfJob.setEndTime(new Date());
    if (wfJob.getStatus() != WorkflowJob.Status.FAILED) {
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        wfJob.setStatus(WorkflowJob.Status.KILLED);
        SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), wfJob.getId(), Status.KILLED, SlaAppType.WORKFLOW_JOB);
        if (slaEvent != null) {
            insertList.add(slaEvent);
        }
        try {
            wfJob.getWorkflowInstance().kill();
        } catch (WorkflowException e) {
            throw new CommandException(ErrorCode.E0725, e.getMessage(), e);
        }
        WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
        ((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.KILLED);
        wfJob.setWorkflowInstance(wfInstance);
    }
    try {
        for (WorkflowActionBean action : actionList) {
            if (action.getStatus() == WorkflowActionBean.Status.RUNNING || action.getStatus() == WorkflowActionBean.Status.DONE) {
                if (!(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
                    action.setPending();
                }
                action.setStatus(WorkflowActionBean.Status.KILLED);
                updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
                queue(new ActionKillXCommand(action.getId(), action.getType()));
            } else if (action.getStatus() == WorkflowActionBean.Status.PREP || action.getStatus() == WorkflowActionBean.Status.START_RETRY || action.getStatus() == WorkflowActionBean.Status.START_MANUAL || action.getStatus() == WorkflowActionBean.Status.END_RETRY || action.getStatus() == WorkflowActionBean.Status.END_MANUAL || action.getStatus() == WorkflowActionBean.Status.USER_RETRY) {
                action.setStatus(WorkflowActionBean.Status.KILLED);
                action.resetPending();
                SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(action.getSlaXml(), action.getId(), Status.KILLED, SlaAppType.WORKFLOW_ACTION);
                if (slaEvent != null) {
                    insertList.add(slaEvent);
                }
                updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
                if (EventHandlerService.isEnabled() && !(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
                    generateEvent(action, wfJob.getUser());
                }
            }
        }
        wfJob.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfJob));
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
        if (EventHandlerService.isEnabled()) {
            generateEvent(wfJob);
        }
        queue(new WorkflowNotificationXCommand(wfJob));
    } catch (JPAExecutorException e) {
        throw new CommandException(e);
    } finally {
        if (wfJob.getStatus() == WorkflowJob.Status.KILLED) {
            // To delete the WF temp dir
            new WfEndXCommand(wfJob).call();
        }
        updateParentIfNecessary(wfJob);
    }
    LOG.info("ENDED WorkflowKillXCommand for jobId=" + wfId);
    return null;
}
Also used : WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) WorkflowException(org.apache.oozie.workflow.WorkflowException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) CommandException(org.apache.oozie.command.CommandException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) ControlNodeActionExecutor(org.apache.oozie.action.control.ControlNodeActionExecutor)

Example 10 with SLAEventBean

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

the class SignalXCommand method endWF.

private void endWF(List<JsonBean> insertList) throws CommandException {
    updateParentIfNecessary(wfJob, 3);
    // To delete the WF temp dir
    new WfEndXCommand(wfJob).call();
    SLAEventBean slaEvent2 = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), wfJob.getId(), Status.FAILED, SlaAppType.WORKFLOW_JOB);
    if (slaEvent2 != null) {
        insertList.add(slaEvent2);
    }
}
Also used : 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