use of org.apache.oozie.SLAEventBean in project oozie by apache.
the class SLAEventsGetForFilterJPAExecutor method execute.
@Override
@SuppressWarnings("unchecked")
public List<SLAEventBean> execute(EntityManager em) throws JPAExecutorException {
List<SLAEventBean> seBeans;
StringBuilder sb = new StringBuilder(selectStr);
Map<String, String> keyVal = new HashMap<String, String>();
for (Map.Entry<String, List<String>> entry : filter.entrySet()) {
if (entry.getKey().equals(OozieClient.FILTER_JOBID) || entry.getKey().equals(OozieClient.FILTER_APPNAME)) {
sb.append(" AND ");
}
if (entry.getKey().equals(OozieClient.FILTER_JOBID)) {
List<String> vals = entry.getValue();
if (vals.size() == 1) {
sb.append("w.slaId = :jobid");
keyVal.put("jobid", vals.get(0));
} else {
for (int i = 0; i < vals.size(); i++) {
String val = vals.get(i);
keyVal.put("jobid" + i, val);
if (i == 0) {
sb.append("w.slaId IN (:jobid" + i);
} else {
sb.append(",:jobid" + i);
}
}
sb.append(")");
}
} else if (entry.getKey().equals(OozieClient.FILTER_APPNAME)) {
List<String> vals = entry.getValue();
if (vals.size() == 1) {
sb.append("w.appName = :appname");
keyVal.put("appname", vals.get(0));
} else {
for (int i = 0; i < vals.size(); i++) {
String val = vals.get(i);
keyVal.put("appname" + i, val);
if (i == 0) {
sb.append("w.appName IN (:appname" + i);
} else {
sb.append(",:appname" + i);
}
}
sb.append(")");
}
}
}
sb.append(" ORDER BY w.event_id ");
try {
Query q = em.createQuery(sb.toString());
q.setMaxResults(len);
q.setParameter("seqid", seqId);
for (Map.Entry<String, String> entry : keyVal.entrySet()) {
q.setParameter(entry.getKey(), entry.getValue());
}
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 SLAEventsGetJPAExecutor method execute.
@Override
@SuppressWarnings("unchecked")
public List<SLAEventBean> execute(EntityManager em) throws JPAExecutorException {
List<SLAEventBean> seBeans;
try {
Query q = em.createNamedQuery("GET_SLA_EVENTS");
q.setMaxResults(limitLen);
seBeans = q.getResultList();
} 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 copyEventBean.
private SLAEventBean copyEventBean(SLAEventBean e) {
SLAEventBean event = new SLAEventBean();
event.setAlertContact(e.getAlertContact());
event.setAlertFrequency(e.getAlertFrequency());
event.setAlertPercentage(e.getAlertPercentage());
event.setAppName(e.getAppName());
event.setAppType(e.getAppType());
event.setAppTypeStr(e.getAppTypeStr());
event.setDevContact(e.getDevContact());
event.setEvent_id(e.getEvent_id());
event.setEventType(e.getEventType());
event.setExpectedEnd(e.getExpectedEnd());
event.setExpectedStart(e.getExpectedStart());
event.setGroupName(e.getGroupName());
event.setJobData(e.getJobData());
event.setJobStatus(e.getJobStatus());
event.setJobStatusStr(e.getJobStatusStr());
event.setNotificationMsg(e.getNotificationMsg());
event.setParentClientId(e.getParentClientId());
event.setParentSlaId(e.getParentSlaId());
event.setQaContact(e.getQaContact());
event.setSeContact(e.getSeContact());
event.setSlaId(e.getSlaId());
event.setStatusTimestamp(e.getStatusTimestamp());
event.setUpstreamApps(e.getUpstreamApps());
event.setUser(e.getUser());
return event;
}
use of org.apache.oozie.SLAEventBean in project oozie by apache.
the class SLADbOperations method createSlaRegistrationEvent.
public static SLAEventBean createSlaRegistrationEvent(Element eSla, String slaId, SlaAppType appType, String user, String groupName, XLog log) 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;
}
use of org.apache.oozie.SLAEventBean in project oozie by apache.
the class SLADbXOperations method createSlaStatusEvent.
/**
* Create SLA status event
*
* @param id SLA Id
* @param status SLA status
* @param appType SLA app type
* @return the event
* @throws Exception in case of error
*/
public static SLAEventBean createSlaStatusEvent(String id, Status status, SlaAppType appType) throws Exception {
SLAEventBean sla = new SLAEventBean();
sla.setSlaId(id);
sla.setJobStatus(status);
sla.setAppType(appType);
sla.setStatusTimestamp(new Date());
return sla;
}
Aggregations