Search in sources :

Example 46 with TimelineFilterList

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

the class TestTimelineReaderWebServicesUtils method testMetricFiltersParsing.

@Test
public void testMetricFiltersParsing() throws Exception {
    String expr = "(((key11 ne 234 AND key12 gt 23) AND " + "(key13 lt 34 OR key14 ge 567)) OR (key21 lt 24 OR key22 le 45))";
    TimelineFilterList expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(Operator.AND, new TimelineFilterList(Operator.AND, new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "key11", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "key12", 23, true)), new TimelineFilterList(Operator.OR, new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key13", 34, true), new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "key14", 567, true))), new TimelineFilterList(Operator.OR, new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key21", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "key22", 45, true)));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "abc ene 234";
    expectedList = new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "abc ne 234";
    expectedList = new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "abc ne 234 AND def gt 23";
    expectedList = new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "def", 23, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "(abc ne 234 AND def gt 23)";
    expectedList = new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "def", 23, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "abc ne 234 AND def gt 23 OR rst lt 24";
    expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "def", 23, true)), new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "rst", 24, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "abc ne 234 AND def gt 23 OR rst lt 24 OR xyz le 456";
    expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "def", 23, true)), new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "rst", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "xyz", 456, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "abc ne 234 AND def gt 23 OR rst lt 24 OR xyz le 456 AND pqr ge 2";
    expectedList = new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "def", 23, true)), new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "rst", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "xyz", 456, true)), new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "pqr", 2, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    // Test with unnecessary spaces.
    expr = "  abc ne   234       AND       def           gt 23 OR     rst lt " + "           24     OR xyz     le     456    AND pqr ge 2        ";
    expectedList = new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "abc", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "def", 23, true)), new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "rst", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "xyz", 456, true)), new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "pqr", 2, true));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "(((key11 ne 234 AND key12 gt 23 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45))";
    expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(Operator.AND, new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "key11", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "key12", 23, true)), new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key13", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "key14", 456, true)), new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "key15", 2, true)), new TimelineFilterList(Operator.OR, new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key16", 34, true), new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "key17", 567, true))), new TimelineFilterList(Operator.OR, new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key21", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "key22", 45, true)));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "   (  (     (        key11      ne     234    AND key12    gt   " + "23    OR    key13    lt    24 OR key14 le 456   AND   key15   ge   2" + "   )   AND ( key16 lt 34 OR key17 ge 567 )    )     OR " + "(   key21 lt 24 OR key22 le 45 )   )    ";
    expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(Operator.AND, new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineCompareFilter(TimelineCompareOp.NOT_EQUAL, "key11", 234, false), new TimelineCompareFilter(TimelineCompareOp.GREATER_THAN, "key12", 23, true)), new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key13", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "key14", 456, true)), new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "key15", 2, true)), new TimelineFilterList(Operator.OR, new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key16", 34, true), new TimelineCompareFilter(TimelineCompareOp.GREATER_OR_EQUAL, "key17", 567, true))), new TimelineFilterList(Operator.OR, new TimelineCompareFilter(TimelineCompareOp.LESS_THAN, "key21", 24, true), new TimelineCompareFilter(TimelineCompareOp.LESS_OR_EQUAL, "key22", 45, true)));
    verifyFilterList(expr, TimelineReaderWebServicesUtils.parseMetricFilters(expr), expectedList);
    expr = "(((key11 ne 234 AND key12 gt 23 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45)";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Improper brackers. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(((key11 ne 234 AND key12 gt v3 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45))";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Non Numeric value. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(((key11 ne (234 AND key12 gt 3 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45))";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Unexpected opening bracket. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(((k)ey11 ne 234 AND key12 gt 3 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45))";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Unexpected closing bracket. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(((key11 rs 234 AND key12 gt 3 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45))";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Improper compare op. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(((key11 ne 234 PI key12 gt 3 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45))";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Improper op. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(((key11 ne 234 PI key12 gt 3 OR key13 lt 24 OR key14 le 456 " + "AND key15 ge 2) AND (key16 lt 34 OR key17 ge 567)) OR (key21 lt 24 " + "OR key22 le 45))";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Improper op. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(key11 ne 234 AND key12 gt 3)) OR (key13 lt 24 OR key14 le 456)";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Unbalanced brackets. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(key11 rne 234 AND key12 gt 3) OR (key13 lt 24 OR key14 le 456)";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Invalid compareop. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    expr = "(key11 ne 234 AND key12 gt 3) OR (key13 lt 24 OR key14 le";
    try {
        TimelineReaderWebServicesUtils.parseMetricFilters(expr);
        fail("Compareop cant be parsed. Exception should have been thrown.");
    } catch (TimelineParseException e) {
    }
    assertNull(TimelineReaderWebServicesUtils.parseMetricFilters(null));
    assertNull(TimelineReaderWebServicesUtils.parseMetricFilters("   "));
}
Also used : TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList) TimelineCompareFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareFilter) Test(org.junit.Test)

Example 47 with TimelineFilterList

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

the class TestFileSystemTimelineReaderImpl method testGetEntitiesByRelations.

@Test
public void testGetEntitiesByRelations() throws Exception {
    // Get entities based on relatesTo.
    TimelineFilterList relatesTo = new TimelineFilterList(Operator.OR);
    Set<Object> relatesToIds = new HashSet<Object>(Arrays.asList((Object) "flow1"));
    relatesTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "flow", relatesToIds));
    Set<TimelineEntity> result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, relatesTo, null, null, null, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(1, result.size());
    // Only one entity with ID id_1 should be returned.
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1")) {
            Assert.fail("Incorrect filtering based on relatesTo");
        }
    }
    // Get entities based on isRelatedTo.
    TimelineFilterList isRelatedTo = new TimelineFilterList(Operator.OR);
    Set<Object> isRelatedToIds = new HashSet<Object>(Arrays.asList((Object) "tid1_2"));
    isRelatedTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type1", isRelatedToIds));
    result = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", null), new TimelineEntityFilters(null, null, null, null, isRelatedTo, null, null, null, null), new TimelineDataToRetrieve());
    Assert.assertEquals(2, result.size());
    // Two entities with IDs' id_1 and id_3 should be returned.
    for (TimelineEntity entity : result) {
        if (!entity.getId().equals("id_1") && !entity.getId().equals("id_3")) {
            Assert.fail("Incorrect filtering based on isRelatedTo");
        }
    }
}
Also used : TimelineKeyValuesFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TimelineFilterList (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList)47 Test (org.junit.Test)32 TimelineEntityFilters (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineEntityFilters)28 TimelineDataToRetrieve (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineDataToRetrieve)27 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)26 TimelineReaderContext (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderContext)26 TimelinePrefixFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelinePrefixFilter)12 TimelineKeyValueFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter)10 TimelineKeyValuesFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter)9 TimelineCompareFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareFilter)8 HashSet (java.util.HashSet)7 TimelineExistsFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineExistsFilter)7 FilterList (org.apache.hadoop.hbase.filter.FilterList)6 TimelineMetric (org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric)5 Operator (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator)3 EnumSet (java.util.EnumSet)2 Set (java.util.Set)2 Configuration (org.apache.hadoop.conf.Configuration)2 TimelineEntities (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntities)2 HBaseTimelineReaderImpl (org.apache.hadoop.yarn.server.timelineservice.storage.HBaseTimelineReaderImpl)2