You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by ce...@apache.org on 2016/05/10 16:53:55 UTC
[3/5] incubator-metron git commit: METRON-141: The ability to do
threat triage closes apache/incubator-metron#108
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/main/java/org/apache/metron/common/query/generated/PredicateParser.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/query/generated/PredicateParser.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/query/generated/PredicateParser.java
new file mode 100644
index 0000000..3586f01
--- /dev/null
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/query/generated/PredicateParser.java
@@ -0,0 +1,1108 @@
+// Generated from org/apache/metron/common/query/generated/Predicate.g4 by ANTLR 4.5
+package org.apache.metron.common.query.generated;
+
+//CHECKSTYLE:OFF
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.antlr.v4.runtime.atn.*;
+import org.antlr.v4.runtime.dfa.DFA;
+import org.antlr.v4.runtime.*;
+import org.antlr.v4.runtime.misc.*;
+import org.antlr.v4.runtime.tree.*;
+import java.util.List;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
+public class PredicateParser extends Parser {
+ static { RuntimeMetaData.checkVersion("4.5", RuntimeMetaData.VERSION); }
+
+ protected static final DFA[] _decisionToDFA;
+ protected static final PredictionContextCache _sharedContextCache =
+ new PredictionContextCache();
+ public static final int
+ AND=1, OR=2, NOT=3, TRUE=4, FALSE=5, EQ=6, NEQ=7, COMMA=8, LBRACKET=9,
+ RBRACKET=10, LPAREN=11, RPAREN=12, IN=13, NIN=14, EXISTS=15, IDENTIFIER=16,
+ STRING_LITERAL=17, SEMI=18, COMMENT=19, WS=20;
+ public static final int
+ RULE_single_rule = 0, RULE_logical_expr = 1, RULE_comparison_expr = 2,
+ RULE_logical_entity = 3, RULE_list_entity = 4, RULE_func_args = 5, RULE_op_list = 6,
+ RULE_identifier_operand = 7, RULE_comparison_operand = 8, RULE_comp_operator = 9;
+ public static final String[] ruleNames = {
+ "single_rule", "logical_expr", "comparison_expr", "logical_entity", "list_entity",
+ "func_args", "op_list", "identifier_operand", "comparison_operand", "comp_operator"
+ };
+
+ private static final String[] _LITERAL_NAMES = {
+ null, null, null, null, null, null, "'=='", "'!='", "','", "'['", "']'",
+ "'('", "')'", "'in'", "'not in'", "'exists'", null, null, "';'"
+ };
+ private static final String[] _SYMBOLIC_NAMES = {
+ null, "AND", "OR", "NOT", "TRUE", "FALSE", "EQ", "NEQ", "COMMA", "LBRACKET",
+ "RBRACKET", "LPAREN", "RPAREN", "IN", "NIN", "EXISTS", "IDENTIFIER", "STRING_LITERAL",
+ "SEMI", "COMMENT", "WS"
+ };
+ public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
+
+ /**
+ * @deprecated Use {@link #VOCABULARY} instead.
+ */
+ @Deprecated
+ public static final String[] tokenNames;
+ static {
+ tokenNames = new String[_SYMBOLIC_NAMES.length];
+ for (int i = 0; i < tokenNames.length; i++) {
+ tokenNames[i] = VOCABULARY.getLiteralName(i);
+ if (tokenNames[i] == null) {
+ tokenNames[i] = VOCABULARY.getSymbolicName(i);
+ }
+
+ if (tokenNames[i] == null) {
+ tokenNames[i] = "<INVALID>";
+ }
+ }
+ }
+
+ @Override
+ @Deprecated
+ public String[] getTokenNames() {
+ return tokenNames;
+ }
+
+ @Override
+
+ public Vocabulary getVocabulary() {
+ return VOCABULARY;
+ }
+
+ @Override
+ public String getGrammarFileName() { return "Predicate.g4"; }
+
+ @Override
+ public String[] getRuleNames() { return ruleNames; }
+
+ @Override
+ public String getSerializedATN() { return _serializedATN; }
+
+ @Override
+ public ATN getATN() { return _ATN; }
+
+ public PredicateParser(TokenStream input) {
+ super(input);
+ _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
+ }
+ public static class Single_ruleContext extends ParserRuleContext {
+ public Logical_exprContext logical_expr() {
+ return getRuleContext(Logical_exprContext.class,0);
+ }
+ public TerminalNode EOF() { return getToken(PredicateParser.EOF, 0); }
+ public Single_ruleContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_single_rule; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterSingle_rule(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitSingle_rule(this);
+ }
+ }
+
+ public final Single_ruleContext single_rule() throws RecognitionException {
+ Single_ruleContext _localctx = new Single_ruleContext(_ctx, getState());
+ enterRule(_localctx, 0, RULE_single_rule);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(20);
+ logical_expr(0);
+ setState(21);
+ match(EOF);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Logical_exprContext extends ParserRuleContext {
+ public Logical_exprContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_logical_expr; }
+
+ public Logical_exprContext() { }
+ public void copyFrom(Logical_exprContext ctx) {
+ super.copyFrom(ctx);
+ }
+ }
+ public static class LogicalEntityContext extends Logical_exprContext {
+ public Logical_entityContext logical_entity() {
+ return getRuleContext(Logical_entityContext.class,0);
+ }
+ public LogicalEntityContext(Logical_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalEntity(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalEntity(this);
+ }
+ }
+ public static class ComparisonExpressionContext extends Logical_exprContext {
+ public Comparison_exprContext comparison_expr() {
+ return getRuleContext(Comparison_exprContext.class,0);
+ }
+ public ComparisonExpressionContext(Logical_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterComparisonExpression(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitComparisonExpression(this);
+ }
+ }
+ public static class LogicalExpressionInParenContext extends Logical_exprContext {
+ public TerminalNode LPAREN() { return getToken(PredicateParser.LPAREN, 0); }
+ public Logical_exprContext logical_expr() {
+ return getRuleContext(Logical_exprContext.class,0);
+ }
+ public TerminalNode RPAREN() { return getToken(PredicateParser.RPAREN, 0); }
+ public LogicalExpressionInParenContext(Logical_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalExpressionInParen(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalExpressionInParen(this);
+ }
+ }
+ public static class NotFuncContext extends Logical_exprContext {
+ public TerminalNode NOT() { return getToken(PredicateParser.NOT, 0); }
+ public TerminalNode LPAREN() { return getToken(PredicateParser.LPAREN, 0); }
+ public Logical_exprContext logical_expr() {
+ return getRuleContext(Logical_exprContext.class,0);
+ }
+ public TerminalNode RPAREN() { return getToken(PredicateParser.RPAREN, 0); }
+ public NotFuncContext(Logical_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterNotFunc(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitNotFunc(this);
+ }
+ }
+ public static class LogicalExpressionAndContext extends Logical_exprContext {
+ public List<Logical_exprContext> logical_expr() {
+ return getRuleContexts(Logical_exprContext.class);
+ }
+ public Logical_exprContext logical_expr(int i) {
+ return getRuleContext(Logical_exprContext.class,i);
+ }
+ public TerminalNode AND() { return getToken(PredicateParser.AND, 0); }
+ public LogicalExpressionAndContext(Logical_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalExpressionAnd(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalExpressionAnd(this);
+ }
+ }
+ public static class LogicalExpressionOrContext extends Logical_exprContext {
+ public List<Logical_exprContext> logical_expr() {
+ return getRuleContexts(Logical_exprContext.class);
+ }
+ public Logical_exprContext logical_expr(int i) {
+ return getRuleContext(Logical_exprContext.class,i);
+ }
+ public TerminalNode OR() { return getToken(PredicateParser.OR, 0); }
+ public LogicalExpressionOrContext(Logical_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalExpressionOr(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalExpressionOr(this);
+ }
+ }
+
+ public final Logical_exprContext logical_expr() throws RecognitionException {
+ return logical_expr(0);
+ }
+
+ private Logical_exprContext logical_expr(int _p) throws RecognitionException {
+ ParserRuleContext _parentctx = _ctx;
+ int _parentState = getState();
+ Logical_exprContext _localctx = new Logical_exprContext(_ctx, _parentState);
+ Logical_exprContext _prevctx = _localctx;
+ int _startState = 2;
+ enterRecursionRule(_localctx, 2, RULE_logical_expr, _p);
+ try {
+ int _alt;
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(35);
+ switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) {
+ case 1:
+ {
+ _localctx = new ComparisonExpressionContext(_localctx);
+ _ctx = _localctx;
+ _prevctx = _localctx;
+
+ setState(24);
+ comparison_expr();
+ }
+ break;
+ case 2:
+ {
+ _localctx = new LogicalExpressionInParenContext(_localctx);
+ _ctx = _localctx;
+ _prevctx = _localctx;
+ setState(25);
+ match(LPAREN);
+ setState(26);
+ logical_expr(0);
+ setState(27);
+ match(RPAREN);
+ }
+ break;
+ case 3:
+ {
+ _localctx = new NotFuncContext(_localctx);
+ _ctx = _localctx;
+ _prevctx = _localctx;
+ setState(29);
+ match(NOT);
+ setState(30);
+ match(LPAREN);
+ setState(31);
+ logical_expr(0);
+ setState(32);
+ match(RPAREN);
+ }
+ break;
+ case 4:
+ {
+ _localctx = new LogicalEntityContext(_localctx);
+ _ctx = _localctx;
+ _prevctx = _localctx;
+ setState(34);
+ logical_entity();
+ }
+ break;
+ }
+ _ctx.stop = _input.LT(-1);
+ setState(45);
+ _errHandler.sync(this);
+ _alt = getInterpreter().adaptivePredict(_input,2,_ctx);
+ while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
+ if ( _alt==1 ) {
+ if ( _parseListeners!=null ) triggerExitRuleEvent();
+ _prevctx = _localctx;
+ {
+ setState(43);
+ switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) {
+ case 1:
+ {
+ _localctx = new LogicalExpressionAndContext(new Logical_exprContext(_parentctx, _parentState));
+ pushNewRecursionContext(_localctx, _startState, RULE_logical_expr);
+ setState(37);
+ if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)");
+ setState(38);
+ match(AND);
+ setState(39);
+ logical_expr(7);
+ }
+ break;
+ case 2:
+ {
+ _localctx = new LogicalExpressionOrContext(new Logical_exprContext(_parentctx, _parentState));
+ pushNewRecursionContext(_localctx, _startState, RULE_logical_expr);
+ setState(40);
+ if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)");
+ setState(41);
+ match(OR);
+ setState(42);
+ logical_expr(6);
+ }
+ break;
+ }
+ }
+ }
+ setState(47);
+ _errHandler.sync(this);
+ _alt = getInterpreter().adaptivePredict(_input,2,_ctx);
+ }
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ unrollRecursionContexts(_parentctx);
+ }
+ return _localctx;
+ }
+
+ public static class Comparison_exprContext extends ParserRuleContext {
+ public Comparison_exprContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_comparison_expr; }
+
+ public Comparison_exprContext() { }
+ public void copyFrom(Comparison_exprContext ctx) {
+ super.copyFrom(ctx);
+ }
+ }
+ public static class ComparisonExpressionParensContext extends Comparison_exprContext {
+ public TerminalNode LPAREN() { return getToken(PredicateParser.LPAREN, 0); }
+ public Comparison_exprContext comparison_expr() {
+ return getRuleContext(Comparison_exprContext.class,0);
+ }
+ public TerminalNode RPAREN() { return getToken(PredicateParser.RPAREN, 0); }
+ public ComparisonExpressionParensContext(Comparison_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterComparisonExpressionParens(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitComparisonExpressionParens(this);
+ }
+ }
+ public static class InExpressionContext extends Comparison_exprContext {
+ public Identifier_operandContext identifier_operand() {
+ return getRuleContext(Identifier_operandContext.class,0);
+ }
+ public TerminalNode IN() { return getToken(PredicateParser.IN, 0); }
+ public List_entityContext list_entity() {
+ return getRuleContext(List_entityContext.class,0);
+ }
+ public InExpressionContext(Comparison_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterInExpression(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitInExpression(this);
+ }
+ }
+ public static class ComparisonExpressionWithOperatorContext extends Comparison_exprContext {
+ public List<Comparison_operandContext> comparison_operand() {
+ return getRuleContexts(Comparison_operandContext.class);
+ }
+ public Comparison_operandContext comparison_operand(int i) {
+ return getRuleContext(Comparison_operandContext.class,i);
+ }
+ public Comp_operatorContext comp_operator() {
+ return getRuleContext(Comp_operatorContext.class,0);
+ }
+ public ComparisonExpressionWithOperatorContext(Comparison_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterComparisonExpressionWithOperator(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitComparisonExpressionWithOperator(this);
+ }
+ }
+ public static class NInExpressionContext extends Comparison_exprContext {
+ public Identifier_operandContext identifier_operand() {
+ return getRuleContext(Identifier_operandContext.class,0);
+ }
+ public TerminalNode NIN() { return getToken(PredicateParser.NIN, 0); }
+ public List_entityContext list_entity() {
+ return getRuleContext(List_entityContext.class,0);
+ }
+ public NInExpressionContext(Comparison_exprContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterNInExpression(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitNInExpression(this);
+ }
+ }
+
+ public final Comparison_exprContext comparison_expr() throws RecognitionException {
+ Comparison_exprContext _localctx = new Comparison_exprContext(_ctx, getState());
+ enterRule(_localctx, 4, RULE_comparison_expr);
+ try {
+ setState(64);
+ switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
+ case 1:
+ _localctx = new ComparisonExpressionWithOperatorContext(_localctx);
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(48);
+ comparison_operand();
+ setState(49);
+ comp_operator();
+ setState(50);
+ comparison_operand();
+ }
+ break;
+ case 2:
+ _localctx = new InExpressionContext(_localctx);
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(52);
+ identifier_operand();
+ setState(53);
+ match(IN);
+ setState(54);
+ list_entity();
+ }
+ break;
+ case 3:
+ _localctx = new NInExpressionContext(_localctx);
+ enterOuterAlt(_localctx, 3);
+ {
+ setState(56);
+ identifier_operand();
+ setState(57);
+ match(NIN);
+ setState(58);
+ list_entity();
+ }
+ break;
+ case 4:
+ _localctx = new ComparisonExpressionParensContext(_localctx);
+ enterOuterAlt(_localctx, 4);
+ {
+ setState(60);
+ match(LPAREN);
+ setState(61);
+ comparison_expr();
+ setState(62);
+ match(RPAREN);
+ }
+ break;
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Logical_entityContext extends ParserRuleContext {
+ public Logical_entityContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_logical_entity; }
+
+ public Logical_entityContext() { }
+ public void copyFrom(Logical_entityContext ctx) {
+ super.copyFrom(ctx);
+ }
+ }
+ public static class LogicalFuncContext extends Logical_entityContext {
+ public TerminalNode IDENTIFIER() { return getToken(PredicateParser.IDENTIFIER, 0); }
+ public TerminalNode LPAREN() { return getToken(PredicateParser.LPAREN, 0); }
+ public Func_argsContext func_args() {
+ return getRuleContext(Func_argsContext.class,0);
+ }
+ public TerminalNode RPAREN() { return getToken(PredicateParser.RPAREN, 0); }
+ public LogicalFuncContext(Logical_entityContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalFunc(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalFunc(this);
+ }
+ }
+ public static class LogicalConstContext extends Logical_entityContext {
+ public TerminalNode TRUE() { return getToken(PredicateParser.TRUE, 0); }
+ public TerminalNode FALSE() { return getToken(PredicateParser.FALSE, 0); }
+ public LogicalConstContext(Logical_entityContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalConst(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalConst(this);
+ }
+ }
+ public static class ExistsFuncContext extends Logical_entityContext {
+ public TerminalNode EXISTS() { return getToken(PredicateParser.EXISTS, 0); }
+ public TerminalNode LPAREN() { return getToken(PredicateParser.LPAREN, 0); }
+ public TerminalNode IDENTIFIER() { return getToken(PredicateParser.IDENTIFIER, 0); }
+ public TerminalNode RPAREN() { return getToken(PredicateParser.RPAREN, 0); }
+ public ExistsFuncContext(Logical_entityContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterExistsFunc(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitExistsFunc(this);
+ }
+ }
+
+ public final Logical_entityContext logical_entity() throws RecognitionException {
+ Logical_entityContext _localctx = new Logical_entityContext(_ctx, getState());
+ enterRule(_localctx, 6, RULE_logical_entity);
+ int _la;
+ try {
+ setState(76);
+ switch (_input.LA(1)) {
+ case TRUE:
+ case FALSE:
+ _localctx = new LogicalConstContext(_localctx);
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(66);
+ _la = _input.LA(1);
+ if ( !(_la==TRUE || _la==FALSE) ) {
+ _errHandler.recoverInline(this);
+ } else {
+ consume();
+ }
+ }
+ break;
+ case EXISTS:
+ _localctx = new ExistsFuncContext(_localctx);
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(67);
+ match(EXISTS);
+ setState(68);
+ match(LPAREN);
+ setState(69);
+ match(IDENTIFIER);
+ setState(70);
+ match(RPAREN);
+ }
+ break;
+ case IDENTIFIER:
+ _localctx = new LogicalFuncContext(_localctx);
+ enterOuterAlt(_localctx, 3);
+ {
+ setState(71);
+ match(IDENTIFIER);
+ setState(72);
+ match(LPAREN);
+ setState(73);
+ func_args();
+ setState(74);
+ match(RPAREN);
+ }
+ break;
+ default:
+ throw new NoViableAltException(this);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class List_entityContext extends ParserRuleContext {
+ public TerminalNode LBRACKET() { return getToken(PredicateParser.LBRACKET, 0); }
+ public Op_listContext op_list() {
+ return getRuleContext(Op_listContext.class,0);
+ }
+ public TerminalNode RBRACKET() { return getToken(PredicateParser.RBRACKET, 0); }
+ public List_entityContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_list_entity; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterList_entity(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitList_entity(this);
+ }
+ }
+
+ public final List_entityContext list_entity() throws RecognitionException {
+ List_entityContext _localctx = new List_entityContext(_ctx, getState());
+ enterRule(_localctx, 8, RULE_list_entity);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(78);
+ match(LBRACKET);
+ setState(79);
+ op_list(0);
+ setState(80);
+ match(RBRACKET);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Func_argsContext extends ParserRuleContext {
+ public Op_listContext op_list() {
+ return getRuleContext(Op_listContext.class,0);
+ }
+ public Func_argsContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_func_args; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterFunc_args(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitFunc_args(this);
+ }
+ }
+
+ public final Func_argsContext func_args() throws RecognitionException {
+ Func_argsContext _localctx = new Func_argsContext(_ctx, getState());
+ enterRule(_localctx, 10, RULE_func_args);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(82);
+ op_list(0);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Op_listContext extends ParserRuleContext {
+ public Identifier_operandContext identifier_operand() {
+ return getRuleContext(Identifier_operandContext.class,0);
+ }
+ public Op_listContext op_list() {
+ return getRuleContext(Op_listContext.class,0);
+ }
+ public TerminalNode COMMA() { return getToken(PredicateParser.COMMA, 0); }
+ public Op_listContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_op_list; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterOp_list(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitOp_list(this);
+ }
+ }
+
+ public final Op_listContext op_list() throws RecognitionException {
+ return op_list(0);
+ }
+
+ private Op_listContext op_list(int _p) throws RecognitionException {
+ ParserRuleContext _parentctx = _ctx;
+ int _parentState = getState();
+ Op_listContext _localctx = new Op_listContext(_ctx, _parentState);
+ Op_listContext _prevctx = _localctx;
+ int _startState = 12;
+ enterRecursionRule(_localctx, 12, RULE_op_list, _p);
+ try {
+ int _alt;
+ enterOuterAlt(_localctx, 1);
+ {
+ {
+ setState(85);
+ identifier_operand();
+ }
+ _ctx.stop = _input.LT(-1);
+ setState(92);
+ _errHandler.sync(this);
+ _alt = getInterpreter().adaptivePredict(_input,5,_ctx);
+ while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
+ if ( _alt==1 ) {
+ if ( _parseListeners!=null ) triggerExitRuleEvent();
+ _prevctx = _localctx;
+ {
+ {
+ _localctx = new Op_listContext(_parentctx, _parentState);
+ pushNewRecursionContext(_localctx, _startState, RULE_op_list);
+ setState(87);
+ if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
+ setState(88);
+ match(COMMA);
+ setState(89);
+ identifier_operand();
+ }
+ }
+ }
+ setState(94);
+ _errHandler.sync(this);
+ _alt = getInterpreter().adaptivePredict(_input,5,_ctx);
+ }
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ unrollRecursionContexts(_parentctx);
+ }
+ return _localctx;
+ }
+
+ public static class Identifier_operandContext extends ParserRuleContext {
+ public Identifier_operandContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_identifier_operand; }
+
+ public Identifier_operandContext() { }
+ public void copyFrom(Identifier_operandContext ctx) {
+ super.copyFrom(ctx);
+ }
+ }
+ public static class LogicalVariableContext extends Identifier_operandContext {
+ public TerminalNode IDENTIFIER() { return getToken(PredicateParser.IDENTIFIER, 0); }
+ public LogicalVariableContext(Identifier_operandContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalVariable(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalVariable(this);
+ }
+ }
+ public static class StringLiteralContext extends Identifier_operandContext {
+ public TerminalNode STRING_LITERAL() { return getToken(PredicateParser.STRING_LITERAL, 0); }
+ public StringLiteralContext(Identifier_operandContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterStringLiteral(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitStringLiteral(this);
+ }
+ }
+ public static class StringFuncContext extends Identifier_operandContext {
+ public TerminalNode IDENTIFIER() { return getToken(PredicateParser.IDENTIFIER, 0); }
+ public TerminalNode LPAREN() { return getToken(PredicateParser.LPAREN, 0); }
+ public Func_argsContext func_args() {
+ return getRuleContext(Func_argsContext.class,0);
+ }
+ public TerminalNode RPAREN() { return getToken(PredicateParser.RPAREN, 0); }
+ public StringFuncContext(Identifier_operandContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterStringFunc(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitStringFunc(this);
+ }
+ }
+
+ public final Identifier_operandContext identifier_operand() throws RecognitionException {
+ Identifier_operandContext _localctx = new Identifier_operandContext(_ctx, getState());
+ enterRule(_localctx, 14, RULE_identifier_operand);
+ try {
+ setState(102);
+ switch ( getInterpreter().adaptivePredict(_input,6,_ctx) ) {
+ case 1:
+ _localctx = new StringLiteralContext(_localctx);
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(95);
+ match(STRING_LITERAL);
+ }
+ break;
+ case 2:
+ _localctx = new LogicalVariableContext(_localctx);
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(96);
+ match(IDENTIFIER);
+ }
+ break;
+ case 3:
+ _localctx = new StringFuncContext(_localctx);
+ enterOuterAlt(_localctx, 3);
+ {
+ setState(97);
+ match(IDENTIFIER);
+ setState(98);
+ match(LPAREN);
+ setState(99);
+ func_args();
+ setState(100);
+ match(RPAREN);
+ }
+ break;
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Comparison_operandContext extends ParserRuleContext {
+ public Comparison_operandContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_comparison_operand; }
+
+ public Comparison_operandContext() { }
+ public void copyFrom(Comparison_operandContext ctx) {
+ super.copyFrom(ctx);
+ }
+ }
+ public static class LogicalConstComparisonContext extends Comparison_operandContext {
+ public Logical_entityContext logical_entity() {
+ return getRuleContext(Logical_entityContext.class,0);
+ }
+ public LogicalConstComparisonContext(Comparison_operandContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterLogicalConstComparison(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitLogicalConstComparison(this);
+ }
+ }
+ public static class IdentifierOperandContext extends Comparison_operandContext {
+ public Identifier_operandContext identifier_operand() {
+ return getRuleContext(Identifier_operandContext.class,0);
+ }
+ public IdentifierOperandContext(Comparison_operandContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterIdentifierOperand(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitIdentifierOperand(this);
+ }
+ }
+
+ public final Comparison_operandContext comparison_operand() throws RecognitionException {
+ Comparison_operandContext _localctx = new Comparison_operandContext(_ctx, getState());
+ enterRule(_localctx, 16, RULE_comparison_operand);
+ try {
+ setState(106);
+ switch ( getInterpreter().adaptivePredict(_input,7,_ctx) ) {
+ case 1:
+ _localctx = new IdentifierOperandContext(_localctx);
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(104);
+ identifier_operand();
+ }
+ break;
+ case 2:
+ _localctx = new LogicalConstComparisonContext(_localctx);
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(105);
+ logical_entity();
+ }
+ break;
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class Comp_operatorContext extends ParserRuleContext {
+ public Comp_operatorContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_comp_operator; }
+
+ public Comp_operatorContext() { }
+ public void copyFrom(Comp_operatorContext ctx) {
+ super.copyFrom(ctx);
+ }
+ }
+ public static class ComparisonOpContext extends Comp_operatorContext {
+ public TerminalNode EQ() { return getToken(PredicateParser.EQ, 0); }
+ public TerminalNode NEQ() { return getToken(PredicateParser.NEQ, 0); }
+ public ComparisonOpContext(Comp_operatorContext ctx) { copyFrom(ctx); }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).enterComparisonOp(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof PredicateListener ) ((PredicateListener)listener).exitComparisonOp(this);
+ }
+ }
+
+ public final Comp_operatorContext comp_operator() throws RecognitionException {
+ Comp_operatorContext _localctx = new Comp_operatorContext(_ctx, getState());
+ enterRule(_localctx, 18, RULE_comp_operator);
+ int _la;
+ try {
+ _localctx = new ComparisonOpContext(_localctx);
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(108);
+ _la = _input.LA(1);
+ if ( !(_la==EQ || _la==NEQ) ) {
+ _errHandler.recoverInline(this);
+ } else {
+ consume();
+ }
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
+ switch (ruleIndex) {
+ case 1:
+ return logical_expr_sempred((Logical_exprContext)_localctx, predIndex);
+ case 6:
+ return op_list_sempred((Op_listContext)_localctx, predIndex);
+ }
+ return true;
+ }
+ private boolean logical_expr_sempred(Logical_exprContext _localctx, int predIndex) {
+ switch (predIndex) {
+ case 0:
+ return precpred(_ctx, 6);
+ case 1:
+ return precpred(_ctx, 5);
+ }
+ return true;
+ }
+ private boolean op_list_sempred(Op_listContext _localctx, int predIndex) {
+ switch (predIndex) {
+ case 2:
+ return precpred(_ctx, 1);
+ }
+ return true;
+ }
+
+ public static final String _serializedATN =
+ "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\26q\4\2\t\2\4\3\t"+
+ "\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\3"+
+ "\2\3\2\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\5\3&\n\3\3"+
+ "\3\3\3\3\3\3\3\3\3\3\3\7\3.\n\3\f\3\16\3\61\13\3\3\4\3\4\3\4\3\4\3\4\3"+
+ "\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\5\4C\n\4\3\5\3\5\3\5\3\5\3"+
+ "\5\3\5\3\5\3\5\3\5\3\5\5\5O\n\5\3\6\3\6\3\6\3\6\3\7\3\7\3\b\3\b\3\b\3"+
+ "\b\3\b\3\b\7\b]\n\b\f\b\16\b`\13\b\3\t\3\t\3\t\3\t\3\t\3\t\3\t\5\ti\n"+
+ "\t\3\n\3\n\5\nm\n\n\3\13\3\13\3\13\2\4\4\16\f\2\4\6\b\n\f\16\20\22\24"+
+ "\2\4\3\2\6\7\3\2\b\tt\2\26\3\2\2\2\4%\3\2\2\2\6B\3\2\2\2\bN\3\2\2\2\n"+
+ "P\3\2\2\2\fT\3\2\2\2\16V\3\2\2\2\20h\3\2\2\2\22l\3\2\2\2\24n\3\2\2\2\26"+
+ "\27\5\4\3\2\27\30\7\2\2\3\30\3\3\2\2\2\31\32\b\3\1\2\32&\5\6\4\2\33\34"+
+ "\7\r\2\2\34\35\5\4\3\2\35\36\7\16\2\2\36&\3\2\2\2\37 \7\5\2\2 !\7\r\2"+
+ "\2!\"\5\4\3\2\"#\7\16\2\2#&\3\2\2\2$&\5\b\5\2%\31\3\2\2\2%\33\3\2\2\2"+
+ "%\37\3\2\2\2%$\3\2\2\2&/\3\2\2\2\'(\f\b\2\2()\7\3\2\2).\5\4\3\t*+\f\7"+
+ "\2\2+,\7\4\2\2,.\5\4\3\b-\'\3\2\2\2-*\3\2\2\2.\61\3\2\2\2/-\3\2\2\2/\60"+
+ "\3\2\2\2\60\5\3\2\2\2\61/\3\2\2\2\62\63\5\22\n\2\63\64\5\24\13\2\64\65"+
+ "\5\22\n\2\65C\3\2\2\2\66\67\5\20\t\2\678\7\17\2\289\5\n\6\29C\3\2\2\2"+
+ ":;\5\20\t\2;<\7\20\2\2<=\5\n\6\2=C\3\2\2\2>?\7\r\2\2?@\5\6\4\2@A\7\16"+
+ "\2\2AC\3\2\2\2B\62\3\2\2\2B\66\3\2\2\2B:\3\2\2\2B>\3\2\2\2C\7\3\2\2\2"+
+ "DO\t\2\2\2EF\7\21\2\2FG\7\r\2\2GH\7\22\2\2HO\7\16\2\2IJ\7\22\2\2JK\7\r"+
+ "\2\2KL\5\f\7\2LM\7\16\2\2MO\3\2\2\2ND\3\2\2\2NE\3\2\2\2NI\3\2\2\2O\t\3"+
+ "\2\2\2PQ\7\13\2\2QR\5\16\b\2RS\7\f\2\2S\13\3\2\2\2TU\5\16\b\2U\r\3\2\2"+
+ "\2VW\b\b\1\2WX\5\20\t\2X^\3\2\2\2YZ\f\3\2\2Z[\7\n\2\2[]\5\20\t\2\\Y\3"+
+ "\2\2\2]`\3\2\2\2^\\\3\2\2\2^_\3\2\2\2_\17\3\2\2\2`^\3\2\2\2ai\7\23\2\2"+
+ "bi\7\22\2\2cd\7\22\2\2de\7\r\2\2ef\5\f\7\2fg\7\16\2\2gi\3\2\2\2ha\3\2"+
+ "\2\2hb\3\2\2\2hc\3\2\2\2i\21\3\2\2\2jm\5\20\t\2km\5\b\5\2lj\3\2\2\2lk"+
+ "\3\2\2\2m\23\3\2\2\2no\t\3\2\2o\25\3\2\2\2\n%-/BN^hl";
+ public static final ATN _ATN =
+ new ATNDeserializer().deserialize(_serializedATN.toCharArray());
+ static {
+ _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
+ for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
+ _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/main/scripts/zk_load_configs.sh
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/scripts/zk_load_configs.sh b/metron-platform/metron-common/src/main/scripts/zk_load_configs.sh
index bd9e9eb..ff64e3d 100755
--- a/metron-platform/metron-common/src/main/scripts/zk_load_configs.sh
+++ b/metron-platform/metron-common/src/main/scripts/zk_load_configs.sh
@@ -30,4 +30,4 @@ export METRON_VERSION=${project.version}
export METRON_HOME=/usr/metron/$METRON_VERSION
export PARSERS_JAR=${project.artifactId}-$METRON_VERSION.jar
export ZK_HOME=${ZK_HOME:-/usr/hdp/current/zookeeper-client}
-java -cp $METRON_HOME/lib/$PARSERS_JAR:$ZK_HOME/lib/* org.apache.metron.common.cli.ConfigurationsUtils "$@"
+java -cp $METRON_HOME/lib/$PARSERS_JAR:$ZK_HOME/lib/* org.apache.metron.common.cli.ConfigurationManager "$@"
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/java/org/apache/metron/common/bolt/ConfiguredBoltTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/bolt/ConfiguredBoltTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/bolt/ConfiguredBoltTest.java
index a791086..6df930b 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/bolt/ConfiguredBoltTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/bolt/ConfiguredBoltTest.java
@@ -24,8 +24,8 @@ import org.apache.metron.common.Constants;
import org.apache.metron.TestConstants;
import org.apache.metron.test.bolt.BaseEnrichmentBoltTest;
import org.apache.metron.common.configuration.Configurations;
-import org.apache.metron.common.configuration.SensorEnrichmentConfig;
-import org.apache.metron.common.cli.ConfigurationsUtils;
+import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
+import org.apache.metron.common.configuration.ConfigurationsUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -119,12 +119,12 @@ public class ConfiguredBoltTest extends BaseEnrichmentBoltTest {
enrichmentFieldMap.put("enrichmentTest", new ArrayList<String>() {{
add("enrichmentField");
}});
- testSensorConfig.setEnrichmentFieldMap(enrichmentFieldMap);
+ testSensorConfig.getEnrichment().setFieldMap(enrichmentFieldMap);
Map<String, List<String>> threatIntelFieldMap = new HashMap<>();
threatIntelFieldMap.put("threatIntelTest", new ArrayList<String>() {{
add("threatIntelField");
}});
- testSensorConfig.setThreatIntelFieldMap(threatIntelFieldMap);
+ testSensorConfig.getThreatIntel().setFieldMap(threatIntelFieldMap);
sampleConfigurations.updateSensorEnrichmentConfig(sensorType, testSensorConfig);
ConfigurationsUtils.writeSensorEnrichmentConfigToZookeeper(sensorType, testSensorConfig, zookeeperUrl);
waitForConfigUpdate(sensorType);
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationManagerIntegrationTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationManagerIntegrationTest.java
new file mode 100644
index 0000000..e17b877
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationManagerIntegrationTest.java
@@ -0,0 +1,176 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.metron.common.cli;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+import org.apache.commons.cli.PosixParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.test.TestingServer;
+import org.apache.hadoop.io.BooleanWritable;
+import org.apache.metron.TestConstants;
+import org.apache.metron.common.configuration.ConfigurationType;
+import org.apache.metron.common.configuration.ConfigurationsUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.DirectoryNotEmptyException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.*;
+
+public class ConfigurationManagerIntegrationTest {
+ private TestingServer testZkServer;
+ private CuratorFramework client;
+ private String zookeeperUrl;
+ private String outDir = "target/configs";
+ private Set<String> sensors = new HashSet<>();
+
+ private void cleanDir(File rootDir) throws IOException {
+ if(rootDir.isDirectory()) {
+ try {
+ Files.delete(Paths.get(rootDir.toURI()));
+ } catch (DirectoryNotEmptyException dne) {
+ for(File f : rootDir.listFiles()) {
+ cleanDir(f);
+ }
+ rootDir.delete();
+ }
+ }
+ else {
+ rootDir.delete();
+ }
+ }
+
+ @Before
+ public void setup() throws Exception {
+ testZkServer = new TestingServer(true);
+ zookeeperUrl = testZkServer.getConnectString();
+ client = ConfigurationsUtils.getClient(zookeeperUrl);
+ client.start();
+ File sensorDir = new File(new File(TestConstants.SAMPLE_CONFIG_PATH), ConfigurationType.SENSOR.getDirectory());
+ sensors.addAll(Collections2.transform(
+ Arrays.asList(sensorDir.list())
+ ,s -> Iterables.getFirst(Splitter.on('.').split(s), "null")
+ )
+ );
+ pushConfigs();
+ }
+
+ private void pushConfigs() throws Exception {
+ String[] args = new String[]{
+ "-z", zookeeperUrl
+ , "--mode", "PUSH"
+ , "--input_dir", TestConstants.SAMPLE_CONFIG_PATH
+ };
+ ConfigurationManager manager = new ConfigurationManager();
+ manager.run(ConfigurationManager.ConfigurationOptions.parse(new PosixParser(), args));
+ }
+
+ public void pullConfigs(boolean force) throws Exception {
+ String[] args = null;
+ if(force) {
+ args = new String[]{
+ "-z", zookeeperUrl
+ , "--mode", "PULL"
+ , "--output_dir", outDir
+ , "--force"
+ };
+ }
+ else {
+ args = new String[]{
+ "-z", zookeeperUrl
+ , "--mode", "PULL"
+ , "--output_dir", outDir
+ };
+ }
+ ConfigurationManager manager = new ConfigurationManager();
+ manager.run(ConfigurationManager.ConfigurationOptions.parse(new PosixParser(), args));
+ }
+
+ public void validateConfigsOnDisk(File configDir) throws IOException {
+ File globalConfigFile = new File(configDir, "global.json");
+ Assert.assertTrue("Global config does not exist", globalConfigFile.exists());
+ validateConfig("global", ConfigurationType.GLOBAL, new String(Files.readAllBytes(Paths.get(globalConfigFile.toURI()))));
+ for(String sensor : sensors) {
+ File sensorFile = new File(configDir, ConfigurationType.SENSOR.getDirectory() + "/" + sensor + ".json");
+ Assert.assertTrue(sensor + " config does not exist", sensorFile.exists());
+ validateConfig(sensor, ConfigurationType.SENSOR, new String(Files.readAllBytes(Paths.get(sensorFile.toURI()))));
+ }
+ }
+
+ @Test
+ public void testPull() throws Exception {
+ cleanDir(new File(outDir));
+ pullConfigs(false);
+ validateConfigsOnDisk(new File(outDir));
+ try {
+ //second time without force should
+ pullConfigs(false);
+ Assert.fail("Should have failed to pull configs in a directory structure that already exists.");
+ }
+ catch(IllegalStateException t) {
+ //make sure we didn't bork anything
+ validateConfigsOnDisk(new File(outDir));
+ }
+ pullConfigs(true);
+ validateConfigsOnDisk(new File(outDir));
+ }
+ public void validateConfig(String name, ConfigurationType type, String data)
+ {
+ try {
+ type.deserialize(data);
+ } catch (Exception e) {
+ Assert.fail("Unable to load config " + name + ": " + data);
+ }
+ }
+ @Test
+ public void testPush() throws Exception {
+ pushConfigs();
+ final Set<String> sensorsInZookeeper = new HashSet<>();
+ final BooleanWritable foundGlobal = new BooleanWritable(false);
+ ConfigurationsUtils.visitConfigs(client, new ConfigurationsUtils.ConfigurationVisitor() {
+ @Override
+ public void visit(ConfigurationType configurationType, String name, String data) {
+ Assert.assertTrue(data.length() > 0);
+ validateConfig(name, configurationType, data);
+ if(configurationType == ConfigurationType.GLOBAL) {
+ validateConfig(name, configurationType, data);
+ foundGlobal.set(true);
+ }
+ else {
+ sensorsInZookeeper.add(name);
+ }
+ }
+ });
+ Assert.assertEquals(sensorsInZookeeper, sensors);
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ client.close();
+ testZkServer.close();
+ testZkServer.stop();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
index bee4af7..3393b41 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
@@ -21,7 +21,7 @@ import junit.framework.Assert;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.test.TestingServer;
import org.apache.metron.TestConstants;
-import org.apache.metron.common.cli.ConfigurationsUtils;
+import org.apache.metron.common.configuration.ConfigurationsUtils;
import org.apache.metron.common.utils.JSONUtils;
import org.junit.After;
import org.junit.Before;
@@ -74,17 +74,6 @@ public class ConfigurationsUtilsTest {
}
- @Test
- public void testCmdLine() throws Exception {
- String[] args = {"-z", zookeeperUrl, "-p", TestConstants.SAMPLE_CONFIG_PATH};
- ConfigurationsUtils.main(args);
- byte[] readGlobalConfigBytes = ConfigurationsUtils.readGlobalConfigBytesFromZookeeper(client);
- Assert.assertTrue(Arrays.equals(testGlobalConfig, readGlobalConfigBytes));
- for(String sensorType: testSensorConfigMap.keySet()) {
- byte[] readSensorConfigBytes = ConfigurationsUtils.readSensorEnrichmentConfigBytesFromZookeeper(sensorType, client);
- Assert.assertTrue(Arrays.equals(testSensorConfigMap.get(sensorType), readSensorConfigBytes));
- }
- }
@After
public void tearDown() throws IOException {
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java
deleted file mode 100644
index b7e3e02..0000000
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/EnrichmentConfigTest.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.metron.common.configuration;
-
-import org.adrianwalker.multilinestring.Multiline;
-import org.apache.metron.common.Constants;
-import org.apache.metron.common.utils.JSONUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class EnrichmentConfigTest {
- /**
- {
- "index": "bro",
- "batchSize": 5,
- "enrichmentFieldMap": {
- "geo": ["ip_dst_addr", "ip_src_addr"],
- "host": ["host"]
- },
- "threatIntelFieldMap": {
- "hbaseThreatIntel": ["ip_dst_addr", "ip_src_addr"]
- },
- "fieldToThreatIntelTypeMap": {
- "ip_dst_addr" : [ "malicious_ip" ]
- ,"ip_src_addr" : [ "malicious_ip" ]
- }
- }
- */
- @Multiline
- public static String sourceConfigStr;
-
- /**
-{
- "zkQuorum" : "localhost:2181"
- ,"sensorToFieldList" : {
- "bro" : {
- "type" : "THREAT_INTEL"
- ,"fieldToEnrichmentTypes" : {
- "ip_src_addr" : [ "playful" ]
- ,"ip_dst_addr" : [ "playful" ]
- }
- }
- }
-}
- */
- @Multiline
- public static String threatIntelConfigStr;
-
- @Test
- public void testThreatIntel() throws Exception {
-
- SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
-
-
- EnrichmentConfig config = JSONUtils.INSTANCE.load(threatIntelConfigStr, EnrichmentConfig.class);
- final Map<String, SensorEnrichmentConfig> outputScs = new HashMap<>();
- EnrichmentConfig.SourceConfigHandler scHandler = new EnrichmentConfig.SourceConfigHandler() {
- @Override
- public SensorEnrichmentConfig readConfig(String sensor) throws Exception {
- if(sensor.equals("bro")) {
- return JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
- }
- else {
- throw new IllegalStateException("Tried to retrieve an unexpected sensor: " + sensor);
- }
- }
-
- @Override
- public void persistConfig(String sensor, SensorEnrichmentConfig config) throws Exception {
- outputScs.put(sensor, config);
- }
- };
- EnrichmentConfig.updateSensorConfigs(scHandler, config.getSensorToFieldList());
- Assert.assertNotNull(outputScs.get("bro"));
- Assert.assertNotSame(outputScs.get("bro"), broSc);
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getThreatIntelFieldMap().get(Constants.SIMPLE_HBASE_THREAT_INTEL).size()
- , 2
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getThreatIntelFieldMap()
- .get(Constants.SIMPLE_HBASE_THREAT_INTEL)
- .contains("ip_src_addr")
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getThreatIntelFieldMap()
- .get(Constants.SIMPLE_HBASE_THREAT_INTEL)
- .contains("ip_dst_addr")
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToThreatIntelTypeMap().keySet().size()
- , 2
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_src_addr").size()
- , 2
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_src_addr").contains("playful")
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_src_addr").contains("malicious_ip")
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_dst_addr").size()
- , 2
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_dst_addr").contains("playful")
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToThreatIntelTypeMap().get("ip_dst_addr").contains("malicious_ip")
- );
- }
-
- /**
- {
- "zkQuorum" : "localhost:2181"
- ,"sensorToFieldList" : {
- "bro" : {
- "type" : "ENRICHMENT"
- ,"fieldToEnrichmentTypes" : {
- "ip_src_addr" : [ "playful" ]
- ,"ip_dst_addr" : [ "playful" ]
- }
- }
- }
- }
- */
- @Multiline
- public static String enrichmentConfigStr;
- @Test
- public void testEnrichment() throws Exception {
-
- SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
-
- EnrichmentConfig config = JSONUtils.INSTANCE.load(enrichmentConfigStr, EnrichmentConfig.class);
- final Map<String, SensorEnrichmentConfig> outputScs = new HashMap<>();
- EnrichmentConfig.SourceConfigHandler scHandler = new EnrichmentConfig.SourceConfigHandler() {
- @Override
- public SensorEnrichmentConfig readConfig(String sensor) throws Exception {
- if(sensor.equals("bro")) {
- return JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
- }
- else {
- throw new IllegalStateException("Tried to retrieve an unexpected sensor: " + sensor);
- }
- }
-
- @Override
- public void persistConfig(String sensor, SensorEnrichmentConfig config) throws Exception {
- outputScs.put(sensor, config);
- }
- };
- EnrichmentConfig.updateSensorConfigs(scHandler, config.getSensorToFieldList());
- Assert.assertNotNull(outputScs.get("bro"));
- Assert.assertNotSame(outputScs.get("bro"), broSc);
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getEnrichmentFieldMap().get(Constants.SIMPLE_HBASE_ENRICHMENT).size()
- , 2
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getEnrichmentFieldMap()
- .get(Constants.SIMPLE_HBASE_ENRICHMENT)
- .contains("ip_src_addr")
- );
- Assert.assertTrue( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getEnrichmentFieldMap()
- .get(Constants.SIMPLE_HBASE_ENRICHMENT)
- .contains("ip_dst_addr")
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToEnrichmentTypeMap().keySet().size()
- , 2
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_src_addr").size()
- , 1
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_src_addr").get(0)
- , "playful"
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_dst_addr").size()
- , 1
- );
- Assert.assertEquals( outputScs.get("bro").toJSON()
- , outputScs.get("bro").getFieldToEnrichmentTypeMap().get("ip_dst_addr").get(0)
- , "playful"
- );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
index 93a3d54..418ee9b 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
@@ -21,7 +21,7 @@ import junit.framework.Assert;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.apache.metron.TestConstants;
-import org.apache.metron.common.cli.ConfigurationsUtils;
+import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
import org.junit.Test;
import java.io.IOException;
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentUpdateConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentUpdateConfigTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentUpdateConfigTest.java
new file mode 100644
index 0000000..009fc22
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentUpdateConfigTest.java
@@ -0,0 +1,224 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.common.configuration;
+
+import org.adrianwalker.multilinestring.Multiline;
+import org.apache.metron.common.Constants;
+import org.apache.metron.common.configuration.enrichment.SensorEnrichmentUpdateConfig;
+import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
+import org.apache.metron.common.utils.JSONUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SensorEnrichmentUpdateConfigTest {
+ /**
+ {
+ "index": "bro",
+ "batchSize": 5,
+ "enrichment" : {
+ "fieldMap": {
+ "geo": ["ip_dst_addr", "ip_src_addr"],
+ "host": ["host"]
+ }
+ },
+ "threatIntel": {
+ "fieldMap": {
+ "hbaseThreatIntel": ["ip_dst_addr", "ip_src_addr"]
+ },
+ "fieldToTypeMap": {
+ "ip_dst_addr" : [ "malicious_ip" ]
+ ,"ip_src_addr" : [ "malicious_ip" ]
+ },
+ "triageConfig" : {
+ "riskLevelRules" : {
+ "not(IN_SUBNET(ip_dst_addr, '192.168.0.0/24'))" : 10
+ },
+ "aggregator" : "MAX"
+ }
+ }
+ }
+ */
+ @Multiline
+ public static String sourceConfigStr;
+
+ /**
+{
+ "zkQuorum" : "localhost:2181"
+ ,"sensorToFieldList" : {
+ "bro" : {
+ "type" : "THREAT_INTEL"
+ ,"fieldToEnrichmentTypes" : {
+ "ip_src_addr" : [ "playful" ]
+ ,"ip_dst_addr" : [ "playful" ]
+ }
+ }
+ }
+}
+ */
+ @Multiline
+ public static String threatIntelConfigStr;
+
+ @Test
+ public void testThreatIntel() throws Exception {
+
+ SensorEnrichmentConfig broSc = (SensorEnrichmentConfig) ConfigurationType.SENSOR.deserialize(sourceConfigStr);
+
+
+ SensorEnrichmentUpdateConfig config = JSONUtils.INSTANCE.load(threatIntelConfigStr, SensorEnrichmentUpdateConfig.class);
+ final Map<String, SensorEnrichmentConfig> outputScs = new HashMap<>();
+ SensorEnrichmentUpdateConfig.SourceConfigHandler scHandler = new SensorEnrichmentUpdateConfig.SourceConfigHandler() {
+ @Override
+ public SensorEnrichmentConfig readConfig(String sensor) throws Exception {
+ if(sensor.equals("bro")) {
+ return JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
+ }
+ else {
+ throw new IllegalStateException("Tried to retrieve an unexpected sensor: " + sensor);
+ }
+ }
+
+ @Override
+ public void persistConfig(String sensor, SensorEnrichmentConfig config) throws Exception {
+ outputScs.put(sensor, config);
+ }
+ };
+ SensorEnrichmentUpdateConfig.updateSensorConfigs(scHandler, config.getSensorToFieldList());
+ Assert.assertNotNull(outputScs.get("bro"));
+ Assert.assertNotSame(outputScs.get("bro"), broSc);
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldMap().get(Constants.SIMPLE_HBASE_THREAT_INTEL).size()
+ , 2
+ );
+ Assert.assertEquals(1, outputScs.get("bro").getThreatIntel().getTriageConfig().getRiskLevelRules().size());
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldMap()
+ .get(Constants.SIMPLE_HBASE_THREAT_INTEL)
+ .contains("ip_src_addr")
+ );
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldMap()
+ .get(Constants.SIMPLE_HBASE_THREAT_INTEL)
+ .contains("ip_dst_addr")
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldToTypeMap().keySet().size()
+ , 2
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldToTypeMap().get("ip_src_addr").size()
+ , 2
+ );
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldToTypeMap().get("ip_src_addr").contains("playful")
+ );
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldToTypeMap().get("ip_src_addr").contains("malicious_ip")
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldToTypeMap().get("ip_dst_addr").size()
+ , 2
+ );
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldToTypeMap().get("ip_dst_addr").contains("playful")
+ );
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getThreatIntel().getFieldToTypeMap().get("ip_dst_addr").contains("malicious_ip")
+ );
+ }
+
+ /**
+ {
+ "zkQuorum" : "localhost:2181"
+ ,"sensorToFieldList" : {
+ "bro" : {
+ "type" : "ENRICHMENT"
+ ,"fieldToEnrichmentTypes" : {
+ "ip_src_addr" : [ "playful" ]
+ ,"ip_dst_addr" : [ "playful" ]
+ }
+ }
+ }
+ }
+ */
+ @Multiline
+ public static String enrichmentConfigStr;
+ @Test
+ public void testEnrichment() throws Exception {
+
+ SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
+
+ SensorEnrichmentUpdateConfig config = JSONUtils.INSTANCE.load(enrichmentConfigStr, SensorEnrichmentUpdateConfig.class);
+ final Map<String, SensorEnrichmentConfig> outputScs = new HashMap<>();
+ SensorEnrichmentUpdateConfig.SourceConfigHandler scHandler = new SensorEnrichmentUpdateConfig.SourceConfigHandler() {
+ @Override
+ public SensorEnrichmentConfig readConfig(String sensor) throws Exception {
+ if(sensor.equals("bro")) {
+ return JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
+ }
+ else {
+ throw new IllegalStateException("Tried to retrieve an unexpected sensor: " + sensor);
+ }
+ }
+
+ @Override
+ public void persistConfig(String sensor, SensorEnrichmentConfig config) throws Exception {
+ outputScs.put(sensor, config);
+ }
+ };
+ SensorEnrichmentUpdateConfig.updateSensorConfigs(scHandler, config.getSensorToFieldList());
+ Assert.assertNotNull(outputScs.get("bro"));
+ Assert.assertNotSame(outputScs.get("bro"), broSc);
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldMap().get(Constants.SIMPLE_HBASE_ENRICHMENT).size()
+ , 2
+ );
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldMap()
+ .get(Constants.SIMPLE_HBASE_ENRICHMENT)
+ .contains("ip_src_addr")
+ );
+ Assert.assertTrue( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldMap()
+ .get(Constants.SIMPLE_HBASE_ENRICHMENT)
+ .contains("ip_dst_addr")
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldToTypeMap().keySet().size()
+ , 2
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldToTypeMap().get("ip_src_addr").size()
+ , 1
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldToTypeMap().get("ip_src_addr").get(0)
+ , "playful"
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldToTypeMap().get("ip_dst_addr").size()
+ , 1
+ );
+ Assert.assertEquals( outputScs.get("bro").toJSON()
+ , outputScs.get("bro").getEnrichment().getFieldToTypeMap().get("ip_dst_addr").get(0)
+ , "playful"
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/java/org/apache/metron/common/query/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/query/QueryParserTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/query/QueryParserTest.java
new file mode 100644
index 0000000..ad798e2
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/query/QueryParserTest.java
@@ -0,0 +1,152 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.metron.common.query;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class QueryParserTest {
+
+ @Test
+ public void testValidation() throws Exception {
+ PredicateProcessor processor = new PredicateProcessor();
+ try {
+ processor.validate("'foo'");
+ Assert.fail("Invalid rule found to be valid.");
+ }
+ catch(ParseException e) {
+
+ }
+ try {
+ processor.validate("enrichedField1 == 'enrichedValue1");
+ Assert.fail("Invalid rule found to be valid.");
+ }
+ catch(ParseException e) {
+
+ }
+ }
+
+ private static boolean run(String rule, VariableResolver resolver) {
+ PredicateProcessor processor = new PredicateProcessor();
+ Assert.assertTrue(rule + " not valid.", processor.validate(rule));
+ return processor.parse(rule, resolver);
+ }
+
+ @Test
+ public void testSimpleOps() throws Exception {
+ final Map<String, String> variableMap = new HashMap<String, String>() {{
+ put("foo", "casey");
+ put("empty", "");
+ put("spaced", "metron is great");
+ put("foo.bar", "casey");
+ }};
+ Assert.assertTrue(run("'casey' == foo.bar", v -> variableMap.get(v)));
+ Assert.assertTrue(run("'casey' == foo", v -> variableMap.get(v)));
+ Assert.assertFalse(run("'casey' != foo", v -> variableMap.get(v)));
+ Assert.assertTrue(run("'stella' == 'stella'", v -> variableMap.get(v)));
+ Assert.assertFalse(run("'stella' == foo", v -> variableMap.get(v)));
+ Assert.assertTrue(run("foo== foo", v -> variableMap.get(v)));
+ Assert.assertTrue(run("empty== ''", v -> variableMap.get(v)));
+ Assert.assertTrue(run("spaced == 'metron is great'", v -> variableMap.get(v)));
+ }
+
+ @Test
+ public void testBooleanOps() throws Exception {
+ final Map<String, String> variableMap = new HashMap<String, String>() {{
+ put("foo", "casey");
+ put("empty", "");
+ put("spaced", "metron is great");
+ }};
+ Assert.assertFalse(run("not('casey' == foo and true)", v -> variableMap.get(v)));
+ Assert.assertTrue(run("not(not('casey' == foo and true))", v -> variableMap.get(v)));
+ Assert.assertTrue(run("('casey' == foo) && ( false != true )", v -> variableMap.get(v)));
+ Assert.assertFalse(run("('casey' == foo) and (FALSE == TRUE)", v -> variableMap.get(v)));
+ Assert.assertFalse(run("'casey' == foo and FALSE", v -> variableMap.get(v)));
+ Assert.assertTrue(run("'casey' == foo and true", v -> variableMap.get(v)));
+ }
+ @Test
+ public void testList() throws Exception {
+ final Map<String, String> variableMap = new HashMap<String, String>() {{
+ put("foo", "casey");
+ put("empty", "");
+ put("spaced", "metron is great");
+ }};
+ Assert.assertTrue(run("foo in [ 'casey', 'david' ]", v -> variableMap.get(v)));
+ Assert.assertTrue(run("foo in [ foo, 'david' ]", v -> variableMap.get(v)));
+ Assert.assertTrue(run("foo in [ 'casey', 'david' ] and 'casey' == foo", v -> variableMap.get(v)));
+ Assert.assertTrue(run("foo in [ 'casey', 'david' ] and foo == 'casey'", v -> variableMap.get(v)));
+ Assert.assertTrue(run("foo in [ 'casey' ]", v -> variableMap.get(v)));
+ Assert.assertFalse(run("foo not in [ 'casey', 'david' ]", v -> variableMap.get(v)));
+ Assert.assertFalse(run("foo not in [ 'casey', 'david' ] and 'casey' == foo", v -> variableMap.get(v)));
+ }
+ @Test
+ public void testExists() throws Exception {
+ final Map<String, String> variableMap = new HashMap<String, String>() {{
+ put("foo", "casey");
+ put("empty", "");
+ put("spaced", "metron is great");
+ }};
+ Assert.assertTrue(run("exists(foo)", v -> variableMap.get(v)));
+ Assert.assertFalse(run("exists(bar)", v -> variableMap.get(v)));
+ Assert.assertTrue(run("exists(bar) or true", v -> variableMap.get(v)));
+ }
+
+ @Test
+ public void testStringFunctions() throws Exception {
+ final Map<String, String> variableMap = new HashMap<String, String>() {{
+ put("foo", "casey");
+ put("ip", "192.168.0.1");
+ put("empty", "");
+ put("spaced", "metron is great");
+ }};
+ Assert.assertTrue(run("true and TO_UPPER(foo) == 'CASEY'", v -> variableMap.get(v)));
+ Assert.assertTrue(run("foo in [ TO_LOWER('CASEY'), 'david' ]", v -> variableMap.get(v)));
+ Assert.assertTrue(run("TO_UPPER(foo) in [ TO_UPPER('casey'), 'david' ] and IN_SUBNET(ip, '192.168.0.0/24')", v -> variableMap.get(v)));
+ Assert.assertFalse(run("TO_LOWER(foo) in [ TO_UPPER('casey'), 'david' ]", v -> variableMap.get(v)));
+ }
+ @Test
+ public void testLogicalFunctions() throws Exception {
+ final Map<String, String> variableMap = new HashMap<String, String>() {{
+ put("foo", "casey");
+ put("ip", "192.168.0.1");
+ put("ip_src_addr", "192.168.0.1");
+ put("ip_dst_addr", "10.0.0.1");
+ put("other_ip", "10.168.0.1");
+ put("empty", "");
+ put("spaced", "metron is great");
+ }};
+ Assert.assertTrue(run("IN_SUBNET(ip, '192.168.0.0/24')", v -> variableMap.get(v)));
+ Assert.assertTrue(run("IN_SUBNET(ip, '192.168.0.0/24', '11.0.0.0/24')", v -> variableMap.get(v)));
+ Assert.assertFalse(run("IN_SUBNET(ip_dst_addr, '192.168.0.0/24', '11.0.0.0/24')", v -> variableMap.get(v)));
+ Assert.assertFalse(run("IN_SUBNET(other_ip, '192.168.0.0/24')", v -> variableMap.get(v)));
+ Assert.assertFalse(run("IN_SUBNET(blah, '192.168.0.0/24')", v -> variableMap.get(v)));
+ Assert.assertTrue(run("true and STARTS_WITH(foo, 'ca')", v -> variableMap.get(v)));
+ Assert.assertTrue(run("true and STARTS_WITH(TO_UPPER(foo), 'CA')", v -> variableMap.get(v)));
+ Assert.assertTrue(run("(true and STARTS_WITH(TO_UPPER(foo), 'CA')) || true", v -> variableMap.get(v)));
+ Assert.assertTrue(run("true and ENDS_WITH(foo, 'sey')", v -> variableMap.get(v)));
+ Assert.assertTrue(run("not(IN_SUBNET(ip_src_addr, '192.168.0.0/24') and IN_SUBNET(ip_dst_addr, '192.168.0.0/24'))", v-> variableMap.get(v)));
+ Assert.assertTrue(run("IN_SUBNET(ip_src_addr, '192.168.0.0/24')", v-> variableMap.get(v)));
+ Assert.assertFalse(run("not(IN_SUBNET(ip_src_addr, '192.168.0.0/24'))", v-> variableMap.get(v)));
+ Assert.assertFalse(run("IN_SUBNET(ip_dst_addr, '192.168.0.0/24')", v-> variableMap.get(v)));
+ Assert.assertTrue(run("not(IN_SUBNET(ip_dst_addr, '192.168.0.0/24'))", v-> variableMap.get(v)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-common/src/test/resources/config/sensors/bro.json
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/resources/config/sensors/bro.json b/metron-platform/metron-common/src/test/resources/config/sensors/bro.json
index 8886495..c8f2a54 100644
--- a/metron-platform/metron-common/src/test/resources/config/sensors/bro.json
+++ b/metron-platform/metron-common/src/test/resources/config/sensors/bro.json
@@ -1,19 +1,27 @@
{
"index": "bro",
"batchSize": 5,
- "enrichmentFieldMap":
- {
- "geo": ["ip_dst_addr", "ip_src_addr"],
- "host": ["host"]
+ "enrichment": {
+ "fieldMap": {
+ "geo": [
+ "ip_dst_addr",
+ "ip_src_addr"
+ ],
+ "host": [
+ "host"
+ ]
+ }
},
- "threatIntelFieldMap":
- {
- "hbaseThreatIntel": ["ip_dst_addr", "ip_src_addr"]
- },
- "fieldToThreatIntelTypeMap":
- {
- "ip_dst_addr" : [ "malicious_ip" ]
+ "threatIntel":{
+ "fieldMap":
+ {
+ "hbaseThreatIntel": ["ip_dst_addr", "ip_src_addr"]
+ },
+ "fieldToTypeMap":
+ {
+ "ip_dst_addr" : [ "malicious_ip" ]
,"ip_src_addr" : [ "malicious_ip" ]
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/deed21e6/metron-platform/metron-data-management/src/main/assembly/assembly.xml
----------------------------------------------------------------------
diff --git a/metron-platform/metron-data-management/src/main/assembly/assembly.xml b/metron-platform/metron-data-management/src/main/assembly/assembly.xml
index c2c384b..0b36f9d 100644
--- a/metron-platform/metron-data-management/src/main/assembly/assembly.xml
+++ b/metron-platform/metron-data-management/src/main/assembly/assembly.xml
@@ -19,7 +19,7 @@
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
- <directory>${project.basedir}/src/main/bash</directory>
+ <directory>${project.basedir}/src/main/scripts</directory>
<outputDirectory>/bin</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<excludes>