use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter in project hadoop by apache.
the class TestHBaseTimelineStorageEntities method testReadEntitiesRelationsAndEventFiltersDefaultView.
@Test
public void testReadEntitiesRelationsAndEventFiltersDefaultView() throws Exception {
TimelineFilterList eventFilter = new TimelineFilterList();
eventFilter.addFilter(new TimelineExistsFilter(TimelineCompareOp.NOT_EQUAL, "end_event"));
TimelineFilterList relatesTo = new TimelineFilterList(Operator.OR);
relatesTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container2", new HashSet<Object>(Arrays.asList("relatesto7"))));
relatesTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container1", new HashSet<Object>(Arrays.asList("relatesto4"))));
TimelineFilterList isRelatedTo = new TimelineFilterList();
isRelatedTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto3"))));
isRelatedTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto5"))));
Set<TimelineEntity> entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, "application_1231111111_1111", "world", null), new TimelineEntityFilters(null, null, null, relatesTo, isRelatedTo, null, null, null, eventFilter), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
int eventCnt = 0;
int isRelatedToCnt = 0;
int relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
eventCnt += timelineEntity.getEvents().size();
isRelatedToCnt += timelineEntity.getIsRelatedToEntities().size();
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("hello2")) {
Assert.fail("Entity id should have been hello2");
}
}
assertEquals(0, eventCnt);
assertEquals(0, isRelatedToCnt);
assertEquals(0, relatesToCnt);
}
use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter 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;
}
use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter in project hadoop by apache.
the class TestTimelineReaderWebServicesUtils method testRelationFiltersParsing.
@Test
public void testRelationFiltersParsing() throws Exception {
String expr = "type1:entity11,type2:entity21:entity22";
TimelineFilterList expectedList = new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type1", Sets.newHashSet((Object) "entity11")), new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type2", Sets.newHashSet((Object) "entity21", "entity22")));
verifyFilterList(expr, TimelineReaderWebServicesUtils.parseRelationFilters(expr), expectedList);
expr = "(type1:entity11,type2:entity21:entity22)";
verifyFilterList(expr, TimelineReaderWebServicesUtils.parseRelationFilters(expr), expectedList);
expr = "(type1:entity11,type2:entity21:entity22) OR (type3:entity31:" + "entity32:entity33,type1:entity11:entity12)";
expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type1", Sets.newHashSet((Object) "entity11")), new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type2", Sets.newHashSet((Object) "entity21", "entity22"))), new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type3", Sets.newHashSet((Object) "entity31", "entity32", "entity33")), new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type1", Sets.newHashSet((Object) "entity11", "entity12"))));
verifyFilterList(expr, TimelineReaderWebServicesUtils.parseRelationFilters(expr), expectedList);
expr = "!(type1:entity11,type2:entity21:entity22,type5:entity51) OR " + "(type3:entity31:entity32:entity33,type1:entity11:entity12)";
expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type1", Sets.newHashSet((Object) "entity11")), new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type2", Sets.newHashSet((Object) "entity21", "entity22")), new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type5", Sets.newHashSet((Object) "entity51"))), new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type3", Sets.newHashSet((Object) "entity31", "entity32", "entity33")), new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type1", Sets.newHashSet((Object) "entity11", "entity12"))));
verifyFilterList(expr, TimelineReaderWebServicesUtils.parseRelationFilters(expr), expectedList);
expr = "(((!(type1:entity11,type2:entity21:entity22,type5:entity51) OR " + "(type3:entity31:entity32:entity33,type1:entity11:entity12)) AND " + "(!(type11:entity111) OR !(type4:entity43:entity44:entity47:entity49," + "type7:entity71))) OR ((type2:entity2,type8:entity88) AND t9:e:e1))";
expectedList = new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type1", Sets.newHashSet((Object) "entity11")), new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type2", Sets.newHashSet((Object) "entity21", "entity22")), new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type5", Sets.newHashSet((Object) "entity51"))), new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type3", Sets.newHashSet((Object) "entity31", "entity32", "entity33")), new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type1", Sets.newHashSet((Object) "entity11", "entity12")))), new TimelineFilterList(Operator.OR, new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type11", Sets.newHashSet((Object) "entity111"))), new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type4", Sets.newHashSet((Object) "entity43", "entity44", "entity47", "entity49")), new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "type7", Sets.newHashSet((Object) "entity71"))))), new TimelineFilterList(new TimelineFilterList(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type2", Sets.newHashSet((Object) "entity2")), new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "type8", Sets.newHashSet((Object) "entity88"))), new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "t9", Sets.newHashSet((Object) "e", "e1"))));
verifyFilterList(expr, TimelineReaderWebServicesUtils.parseRelationFilters(expr), expectedList);
expr = " ( ( ( ! ( type1:entity11 , type2:entity21:entity22" + " , type5:entity51 ) OR ( type3:entity31:entity32:entity33 " + " , type1:entity11:entity12)) AND (!( type11:entity111 ) OR " + " ! ( type4:entity43:entity44:entity47:entity49 , " + "type7:entity71 ) ) ) OR ( ( type2:entity2 , type8:entity88) " + "AND t9:e:e1 ) ) ";
verifyFilterList(expr, TimelineReaderWebServicesUtils.parseRelationFilters(expr), expectedList);
expr = "(((!(type1 : entity11,type2:entity21:entity22,type5:entity51) OR " + "(type3:entity31:entity32:entity33,type1:entity11:entity12)) AND " + "(!(type11:entity111) OR !(type4:entity43:entity44:entity47:entity49," + "type7:entity71))) OR ((type2:entity2,type8:entity88) AND t9:e:e1))";
try {
TimelineReaderWebServicesUtils.parseRelationFilters(expr);
fail("Space not allowed in relation expression. Exception should have " + "been thrown");
} catch (TimelineParseException e) {
}
}
use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter in project hadoop by apache.
the class TestHBaseTimelineStorageApps method testReadAppsRelationsAndEventFiltersDefaultView.
@Test
public void testReadAppsRelationsAndEventFiltersDefaultView() throws Exception {
TimelineFilterList eventFilter = new TimelineFilterList();
eventFilter.addFilter(new TimelineExistsFilter(TimelineCompareOp.NOT_EQUAL, "end_event"));
TimelineFilterList relatesTo = new TimelineFilterList(Operator.OR);
relatesTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container2", new HashSet<Object>(Arrays.asList("relatesto7"))));
relatesTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "container1", new HashSet<Object>(Arrays.asList("relatesto4"))));
TimelineFilterList isRelatedTo = new TimelineFilterList();
isRelatedTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto3"))));
isRelatedTo.addFilter(new TimelineKeyValuesFilter(TimelineCompareOp.NOT_EQUAL, "task1", new HashSet<Object>(Arrays.asList("relatedto5"))));
Set<TimelineEntity> entities = reader.getEntities(new TimelineReaderContext("cluster1", "user1", "some_flow_name", 1002345678919L, null, TimelineEntityType.YARN_APPLICATION.toString(), null), new TimelineEntityFilters(null, null, null, relatesTo, isRelatedTo, null, null, null, eventFilter), new TimelineDataToRetrieve());
assertEquals(1, entities.size());
int eventCnt = 0;
int isRelatedToCnt = 0;
int relatesToCnt = 0;
for (TimelineEntity timelineEntity : entities) {
eventCnt += timelineEntity.getEvents().size();
isRelatedToCnt += timelineEntity.getIsRelatedToEntities().size();
relatesToCnt += timelineEntity.getRelatesToEntities().size();
if (!timelineEntity.getId().equals("application_1111111111_4444")) {
Assert.fail("Entity id should have been application_1111111111_4444");
}
}
assertEquals(0, eventCnt);
assertEquals(0, isRelatedToCnt);
assertEquals(0, relatesToCnt);
}
use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter in project hadoop by apache.
the class TestHBaseTimelineStorageApps method testReadAppsIsRelatedTo.
@Test
public void testReadAppsIsRelatedTo() 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, null, TimelineEntityType.YARN_APPLICATION.toString(), 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("application_1111111111_2222") && !timelineEntity.getId().equals("application_1111111111_3333")) {
Assert.fail("Entity ids' should have been application_1111111111_2222" + " and application_1111111111_3333");
}
}
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, null, TimelineEntityType.YARN_APPLICATION.toString(), 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("application_1111111111_4444")) {
Assert.fail("Entity id should have been application_1111111111_4444");
}
}
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, null, TimelineEntityType.YARN_APPLICATION.toString(), 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("application_1111111111_2222") && !timelineEntity.getId().equals("application_1111111111_3333")) {
Assert.fail("Entity ids' should have been application_1111111111_2222" + " and application_1111111111_3333");
}
}
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, null, TimelineEntityType.YARN_APPLICATION.toString(), 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("application_1111111111_3333")) {
Assert.fail("Entity id should have been application_1111111111_3333");
}
}
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, null, TimelineEntityType.YARN_APPLICATION.toString(), 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, null, TimelineEntityType.YARN_APPLICATION.toString(), 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, null, TimelineEntityType.YARN_APPLICATION.toString(), 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("application_1111111111_3333")) {
Assert.fail("Entity id should have been application_1111111111_3333");
}
}
assertEquals(0, isRelatedToCnt);
}
Aggregations