Search in sources :

Example 6 with TimelineKeyValueFilter

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter in project hadoop by apache.

the class TimelineStorageUtils method matchFilters.

/**
   * Common routine to match different filters. Iterates over a filter list and
   * calls routines based on filter type.
   *
   * @param entity Timeline entity.
   * @param filters filter list.
   * @param entityFiltersType type of filters which are being matched.
   * @return a boolean flag to indicate if filter matches.
   * @throws IOException if an unsupported filter for matching this specific
   *     filter is being matched.
   */
private static boolean matchFilters(TimelineEntity entity, TimelineFilterList filters, TimelineEntityFiltersType entityFiltersType) throws IOException {
    if (filters == null || filters.getFilterList().isEmpty()) {
        return false;
    }
    TimelineFilterList.Operator operator = filters.getOperator();
    for (TimelineFilter filter : filters.getFilterList()) {
        TimelineFilterType filterType = filter.getFilterType();
        if (!entityFiltersType.isValidFilter(filterType)) {
            throw new IOException("Unsupported filter " + filterType);
        }
        boolean matched = false;
        switch(filterType) {
            case LIST:
                matched = matchFilters(entity, (TimelineFilterList) filter, entityFiltersType);
                break;
            case COMPARE:
                matched = matchCompareFilter(entity, (TimelineCompareFilter) filter, entityFiltersType);
                break;
            case EXISTS:
                matched = matchExistsFilter(entity, (TimelineExistsFilter) filter, entityFiltersType);
                break;
            case KEY_VALUE:
                matched = matchKeyValueFilter(entity, (TimelineKeyValueFilter) filter, entityFiltersType);
                break;
            case KEY_VALUES:
                matched = matchKeyValuesFilter(entity, (TimelineKeyValuesFilter) filter, entityFiltersType);
                break;
            default:
                throw new IOException("Unsupported filter " + filterType);
        }
        if (!matched) {
            if (operator == TimelineFilterList.Operator.AND) {
                return false;
            }
        } else {
            if (operator == TimelineFilterList.Operator.OR) {
                return true;
            }
        }
    }
    return operator == TimelineFilterList.Operator.AND;
}
Also used : TimelineKeyValueFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter) TimelineKeyValuesFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList) TimelineFilterType(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilter.TimelineFilterType) TimelineCompareFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareFilter) TimelineFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilter) IOException(java.io.IOException) TimelineExistsFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineExistsFilter)

Example 7 with TimelineKeyValueFilter

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter in project hadoop by apache.

the class TestFileSystemTimelineReaderImpl method testGetFilteredEntities.

@Test
public void testGetFilteredEntities() throws Exception {
    // Get entities based on info filters.
    TimelineFilterList infoFilterList = new TimelineFilterList();
    infoFilterList.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "info2", 3.5));
    Set<TimelineEntity> result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList, null, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    // Only one entity with ID id_3 should be returned.
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_3")) {
            Assert.fail("Incorrect filtering based on info filters");
        }
    }
    // Get entities based on config filters.
    TimelineFilterList confFilterList = new TimelineFilterList();
    confFilterList.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_1", "123"));
    confFilterList.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_3", "abc"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, confFilterList, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_3")) {
            Assert.fail("Incorrect filtering based on config filters");
        }
    }
    // Get entities based on event filters.
    TimelineFilterList eventFilters = new TimelineFilterList();
    eventFilters.addFilter(new TimelineExistsFilter(TimelineCompareOp.EQUAL, "event_2"));
    eventFilters.addFilter(new TimelineExistsFilter(TimelineCompareOp.EQUAL, "event_4"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, null, null, eventFilters), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_3")) {
            Assert.fail("Incorrect filtering based on event filters");
        }
    }
    // Get entities based on metric filters.
    TimelineFilterList metricFilterList = new TimelineFilterList();
    metricFilterList.addFilter(new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "metric3", 0L));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, null, metricFilterList, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    // Two entities with IDs' id_1 and id_2 should be returned.
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1") && !entity.getId().equals("id_2")) {
            Assert.fail("Incorrect filtering based on metric filters");
        }
    }
    // Get entities based on complex config filters.
    TimelineFilterList list1 = new TimelineFilterList();
    list1.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_1", "129"));
    list1.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_3", "def"));
    TimelineFilterList list2 = new TimelineFilterList();
    list2.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_2", "23"));
    list2.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_3", "abc"));
    TimelineFilterList confFilterList1 = new TimelineFilterList(Operator.OR, list1, list2);
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, confFilterList1, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1") && !entity.getId().equals("id_2")) {
            Assert.fail("Incorrect filtering based on config filters");
        }
    }
    TimelineFilterList list3 = new TimelineFilterList();
    list3.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "config_1", "123"));
    list3.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "config_3", "abc"));
    TimelineFilterList list4 = new TimelineFilterList();
    list4.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_2", "23"));
    TimelineFilterList confFilterList2 = new TimelineFilterList(Operator.OR, list3, list4);
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, confFilterList2, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1") && !entity.getId().equals("id_2")) {
            Assert.fail("Incorrect filtering based on config filters");
        }
    }
    TimelineFilterList confFilterList3 = new TimelineFilterList();
    confFilterList3.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "config_1", "127"));
    confFilterList3.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "config_3", "abc"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, confFilterList3, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_2")) {
            Assert.fail("Incorrect filtering based on config filters");
        }
    }
    TimelineFilterList confFilterList4 = new TimelineFilterList();
    confFilterList4.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_dummy", "dummy"));
    confFilterList4.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_3", "def"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, confFilterList4, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(0, result.size());
    TimelineFilterList confFilterList5 = new TimelineFilterList(Operator.OR);
    confFilterList5.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_dummy", "dummy"));
    confFilterList5.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "config_3", "def"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, confFilterList5, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_2")) {
            Assert.fail("Incorrect filtering based on config filters");
        }
    }
    // Get entities based on complex metric filters.
    TimelineFilterList list6 = new TimelineFilterList();
    list6.addFilter(new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "metric1", 200));
    list6.addFilter(new TimelineCompareFilter(TimelineCompareOp.EQUAL, "metric3", 23));
    TimelineFilterList list7 = new TimelineFilterList();
    list7.addFilter(new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "metric2", 74));
    TimelineFilterList metricFilterList1 = new TimelineFilterList(Operator.OR, list6, list7);
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, null, metricFilterList1, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    // Two entities with IDs' id_2 and id_3 should be returned.
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_2") && !entity.getId().equals("id_3")) {
            Assert.fail("Incorrect filtering based on metric filters");
        }
    }
    TimelineFilterList metricFilterList2 = new TimelineFilterList();
    metricFilterList2.addFilter(new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "metric2", 70));
    metricFilterList2.addFilter(new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "metric3", 23));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, null, metricFilterList2, null), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1")) {
            Assert.fail("Incorrect filtering based on metric filters");
        }
    }
    TimelineFilterList metricFilterList3 = new TimelineFilterList();
    metricFilterList3.addFilter(new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "dummy_metric", 30));
    metricFilterList3.addFilter(new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "metric3", 23));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, null, metricFilterList3, null), new TimelineDataToRetrieve());
    Assert.assertEquals(0, result.size());
    TimelineFilterList metricFilterList4 = new TimelineFilterList(Operator.OR);
    metricFilterList4.addFilter(new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "dummy_metric", 30));
    metricFilterList4.addFilter(new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "metric3", 23));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, null, metricFilterList4, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1") && !entity.getId().equals("id_2")) {
            Assert.fail("Incorrect filtering based on metric filters");
        }
    }
    TimelineFilterList metricFilterList5 = new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "metric2", 74));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, null, null, metricFilterList5, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1") && !entity.getId().equals("id_2")) {
            Assert.fail("Incorrect filtering based on metric filters");
        }
    }
    TimelineFilterList infoFilterList1 = new TimelineFilterList();
    infoFilterList1.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "info2", 3.5));
    infoFilterList1.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "info4", 20));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList1, null, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(0, result.size());
    TimelineFilterList infoFilterList2 = new TimelineFilterList(Operator.OR);
    infoFilterList2.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "info2", 3.5));
    infoFilterList2.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "info1", "val1"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList2, null, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1") && !entity.getId().equals("id_3")) {
            Assert.fail("Incorrect filtering based on info filters");
        }
    }
    TimelineFilterList infoFilterList3 = new TimelineFilterList();
    infoFilterList3.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "dummy_info", 1));
    infoFilterList3.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "info2", "val5"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList3, null, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(0, result.size());
    TimelineFilterList infoFilterList4 = new TimelineFilterList(Operator.OR);
    infoFilterList4.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "dummy_info", 1));
    infoFilterList4.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "info2", "val5"));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList4, null, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1")) {
            Assert.fail("Incorrect filtering based on info filters");
        }
    }
}
Also used : TimelineKeyValueFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList) TimelineReaderContext(org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderContext) TimelineEntityFilters(org.apache.hadoop.yarn.server.timelineservice.reader.TimelineEntityFilters) TimelineCompareFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareFilter) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) TimelineExistsFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineExistsFilter) TimelineDataToRetrieve(org.apache.hadoop.yarn.server.timelineservice.reader.TimelineDataToRetrieve) Test(org.junit.Test)

Example 8 with TimelineKeyValueFilter

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter in project hadoop by apache.

the class TestTimelineReaderWebServicesUtils method testInfoFiltersParsing.

@Test
public void testInfoFiltersParsing() throws Exception {
    String expr = "(((key11 ne 234 AND key12 eq val12) AND " + "(key13 ene val13 OR key14 eq 567)) OR (key21 eq val_21 OR key22 eq " + "5.0))";
    TimelineFilterList expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(Operator.AND, new TimelineFilterList(Operator.AND, new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "key11", 234, false), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key12", "val12", true)), new TimelineFilterList(Operator.OR, new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "key13", "val13", true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key14", 567, true))), new TimelineFilterList(Operator.OR, new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key21", "val_21", true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key22", 5.0, true)));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseKVFilters(expr, false), expectedList);
    expr = "abc ne 234 AND def eq 23 OR rst ene 24 OR xyz eq 456 AND pqr eq " + "val.1234";
    expectedList = new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "def", 23, true)), new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "rst", 24, true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "xyz", 456, true)), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "pqr", "val.1234", true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseKVFilters(expr, false), expectedList);
    // Test with unnecessary spaces.
    expr = "  abc ne   234       AND       def           eq 23 OR     rst ene " + "           24     OR xyz     eq     456    AND pqr eq 2        ";
    expectedList = new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "def", 23, true)), new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "rst", 24, true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "xyz", 456, true)), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "pqr", 2, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseKVFilters(expr, false), expectedList);
}
Also used : TimelineKeyValueFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList) Test(org.junit.Test)

Example 9 with TimelineKeyValueFilter

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter in project hadoop by apache.

the class TestHBaseTimelineStorageEntities method testReadEntitiesInfoFilters.

@Test
public void testReadEntitiesInfoFilters() throws Exception {
    TimelineFilterList list1 = new TimelineFilterList();
    list1.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "infoMapKey3", 71.4));
    list1.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "infoMapKey1", "infoMapValue2"));
    TimelineFilterList list2 = new TimelineFilterList();
    list2.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "infoMapKey1", "infoMapValue1"));
    list2.addFilter(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "infoMapKey2", 10));
    TimelineFilterList infoFilterList = new TimelineFilterList(Operator.OR, list1, list2);
    Set<TimelineEntity> entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO), null));
    assertEquals(2, entities.size());
    int infoCnt = 0;
    for (TimelineEntity entity : entities) {
        infoCnt += entity.getInfo().size();
    }
    assertEquals(5, infoCnt);
    TimelineFilterList infoFilterList1 = new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "infoMapKey1", "infoMapValue1"));
    entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList1, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO), null));
    assertEquals(1, entities.size());
    infoCnt = 0;
    for (TimelineEntity entity : entities) {
        infoCnt += entity.getInfo().size();
    }
    assertEquals(3, infoCnt);
    TimelineFilterList infoFilterList2 = new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "infoMapKey1", "infoMapValue2"), new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "infoMapKey3", 71.4));
    entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList2, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO), null));
    assertEquals(0, entities.size());
    TimelineFilterList infoFilterList3 = new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "dummy_info", "some_value"));
    entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList3, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO), null));
    assertEquals(0, entities.size());
    TimelineFilterList infoFilterList4 = new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "dummy_info", "some_value"));
    entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList4, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO), null));
    assertEquals(0, entities.size());
    TimelineFilterList infoFilterList5 = new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "dummy_info", "some_value", false));
    entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, null, infoFilterList5, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO), null));
    assertEquals(3, entities.size());
}
Also used : TimelineKeyValueFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList) TimelineReaderContext(org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderContext) TimelineEntityFilters(org.apache.hadoop.yarn.server.timelineservice.reader.TimelineEntityFilters) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) TimelineDataToRetrieve(org.apache.hadoop.yarn.server.timelineservice.reader.TimelineDataToRetrieve) Test(org.junit.Test)

Example 10 with TimelineKeyValueFilter

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter in project hadoop by apache.

the class TestTimelineReaderWebServicesUtils method testConfigFiltersParsing.

@Test
public void testConfigFiltersParsing() throws Exception {
    String expr = "(((key11 ne 234 AND key12 eq val12) AND " + "(key13 ene val13 OR key14 eq 567)) OR (key21 eq val_21 OR key22 eq " + "val.22))";
    TimelineFilterList expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(Operator.AND, new TimelineFilterList(Operator.AND, new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "key11", "234", false), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key12", "val12", true)), new TimelineFilterList(Operator.OR, new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "key13", "val13", true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key14", "567", true))), new TimelineFilterList(Operator.OR, new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key21", "val_21", true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "key22", "val.22", true)));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseKVFilters(expr, true), expectedList);
    expr = "abc ne 234 AND def eq 23 OR rst ene 24 OR xyz eq 456 AND pqr eq 2";
    expectedList = new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "abc", "234", false), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "def", "23", true)), new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "rst", "24", true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "xyz", "456", true)), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "pqr", "2", true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseKVFilters(expr, true), expectedList);
    // Test with unnecessary spaces.
    expr = "  abc ne   234       AND       def           eq 23 OR     rst ene " + "           24     OR xyz     eq     456    AND pqr eq 2        ";
    expectedList = new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "abc", "234", false), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "def", "23", true)), new TimelineKeyValueFilter(TimelineCompareOp.NOT_EQUAL, "rst", "24", true), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "xyz", "456", true)), new TimelineKeyValueFilter(TimelineCompareOp.EQUAL, "pqr", "2", true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseKVFilters(expr, true), expectedList);
    expr = "abc gt 234 AND def eq 23 OR rst ene 24 OR xyz eq 456 AND pqr eq 2";
    try {
        TimelineReaderWebServicesUtils.parseKVFilters(expr, true);
        fail("Invalid compareop specified for config filters. Should be either" + " eq,ne or ene and exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
}
Also used : TimelineKeyValueFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList) Test(org.junit.Test)

Aggregations

TimelineFilterList (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList)10 TimelineKeyValueFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter)10 Test (org.junit.Test)9 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)7 TimelineDataToRetrieve (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineDataToRetrieve)7 TimelineEntityFilters (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineEntityFilters)7 TimelineReaderContext (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderContext)7 TimelineCompareFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareFilter)2 TimelineExistsFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineExistsFilter)2 TimelinePrefixFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelinePrefixFilter)2 IOException (java.io.IOException)1 TimelineFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilter)1 TimelineFilterType (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilter.TimelineFilterType)1 TimelineKeyValuesFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter)1