use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilter 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;
}
Aggregations