Search in sources :

Example 1 with TimelineFilter

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;
}
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)

Aggregations

IOException (java.io.IOException)1 TimelineCompareFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareFilter)1 TimelineExistsFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineExistsFilter)1 TimelineFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilter)1 TimelineFilterType (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilter.TimelineFilterType)1 TimelineFilterList (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList)1 TimelineKeyValueFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter)1 TimelineKeyValuesFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter)1