Search in sources :

Example 26 with SLAEventBean

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;
}
Also used : Query(javax.persistence.Query) HashMap(java.util.HashMap) SLAEventBean(org.apache.oozie.SLAEventBean) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 27 with SLAEventBean

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;
}
Also used : Query(javax.persistence.Query) SLAEventBean(org.apache.oozie.SLAEventBean)

Example 28 with SLAEventBean

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;
}
Also used : SLAEventBean(org.apache.oozie.SLAEventBean)

Example 29 with SLAEventBean

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;
}
Also used : SLAEventBean(org.apache.oozie.SLAEventBean) Date(java.util.Date)

Example 30 with SLAEventBean

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;
}
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