Search in sources :

Example 16 with Pair

use of org.apache.oozie.util.Pair in project oozie by apache.

the class TestSLACalculatorMemory method testDisablingAlertsEvents.

@SuppressWarnings("serial")
public void testDisablingAlertsEvents() throws Exception {
    SLAService slaService = Services.get().get(SLAService.class);
    EventHandlerService ehs = Services.get().get(EventHandlerService.class);
    SLACalculator slaCalculator = slaService.getSLACalculator();
    // create dummy sla records and coord action records
    String id1 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 1);
    String id2 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 2);
    SLACalcStatus slaCalcObj1 = slaCalculator.get(id1);
    assertFalse(slaCalcObj1.getSLAConfigMap().containsKey(OozieClient.SLA_DISABLE_ALERT));
    SLACalcStatus slaCalcObj2 = slaCalculator.get(id2);
    assertFalse(slaCalcObj2.getSLAConfigMap().containsKey(OozieClient.SLA_DISABLE_ALERT));
    slaCalculator.updateAllSlaStatus();
    assertTrue(ehs.getEventQueue().size() > 0);
    // check that SLACalculator sends no event
    ehs.getEventQueue().clear();
    SLASummaryBean persistentSla = new SLASummaryBean(slaCalcObj1);
    // reset eventProcessed for the sla calc objects
    persistentSla.setEventProcessed(0);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, persistentSla);
    persistentSla = new SLASummaryBean(slaCalcObj2);
    persistentSla.setEventProcessed(0);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, persistentSla);
    // CASE I : list of sla ids, no new params
    slaService.enableChildJobAlert(Arrays.asList(id1, id2));
    slaCalculator.updateAllSlaStatus();
    assertTrue(ehs.getEventQueue().isEmpty());
    // CASE II : ALL
    _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 3);
    _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 4);
    slaCalculator.enableChildJobAlert(Arrays.asList("00020-1234567-wrkf-C"));
    slaCalculator.updateAllSlaStatus();
    assertFalse(ehs.getEventQueue().isEmpty());
    // CASE III : resume w/ new params
    final String id5 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 5);
    Date now = new Date();
    now.setTime(now.getTime() - 10 * 60 * 1000);
    final String newParams = RestConstants.SLA_NOMINAL_TIME + "=" + DateUtils.formatDateOozieTZ(now) + ";" + RestConstants.SLA_SHOULD_END + "=5";
    slaCalculator.changeDefinition(new ArrayList<Pair<String, Map<String, String>>>() {

        {
            add(new Pair<String, Map<String, String>>(id5, JobUtils.parseChangeValue(newParams)));
        }
    });
    slaCalculator.updateAllSlaStatus();
    assertTrue(ehs.getEventQueue().size() > 0);
}
Also used : EventHandlerService(org.apache.oozie.service.EventHandlerService) SLAService(org.apache.oozie.sla.service.SLAService) Date(java.util.Date) Pair(org.apache.oozie.util.Pair)

Aggregations

Pair (org.apache.oozie.util.Pair)16 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)6 ActionDependency (org.apache.oozie.dependency.ActionDependency)6 List (java.util.List)5 Map (java.util.Map)5 Configuration (org.apache.hadoop.conf.Configuration)5 Date (java.util.Date)4 XConfiguration (org.apache.oozie.util.XConfiguration)4 File (java.io.File)3 FileWriter (java.io.FileWriter)3 Reader (java.io.Reader)3 Writer (java.io.Writer)3 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)3 CommandException (org.apache.oozie.command.CommandException)3 JPAService (org.apache.oozie.service.JPAService)3 SLAService (org.apache.oozie.sla.service.SLAService)3 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)2 FILTER_COMPARATORS (org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS)2