Search in sources :

Example 16 with SLASummaryBean

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

the class TestSLASummaryQueryExecutor method testGet.

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

Example 17 with SLASummaryBean

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

the class TestSLASummaryQueryExecutor method testExecuteUpdate.

public void testExecuteUpdate() throws Exception {
    SLASummaryBean bean = addRecordToSLASummaryTable("test-sla-summary", SLAStatus.IN_PROCESS);
    SLASummaryBean retBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, bean.getId());
    Date createdTime = retBean.getCreatedTime();
    assertNotNull(createdTime);
    Date startTime = new Date(System.currentTimeMillis() - 1000 * 3600 * 2);
    Date endTime = new Date(System.currentTimeMillis() - 1000 * 3600 * 1);
    bean.setActualStart(startTime);
    bean.setActualEnd(endTime);
    bean.setSLAStatus(SLAStatus.MET);
    // Should not be updated
    bean.setCreatedTime(startTime);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, bean);
    retBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, bean.getId());
    assertEquals(bean.getActualStartTimestamp(), retBean.getActualStartTimestamp());
    assertEquals(bean.getActualEndTimestamp(), retBean.getActualEndTimestamp());
    assertEquals(SLAStatus.MET, retBean.getSLAStatus());
    // Created time should not be updated
    assertEquals(createdTime, retBean.getCreatedTime());
    // test UPDATE_SLA_SUMMARY_FOR_ACTUAL_TIMES
    bean = addRecordToSLASummaryTable("test-sla-summary", SLAStatus.IN_PROCESS);
    bean.setActualStart(startTime);
    bean.setActualStart(endTime);
    bean.setActualDuration(endTime.getTime() - startTime.getTime());
    bean.setLastModifiedTime(new Date());
    bean.setEventProcessed(8);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_STATUS_ACTUAL_TIMES, bean);
    retBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, bean.getId());
    assertEquals(bean.getActualStartTimestamp(), retBean.getActualStartTimestamp());
    assertEquals(bean.getActualEndTimestamp(), retBean.getActualEndTimestamp());
    assertEquals(bean.getActualDuration(), retBean.getActualDuration());
    assertEquals(bean.getLastModifiedTimestamp(), retBean.getLastModifiedTimestamp());
    assertEquals(bean.getEventProcessed(), retBean.getEventProcessed());
}
Also used : SLASummaryBean(org.apache.oozie.sla.SLASummaryBean) Date(java.util.Date)

Example 18 with SLASummaryBean

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

the class TestSLASummaryQueryExecutor method testUpdateQuery.

public void testUpdateQuery() throws Exception {
    EntityManager em = jpaService.getEntityManager();
    SLASummaryBean bean = addRecordToSLASummaryTable("test-sla-summary", SLAStatus.IN_PROCESS);
    // UPDATE_SLA_SUMMARY_FOR_STATUS_ACTUAL_TIMES
    Query query = SLASummaryQueryExecutor.getInstance().getUpdateQuery(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_STATUS_ACTUAL_TIMES, bean, em);
    assertEquals(query.getParameterValue("jobId"), bean.getId());
    assertEquals(query.getParameterValue("slaStatus"), bean.getSLAStatus().toString());
    assertEquals(query.getParameterValue("lastModifiedTS"), bean.getLastModifiedTimestamp());
    assertEquals(query.getParameterValue("eventStatus"), bean.getEventStatus().toString());
    assertEquals(query.getParameterValue("jobStatus"), bean.getJobStatus());
    assertEquals(query.getParameterValue("eventProcessed"), bean.getEventProcessed());
    assertEquals(query.getParameterValue("actualStartTS"), bean.getActualStartTimestamp());
    assertEquals(query.getParameterValue("actualEndTS"), bean.getActualEndTimestamp());
    assertEquals(query.getParameterValue("actualDuration"), bean.getActualDuration());
    // UPDATE_SLA_SUMMARY_REGISTRATION
    query = SLASummaryQueryExecutor.getInstance().getUpdateQuery(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, bean, em);
    assertEquals(query.getParameterValue("appName"), bean.getAppName());
    assertEquals(query.getParameterValue("appType"), bean.getAppType().toString());
    assertEquals(query.getParameterValue("nominalTime"), bean.getNominalTimestamp());
    assertEquals(query.getParameterValue("expectedStartTime"), bean.getExpectedStartTimestamp());
    assertEquals(query.getParameterValue("expectedEndTime"), bean.getExpectedEndTimestamp());
    assertEquals(query.getParameterValue("expectedDuration"), bean.getExpectedDuration());
    assertEquals(query.getParameterValue("jobStatus"), bean.getJobStatus());
    assertEquals(query.getParameterValue("slaStatus"), bean.getSLAStatus().toString());
    assertEquals(query.getParameterValue("eventStatus"), bean.getEventStatus().toString());
    assertEquals(query.getParameterValue("lastModTime"), bean.getLastModifiedTimestamp());
    assertEquals(query.getParameterValue("user"), bean.getUser());
    assertEquals(query.getParameterValue("parentId"), bean.getParentId());
    assertEquals(query.getParameterValue("eventProcessed"), bean.getEventProcessed());
    assertEquals(query.getParameterValue("actualDuration"), bean.getActualDuration());
    assertEquals(query.getParameterValue("actualEndTS"), bean.getActualEndTimestamp());
    assertEquals(query.getParameterValue("actualStartTS"), bean.getActualStartTimestamp());
    assertEquals(query.getParameterValue("jobId"), bean.getId());
    em.close();
}
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 19 with SLASummaryBean

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

the class DummySLACalculatorMemory method createDBEntryForStarted.

private SLASummaryBean createDBEntryForStarted(String actionId, Date expectedStartTS, Date expectedEndTS, int eventProcessed) throws Exception {
    ArrayList<JsonBean> insertList = new ArrayList<JsonBean>();
    Date modTime = new Date();
    WorkflowJobBean wf = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, actionId);
    wf.setStatus(wf.getStatus());
    wf.setStartTime(expectedStartTS);
    wf.setLastModifiedTime(modTime);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wf);
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    coordAction.setId(actionId);
    coordAction.setJobId(actionId.split("@", -1)[0]);
    coordAction.setStatusStr("RUNNING");
    coordAction.setLastModifiedTime(modTime);
    coordAction.setExternalId(wf.getId());
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(actionId.split("@", -1)[0]);
    coordJob.setUser("dummy");
    coordJob.setAppName("dummy");
    coordJob.setStatusStr("RUNNING");
    coordJob.setAppNamespace("dummy");
    SLASummaryBean sla = new SLASummaryBean();
    sla.setId(actionId);
    sla.setAppType(AppType.COORDINATOR_ACTION);
    sla.setJobStatus("RUNNING");
    sla.setSLAStatus(SLAStatus.IN_PROCESS);
    sla.setEventProcessed(eventProcessed);
    sla.setLastModifiedTime(modTime);
    sla.setExpectedStart(expectedStartTS);
    sla.setActualStart(expectedStartTS);
    sla.setExpectedEnd(expectedEndTS);
    sla.setExpectedDuration(10 * 60 * 1000);
    SLARegistrationBean reg = new SLARegistrationBean();
    reg.setId(actionId);
    insertList.add(coordAction);
    insertList.add(coordJob);
    insertList.add(sla);
    insertList.add(reg);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    return sla;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 20 with SLASummaryBean

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

the class DummySLACalculatorMemory method createDBEntry.

private void createDBEntry(String actionId, Date expectedStartTS, Date expectedEndTS) throws Exception {
    ArrayList<JsonBean> insertList = new ArrayList<JsonBean>();
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    Date modTime = new Date(System.currentTimeMillis() - 1000 * 3600 * 2);
    coordAction.setId(actionId);
    coordAction.setJobId(actionId.split("@", -1)[0]);
    coordAction.setStatusStr("WAITING");
    coordAction.setLastModifiedTime(modTime);
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(actionId.split("@", -1)[0]);
    coordJob.setUser("dummy");
    coordJob.setAppName("dummy");
    coordJob.setStatusStr("RUNNING");
    coordJob.setAppNamespace("dummy");
    SLASummaryBean sla = new SLASummaryBean();
    sla.setId(actionId);
    sla.setAppType(AppType.COORDINATOR_ACTION);
    sla.setJobStatus("WAITING");
    sla.setSLAStatus(SLAStatus.NOT_STARTED);
    sla.setEventProcessed(0);
    sla.setLastModifiedTime(modTime);
    sla.setExpectedStart(expectedStartTS);
    sla.setExpectedEnd(expectedEndTS);
    sla.setExpectedDuration(10 * 60 * 1000);
    SLARegistrationBean reg = new SLARegistrationBean();
    reg.setId(actionId);
    insertList.add(coordAction);
    insertList.add(coordJob);
    insertList.add(sla);
    insertList.add(reg);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) Date(java.util.Date) 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