From 81411da3a51635a0ad9132bb4b693a49bdbecdce Mon Sep 17 00:00:00 2001 From: Andre F de Miranda Date: Wed, 21 Jun 2017 15:08:08 +1000 Subject: [PATCH] NIFI-4098 - Adjust ParseCEF to re-use bean validator in order to improve performance --- nifi-assembly/NOTICE | 16 +++++++++- .../src/main/resources/META-INF/NOTICE | 16 +++++++++- .../nifi-standard-processors/pom.xml | 29 ++++++++++++++++++- .../nifi/processors/standard/ParseCEF.java | 13 ++++++++- 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/nifi-assembly/NOTICE b/nifi-assembly/NOTICE index 0873c21b73de..8e79dc7d0d0d 100644 --- a/nifi-assembly/NOTICE +++ b/nifi-assembly/NOTICE @@ -44,6 +44,20 @@ Apache Software License v2 The following binary components are provided under the Apache Software License v2 + (ASLv2) Apache BVal Project + The following NOTICE information applies: + Apache BVal project + Copyright 2010-2016 The Apache Software Foundation. + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + The following copyright notice(s) were affixed to portions of this code + with which this file is now or was at one time distributed. + + This product includes software developed by Agimatec GmbH. + Copyright 2007-2010 Agimatec GmbH. All rights reserved. + (ASLv2) Apache Commons IO The following NOTICE information applies: Apache Commons IO @@ -255,7 +269,7 @@ The following binary components are provided under the Apache Software License v (ASLv2) Apache Commons Lang The following NOTICE information applies: Apache Commons Lang - Copyright 2001-2015 The Apache Software Foundation + Copyright 2001-2017 The Apache Software Foundation This product includes software from the Spring Framework, under the Apache License 2.0 (see: StringUtils.containsWhitespace()) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/NOTICE b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/NOTICE index 05a1482660af..e67f5e419a14 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/NOTICE +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-nar/src/main/resources/META-INF/NOTICE @@ -26,6 +26,20 @@ Apache Software License v2 The following binary components are provided under the Apache Software License v2 + (ASLv2) Apache BVal Project + The following NOTICE information applies: + Apache BVal project + Copyright 2010-2016 The Apache Software Foundation. + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + The following copyright notice(s) were affixed to portions of this code + with which this file is now or was at one time distributed. + + This product includes software developed by Agimatec GmbH. + Copyright 2007-2010 Agimatec GmbH. All rights reserved. + (ASLv2) Apache Commons IO The following NOTICE information applies: Apache Commons IO @@ -34,7 +48,7 @@ The following binary components are provided under the Apache Software License v (ASLv2) Apache Commons Lang The following NOTICE information applies: Apache Commons Lang - Copyright 2001-2015 The Apache Software Foundation + Copyright 2001-2017 The Apache Software Foundation This product includes software from the Spring Framework, under the Apache License 2.0 (see: StringUtils.containsWhitespace()) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml index fcbfdf3c521d..688e542a8be8 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml @@ -305,7 +305,7 @@ com.fluenda ParCEFone - 1.2.4 + 1.2.5 org.slf4j @@ -313,6 +313,33 @@ + + org.apache.bval + bval-jsr + 1.1.2 + + + org.apache.tomcat + tomcat-el-api + + + org.apache.geronimo.specs + geronimo-annotation_1.2_spec + + + org.apache.geronimo.specs + geronimo-jcdi_1.1.spec + + + org.apache.geronimo.specs + geronimo-jpa_2.0.spec + + + org.apache.bval + bval-xstream + + + io.thekraken grok diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseCEF.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseCEF.java index 45e697543bfa..414b05881257 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseCEF.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseCEF.java @@ -25,12 +25,15 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.node.ObjectNode; + import com.fluenda.parcefone.event.CEFHandlingException; import com.fluenda.parcefone.event.CommonEvent; import com.fluenda.parcefone.parser.CEFParser; import com.martiansoftware.macnificent.MacAddress; +import org.apache.bval.jsr.ApacheValidationProvider; + import org.apache.nifi.annotation.behavior.EventDriven; import org.apache.nifi.annotation.behavior.InputRequirement; import org.apache.nifi.annotation.behavior.InputRequirement.Requirement; @@ -59,6 +62,8 @@ import org.apache.nifi.stream.io.BufferedOutputStream; import org.apache.nifi.stream.io.StreamUtils; +import javax.validation.Validation; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -170,6 +175,9 @@ public class ParseCEF extends AbstractProcessor { .description("Any FlowFile that is successfully parsed as a CEF message will be transferred to this Relationship.") .build(); + // Create a Bean validator to be shared by the parser instances. + final javax.validation.Validator validator = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator();; + @Override public List getSupportedPropertyDescriptors() { final Listproperties = new ArrayList<>(); @@ -219,7 +227,8 @@ public void onTrigger(final ProcessContext context, final ProcessSession session return; } - final CEFParser parser = new CEFParser(); + final CEFParser parser = new CEFParser(validator); + final byte[] buffer = new byte[(int) flowFile.getSize()]; session.read(flowFile, new InputStreamCallback() { @Override @@ -312,6 +321,8 @@ public void process(OutputStream out) throws IOException { } catch (CEFHandlingException e) { // The flowfile has failed parsing & validation, routing to failure and committing getLogger().error("Failed to parse {} as a CEF message due to {}; routing to failure", new Object[] {flowFile, e}); + // Create a provenance event recording the routing to failure + session.getProvenanceReporter().route(flowFile, REL_FAILURE); session.transfer(flowFile, REL_FAILURE); session.commit(); return;