浏览代码

YARN-8107. Give an informative message when incorrect format is used in ATSv2 filter attributes. (Rohith Sharma K S via Haibo Chen)

Haibo Chen 7 年之前
父节点
当前提交
024d7c0870

+ 6 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForCompareExpr.java

@@ -282,7 +282,12 @@ abstract class TimelineParserForCompareExpr implements TimelineParser {
           parseValue(expr.substring(kvStartOffset, offset)));
     }
     if (filterList == null || filterList.getFilterList().isEmpty()) {
-      filterList = new TimelineFilterList(currentFilter);
+      if (currentFilter == null) {
+        throw new TimelineParseException(
+            "Invalid expression provided for " + exprName);
+      } else {
+        filterList = new TimelineFilterList(currentFilter);
+      }
     } else if (currentFilter != null) {
       filterList.addFilter(currentFilter);
     }

+ 6 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForEqualityExpr.java

@@ -325,7 +325,12 @@ abstract class TimelineParserForEqualityExpr implements TimelineParser {
       }
     }
     if (filterList == null || filterList.getFilterList().isEmpty()) {
-      filterList = new TimelineFilterList(currentFilter);
+      if (currentFilter == null) {
+        throw new TimelineParseException(
+            "Invalid expression provided for " + exprName);
+      } else {
+        filterList = new TimelineFilterList(currentFilter);
+      }
     } else if (currentFilter != null) {
       filterList.addFilter(currentFilter);
     }

+ 25 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesUtils.java

@@ -31,6 +31,7 @@ import org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilte
 import org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter;
 import org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter;
 import org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelinePrefixFilter;
+import org.junit.Assert;
 import org.junit.Test;
 
 import com.google.common.collect.Sets;
@@ -520,6 +521,30 @@ public class TestTimelineReaderWebServicesUtils {
     );
     verifyFilterList(expr, TimelineReaderWebServicesUtils.
         parseKVFilters(expr, false), expectedList);
+
+    expr = "abdeq";
+    try {
+      TimelineReaderWebServicesUtils.parseKVFilters(expr, false);
+      Assert.fail("Expression valuation should throw exception.");
+    } catch (TimelineParseException e) {
+      // expected: do nothing
+    }
+
+    expr = "abc gt 234 AND defeq";
+    try {
+      TimelineReaderWebServicesUtils.parseKVFilters(expr, false);
+      Assert.fail("Expression valuation should throw exception.");
+    } catch (TimelineParseException e) {
+      // expected: do nothing
+    }
+
+    expr = "((key11 ne 234 AND key12 eq val12) AND (key13eq OR key14 eq va14))";
+    try {
+      TimelineReaderWebServicesUtils.parseKVFilters(expr, false);
+      Assert.fail("Expression valuation should throw exception.");
+    } catch (TimelineParseException e) {
+      // expected: do nothing
+    }
   }
 
   @Test