metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ceste...@apache.org
Subject [63/66] [abbrv] incubator-metron git commit: METRON-255: Expose the IPProtocolTransformer as a function in the Stellar transformation language. This closes apache/incubator-metron#172
Date Fri, 24 Jun 2016 20:58:01 GMT
METRON-255: Expose the IPProtocolTransformer as a function in the Stellar transformation language.
This closes apache/incubator-metron#172


Project: http://git-wip-us.apache.org/repos/asf/incubator-metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metron/commit/8afeec8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metron/tree/8afeec8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metron/diff/8afeec8f

Branch: refs/heads/master
Commit: 8afeec8f051df134d6c13d5876a2825b20760253
Parents: 3b88e01
Author: cstella <cestella@gmail.com>
Authored: Fri Jun 24 09:59:02 2016 -0400
Committer: cstella <cestella@gmail.com>
Committed: Fri Jun 24 09:59:02 2016 -0400

----------------------------------------------------------------------
 .../common/dsl/TransformationFunctions.java     |  2 ++
 .../IPProtocolTransformation.java               | 25 +++++++++++++++++++-
 .../transformation/TransformationTest.java      |  8 +++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8afeec8f/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/TransformationFunctions.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/TransformationFunctions.java
b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/TransformationFunctions.java
index 3cc51ce..2ff120d 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/TransformationFunctions.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/TransformationFunctions.java
@@ -22,6 +22,7 @@ import org.apache.metron.common.dsl.functions.DateFunctions;
 import org.apache.metron.common.dsl.functions.MapFunctions;
 import org.apache.metron.common.dsl.functions.NetworkFunctions;
 import org.apache.metron.common.dsl.functions.StringFunctions;
+import org.apache.metron.common.field.transformation.IPProtocolTransformation;
 import org.apache.metron.common.utils.ConversionUtils;
 
 import java.util.List;
@@ -48,6 +49,7 @@ public enum TransformationFunctions implements Function<List<Object>,
Object> {
   ,URL_TO_PATH(new NetworkFunctions.URLToPath())
   ,URL_TO_PROTOCOL(new NetworkFunctions.URLToProtocol())
   ,TO_EPOCH_TIMESTAMP(new DateFunctions.ToTimestamp())
+  ,PROTOCOL_TO_NAME(new IPProtocolTransformation())
   ;
   Function<List<Object>, Object> func;
   TransformationFunctions(Function<List<Object>, Object> func) {

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8afeec8f/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 b0e9a9c..c789018 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,10 +19,15 @@
 package org.apache.metron.common.field.transformation;
 
 
+import org.apache.hadoop.yarn.util.ConverterUtils;
+import org.apache.metron.common.utils.ConversionUtils;
+
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
 
-public class IPProtocolTransformation extends SimpleFieldTransformation {
+public class IPProtocolTransformation extends SimpleFieldTransformation implements Function<List<Object>,
Object> {
 
   private final static Map<Integer, String> PROTOCOLS = new HashMap<>();
 
@@ -175,4 +180,22 @@ public class IPProtocolTransformation extends SimpleFieldTransformation
{
     }
     return ret;
   }
+
+
+  @Override
+  public Object apply(List<Object> objects) {
+    Object keyObj = objects.get(0);
+    if(keyObj == null) {
+      return keyObj;
+    }
+    Integer key = ConversionUtils.convert(keyObj, Integer.class);
+    if(key == null ) {
+      return keyObj;
+    }
+    Object ret = PROTOCOLS.get(key);
+    if(ret == null ) {
+      return keyObj;
+    }
+    return ret;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8afeec8f/metron-platform/metron-common/src/test/java/org/apache/metron/common/transformation/TransformationTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/transformation/TransformationTest.java
b/metron-platform/metron-common/src/test/java/org/apache/metron/common/transformation/TransformationTest.java
index 7884098..d0f32ef 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/transformation/TransformationTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/transformation/TransformationTest.java
@@ -105,6 +105,14 @@ public class TransformationTest {
   }
 
   @Test
+  public void testProtocolToName() {
+    String query = "PROTOCOL_TO_NAME(protocol)";
+    Assert.assertEquals("TCP", run(query, ImmutableMap.of("protocol", "6")));
+    Assert.assertEquals("TCP", run(query, ImmutableMap.of("protocol", 6)));
+    Assert.assertEquals(null, run(query, ImmutableMap.of("foo", 6)));
+    Assert.assertEquals("chicken", run(query, ImmutableMap.of("protocol", "chicken")));
+  }
+  @Test
   public void testDateConversion() {
     long expected =1452013350000L;
     {


Mime
View raw message