You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by ma...@apache.org on 2017/07/02 22:43:47 UTC
[21/25] metron git commit: METRON-877 Extract core implementation and
UDF support,
create metron-stellar module (mattf-horton) closes apache/metron#616
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
deleted file mode 100644
index 1ae790d..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
+++ /dev/null
@@ -1,476 +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.dsl.functions;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.metron.common.dsl.BaseStellarFunction;
-import org.apache.metron.common.dsl.ParseException;
-import org.apache.metron.common.dsl.Stellar;
-import org.apache.metron.common.utils.ConversionUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class StringFunctions {
-
- @Stellar(name="REGEXP_MATCH"
- ,description = "Determines whether a regex matches a string"
- , params = {
- "string - The string to test"
- ,"pattern - The proposed regex pattern"
- }
- , returns = "True if the regex pattern matches the string and false if otherwise.")
- public static class RegexpMatch extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> list) {
- if(list.size() < 2) {
- throw new IllegalStateException("REGEXP_MATCH expects two args: [string, pattern] where pattern is a regexp pattern");
- }
- String pattern = (String) list.get(1);
- String str = (String) list.get(0);
- if(str == null || pattern == null) {
- return false;
- }
- return str.matches(pattern);
- }
- }
-
- @Stellar(name="ENDS_WITH"
- ,description = "Determines whether a string ends with a specified suffix"
- , params = {
- "string - The string to test"
- ,"suffix - The proposed suffix"
- }
- , returns = "True if the string ends with the specified suffix and false if otherwise")
- public static class EndsWith extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> list) {
- if(list.size() < 2) {
- throw new IllegalStateException("ENDS_WITH expects two args: [string, suffix] where suffix is the string fragment that the string should end with");
- }
- String prefix = (String) list.get(1);
- String str = (String) list.get(0);
- if(str == null || prefix == null) {
- return false;
- }
- return str.endsWith(prefix);
- }
- }
-
- @Stellar(name="STARTS_WITH"
- ,description = "Determines whether a string starts with a prefix"
- , params = {
- "string - The string to test"
- ,"prefix - The proposed prefix"
- }
- , returns = "True if the string starts with the specified prefix and false if otherwise"
- )
- public static class StartsWith extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> list) {
- if(list.size() < 2) {
- throw new IllegalStateException("STARTS_WITH expects two args: [string, prefix] where prefix is the string fragment that the string should start with");
- }
- String prefix = (String) list.get(1);
- String str = (String) list.get(0);
- if(str == null || prefix == null) {
- return false;
- }
- return str.startsWith(prefix);
- }
- }
-
- @Stellar( name="TO_LOWER"
- , description = "Transforms the first argument to a lowercase string"
- , params = { "input - String" }
- , returns = "Lowercase string"
- )
- public static class ToLower extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> strings) {
- return strings.get(0)==null?null:strings.get(0).toString().toLowerCase();
- }
- }
-
- @Stellar( name="TO_UPPER"
- , description = "Transforms the first argument to an uppercase string"
- , params = { "input - String" }
- , returns = "Uppercase string"
- )
- public static class ToUpper extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> strings) {
- return strings.get(0)==null?null:strings.get(0).toString().toUpperCase();
- }
- }
-
- @Stellar(name="TO_STRING"
- , description = "Transforms the first argument to a string"
- , params = { "input - Object" }
- , returns = "String"
- )
- public static class ToString extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> strings) {
- return strings.get(0)==null?null:strings.get(0).toString();
- }
- }
-
- @Stellar(name="TRIM"
- , description = "Trims whitespace from both sides of a string."
- , params = { "input - String" }
- , returns = "String"
- )
- public static class Trim extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> strings) {
- return strings.get(0)==null?null:strings.get(0).toString().trim();
- }
- }
-
- @Stellar( name="JOIN"
- , description="Joins the components in the list of strings with the specified delimiter."
- , params = { "list - List of strings", "delim - String delimiter"}
- , returns = "String"
- )
- public static class JoinFunction extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- List<Object> arg1 = (List<Object>) args.get(0);
- String delim = (String) args.get(1);
- return Joiner.on(delim).join(Iterables.filter(arg1, x -> x != null));
- }
- }
-
- @Stellar(name="SPLIT"
- , description="Splits the string by the delimiter."
- , params = { "input - String to split", "delim - String delimiter"}
- , returns = "List of strings"
- )
- public static class SplitFunction extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- List ret = new ArrayList();
- Object o1 = args.get(0);
- if(o1 != null) {
- String arg1 = o1.toString();
- String delim = (String) args.get(1);
- Iterables.addAll(ret, Splitter.on(delim).split(arg1));
- }
- return ret;
- }
- }
-
- @Stellar(name="GET_LAST"
- , description="Returns the last element of the list"
- , params = { "input - List"}
- , returns = "Last element of the list"
- )
- public static class GetLast extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- List<Object> arg1 = (List<Object>) args.get(0);
- return Iterables.getLast(arg1, null);
- }
- }
-
- @Stellar(name="GET_FIRST"
- , description="Returns the first element of the list"
- , params = { "input - List"}
- , returns = "First element of the list"
- )
- public static class GetFirst extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- List<Object> arg1 = (List<Object>) args.get(0);
- return Iterables.getFirst(arg1, null);
- }
- }
-
- @Stellar(name="GET"
- , description="Returns the i'th element of the list "
- , params = { "input - List", "i - The index (0-based)"}
- , returns = "First element of the list"
- )
- public static class Get extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- List<Object> arg1 = (List<Object>) args.get(0);
- int offset = (Integer) args.get(1);
- if(offset < arg1.size()) {
- return Iterables.get(arg1, offset);
- }
- return null;
- }
- }
-
- private enum FillDirection{
- LEFT,
- RIGHT
- }
-
- @Stellar(name="FILL_LEFT"
- , description="Fills or pads a given string with a given character, to a given length on the left"
- , params = { "input - string", "fill - the fill character", "len - the required length"}
- , returns = "Filled String"
- )
- public static class FillLeft extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- if(args.size() < 3) {
- throw new IllegalStateException("FILL_LEFT expects three args: [string,char,length] where char is the fill character string and length is the required length of the result");
- }
- return fill(FillDirection.LEFT,args.get(0),args.get(1),args.get(2));
- }
- }
-
- @Stellar(name="FILL_RIGHT"
- , description="Fills or pads a given string with a given character, to a given length on the right"
- , params = { "input - string", "fill - the fill character", "len - the required length"}
- , returns = "Filled String"
- )
- public static class FillRight extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- if(args.size() < 3) {
- throw new IllegalStateException("FILL_RIGHT expects three args: [string,char,length] where char is the fill character string and length is the required length of the result");
- }
- return fill(FillDirection.RIGHT,args.get(0),args.get(1),args.get(2));
- }
- }
-
- private static Object fill(FillDirection direction, Object inputObject, Object fillObject, Object requiredLengthObject)throws ParseException{
- if(inputObject == null) {
- return null;
- }
- String input = inputObject.toString();
-
- if(requiredLengthObject == null || fillObject == null) {
- throw new IllegalStateException("Required Length and Fill String are both required");
- }
-
- String fill = fillObject.toString();
- if(org.apache.commons.lang.StringUtils.isEmpty(fill)){
- throw new IllegalStateException("The fill cannot be an empty string");
- }
- fill = fill.substring(0,1);
- Integer requiredLength = ConversionUtils.convert(requiredLengthObject,Integer.class);
- if(requiredLength == null){
- throw new IllegalStateException("Required Length not a valid Integer: " + requiredLengthObject.toString());
- }
-
- if(direction == FillDirection.LEFT) {
- return org.apache.commons.lang.StringUtils.leftPad(input,requiredLength,fill);
- }
- return org.apache.commons.lang.StringUtils.rightPad(input,requiredLength,fill);
- }
-
- @Stellar( namespace="STRING"
- , name="ENTROPY"
- , description = "Computes the base-2 shannon entropy of a string"
- , params = { "input - String" }
- , returns = "The base-2 shannon entropy of the string (https://en.wikipedia.org/wiki/Entropy_(information_theory)#Definition). The unit of this is bits."
- )
- public static class Entropy extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> strings) {
- /*
- Shannon entropy is defined as follows:
- \Eta(X) = - \sum(p(x_i)*log_2(p(x_i)), i=0, n-1) where x_i are distinct characters in the string.
- */
- Map<Character, Integer> frequency = new HashMap<>();
- if(strings.size() != 1) {
- throw new IllegalArgumentException("STRING_ENTROPY expects exactly one argument which is a string.");
- }
- String input = ConversionUtils.convert(strings.get(0), String.class);
- if(StringUtils.isEmpty(input)) {
- return 0.0;
- }
- for(int i = 0;i < input.length();++i) {
- char c = input.charAt(i);
- frequency.put(c, frequency.getOrDefault(c, 0) + 1);
- }
- double ret = 0.0;
- double log2 = Math.log(2);
- for(Integer f : frequency.values()) {
- double p = f.doubleValue()/input.length();
- ret -= p * Math.log(p) / log2;
- }
- return ret;
- }
- }
-
- @Stellar( name="FORMAT"
- , description = "Returns a formatted string using the specified format string and arguments. Uses Java's string formatting conventions."
- , params = { "format - string", "arguments... - object(s)" }
- , returns = "A formatted string."
- )
- public static class Format extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> args) {
-
- if(args.size() == 0) {
- throw new IllegalArgumentException("[FORMAT] missing argument: format string");
- }
-
- String format = ConversionUtils.convert(args.get(0), String.class);
- Object[] formatArgs = args.subList(1, args.size()).toArray();
-
- return String.format(format, formatArgs);
- }
- }
-
- @Stellar( name="CHOMP"
- , description = "Removes one newline from end of a String if it's there, otherwise leave it alone. A newline is \"\\n\", \"\\r\", or \"\\r\\n\""
- , params = { "the String to chomp a newline from, may be null"}
- , returns = "String without newline, null if null String input"
- )
- public static class Chomp extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> strings) {
-
- if(strings == null || strings.size() == 0 ) {
- throw new IllegalArgumentException("[CHOMP] missing argument: string to be chopped");
- }
- String var = strings.get(0) == null?null: (String) strings.get(0);
- if(var == null) {
- return null;
- }
- else if(var.length() == 0) {
- return var;
- }
- else {
- return StringUtils.chomp(var);
- }
- }
- }
- @Stellar( name="CHOP"
- , description = "Remove the last character from a String"
- , params = { "the String to chop last character from, may be null"}
- , returns = "String without last character, null if null String input"
- )
- public static class Chop extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> strings) {
-
- if(strings == null || strings.size() == 0 ) {
- throw new IllegalArgumentException("[CHOP] missing argument: string to be chopped");
- }
- String var = strings.get(0) == null?null: (String) strings.get(0);
- if(var == null) {
- return null;
- }
- else if(var.length() == 0) {
- return var;
- }
- else {
- return StringUtils.chop(var);
- }
- }
- }
-
- @Stellar( name = "PREPEND_IF_MISSING"
- , description = "Prepends the prefix to the start of the string if the string does not already start with any of the prefixes"
- , params = {
- "str - The string."
- , "prefix - The string prefix to prepend to the start of the string"
- , "additionalprefix - Optional - Additional string prefix that is valid"
- }
- , returns = "A new String if prefix was prepended, the same string otherwise."
- )
- public static class PrependIfMissing extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> strings) {
-
- String prefixed;
- switch (strings.size()) {
- case 2: prefixed = StringUtils.prependIfMissing((String) strings.get(0), (String) strings.get(1));
- break;
- case 3: prefixed = StringUtils.prependIfMissing((String) strings.get(0), (String) strings.get(1), (String) strings.get(2));
- break;
- default: throw new IllegalArgumentException("[PREPEND_IF_MISSING] incorrect arguments: " + strings.toString() + "\nUsage: PREPEND_IF_MISSING <String> <prefix> [<prefix>...]");
- }
- return prefixed;
- }
- }
-
- @Stellar( name = "APPEND_IF_MISSING"
- , description = "Appends the suffix to the end of the string if the string does not already end with any of the suffixes"
- , params = {
- "str - The string."
- , "suffix - The string suffix to append to the end of the string"
- , "additionalsuffix - Optional - Additional string suffix that is a valid terminator"
- }
- , returns = "A new String if suffix was appended, the same string otherwise."
- )
- public static class AppendIfMissing extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> strings) {
-
- String suffixed;
- switch (strings.size()) {
- case 2:
- suffixed = StringUtils.appendIfMissing((String) strings.get(0), (String) strings.get(1));
- break;
- case 3:
- suffixed = StringUtils.appendIfMissing((String) strings.get(0), (String) strings.get(1), (String) strings.get(2));
- break;
- default:
- throw new IllegalArgumentException("[APPEND_IF_MISSING] incorrect arguments. Usage: APPEND_IF_MISSING <String> <prefix> [<prefix>...]");
- }
- return suffixed;
- }
- }
-
- @Stellar( name = "COUNT_MATCHES"
- , description = "Counts how many times the substring appears in the larger string"
- , params = {
- "str - the CharSequence to check, may be null"
- , "sub - the substring to count, may be null"
- }
- , returns = "the number of non-overlapping occurrences, 0 if either CharSequence is null"
- )
- public static class CountMatches extends BaseStellarFunction {
-
- @Override
- public Object apply(List<Object> strings) {
-
- if(strings.size() != 2) {
- throw new IllegalArgumentException("[COUNT_MATCHES] incorrect arguments. Usage: COUNT_MATCHES <String> <substring>");
- }
-
- int matchcount;
- matchcount = StringUtils.countMatches((String) strings.get(0), (String) strings.get(1));
- return matchcount;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/SystemFunctions.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/SystemFunctions.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/SystemFunctions.java
deleted file mode 100644
index 13ca74d..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/SystemFunctions.java
+++ /dev/null
@@ -1,87 +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.dsl.functions;
-
-import org.apache.metron.common.dsl.BaseStellarFunction;
-import org.apache.metron.common.dsl.Stellar;
-import org.apache.metron.common.system.Environment;
-
-import java.util.List;
-import java.util.function.Function;
-
-public class SystemFunctions {
-
- @Stellar(namespace = "SYSTEM",
- name = "ENV_GET",
- description = "Returns the value associated with an environment variable",
- params = {
- "env_var - Environment variable name to get the value for"
- },
- returns = "String"
- )
- public static class EnvGet extends BaseStellarFunction {
- private Environment env;
-
- public EnvGet() {
- this(new Environment());
- }
-
- public EnvGet(Environment env) {
- this.env = env;
- }
-
- @Override
- public Object apply(List<Object> args) {
- return extractTypeChecked(args, 0, String.class, x -> env.get((String) x.get(0)));
- }
- }
-
- /**
- * Extract type-checked value from an argument list using the specified type check and extraction function
- *
- * @param args Arguments to check
- * @param i Index of argument to extract
- * @param clazz Object type to verify
- * @param extractFunc Function applied to extract the value from args
- * @return value from args if passes type checks, null otherwise
- */
- public static Object extractTypeChecked(List<Object> args, int i, Class clazz, Function<List<Object>, Object> extractFunc) {
- if (args.size() < i + 1) {
- return null;
- } else if (clazz.isInstance(args.get(i))) {
- return extractFunc.apply(args);
- } else {
- return null;
- }
- }
-
- @Stellar(namespace = "SYSTEM",
- name = "PROPERTY_GET",
- description = "Returns the value associated with a Java system property",
- params = {
- "key - Property to get the value for"
- },
- returns = "String"
- )
- public static class PropertyGet extends BaseStellarFunction {
- @Override
- public Object apply(List<Object> args) {
- return extractTypeChecked(args, 0, String.class, x -> System.getProperty((String) args.get(0)));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/BaseFunctionResolver.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/BaseFunctionResolver.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/BaseFunctionResolver.java
deleted file mode 100644
index ba4f442..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/BaseFunctionResolver.java
+++ /dev/null
@@ -1,202 +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.dsl.functions.resolver;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.Stellar;
-import org.apache.metron.common.dsl.StellarFunction;
-import org.apache.metron.common.dsl.StellarFunctionInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static java.lang.String.format;
-
-/**
- * The base implementation of a function resolver that provides a means for lazy
- * initialization, thread-safety, and a mechanism for function resolution.
- *
- * Concrete function resolvers can override the `resolvables` method which
- * defines the classes that are interrogated further to discover Stellar functions.
- */
-public abstract class BaseFunctionResolver implements FunctionResolver, Serializable {
-
- protected static final Logger LOG = LoggerFactory.getLogger(BaseFunctionResolver.class);
-
- /**
- * Maps a function name to the metadata necessary to execute the Stellar function.
- */
- private Supplier<Map<String, StellarFunctionInfo>> functions;
-
- /**
- * The Stellar execution context that can be used to inform the function resolution process.
- */
- protected Context context;
-
- public BaseFunctionResolver() {
- // memoize provides lazy initialization and thread-safety (the ugly cast is necessary for serialization)
- functions = Suppliers.memoize((Supplier<Map<String, StellarFunctionInfo>> & Serializable) this::resolveFunctions);
- }
-
- /**
- * Returns a set of classes that should undergo further interrogation for resolution
- * (aka discovery) of Stellar functions.
- */
- public abstract Set<Class<? extends StellarFunction>> resolvables();
-
- /**
- * Provides metadata about each Stellar function that is resolvable.
- */
- @Override
- public Iterable<StellarFunctionInfo> getFunctionInfo() {
- return functions.get().values();
- }
-
- /**
- * The names of all Stellar functions that are resolvable.
- */
- @Override
- public Iterable<String> getFunctions() {
- return functions.get().keySet();
- }
-
- /**
- * Initialize the function resolver.
- * @param context Context used to initialize.
- */
- @Override
- public void initialize(Context context) {
- this.context = context;
- }
-
- /**
- * Resolves a function by name.
- * @param functionName The name of the function to resolve.
- * @return The executable StellarFunction.
- */
- @Override
- public StellarFunction apply(String functionName) {
- StellarFunctionInfo info = functions.get().get(functionName);
- if(info == null) {
- throw new IllegalStateException(format("Unknown function: `%s`", functionName));
- }
- return info.getFunction();
- }
-
- /**
- * Performs the core process of function resolution.
- */
- protected Map<String, StellarFunctionInfo> resolveFunctions() {
-
- // maps a function name to its definition
- Map<String, StellarFunctionInfo> functions = new HashMap<>();
-
- for(Class<? extends StellarFunction> clazz : resolvables()) {
- StellarFunctionInfo fn = resolveFunction(clazz);
- if(fn != null) {
- // check for duplicate function names
- StellarFunctionInfo fnSameName = functions.get(fn.getName());
- if (fnSameName != null && ObjectUtils.notEqual(fnSameName, fn)) {
- LOG.warn(format(
- "Namespace conflict: duplicate function names; `%s` implemented by [%s, %s]",
- fn.getName(), fnSameName.getFunction(), fn.getFunction()));
- }
-
- functions.put(fn.getName(), fn);
- }
- }
-
- return functions;
- }
-
- /**
- * Resolves a Stellar function from a given class.
- * @param clazz The class.
- */
- public static StellarFunctionInfo resolveFunction(Class<? extends StellarFunction> clazz) {
- StellarFunctionInfo info = null;
-
- // the class must be annotated
- if (clazz.isAnnotationPresent(Stellar.class)) {
-
- Stellar annotation = clazz.getAnnotation(Stellar.class);
- String fullyQualifiedName = getNameFromAnnotation(annotation);
- StellarFunction function = createFunction(clazz);
-
- if (fullyQualifiedName != null && function != null) {
- info = new StellarFunctionInfo(
- annotation.description(),
- fullyQualifiedName,
- annotation.params(),
- annotation.returns(),
- function);
- }
- }
-
- return info;
- }
-
- /**
- * Returns the fully-qualified function name from a Stellar annotation.
- * @param annotation The Stellar annotation.
- */
- public static String getNameFromAnnotation(Stellar annotation) {
-
- // find the function name
- String name = annotation.name();
- if(name == null || name.trim().length() == 0) {
- return null;
- } else {
- name = name.trim();
- }
-
- // find the function namespace
- String namespace = annotation.namespace();
- if(namespace == null || namespace.length() == 0) {
- namespace = null;
- } else {
- namespace = namespace.trim();
- }
-
- return Joiner.on("_").skipNulls().join(Arrays.asList(namespace, name));
- }
-
- /**
- * Instantiate the StellarFunction implementation class.
- * @param clazz The class containing a Stellar function definition.
- */
- public static StellarFunction createFunction(Class<? extends StellarFunction> clazz) {
- try {
- return clazz.getConstructor().newInstance();
-
- } catch (Exception e) {
- LOG.error("Unable to load " + clazz.getName() + " because " + e.getMessage(), e);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/ClasspathFunctionResolver.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/ClasspathFunctionResolver.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/ClasspathFunctionResolver.java
deleted file mode 100644
index 3c9524b..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/ClasspathFunctionResolver.java
+++ /dev/null
@@ -1,264 +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.dsl.functions.resolver;
-
-import org.apache.commons.vfs2.FileObject;
-import org.apache.commons.vfs2.FileSystemException;
-import org.apache.commons.vfs2.impl.VFSClassLoader;
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.Stellar;
-import org.apache.metron.common.dsl.StellarFunction;
-import org.apache.metron.common.utils.VFSClassloaderUtil;
-import org.apache.metron.common.utils.ConversionUtils;
-import org.atteo.classindex.ClassIndex;
-import org.reflections.util.ClasspathHelper;
-import org.reflections.util.FilterBuilder;
-
-import java.net.URL;
-import java.util.*;
-
-import static org.apache.metron.common.dsl.Context.Capabilities.STELLAR_CONFIG;
-import static org.apache.metron.common.dsl.functions.resolver.ClasspathFunctionResolver.Config.STELLAR_SEARCH_EXCLUDES_KEY;
-import static org.apache.metron.common.dsl.functions.resolver.ClasspathFunctionResolver.Config.STELLAR_SEARCH_INCLUDES_KEY;
-import static org.apache.metron.common.dsl.functions.resolver.ClasspathFunctionResolver.Config.STELLAR_VFS_PATHS;
-
-/**
- * Performs function resolution for Stellar by searching the classpath.
- *
- * By default, the entire classpath will be searched for Stellar functions. At times,
- * this can take quite a while. To shorten the search time, a property can be
- * defined to either include or exclude certain packages. The fewer packages there are
- * to search, the quicker the search will be.
- *
- * The properties are pulled from the Context's 'STELLAR_CONFIG'. In the REPL, this
- * is defined in a file called 'stellar.properties' on the classpath.
- *
- * The following property definition will include only Stellar functions that are
- * part of Apache Metron.
- *
- * stellar.function.resolver.includes = org.apache.metron.*
- *
- * The following property definition will exclude Stellar functions that are part of
- * Metron's management suite of function.
- *
- * stellar.function.resolver.excludes = org.apache.metron.management.*
- *
- * The following property definition would also exclude the Stellar functions that are
- * part of the management suite of functions. Of course, this may also exclude other
- * packages, but this serves as an example of the types of expression that can be used.
- *
- * stellar.function.resolver.excludes = org\\.management.*
- *
- */
-public class ClasspathFunctionResolver extends BaseFunctionResolver {
- public enum Config {
- /**
- * The set of paths. These paths are comma separated URLs with optional regex patterns at the end.
- * e.g. hdfs://node1:8020/apps/metron/stellar/.*.jar,hdfs://node1:8020/apps/metron/my_org/.*.jar
- * would signify all the jars under /apps/metron/stellar and /apps/metron/my_org in HDFS.
- */
- STELLAR_VFS_PATHS("stellar.function.paths", ""),
- /**
- * The key for a global property that defines one or more regular expressions
- * that specify what should be included when searching for Stellar functions.
- */
- STELLAR_SEARCH_INCLUDES_KEY("stellar.function.resolver.includes", ""),
- /**
- * The key for a global property that defines one or more regular expressions
- * that specify what should be excluded when searching for Stellar functions.
- */
- STELLAR_SEARCH_EXCLUDES_KEY("stellar.function.resolver.excludes", ""),
-
-
- ;
- String param;
- Object defaultValue;
- Config(String param, String defaultValue) {
- this.param = param;
- this.defaultValue = defaultValue;
- }
-
- public String param() {
- return param;
- }
-
- public Object get(Map<String, Object> config) {
- return config.getOrDefault(param, defaultValue);
- }
-
- public <T> T get(Map<String, Object> config, Class<T> clazz) {
- return ConversionUtils.convert(get(config), clazz);
- }
- }
-
-
- /**
- * The includes and excludes can include a list of multiple includes or excludes that
- * are delimited by these values.
- */
- private static final String STELLAR_SEARCH_DELIMS = "[,:]";
-
-
- /**
- * Regular expressions defining packages that should be included in the Stellar function resolution
- * process.
- */
- private List<String> includes;
-
- /**
- * Regular expressions defining packages that should be excluded from the Stellar function resolution
- * process.
- */
- private List<String> excludes;
-
- /**
- * Classloaders to try to load from
- */
- private List<ClassLoader> classLoaders;
-
- public ClasspathFunctionResolver() {
- this.includes = new ArrayList<>();
- this.excludes = new ArrayList<>();
- this.classLoaders = new ArrayList<>();
- }
-
- /**
- * Use one or more classloaders
- * @param classloaders
- */
- public void classLoaders(ClassLoader... classloaders) {
- classLoaders.clear();
- Arrays.stream(classloaders).forEach(c -> classLoaders.add(c));
- }
-
- /**
- * Includes one or more packages in the Stellar function resolution process. The packages
- * to include can be specified with a regular expression.
- * @param toInclude The regular expressions.
- */
- public void include(String... toInclude) {
- for(String incl : toInclude) {
- includes.add(incl);
- }
- }
-
- /**
- * Excludes one or more packages from the Stellar function resolution process. The packages
- * to exclude can be specified with a regular expression.
- * @param toExclude The regular expressions defining packages that should be excluded.
- */
- public void exclude(String... toExclude) {
- for(String excl : toExclude) {
- excludes.add(excl);
- }
- }
-
- @Override
- public void initialize(Context context) {
- super.initialize(context);
- if(context != null) {
-
- Optional<Object> optional = context.getCapability(STELLAR_CONFIG, false);
- if (optional.isPresent()) {
- Map<String, Object> stellarConfig = (Map<String, Object>) optional.get();
- if(LOG.isDebugEnabled()) {
- LOG.debug("Setting up classloader using the following config: " + stellarConfig);
- }
-
- include(STELLAR_SEARCH_INCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
- exclude(STELLAR_SEARCH_EXCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
- Optional<ClassLoader> vfsLoader = null;
- try {
- vfsLoader = VFSClassloaderUtil.configureClassloader(STELLAR_VFS_PATHS.get(stellarConfig, String.class));
- if(vfsLoader.isPresent()) {
- LOG.debug("CLASSLOADER LOADED WITH: " + STELLAR_VFS_PATHS.get(stellarConfig, String.class));
- if(LOG.isDebugEnabled()) {
- for (FileObject fo : ((VFSClassLoader) vfsLoader.get()).getFileObjects()) {
- LOG.error(fo.getURL() + " - " + fo.exists());
- }
- }
- classLoaders(vfsLoader.get());
- }
- } catch (FileSystemException e) {
- LOG.error("Unable to process filesystem: " + e.getMessage(), e);
- }
- }
- else {
- LOG.info("No stellar config set; I'm reverting to the context classpath with no restrictions.");
- if(LOG.isDebugEnabled()) {
- try {
- throw new IllegalStateException("No config set, stacktrace follows.");
- } catch (IllegalStateException ise) {
- LOG.error(ise.getMessage(), ise);
- }
- }
- }
- }
- else {
- throw new IllegalStateException("CONTEXT IS NULL!");
- }
- }
-
- /**
- * Returns a set of classes that should undergo further interrogation for resolution
- * (aka discovery) of Stellar functions.
- */
- @Override
- public Set<Class<? extends StellarFunction>> resolvables() {
-
- ClassLoader[] cls = null;
- if(this.classLoaders.size() == 0) {
- LOG.warn("Using System classloader");
- cls = new ClassLoader[] { getClass().getClassLoader() };
- }
- else {
- cls = new ClassLoader[this.classLoaders.size()];
- for (int i = 0; i < this.classLoaders.size(); ++i) {
- cls[i] = this.classLoaders.get(i);
- }
- }
-
- FilterBuilder filterBuilder = new FilterBuilder();
- excludes.forEach(excl -> {
- if(excl != null) {
- filterBuilder.exclude(excl);
- }
- });
- includes.forEach(incl -> {
- if(incl != null) {
- filterBuilder.include(incl);
- }
- });
- Set<String> classes = new HashSet<>();
- Set<Class<? extends StellarFunction>> ret = new HashSet<>();
- for(ClassLoader cl : cls) {
- for(Class<?> c : ClassIndex.getAnnotated(Stellar.class, cl)) {
- if(StellarFunction.class.isAssignableFrom(c) && filterBuilder.apply(c.getCanonicalName())) {
- String className = c.getName();
- if(!classes.contains(className)) {
- ret.add((Class<? extends StellarFunction>) c);
- classes.add(className);
- }
- }
- }
- }
- return ret;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/FunctionResolver.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/FunctionResolver.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/FunctionResolver.java
deleted file mode 100644
index c3e32ee..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/FunctionResolver.java
+++ /dev/null
@@ -1,46 +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.dsl.functions.resolver;
-
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.StellarFunction;
-import org.apache.metron.common.dsl.StellarFunctionInfo;
-
-import java.util.function.Function;
-
-/**
- * Responsible for function resolution in Stellar.
- */
-public interface FunctionResolver extends Function<String, StellarFunction> {
-
- /**
- * Provides metadata about each Stellar function that is resolvable.
- */
- Iterable<StellarFunctionInfo> getFunctionInfo();
-
- /**
- * The names of all Stellar functions that are resolvable.
- */
- Iterable<String> getFunctions();
-
- /**
- * Initialize the function resolver.
- * @param context Context used to initialize.
- */
- void initialize(Context context);
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SimpleFunctionResolver.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SimpleFunctionResolver.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SimpleFunctionResolver.java
deleted file mode 100644
index 027574f..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SimpleFunctionResolver.java
+++ /dev/null
@@ -1,59 +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.dsl.functions.resolver;
-
-import org.apache.metron.common.dsl.StellarFunction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * A simple Stellar function resolver that resolves functions from specific
- * classes rather than by searching the classpath.
- *
- * FunctionResolver functionResolver = new SimpleFunctionResolver()
- * .withClass(OneStellarFunction.class)
- * .withClass(AnotherStellarFunction.class)
- * .withClass(YetAnotherFunction.class)
- */
-public class SimpleFunctionResolver extends BaseFunctionResolver {
-
- protected static final Logger LOG = LoggerFactory.getLogger(SimpleFunctionResolver.class);
-
- /**
- * The classes that will be further interrogated for Stellar functions.
- */
- Set<Class<? extends StellarFunction>> classesToResolve = new HashSet<>();
-
- @Override
- public Set<Class<? extends StellarFunction>> resolvables() {
- return classesToResolve;
- }
-
- /**
- * Will attempt to resolve any Stellar functions defined within the specified class.
- * @param clazz The class which may contain a Stellar function.
- */
- public SimpleFunctionResolver withClass(Class<? extends StellarFunction> clazz) {
- this.classesToResolve.add(clazz);
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SingletonFunctionResolver.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SingletonFunctionResolver.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SingletonFunctionResolver.java
deleted file mode 100644
index 0c74a51..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/resolver/SingletonFunctionResolver.java
+++ /dev/null
@@ -1,34 +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.dsl.functions.resolver;
-
-/**
- * Performs function resolution for Stellar by searching the classpath. The
- * class acts as a singleton to avoid repetitive classpath searches.
- */
-public class SingletonFunctionResolver extends ClasspathFunctionResolver {
-
- private static SingletonFunctionResolver INSTANCE = new SingletonFunctionResolver();
-
- private SingletonFunctionResolver() {}
-
- public static FunctionResolver getInstance() {
- return INSTANCE;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/FieldTransformation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/FieldTransformation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/FieldTransformation.java
index bb33bf7..d75df55 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/FieldTransformation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/FieldTransformation.java
@@ -18,7 +18,7 @@
package org.apache.metron.common.field.transformation;
-import org.apache.metron.common.dsl.Context;
+import org.apache.metron.stellar.dsl.Context;
import java.io.Serializable;
import java.util.LinkedHashMap;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/IPProtocolTransformation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/IPProtocolTransformation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/IPProtocolTransformation.java
index 1488a9a..0518d6b 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/IPProtocolTransformation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/IPProtocolTransformation.java
@@ -19,11 +19,11 @@
package org.apache.metron.common.field.transformation;
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.ParseException;
-import org.apache.metron.common.dsl.Stellar;
-import org.apache.metron.common.dsl.StellarFunction;
-import org.apache.metron.common.utils.ConversionUtils;
+import org.apache.metron.stellar.dsl.Context;
+import org.apache.metron.stellar.dsl.ParseException;
+import org.apache.metron.stellar.dsl.Stellar;
+import org.apache.metron.stellar.dsl.StellarFunction;
+import org.apache.metron.stellar.common.utils.ConversionUtils;
import java.util.HashMap;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/RemoveTransformation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/RemoveTransformation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/RemoveTransformation.java
index 3b5ae5f..a94ccd8 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/RemoveTransformation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/RemoveTransformation.java
@@ -18,9 +18,9 @@
package org.apache.metron.common.field.transformation;
-import org.apache.metron.common.dsl.*;
-import org.apache.metron.common.dsl.functions.resolver.FunctionResolver;
-import org.apache.metron.common.stellar.StellarPredicateProcessor;
+import org.apache.metron.stellar.dsl.*;
+import org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver;
+import org.apache.metron.stellar.common.StellarPredicateProcessor;
import java.util.HashMap;
import java.util.LinkedHashMap;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/SimpleFieldTransformation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/SimpleFieldTransformation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/SimpleFieldTransformation.java
index 1f8efbd..252e5e5 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/SimpleFieldTransformation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/SimpleFieldTransformation.java
@@ -19,7 +19,7 @@
package org.apache.metron.common.field.transformation;
import com.google.common.collect.Iterables;
-import org.apache.metron.common.dsl.Context;
+import org.apache.metron.stellar.dsl.Context;
import java.util.LinkedHashMap;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/StellarTransformation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/StellarTransformation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/StellarTransformation.java
index e2ef7c9..54c7236 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/StellarTransformation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/transformation/StellarTransformation.java
@@ -18,11 +18,11 @@
package org.apache.metron.common.field.transformation;
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.MapVariableResolver;
-import org.apache.metron.common.dsl.StellarFunctions;
-import org.apache.metron.common.dsl.VariableResolver;
-import org.apache.metron.common.stellar.StellarProcessor;
+import org.apache.metron.stellar.dsl.Context;
+import org.apache.metron.stellar.dsl.MapVariableResolver;
+import org.apache.metron.stellar.dsl.StellarFunctions;
+import org.apache.metron.stellar.dsl.VariableResolver;
+import org.apache.metron.stellar.common.StellarProcessor;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/FieldValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/FieldValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/FieldValidation.java
index 59ba9bb..767cfc1 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/FieldValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/FieldValidation.java
@@ -18,7 +18,7 @@
package org.apache.metron.common.field.validation;
-import org.apache.metron.common.dsl.Context;
+import org.apache.metron.stellar.dsl.Context;
import java.io.Serializable;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/QueryValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/QueryValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/QueryValidation.java
index ee4314a..074e20a 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/QueryValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/QueryValidation.java
@@ -18,10 +18,10 @@
package org.apache.metron.common.field.validation;
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.MapVariableResolver;
-import org.apache.metron.common.dsl.StellarFunctions;
-import org.apache.metron.common.stellar.StellarPredicateProcessor;
+import org.apache.metron.stellar.dsl.Context;
+import org.apache.metron.stellar.dsl.MapVariableResolver;
+import org.apache.metron.stellar.dsl.StellarFunctions;
+import org.apache.metron.stellar.common.StellarPredicateProcessor;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/SimpleValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/SimpleValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/SimpleValidation.java
index 33f7896..3a0b4f8 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/SimpleValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/SimpleValidation.java
@@ -18,7 +18,7 @@
package org.apache.metron.common.field.validation;
-import org.apache.metron.common.dsl.Context;
+import org.apache.metron.stellar.dsl.Context;
import java.util.List;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/DomainValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/DomainValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/DomainValidation.java
index f199541..88d9510 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/DomainValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/DomainValidation.java
@@ -19,12 +19,10 @@
package org.apache.metron.common.field.validation.network;
import org.apache.commons.validator.routines.DomainValidator;
-import org.apache.metron.common.dsl.Predicate2StellarFunction;
-import org.apache.metron.common.dsl.Stellar;
-import org.apache.metron.common.field.validation.FieldValidation;
+import org.apache.metron.stellar.dsl.Predicate2StellarFunction;
+import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.common.field.validation.SimpleValidation;
-import java.util.Map;
import java.util.function.Predicate;
public class DomainValidation extends SimpleValidation {
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/EmailValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/EmailValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/EmailValidation.java
index f666a4e..7fd487e 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/EmailValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/EmailValidation.java
@@ -19,11 +19,10 @@
package org.apache.metron.common.field.validation.network;
import org.apache.commons.validator.routines.EmailValidator;
-import org.apache.metron.common.dsl.Predicate2StellarFunction;
-import org.apache.metron.common.dsl.Stellar;
+import org.apache.metron.stellar.dsl.Predicate2StellarFunction;
+import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.common.field.validation.SimpleValidation;
-import java.util.Map;
import java.util.function.Predicate;
public class EmailValidation extends SimpleValidation {
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/IPValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/IPValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/IPValidation.java
index d14684c..552d437 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/IPValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/IPValidation.java
@@ -19,9 +19,9 @@
package org.apache.metron.common.field.validation.network;
import org.apache.commons.validator.routines.InetAddressValidator;
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.Predicate2StellarFunction;
-import org.apache.metron.common.dsl.Stellar;
+import org.apache.metron.stellar.dsl.Context;
+import org.apache.metron.stellar.dsl.Predicate2StellarFunction;
+import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.common.field.validation.FieldValidation;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/URLValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/URLValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/URLValidation.java
index 1e3f162..33ffb3f 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/URLValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/network/URLValidation.java
@@ -19,8 +19,8 @@
package org.apache.metron.common.field.validation.network;
import org.apache.commons.validator.routines.UrlValidator;
-import org.apache.metron.common.dsl.Predicate2StellarFunction;
-import org.apache.metron.common.dsl.Stellar;
+import org.apache.metron.stellar.dsl.Predicate2StellarFunction;
+import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.common.field.validation.SimpleValidation;
import java.util.function.Predicate;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java
index f3fb445..c326d93 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java
@@ -18,9 +18,9 @@
package org.apache.metron.common.field.validation.primitive;
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.Predicate2StellarFunction;
-import org.apache.metron.common.dsl.Stellar;
+import org.apache.metron.stellar.dsl.Context;
+import org.apache.metron.stellar.dsl.Predicate2StellarFunction;
+import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.common.field.validation.FieldValidation;
import java.text.ParseException;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/IntegerValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/IntegerValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/IntegerValidation.java
index e702670..1cebeaa 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/IntegerValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/IntegerValidation.java
@@ -18,10 +18,9 @@
package org.apache.metron.common.field.validation.primitive;
-import org.apache.commons.validator.routines.DoubleValidator;
import org.apache.commons.validator.routines.LongValidator;
-import org.apache.metron.common.dsl.Predicate2StellarFunction;
-import org.apache.metron.common.dsl.Stellar;
+import org.apache.metron.stellar.dsl.Predicate2StellarFunction;
+import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.common.field.validation.SimpleValidation;
import java.util.function.Predicate;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/RegexValidation.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/RegexValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/RegexValidation.java
index fc44f40..b67663d 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/RegexValidation.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/RegexValidation.java
@@ -18,7 +18,7 @@
package org.apache.metron.common.field.validation.primitive;
-import org.apache.metron.common.dsl.Context;
+import org.apache.metron.stellar.dsl.Context;
import org.apache.metron.common.field.validation.FieldValidation;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/message/MessageGetters.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/message/MessageGetters.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/message/MessageGetters.java
index a496e08..7004d78 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/message/MessageGetters.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/message/MessageGetters.java
@@ -17,7 +17,7 @@
*/
package org.apache.metron.common.message;
-import org.apache.metron.common.utils.ConversionUtils;
+import org.apache.metron.stellar.common.utils.ConversionUtils;
import java.util.function.Function;
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java
deleted file mode 100644
index 5bf4a64..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BaseStellarProcessor.java
+++ /dev/null
@@ -1,239 +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.stellar;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.util.concurrent.UncheckedExecutionException;
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.ParserRuleContext;
-import org.antlr.v4.runtime.TokenStream;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Stack;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.metron.common.dsl.Context;
-import org.apache.metron.common.dsl.ErrorListener;
-import org.apache.metron.common.dsl.ParseException;
-import org.apache.metron.common.dsl.StellarFunctions;
-import org.apache.metron.common.dsl.VariableResolver;
-import org.apache.metron.common.dsl.functions.resolver.FunctionResolver;
-import org.apache.metron.common.stellar.evaluators.ArithmeticEvaluator;
-import org.apache.metron.common.stellar.evaluators.ComparisonExpressionWithOperatorEvaluator;
-import org.apache.metron.common.stellar.evaluators.NumberLiteralEvaluator;
-import org.apache.metron.common.stellar.generated.StellarBaseListener;
-import org.apache.metron.common.stellar.generated.StellarLexer;
-import org.apache.metron.common.stellar.generated.StellarParser;
-
-import static org.apache.commons.lang3.StringUtils.isEmpty;
-
-/**
- * The base implementation of a Stellar processor. This is used to evaluate Stellar expressions.
- *
- * @param <T> The type that the processor expects to return after processing a Stellar expression.
- * @see StellarProcessor
- * @see StellarPredicateProcessor
- */
-public class BaseStellarProcessor<T> {
- public static final int DEFAULT_CACHE_SIZE = 500;
- public static final int DEFAULT_EXPIRY_TIME = 10;
- public static final TimeUnit DEFAULT_EXPIRY_TIME_UNITS = TimeUnit.MINUTES;
-
- /**
- * The default expression cache. This is used when the expression cache is not otherwise specified.
- */
- private static Cache<String, StellarCompiler.Expression> defaultExpressionCache;
- static {
- defaultExpressionCache = createCache(DEFAULT_CACHE_SIZE, DEFAULT_EXPIRY_TIME, DEFAULT_EXPIRY_TIME_UNITS);
- }
- /**
- * The class containing the type that the Stellar expression being processed will evaluate to.
- */
- private Class<T> clazz;
-
- /**
- * @param clazz The class containing the type that the Stellar expression being processed will evaluate to.
- */
- Cache<String, StellarCompiler.Expression> expressionCache;
-
- /**
- * Create a default stellar processor. This processor uses the static expression cache.
- */
- BaseStellarProcessor(final Class<T> clazz) {
- this(clazz, defaultExpressionCache);
- }
-
- BaseStellarProcessor(final Class<T> clazz, int cacheSize, int expiryTime, TimeUnit expiryUnit) {
- this(clazz, createCache(cacheSize, expiryTime, expiryUnit));
- }
-
- BaseStellarProcessor(final Class<T> clazz, Cache<String, StellarCompiler.Expression> expressionCache) {
- this.clazz = clazz;
- this.expressionCache = expressionCache;
- }
-
- static Cache<String, StellarCompiler.Expression> createCache( int cacheSize
- , int expiryTime
- , TimeUnit expiryUnit
- ) {
- CacheLoader<String, StellarCompiler.Expression> loader = new CacheLoader<String, StellarCompiler.Expression>() {
- @Override
- public StellarCompiler.Expression load(String key) throws Exception {
- return compile(key);
- }
- };
- return CacheBuilder.newBuilder()
- .maximumSize(cacheSize)
- .expireAfterAccess(expiryTime, expiryUnit)
- .build(loader);
- }
-
- /**
- * Parses the given rule and returns a set of variables that are used in the given Stellar expression, {@code rule}.
- *
- * @param rule The Stellar expression to find out what variables are used.
- * @return A set of variables used in the given Stellar expression.
- */
- public Set<String> variablesUsed(final String rule) {
- if (rule == null || isEmpty(rule.trim())) {
- return null;
- }
- StellarCompiler.Expression expression = null;
- try {
- expression = expressionCache.get(rule, () -> compile(rule));
- } catch (ExecutionException e) {
- throw new ParseException("Unable to parse: " + rule + " due to: " + e.getMessage(), e);
- }
- return expression.variablesUsed;
- }
-
- /**
- * Parses and evaluates the given Stellar expression, {@code rule}.
- * @param rule The Stellar expression to parse and evaluate.
- * @param variableResolver The {@link VariableResolver} to determine values of variables used in the Stellar expression, {@code rule}.
- * @param functionResolver The {@link FunctionResolver} to determine values of functions used in the Stellar expression, {@code rule}.
- * @param context The context used during validation.
- * @return The value of the evaluated Stellar expression, {@code rule}.
- */
- public T parse(final String rule, final VariableResolver variableResolver, final FunctionResolver functionResolver, final Context context) {
- StellarCompiler.Expression expression = null;
- if (rule == null || isEmpty(rule.trim())) {
- return null;
- }
- try {
- expression = expressionCache.get(rule, () -> compile(rule));
- } catch (ExecutionException|UncheckedExecutionException e) {
- throw new ParseException("Unable to parse: " + rule + " due to: " + e.getMessage(), e);
- }
- return clazz.cast(expression.apply(new StellarCompiler.ExpressionState(context, functionResolver, variableResolver)));
- }
-
- /**
- * Parses and evaluates the given Stellar expression, {@code rule}.
- * @param rule The Stellar expression to parse and evaluate.
- * @return The Expression, which can be reevaluated without reparsing in different Contexts and Resolvers.
- */
- public static StellarCompiler.Expression compile(final String rule) {
- if (rule == null || isEmpty(rule.trim())) {
- return null;
- }
-
- ANTLRInputStream input = new ANTLRInputStream(rule);
- StellarLexer lexer = new StellarLexer(input);
- lexer.removeErrorListeners();
- lexer.addErrorListener(new ErrorListener());
- TokenStream tokens = new CommonTokenStream(lexer);
- StellarParser parser = new StellarParser(tokens);
-
- StellarCompiler treeBuilder = new StellarCompiler(
- ArithmeticEvaluator.INSTANCE,
- NumberLiteralEvaluator.INSTANCE,
- ComparisonExpressionWithOperatorEvaluator.INSTANCE
- );
- parser.addParseListener(treeBuilder);
- parser.removeErrorListeners();
- parser.addErrorListener(new ErrorListener());
- parser.transformation();
- return treeBuilder.getExpression();
- }
-
- /**
- * This method determines if a given rule is valid or not. If the given rule is valid then true
- * will be returned otherwise a {@link ParseException} is thrown. If it is desired to return a boolean
- * whether the rule is valid or not, use the {@link #validate(String, boolean, Context) validate} method. It is important
- * to note that all variables will resolve to 'null.'
- *
- * @param rule The rule to validate.
- * @return If the given rule is valid then true otherwise an exception is thrown.
- * @throws ParseException If the rule is invalid an exception of this type is thrown.
- */
- public boolean validate(final String rule) throws ParseException {
- return validate(rule, true, Context.EMPTY_CONTEXT());
- }
-
- /**
- * Validates a given Stellar expression based on given context.
- * @param rule The Stellar expression to validate.
- * @param context The context used to validate the Stellar expression.
- * @return If valid Stellar expression true, otherwise an exception will be thrown.
- * @throws ParseException The exception containing the information as to why the expression is not valid.
- */
- public boolean validate(final String rule, final Context context) throws ParseException {
- return validate(rule, true, context);
- }
-
- /**
- * Here it is not desirable to add our custom listener. It is not the intent to evaluate the rule.
- * The rule is only meant to be validated. Validate in this instance means check whether or not the
- * rule is syntactically valid and whether the functions used exist. For example, it will not check
- * for variables that are not defined. Currently all variables resolve to 'null.' This is mainly to
- * make sure things function as expected when values are null.
- *
- * @param rule The Stellar transformation to validate.
- * @param throwException If true an invalid Stellar transformation will throw a {@link ParseException} otherwise a boolean will be returned.
- * @param context The Stellar context to be used when validating the Stellar transformation.
- * @return If {@code throwException} is true and {@code rule} is invalid a {@link ParseException} is thrown. If
- * {@code throwException} is false and {@code rule} is invalid then false is returned. Otherwise true if {@code rule} is valid,
- * false if {@code rule} is invalid.
- * @throws ParseException Thrown if {@code rule} is invalid and {@code throwException} is true.
- */
- public boolean validate(final String rule, final boolean throwException, final Context context) throws ParseException {
- if (rule == null || isEmpty(rule.trim())) {
- return true;
- }
-
- try {
- parse(rule, x -> null, StellarFunctions.FUNCTION_RESOLVER(), context);
- } catch (Throwable t) {
- if (throwException) {
- throw new ParseException("Unable to parse " + rule + ": " + t.getMessage(), t);
- } else {
- return false;
- }
- }
-
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BooleanOp.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BooleanOp.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BooleanOp.java
deleted file mode 100644
index b6631fe..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/BooleanOp.java
+++ /dev/null
@@ -1,23 +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.stellar;
-
-public interface BooleanOp {
- boolean op(boolean left, boolean right);
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.java
deleted file mode 100644
index 16bc07a..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/FrameContext.java
+++ /dev/null
@@ -1,45 +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.stellar;
-
-public enum FrameContext {
- BOOLEAN_AND,
- BOOLEAN_OR;
-
- public static class Context {
- private FrameContext variety;
- public Context(FrameContext variety) {
- this.variety = variety;
- }
-
- public FrameContext getVariety() {
- return variety;
- }
-
- @Override
- public String toString() {
- return "Context{" +
- "variety=" + variety +
- '}';
- }
- }
-
- public Context create() {
- return new Context(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/LambdaExpression.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/LambdaExpression.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/LambdaExpression.java
deleted file mode 100644
index f5b0f07..0000000
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/LambdaExpression.java
+++ /dev/null
@@ -1,68 +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.stellar;
-
-import org.apache.metron.common.dsl.Token;
-import org.apache.metron.common.dsl.VariableResolver;
-
-import java.util.ArrayDeque;
-import java.util.Deque;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-
-
-public class LambdaExpression extends StellarCompiler.Expression {
- StellarCompiler.ExpressionState state;
- List<String> variables;
- public LambdaExpression(List<String> variables, Deque<Token<?>> tokenDeque, StellarCompiler.ExpressionState state) {
- super(tokenDeque);
- this.state = state;
- this.variables = variables;
- }
-
- @Override
- public Deque<Token<?>> getTokenDeque() {
- Deque<Token<?>> ret = new ArrayDeque<>(super.getTokenDeque().size());
- for(Token<?> token : super.getTokenDeque()) {
- ret.add(token);
- }
- return ret;
- }
-
- public Object apply(List<Object> variableArgs) {
- Map<String, Object> lambdaVariables = new HashMap<>();
- int i = 0;
- for(;i < Math.min(variables.size(),variableArgs.size()) ;++i) {
- lambdaVariables.put(variables.get(i), variableArgs.get(i));
- }
- for(;i < variables.size();++i) {
- lambdaVariables.put(variables.get(i), null);
- }
-
- VariableResolver variableResolver = variable -> lambdaVariables.getOrDefault(variable
- , state.variableResolver.resolve(variable)
- );
- StellarCompiler.ExpressionState localState = new StellarCompiler.ExpressionState(
- state.context
- , state.functionResolver
- , variableResolver);
- return apply(localState);
- }
-}