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());
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations