Search in sources :

Example 21 with SLASummaryBean

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

the class DummySLACalculatorMemory method testNoDuplicateEventsInHA.

public void testNoDuplicateEventsInHA() throws Exception {
    String id1 = "0000001-130521183438837-oozie-test-C@1";
    SLAService slas = Services.get().get(SLAService.class);
    SLACalculatorMemory slaCalcMem = (SLACalculatorMemory) slas.getSLACalculator();
    // loads the job in sla map
    slaCalcMem.init(Services.get().getConf());
    EventHandlerService ehs = Services.get().get(EventHandlerService.class);
    EventQueue ehs_q = ehs.getEventQueue();
    DummyZKOozie dummyOozie_1 = null;
    try {
        // start another dummy oozie instance (dummy sla and event handler services)
        dummyOozie_1 = new DummyZKOozie("a", "http://blah");
        DummySLACalculatorMemory dummySlaCalcMem = new DummySLACalculatorMemory();
        dummySlaCalcMem.init(Services.get().getConf());
        EventHandlerService dummyEhs = new EventHandlerService();
        dummySlaCalcMem.setEventHandlerService(dummyEhs);
        dummyEhs.init(Services.get());
        EventQueue dummyEhs_q = dummyEhs.getEventQueue();
        // get MISS
        Date expectedStartTS = new Date(System.currentTimeMillis() + 2 * 3600 * 1000);
        // get MISS
        Date expectedEndTS = new Date(System.currentTimeMillis() + 1 * 3600 * 1000);
        SLASummaryBean sla = createDBEntryForStarted(id1, expectedStartTS, expectedEndTS, 0);
        sla.setExpectedDuration(-1);
        sla.setLastModifiedTime(new Date());
        SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_EXPECTED_TIMES, sla);
        // Action started on Server 1
        updateCoordAction(id1, "RUNNING");
        slaCalcMem.addJobStatus(id1, CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(), null);
        assertEquals(1, ehs_q.size());
        SLACalcStatus s1 = (SLACalcStatus) ehs_q.poll();
        assertEquals(SLAStatus.IN_PROCESS, s1.getSLAStatus());
        // Action ended on Server 2
        updateCoordAction(id1, "FAILED");
        dummySlaCalcMem.addJobStatus(id1, CoordinatorAction.Status.FAILED.name(), EventStatus.FAILURE, new Date(System.currentTimeMillis() - 1800 * 1000), new Date());
        SLACalcStatus s2 = (SLACalcStatus) dummyEhs_q.poll();
        assertEquals(SLAStatus.MISS, s2.getSLAStatus());
        slaCalcMem.updateAllSlaStatus();
        dummySlaCalcMem.updateAllSlaStatus();
        // no dupe event should be created again by Server 1
        assertEquals(0, ehs_q.size());
    } finally {
        if (dummyOozie_1 != null) {
            dummyOozie_1.teardown();
        }
    }
}
Also used : TestSLAService(org.apache.oozie.sla.TestSLAService) SLAService(org.apache.oozie.sla.service.SLAService) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) SLACalculatorMemory(org.apache.oozie.sla.SLACalculatorMemory) EventQueue(org.apache.oozie.event.EventQueue) Date(java.util.Date) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 22 with SLASummaryBean

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

the class XDataTestCase method addRecordToSLASummaryTable.

/**
 * Insert sla summary for test
 * @param appName application name
 * @param status  sla status
 * @return
 * @throws Exception
 */
protected SLASummaryBean addRecordToSLASummaryTable(String appName, SLAStatus status) throws Exception {
    SLASummaryBean sla = new SLASummaryBean();
    Date today = new Date();
    sla.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.COORDINATOR));
    sla.setAppName(appName);
    sla.setAppType(AppType.COORDINATOR_JOB);
    sla.setCreatedTime(today);
    sla.setNominalTime(today);
    sla.setExpectedStart(today);
    sla.setExpectedEnd(today);
    sla.setExpectedDuration(100);
    sla.setJobStatus("RUNNING");
    sla.setSLAStatus(status);
    sla.setEventStatus(EventStatus.START_MET);
    sla.setLastModifiedTime(today);
    sla.setUser("oozie");
    sla.setParentId(Services.get().get(UUIDService.class).generateId(ApplicationType.BUNDLE));
    sla.setEventProcessed(1);
    sla.setActualStart(today);
    sla.setActualEnd(today);
    sla.setActualDuration(100);
    try {
        SLASummaryQueryExecutor.getInstance().insert(sla);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test sla event record to table");
        throw je;
    }
    return sla;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean) Date(java.util.Date)

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