use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList in project hadoop by apache.
the class TestHBaseTimelineStorageEntities method testReadEntitiesIsRelatedTo.
@Test
public void testReadEntitiesIsRelatedTo() throws Exception {
TimelineFilterList irt = new TimelineFilterList(Operator.OR);
irt.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task", new HashSet<Object>(Arrays.asList("relatedto1"))));
irt.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task2", new HashSet<Object>(Arrays.asList("relatedto4"))));
Set<TimelineEntity> entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, irt, null, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.ALL), null));
assertEquals(2, entities.size());
int isRelatedToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
isRelatedToCnt += timelineEntity.getIsRelatedToEntities().size();
if (!timelineEntity.getId().equals("hello") && !timelineEntity.getId().equals("hello1")) {
Assert.fail("Entity ids' should have been hello and hello1");
}
}
assertEquals(3, isRelatedToCnt);
TimelineFilterList irt1 = new TimelineFilterList();
irt1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto3"))));
irt1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto5"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, irt1, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
isRelatedToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
isRelatedToCnt += timelineEntity.getIsRelatedToEntities().size();
if (!timelineEntity.getId().equals("hello2")) {
Assert.fail("Entity id should have been hello2");
}
}
assertEquals(0, isRelatedToCnt);
TimelineFilterList irt2 = new TimelineFilterList(Operator.OR);
irt2.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task", new HashSet<Object>(Arrays.asList("relatedto1"))));
irt2.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task2", new HashSet<Object>(Arrays.asList("relatedto4"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, irt2, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(2, entities.size());
isRelatedToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
isRelatedToCnt += timelineEntity.getIsRelatedToEntities().size();
if (!timelineEntity.getId().equals("hello") && !timelineEntity.getId().equals("hello1")) {
Assert.fail("Entity ids' should have been hello and hello1");
}
}
assertEquals(0, isRelatedToCnt);
TimelineFilterList irt3 = new TimelineFilterList();
irt3.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto3", "relatedto5"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, irt3, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
isRelatedToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
isRelatedToCnt += timelineEntity.getIsRelatedToEntities().size();
if (!timelineEntity.getId().equals("hello1")) {
Assert.fail("Entity id should have been hello1");
}
}
assertEquals(0, isRelatedToCnt);
TimelineFilterList irt4 = new TimelineFilterList();
irt4.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto3"))));
irt4.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "dummy_task", new HashSet<Object>(Arrays.asList("relatedto5"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, irt4, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(0, entities.size());
TimelineFilterList irt5 = new TimelineFilterList();
irt5.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto3", "relatedto7"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, irt5, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(0, entities.size());
TimelineFilterList list1 = new TimelineFilterList();
list1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task", new HashSet<Object>(Arrays.asList("relatedto1"))));
list1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "dummy_task", new HashSet<Object>(Arrays.asList("relatedto4"))));
TimelineFilterList list2 = new TimelineFilterList();
list2.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task2", new HashSet<Object>(Arrays.asList("relatedto4"))));
TimelineFilterList irt6 = new TimelineFilterList(Operator.OR, list1, list2);
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, null, irt6, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
isRelatedToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
isRelatedToCnt += timelineEntity.getIsRelatedToEntities().size();
if (!timelineEntity.getId().equals("hello1")) {
Assert.fail("Entity id should have been hello1");
}
}
assertEquals(0, isRelatedToCnt);
}
use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList in project hadoop by apache.
the class TestHBaseTimelineStorageEntities method testReadEntitiesRelatesTo.
@Test
public void testReadEntitiesRelatesTo() throws Exception {
TimelineFilterList rt = new TimelineFilterList(Operator.OR);
rt.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container2", new HashSet<Object>(Arrays.asList("relatesto7"))));
rt.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container1", new HashSet<Object>(Arrays.asList("relatesto4"))));
Set<TimelineEntity> entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt, null, null, null, null, null), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.ALL), null));
assertEquals(2, entities.size());
int relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("hello") && !timelineEntity.getId().equals("hello2")) {
Assert.fail("Entity ids' should have been hello and hello2");
}
}
assertEquals(3, relatesToCnt);
TimelineFilterList rt1 = new TimelineFilterList();
rt1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto1"))));
rt1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto3"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt1, null, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("hello1")) {
Assert.fail("Entity id should have been hello1");
}
}
assertEquals(0, relatesToCnt);
TimelineFilterList rt2 = new TimelineFilterList(Operator.OR);
rt2.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container2", new HashSet<Object>(Arrays.asList("relatesto7"))));
rt2.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container1", new HashSet<Object>(Arrays.asList("relatesto4"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt2, null, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(2, entities.size());
relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("hello") && !timelineEntity.getId().equals("hello2")) {
Assert.fail("Entity ids' should have been hello and hello2");
}
}
assertEquals(0, relatesToCnt);
TimelineFilterList rt3 = new TimelineFilterList();
rt3.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto1", "relatesto3"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt3, null, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("hello")) {
Assert.fail("Entity id should have been hello");
}
}
assertEquals(0, relatesToCnt);
TimelineFilterList rt4 = new TimelineFilterList();
rt4.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto1"))));
rt4.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "dummy_container", new HashSet<Object>(Arrays.asList("relatesto5"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt4, null, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(0, entities.size());
TimelineFilterList rt5 = new TimelineFilterList();
rt5.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container", new HashSet<Object>(Arrays.asList("relatedto1", "relatesto8"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt5, null, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(0, entities.size());
TimelineFilterList list1 = new TimelineFilterList();
list1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container2", new HashSet<Object>(Arrays.asList("relatesto7"))));
list1.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "dummy_container", new HashSet<Object>(Arrays.asList("relatesto4"))));
TimelineFilterList list2 = new TimelineFilterList();
list2.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container1", new HashSet<Object>(Arrays.asList("relatesto4"))));
TimelineFilterList rt6 = new TimelineFilterList(Operator.OR, list1, list2);
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt6, null, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("hello")) {
Assert.fail("Entity id should have been hello");
}
}
assertEquals(0, relatesToCnt);
TimelineFilterList list3 = new TimelineFilterList();
list3.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto1"))));
list3.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container1", new HashSet<Object>(Arrays.asList("relatesto4"))));
TimelineFilterList list4 = new TimelineFilterList();
list4.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto1"))));
list4.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto2"))));
TimelineFilterList combinedList = new TimelineFilterList(Operator.OR, list3, list4);
TimelineFilterList rt7 = new TimelineFilterList(Operator.AND, combinedList, new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "container", new HashSet<Object>(Arrays.asList("relatesto3"))));
entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, rt7, null, null, null, null, null), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("hello1")) {
Assert.fail("Entity id should have been hello1");
}
}
assertEquals(0, relatesToCnt);
}
use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList 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) {
}
}
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(" "));
}
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");
}
}
}
Aggregations