Search in sources :

Example 1 with SLAEventsXCommand

use of org.apache.oozie.command.coord.SLAEventsXCommand 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 SLAEventBean (org.apache.oozie.SLAEventBean)1 CommandException (org.apache.oozie.command.CommandException)1 SLAEventsXCommand (org.apache.oozie.command.coord.SLAEventsXCommand)1 Element (org.jdom.Element)1