[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user asfgit closed the pull request at: https://github.com/apache/incubator-metron/pull/136 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user nickwallen commented on the pull request: https://github.com/apache/incubator-metron/pull/136#issuecomment-221925290 ð --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user nickwallen commented on a diff in the pull request: https://github.com/apache/incubator-metron/pull/136#discussion_r64776627 --- Diff: metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/RemoveTransformationTest.java --- @@ -0,0 +1,100 @@ +/** + * 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.field.transformation; + +import com.google.common.collect.Iterables; +import org.adrianwalker.multilinestring.Multiline; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.metron.common.configuration.FieldTransformer; +import org.apache.metron.common.configuration.SensorParserConfig; +import org.json.simple.JSONObject; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; + +public class RemoveTransformationTest { + /** + { +"fieldTransformations" : [ + { +"input" : "field1" + , "transformation" : "REMOVE" + } + ] + } + */ + @Multiline + public static String removeUnconditionalConfig; + + @Test + public void testUnconditionalRemove() throws Exception{ +SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeUnconditionalConfig)); +FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null); +JSONObject input = new JSONObject(new HashMap() {{ + put("field1", "foo"); +}}); +handler.transformAndUpdate(input, new HashMap<>()); +Assert.assertFalse(input.containsKey("field1")); + } + + /** + { +"fieldTransformations" : [ + { +"input" : "field1" + , "transformation" : "REMOVE" + , "config" : { + "condition" : "exists(field2) and field2 == 'foo'" + } + } + ] + } + */ + @Multiline + public static String removeConditionalConfig; + @Test + public void testConditionalRemove() throws Exception { +SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeConditionalConfig)); +FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null); +{ + JSONObject input = new JSONObject(new HashMap () {{ +put("field1", "foo"); + }}); + handler.transformAndUpdate(input, new HashMap<>()); + Assert.assertTrue(input.containsKey("field1")); +} +{ + JSONObject input = new JSONObject(new HashMap () {{ +put("field1", "foo"); +put("field2", "bar"); + }}); + handler.transformAndUpdate(input, new HashMap<>()); + Assert.assertTrue(input.containsKey("field1")); +} +{ + JSONObject input = new JSONObject(new HashMap () {{ +put("field1", "bar"); +put("field2", "foo"); + }}); + handler.transformAndUpdate(input, new HashMap<>()); + Assert.assertEquals("bar", input.get("field1")); --- End diff -- Does this test ensure that 'field2' has been removed? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user nickwallen commented on a diff in the pull request: https://github.com/apache/incubator-metron/pull/136#discussion_r64777163 --- Diff: metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/RemoveTransformationTest.java --- @@ -0,0 +1,100 @@ +/** + * 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.field.transformation; + +import com.google.common.collect.Iterables; +import org.adrianwalker.multilinestring.Multiline; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.metron.common.configuration.FieldTransformer; +import org.apache.metron.common.configuration.SensorParserConfig; +import org.json.simple.JSONObject; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; + +public class RemoveTransformationTest { + /** + { +"fieldTransformations" : [ + { +"input" : "field1" + , "transformation" : "REMOVE" + } + ] + } + */ + @Multiline + public static String removeUnconditionalConfig; + + @Test + public void testUnconditionalRemove() throws Exception{ +SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeUnconditionalConfig)); +FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null); +JSONObject input = new JSONObject(new HashMap() {{ + put("field1", "foo"); +}}); +handler.transformAndUpdate(input, new HashMap<>()); +Assert.assertFalse(input.containsKey("field1")); + } + + /** + { +"fieldTransformations" : [ + { +"input" : "field1" + , "transformation" : "REMOVE" + , "config" : { + "condition" : "exists(field2) and field2 == 'foo'" + } + } + ] + } + */ + @Multiline + public static String removeConditionalConfig; + @Test + public void testConditionalRemove() throws Exception { +SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeConditionalConfig)); +FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null); +{ + JSONObject input = new JSONObject(new HashMap () {{ +put("field1", "foo"); + }}); + handler.transformAndUpdate(input, new HashMap<>()); + Assert.assertTrue(input.containsKey("field1")); +} +{ + JSONObject input = new JSONObject(new HashMap () {{ +put("field1", "foo"); +put("field2", "bar"); + }}); + handler.transformAndUpdate(input, new HashMap<>()); + Assert.assertTrue(input.containsKey("field1")); +} +{ + JSONObject input = new JSONObject(new HashMap () {{ +put("field1", "bar"); +put("field2", "foo"); + }}); + handler.transformAndUpdate(input, new HashMap<>()); + Assert.assertEquals("bar", input.get("field1")); --- End diff -- Actually, I think you're intending that 'field1' should be removed? I'm not sure. Comments would be awesome. I'm not that bright. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user cestella commented on the pull request: https://github.com/apache/incubator-metron/pull/136#issuecomment-221862988 Yeah, I was thinking about that too. I think transformation is a more descriptive term. You're the 2nd person (in addition to myself) who has made that comment. I think that means I should call it transformation. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user nickwallen commented on the pull request: https://github.com/apache/incubator-metron/pull/136#issuecomment-221862663 I am wondering if `mapping` is the most descriptive word we can use here. We are also using map in a lot of different contexts in the configuration that makes it a bit confusing; `fieldToTypeMap`, `fieldMap`. I am sure there are better alternatives, but `transform` is the word that comes first to my mind. I think if we write the docs, the most descriptive word will more easily fall out. That's what tends to happen for me at least. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user nickwallen commented on the pull request: https://github.com/apache/incubator-metron/pull/136#issuecomment-221860284 Can you provide some documentation, README or otherwise, on how this will work for a user. Hard to visualize with what you've submitted. What steps do I need to take to use this functionality? What configs do I need to deploy? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
Github user mmiklavc commented on a diff in the pull request: https://github.com/apache/incubator-metron/pull/136#discussion_r64726176 --- Diff: metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/bolt/ParserBolt.java --- @@ -61,18 +62,32 @@ public void prepare(Map stormConf, TopologyContext context, OutputCollector coll this.collector = collector; parser.init(); writer.init(); +SensorParserConfig config = getConfigurations().getSensorParserConfig(sensorType); +if(config != null) { + config.init(); +} } @SuppressWarnings("unchecked") @Override public void execute(Tuple tuple) { byte[] originalMessage = tuple.getBinary(0); +SensorParserConfig sensorParserConfig = configurations.getSensorParserConfig(sensorType); try { List messages = parser.parse(originalMessage); for(JSONObject message: messages) { if (parser.validate(message)) { if (filter != null && filter.emitTuple(message)) { message.put(Constants.SENSOR_TYPE, sensorType); +List fieldMappings = sensorParserConfig == null?null:sensorParserConfig.getFieldMappings(); --- End diff -- If I'm interpreting correctly, org.apache.metron.common.configuration.SensorParserConfig won't vary with this implementation (i.e. not a user-provided impl). That said, I believe `sensorParserConfig.getFieldMappings()` should always return a non-null `List` (per the default init in that class -> `fieldMappings = new ArrayList<>()`) Maybe simplify line 82-84 to this? ``` if(sensorParserConfig != null) { for(MappingHandler handler: sensorParserConfig.getFieldMappings()) { ... } } ``` Also, might be worth a small test to see if line 85 handler null check can also go away. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-metron pull request: METRON-186: Create a fieldMapping f...
GitHub user cestella opened a pull request: https://github.com/apache/incubator-metron/pull/136 METRON-186: Create a fieldMapping functionality which allows for parsed fields to be transformed Currently the parsers take care of transforming raw data to the parsed JSON representation. Allow for a layer to be placed at a sensor level to transform input fields from the parsed messages to create new fields. For instance, mapping IANA protocol numbers to a standardized textual representation (i.e. 6 maps to TCP). This should be generalized, so that we can provide common functions and users can define the input fields and the output field to use. This configuration should live with the sensor configuration in zookeeper. You can merge this pull request into a Git repository by running: $ git pull https://github.com/cestella/incubator-metron transformers Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-metron/pull/136.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #136 commit 0d3b31be29b4238e1923d4d812e40dca4afe64f2 Author: cstellaDate: 2016-05-25T19:01:55Z Creating mapping infrastructure for parsing. commit 7e1366735a0ed8eb78ec7103759b6a2574beff2f Author: cstella Date: 2016-05-25T21:16:47Z Renamed and refactored a bit. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---