Search in sources :

Example 6 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class TestV2SLAServlet method insertEntriesIntoSLASummaryTable.

private void insertEntriesIntoSLASummaryTable(String jobID, String parentId, String appName, AppType appType, EventStatus eventStatus, SLAStatus slaStatus, Date expectedStartTime, Date actualStartTime, long expectedDuration, long actualDuration, Date expectedEndTime, Date actualEndTime, Date nominalTime) throws JPAExecutorException {
    SLASummaryBean bean = new SLASummaryBean();
    bean.setId(jobID);
    bean.setParentId(parentId);
    bean.setAppName(appName);
    bean.setAppType(appType);
    bean.setJobStatus("RUNNING");
    bean.setEventStatus(eventStatus);
    bean.setSLAStatus(slaStatus);
    bean.setNominalTime(nominalTime);
    bean.setExpectedStart(expectedStartTime);
    bean.setActualStart(actualStartTime);
    bean.setExpectedDuration(expectedDuration);
    bean.setActualDuration(actualDuration);
    bean.setExpectedEnd(expectedEndTime);
    bean.setActualEnd(actualEndTime);
    bean.setUser("testuser");
    bean.setLastModifiedTime(Calendar.getInstance().getTime());
    SLASummaryQueryExecutor.getInstance().insert(bean);
}
Also used : SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 7 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class SLAJobHistoryXCommand method updateSLASummary.

/**
 * Update sla summary.
 *
 * @param id the id
 * @param startTime the start time
 * @param endTime the end time
 * @param status the status
 * @throws JPAExecutorException the JPA executor exception
 */
protected void updateSLASummary(String id, Date startTime, Date endTime, String status) throws JPAExecutorException {
    SLASummaryBean sla = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, id);
    if (sla.getJobStatus().equals(status) && sla.getEventProcessed() == 8) {
        LOG.debug("SLA job is already updated", sla.getId(), sla.getEventProcessed(), sla.getJobStatus());
        return;
    }
    if (sla != null) {
        sla.setActualStart(startTime);
        sla.setActualEnd(endTime);
        if (startTime != null && endTime != null) {
            sla.setActualDuration(endTime.getTime() - startTime.getTime());
        }
        sla.setLastModifiedTime(new Date());
        sla.setEventProcessed(8);
        sla.setJobStatus(status);
        SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_STATUS_ACTUAL_TIMES, sla);
        LOG.debug(" Stored SLA SummaryBean Job [{0}] eventProc = [{1}], status = [{2}]", sla.getId(), sla.getEventProcessed(), sla.getJobStatus());
    }
}
Also used : SLASummaryBean(org.apache.oozie.sla.SLASummaryBean) Date(java.util.Date)

Example 8 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class TestSLASummaryQueryExecutor method testGetQuery.

public void testGetQuery() throws Exception {
    EntityManager em = jpaService.getEntityManager();
    SLASummaryBean bean = addRecordToSLASummaryTable("test-sla-summary", SLAStatus.IN_PROCESS);
    // GET_SLA_SUMMARY
    Query query = SLASummaryQueryExecutor.getInstance().getSelectQuery(SLASummaryQuery.GET_SLA_SUMMARY, em, bean.getId());
    assertEquals(query.getParameterValue("id"), bean.getId());
    // GET_SLA_SUMMARY_EVENTPROCESSED
    query = SLASummaryQueryExecutor.getInstance().getSelectQuery(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, em, bean.getId());
    assertEquals(query.getParameterValue("id"), bean.getId());
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 9 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class TestSLASummaryQueryExecutor method testGetValue.

public void testGetValue() throws Exception {
    SLASummaryBean bean = addRecordToSLASummaryTable("test-sla-summary", SLAStatus.IN_PROCESS);
    // GET_SLA_REG_ON_RESTART
    Object ret = ((SLASummaryQueryExecutor) SLASummaryQueryExecutor.getInstance()).getSingleValue(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, bean.getId());
    assertEquals(bean.getEventProcessed(), ((Byte) ret).byteValue());
}
Also used : SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 10 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class CoordChangeXCommand method deleteAction.

/**
 * Delete coordinator action
 *
 * @param actionNum coordinator action number
 */
private Date deleteAction(int actionNum, Date afterDate) throws CommandException {
    try {
        if (actionNum <= 0) {
            return null;
        }
        String actionId = jobId + "@" + actionNum;
        CoordinatorActionBean bean = CoordActionQueryExecutor.getInstance().getIfExist(CoordActionQueryExecutor.CoordActionQuery.GET_COORD_ACTION, actionId);
        if (bean == null) {
            return null;
        }
        if (afterDate.compareTo(bean.getNominalTime()) <= 0) {
            if (bean.getStatus() == CoordinatorAction.Status.WAITING || bean.getStatus() == CoordinatorAction.Status.READY) {
                // delete SLA registration entry (if any) for action
                if (SLAService.isEnabled()) {
                    Services.get().get(SLAService.class).removeRegistration(actionId);
                }
                SLARegistrationBean slaReg = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, actionId);
                if (slaReg != null) {
                    LOG.debug("Deleting registration bean corresponding to action " + slaReg.getId());
                    deleteList.add(slaReg);
                }
                SLASummaryBean slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, actionId);
                if (slaSummaryBean != null) {
                    LOG.debug("Deleting summary bean corresponding to action " + slaSummaryBean.getId());
                    deleteList.add(slaSummaryBean);
                }
                deleteList.add(bean);
            } else {
                throw new CommandException(ErrorCode.E1022, bean.getId());
            }
            return bean.getNominalTime();
        } else {
            return null;
        }
    } catch (JPAExecutorException e) {
        throw new CommandException(e);
    }
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) SLAService(org.apache.oozie.sla.service.SLAService) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CommandException(org.apache.oozie.command.CommandException) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Aggregations

SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)22 Date (java.util.Date)8 Query (javax.persistence.Query)8 EntityManager (javax.persistence.EntityManager)6 JPAService (org.apache.oozie.service.JPAService)6 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)6 ArrayList (java.util.ArrayList)5 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)5 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 JsonBean (org.apache.oozie.client.rest.JsonBean)4 SLARegQuery (org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery)3 SLASummaryQuery (org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery)3 Timestamp (java.sql.Timestamp)2 List (java.util.List)2 Map (java.util.Map)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 CommandException (org.apache.oozie.command.CommandException)2 SLAService (org.apache.oozie.sla.service.SLAService)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1