Search in sources :

Example 1 with FILTER_COMPARATORS

use of org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS in project oozie by apache.

the class TestCoordJobGetActionsSubsetJPAExecutor method testCoordActionFilter.

// Check status filters for Coordinator actions
public void testCoordActionFilter() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    // Add Coordinator action with nominal time: 2009-12-15T01:00Z
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    // Add Coordinator action with nominal time: 2009-02-01T23:59Z
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0);
    // Create lists for status filter to test positive filter
    Map<Pair<String, FILTER_COMPARATORS>, List<Object>> filterMap = new HashMap<Pair<String, FILTER_COMPARATORS>, List<Object>>();
    List<Object> positiveFilter = new ArrayList<Object>();
    positiveFilter.add("RUNNING");
    positiveFilter.add("KILLED");
    filterMap.put(POSITIVE_STATUS_FILTER, positiveFilter);
    List<CoordinatorActionBean> actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 1);
    assertEquals(actions.get(0).getActionNumber(), 1);
    // Create lists for status filter to test negative filter
    filterMap.clear();
    List<Object> negativeFilter = new ArrayList<Object>();
    negativeFilter.add("WAITING");
    negativeFilter.add("KILLED");
    filterMap.put(NEGATIVE_STATUS_FILTER, negativeFilter);
    actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 1);
    assertEquals(actions.get(0).getActionNumber(), 1);
    // Test Combination of include/exclude filters - no dup
    filterMap.clear();
    filterMap.put(POSITIVE_STATUS_FILTER, positiveFilter);
    filterMap.put(NEGATIVE_STATUS_FILTER, negativeFilter);
    actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 1);
    assertEquals(actions.get(0).getActionNumber(), 1);
    // Test Combination of include/exclude filters - dup --> no result
    filterMap.clear();
    filterMap.put(POSITIVE_STATUS_FILTER, positiveFilter);
    filterMap.put(NEGATIVE_STATUS_FILTER, positiveFilter);
    actions = _testGetActionsSubsetFilter(job.getId(), 1, filterMap, 1, 2);
    assertEquals(actions.size(), 0);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) FILTER_COMPARATORS(org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS) HashMap(java.util.HashMap) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.apache.oozie.util.Pair)

Example 2 with FILTER_COMPARATORS

use of org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS in project oozie by apache.

the class TestCoordJobGetActionsSubsetJPAExecutor method testGetActionsWithNominalTimeFilter.

public void testGetActionsWithNominalTimeFilter() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    String[] timeStr = { "2009-02-01T00:00Z", "2009-02-01T05:00Z", "2009-02-01T10:00Z", "2009-02-01T15:00Z" };
    Date[] ntime = { getSqlTime(timeStr[0]), getSqlTime(timeStr[1]), getSqlTime(timeStr[2]), getSqlTime(timeStr[3]) };
    List<String> actionIds = new ArrayList<String>(timeStr.length);
    int startAction = 5;
    for (Date time : ntime) {
        CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), startAction++, Status.WAITING, "coord-action-get.xml", 0, time);
        actionIds.add(action.getId());
    }
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    // Filter with nominalTime >=, asc
    Map<Pair<String, FILTER_COMPARATORS>, List<Object>> filterMap = new HashMap<Pair<String, FILTER_COMPARATORS>, List<Object>>();
    filterMap.put(Pair.of(OozieClient.FILTER_NOMINAL_TIME, FILTER_COMPARATORS.GREATER_EQUAL), getList(ntime[2]));
    CoordJobGetActionsSubsetJPAExecutor actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 10, false);
    List<CoordinatorActionBean> actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(2), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(3), actions.get(1).getId());
    // Filter with nominalTime >=, desc
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 10, true);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(3), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(2), actions.get(1).getId());
    // Filter with nominalTime <, asc
    filterMap.clear();
    filterMap.put(Pair.of(OozieClient.FILTER_NOMINAL_TIME, FILTER_COMPARATORS.LESSTHAN), getList(ntime[2]));
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 10, false);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(0), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(1), actions.get(1).getId());
    // Filter with nominalTime <, desc
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 10, true);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(1), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(0), actions.get(1).getId());
    // Filter with nominalTime >=, nominalTime <, asc
    filterMap.put(Pair.of(OozieClient.FILTER_NOMINAL_TIME, FILTER_COMPARATORS.GREATER_EQUAL), getList(ntime[1]));
    filterMap.put(Pair.of(OozieClient.FILTER_NOMINAL_TIME, FILTER_COMPARATORS.LESSTHAN), getList(ntime[3]));
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 10, false);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(1), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(2), actions.get(1).getId());
    // Filter with nominalTime >=, nominalTime <, desc
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 10, true);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(2), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(1), actions.get(1).getId());
    // Filter with nominalTime >=, nominalTime <, desc, offset
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 2, 10, true);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(1, actions.size());
    Assert.assertEquals(actionIds.get(1), actions.get(0).getId());
    // Filter with nominalTime >=, nominalTime <, asc, offset
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 2, 10, false);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(1, actions.size());
    Assert.assertEquals(actionIds.get(2), actions.get(0).getId());
    // Filter with nominalTime >=, nominalTime <, desc, len
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 2, true);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(2), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(1), actions.get(1).getId());
    // Filter with nominalTime >=, nominalTime <, asc, len
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 2, false);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(1), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(2), actions.get(1).getId());
    // Filter with nominalTime >=, nominalTime <, asc, offset, len
    filterMap.put(Pair.of(OozieClient.FILTER_NOMINAL_TIME, FILTER_COMPARATORS.LESSTHAN), getList(getSqlTime("2009-02-01T23:00Z")));
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 2, 2, false);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(2), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(3), actions.get(1).getId());
    // Filter with nominalTime >=, nominalTime <, desc, offset, len
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 2, 2, true);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(2, actions.size());
    Assert.assertEquals(actionIds.get(2), actions.get(0).getId());
    Assert.assertEquals(actionIds.get(1), actions.get(1).getId());
    // Filter with nominalTime and status
    filterMap.put(Pair.of(OozieClient.FILTER_STATUS, FILTER_COMPARATORS.EQUALS), getList(Status.SUCCEEDED.name()));
    actionGetCmd = new CoordJobGetActionsSubsetJPAExecutor(job.getId(), filterMap, 1, 10, true);
    actions = jpaService.execute(actionGetCmd);
    Assert.assertEquals(0, actions.size());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) FILTER_COMPARATORS(org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS) ArrayList(java.util.ArrayList) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) Pair(org.apache.oozie.util.Pair)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 FILTER_COMPARATORS (org.apache.oozie.CoordinatorEngine.FILTER_COMPARATORS)2 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)2 Pair (org.apache.oozie.util.Pair)2 Date (java.util.Date)1 JPAService (org.apache.oozie.service.JPAService)1