metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject incubator-metron git commit: METRON-284 SensorParserConfig object cannot be serialized with the default Jackson ObjectMapper (cestella via dlyle65535) closes apache/incubator-metron#184
Date Wed, 27 Jul 2016 18:00:55 GMT
Repository: incubator-metron
Updated Branches:
  refs/heads/master 63209e7e3 -> b0423073c


METRON-284 SensorParserConfig object cannot be serialized with the default Jackson ObjectMapper
(cestella via dlyle65535) closes apache/incubator-metron#184


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

Branch: refs/heads/master
Commit: b0423073c5fed7c32be2e3943a940b0260d267f4
Parents: 63209e7
Author: cestella <cestella@gmail.com>
Authored: Wed Jul 27 14:00:25 2016 -0400
Committer: David Lyle <dlyle65535@gmail.com>
Committed: Wed Jul 27 14:00:25 2016 -0400

----------------------------------------------------------------------
 .../common/configuration/FieldTransformer.java  | 10 ++++-
 .../SensorEnrichmentConfigTest.java             | 17 ++++++++
 .../configuration/SensorParserConfigTest.java   | 41 ++++++++++++++++++++
 .../transformation/FieldTransformationTest.java |  2 +-
 4 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/b0423073/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/FieldTransformer.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/FieldTransformer.java
b/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/FieldTransformer.java
index 6948a92..4e34e04 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/FieldTransformer.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/FieldTransformer.java
@@ -18,6 +18,7 @@
 
 package org.apache.metron.common.configuration;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.google.common.collect.ImmutableList;
 import org.apache.metron.common.field.transformation.FieldTransformation;
 import org.apache.metron.common.field.transformation.FieldTransformations;
@@ -33,6 +34,7 @@ public class FieldTransformer implements Serializable {
   private List<String> input = new ArrayList<>();
   private List<String> output;
   private FieldTransformation transformation;
+  private String transformationName;
   private Map<String, Object> config = new HashMap<>();
   private boolean initialized = false;
   public FieldTransformer() {
@@ -72,11 +74,17 @@ public class FieldTransformer implements Serializable {
     this.config = config;
   }
 
-  public FieldTransformation getTransformation() {
+  public String getTransformation() {
+    return transformationName;
+  }
+
+  @JsonIgnore
+  public FieldTransformation getFieldTransformation() {
     return transformation;
   }
 
   public void setTransformation(String transformation) {
+    this.transformationName = transformation;
     this.transformation = FieldTransformations.get(transformation);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/b0423073/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 dbf894b..305182b 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
@@ -20,10 +20,14 @@ package org.apache.metron.common.configuration;
 import junit.framework.Assert;
 import nl.jqno.equalsverifier.EqualsVerifier;
 import nl.jqno.equalsverifier.Warning;
+import org.apache.commons.io.IOUtils;
 import org.apache.metron.TestConstants;
 import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
 import org.junit.Test;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.util.Map;
 
@@ -38,4 +42,17 @@ public class SensorEnrichmentConfigTest {
     Assert.assertNotNull(sensorEnrichmentConfig);
     Assert.assertTrue(sensorEnrichmentConfig.toString() != null && sensorEnrichmentConfig.toString().length()
> 0);
   }
+
+  @Test
+  public void testSerDe() throws IOException {
+    for(File enrichmentConfig : new File(new File(TestConstants.ENRICHMENTS_CONFIGS_PATH),
"enrichments").listFiles()) {
+      SensorEnrichmentConfig config = null;
+      try (BufferedReader br = new BufferedReader(new FileReader(enrichmentConfig))) {
+        String parserStr = IOUtils.toString(br);
+        config = SensorEnrichmentConfig.fromBytes(parserStr.getBytes());
+      }
+      SensorEnrichmentConfig config2 = SensorEnrichmentConfig.fromBytes(config.toJSON().getBytes());
+      Assert.assertEquals(config2, config);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/b0423073/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorParserConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorParserConfigTest.java
b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorParserConfigTest.java
new file mode 100644
index 0000000..fe69ed9
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorParserConfigTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.apache.commons.io.IOUtils;
+import org.apache.metron.TestConstants;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.*;
+
+public class SensorParserConfigTest {
+
+  @Test
+  public void testSerDe() throws IOException {
+    for(File parserConfig : new File(new File(TestConstants.PARSER_CONFIGS_PATH), "parsers").listFiles())
{
+      SensorParserConfig config = null;
+      try (BufferedReader br = new BufferedReader(new FileReader(parserConfig))) {
+        String parserStr = IOUtils.toString(br);
+        config = SensorParserConfig.fromBytes(parserStr.getBytes());
+      }
+      SensorParserConfig config2 = SensorParserConfig.fromBytes(config.toJSON().getBytes());
+      Assert.assertEquals(config2, config);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/b0423073/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/FieldTransformationTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/FieldTransformationTest.java
b/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/FieldTransformationTest.java
index 4f0319a..fe87c55 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/FieldTransformationTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/FieldTransformationTest.java
@@ -106,7 +106,7 @@ public class FieldTransformationTest {
   public void testValidSerde_simple() throws IOException {
     SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(config));
     Assert.assertEquals(1, c.getFieldTransformations().size());
-    Assert.assertEquals(IPProtocolTransformation.class, c.getFieldTransformations().get(0).getTransformation().getClass());
+    Assert.assertEquals(IPProtocolTransformation.class, c.getFieldTransformations().get(0).getFieldTransformation().getClass());
     Assert.assertEquals(ImmutableList.of("protocol"), c.getFieldTransformations().get(0).getInput());
   }
 


Mime
View raw message