Search in sources :

Example 1 with SLAEventBean

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

the class SLAServlet method doGet.

/**
 * Return information about SLA Events.
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Element eResponse = new Element("sla-message");
    List<SLAEventBean> slaEvntList = null;
    try {
        stopCron();
        String gtSequenceNum = request.getParameter(RestConstants.SLA_GT_SEQUENCE_ID);
        String strMaxEvents = request.getParameter(RestConstants.MAX_EVENTS);
        String filter = request.getParameter(RestConstants.JOBS_FILTER_PARAM);
        Map<String, List<String>> filterList = parseFilter(filter, SLA_FILTER_NAMES);
        // Default
        int maxNoEvents = 100;
        XLog.getLog(getClass()).debug("Got SLA GET request for :" + gtSequenceNum + " and max-events :" + strMaxEvents);
        if (strMaxEvents != null && strMaxEvents.length() > 0) {
            maxNoEvents = Integer.parseInt(strMaxEvents);
        }
        if (gtSequenceNum != null) {
            long seqId = Long.parseLong(gtSequenceNum);
            stopCron();
            SLAEventsXCommand seCommand = new SLAEventsXCommand(seqId, maxNoEvents, filterList);
            slaEvntList = seCommand.call();
            long lastSeqId = seCommand.getLastSeqId();
            eResponse = new Element("sla-message");
            for (SLAEventBean event : slaEvntList) {
                eResponse.addContent(event.toXml());
            }
            Element eLastSeq = new Element("last-sequence-id");
            eLastSeq.addContent(String.valueOf(lastSeqId));
            eResponse.addContent(eLastSeq);
            XLog.getLog(getClass()).debug("Writing back SLA Servlet  Caller with last-seq-id " + lastSeqId);
            startCron();
        } else {
            XLog.getLog(getClass()).error("gt-sequence-id parameter is not specified in the http request");
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0401, "gt-sequence-id parameter is not specified in the http request");
        }
        startCron();
        response.setContentType(XML_UTF8);
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().write(XmlUtils.prettyPrint(eResponse) + "\n");
    } catch (CommandException ce) {
        ce.printStackTrace();
        XLog.getLog(getClass()).error("Command exception ", ce);
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ce);
    } catch (RuntimeException re) {
        re.printStackTrace();
        XLog.getLog(getClass()).error("Runtime error ", re);
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0307, re.getMessage());
    }
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) List(java.util.List) CommandException(org.apache.oozie.command.CommandException) SLAEventsXCommand(org.apache.oozie.command.coord.SLAEventsXCommand) SLAEventBean(org.apache.oozie.SLAEventBean)

Example 2 with SLAEventBean

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

the class SLAEventsGetForSeqIdJPAExecutor method execute.

@Override
@SuppressWarnings("unchecked")
public List<SLAEventBean> execute(EntityManager em) throws JPAExecutorException {
    List<SLAEventBean> seBeans;
    try {
        Query q = em.createNamedQuery("GET_SLA_EVENT_NEWER_SEQ_LIMITED");
        q.setParameter("id", seqId);
        q.setMaxResults(limitLen);
        seBeans = q.getResultList();
        for (SLAEventBean j : seBeans) {
            lastSeqId[0] = Math.max(lastSeqId[0], j.getEvent_id());
        }
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
    return seBeans;
}
Also used : Query(javax.persistence.Query) SLAEventBean(org.apache.oozie.SLAEventBean)

Example 3 with SLAEventBean

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

the class SLAStore method getSLAEventListNewerSeqLimited.

/**
 * Get a list of SLA Events newer than a specific sequence with limit
 * clause.
 *
 * @param seqId sequence id
 * @return List of SLA Events
 * @throws StoreException
 */
public List<SLAEventBean> getSLAEventListNewerSeqLimited(final long seqId, final int limitLen, long[] lastSeqId) throws StoreException {
    ParamChecker.notNull(seqId, "SLAEventListNewerSeqLimited");
    ParamChecker.checkGTZero(limitLen, "SLAEventListNewerSeqLimited");
    lastSeqId[0] = seqId;
    List<SLAEventBean> seBeans = (List<SLAEventBean>) doOperation("getSLAEventListNewerSeqLimited", new Callable<List<SLAEventBean>>() {

        public List<SLAEventBean> call() throws StoreException, JPAExecutorException {
            List<SLAEventBean> seBeans;
            try {
                JPAService jpaService = Services.get().get(JPAService.class);
                List<SLAEventBean> slaEventList = null;
                long[] lastSeqId = new long[1];
                if (jpaService != null) {
                    seBeans = jpaService.execute(new SLAEventsGetForSeqIdJPAExecutor(seqId, limitLen, lastSeqId));
                } else {
                    throw new StoreException(ErrorCode.E0610);
                }
            } catch (IllegalStateException e) {
                throw new StoreException(ErrorCode.E0601, e.getMessage(), e);
            } catch (JPAExecutorException e) {
                throw new JPAExecutorException(ErrorCode.E0610, e.getMessage(), e);
            }
            return seBeans;
        }
    });
    List<SLAEventBean> eventList = new ArrayList<SLAEventBean>();
    for (SLAEventBean j : seBeans) {
        lastSeqId[0] = Math.max(lastSeqId[0], j.getEvent_id());
        eventList.add(j);
    }
    return eventList;
}
Also used : SLAEventsGetForSeqIdJPAExecutor(org.apache.oozie.executor.jpa.SLAEventsGetForSeqIdJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) SLAEventBean(org.apache.oozie.SLAEventBean) Callable(java.util.concurrent.Callable)

Example 4 with SLAEventBean

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

the class SLADbOperations method createSlaStatusEvent.

public static SLAEventBean createSlaStatusEvent(String id, Status status, SlaAppType appType, String appName, XLog log) throws Exception {
    SLAEventBean sla = new SLAEventBean();
    sla.setSlaId(id);
    sla.setJobStatus(status);
    sla.setAppType(appType);
    sla.setAppName(appName);
    sla.setStatusTimestamp(new Date());
    return sla;
}
Also used : SLAEventBean(org.apache.oozie.SLAEventBean) Date(java.util.Date)

Example 5 with SLAEventBean

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

the class SLADbOperations method createSlaRegistrationEvent.

public static SLAEventBean createSlaRegistrationEvent(Element eSla, Store store, String slaId, SlaAppType appType, String user, String groupName) throws Exception {
    if (eSla == null) {
        return null;
    }
    SLAEventBean sla = new SLAEventBean();
    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) {
        // TODO:
        throw new RuntimeException("Nominal time is required");
    // change to
    // CommandException
    }
    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 : SLAEventBean(org.apache.oozie.SLAEventBean) Date(java.util.Date)

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