You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by trixpan <gi...@git.apache.org> on 2017/04/05 02:11:05 UTC

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

GitHub user trixpan opened a pull request:

    https://github.com/apache/nifi/pull/1650

    NIFI-2661 - Abstract the GeoEnrichIP processor

    NIFI-2661 - Introduce ISPEnrichIP Processor
    
    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [X] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [X] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [X] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [X] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [X] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [X] Have you written or updated unit tests to verify your changes?
    - [X] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [X] ~~~If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?~~~
    - [X] ~~~If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?~~~
    - [X] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [X] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/trixpan/nifi NIFI-2661

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/1650.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 #1650
    
----
commit 6c10108d99a9e341c93cf6524d54befe84aa4d05
Author: Andre F de Miranda <tr...@users.noreply.github.com>
Date:   2017-04-05T02:05:51Z

    NIFI-2661 - Abstract the GeoEnrichIP processor
    NIFI-2661 - Introduce ISPEnrichIP Processor

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by trixpan <gi...@git.apache.org>.
Github user trixpan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113411573
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/GeoEnrichIP.java ---
    @@ -208,6 +120,8 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
                 attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString());
             }
     
    +        attrs.put(new StringBuilder(ipAttributeName).append(".accuracy").toString(), response.getLocation().getAccuracyRadius().toString() );
    --- End diff --
    
    hopefully fixed


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113246522
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestISPEnrichIP.java ---
    @@ -0,0 +1,310 @@
    +/*
    + * 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.nifi.processors;
    +
    +import com.fasterxml.jackson.databind.DeserializationFeature;
    +import com.fasterxml.jackson.databind.InjectableValues;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.maxmind.geoip2.exception.GeoIp2Exception;
    +import com.maxmind.geoip2.model.IspResponse;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.flowfile.FlowFile;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processors.maxmind.DatabaseReader;
    +import org.apache.nifi.util.MockFlowFile;
    +import org.apache.nifi.util.TestRunner;
    +import org.apache.nifi.util.TestRunners;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.powermock.core.classloader.annotations.PrepareForTest;
    +import org.powermock.modules.junit4.PowerMockRunner;
    +
    +import java.io.IOException;
    +import java.net.InetAddress;
    +import java.net.UnknownHostException;
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +
    +import static org.junit.Assert.*;
    --- End diff --
    
    These star-imports cause CheckStyle violations


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113442128
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/GeoEnrichIP.java ---
    @@ -76,26 +76,36 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             final DatabaseReader dbReader = databaseReaderRef.get();
             final String ipAttributeName = context.getProperty(IP_ADDRESS_ATTRIBUTE).evaluateAttributeExpressions(flowFile).getValue();
             final String ipAttributeValue = flowFile.getAttribute(ipAttributeName);
    -        if (StringUtils.isEmpty(ipAttributeName)) { //TODO need to add additional validation - should look like an IPv4 or IPv6 addr for instance
    +
    +        if (StringUtils.isEmpty(ipAttributeName)) {
                 session.transfer(flowFile, REL_NOT_FOUND);
    -            getLogger().warn("Unable to find ip address for {}", new Object[]{flowFile});
    +            getLogger().warn("FlowFile '{}' aatribute '{}' was empty. Routing to failure",
    --- End diff --
    
    minor typo here, will fix while merging


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by trixpan <gi...@git.apache.org>.
Github user trixpan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113340946
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/GeoEnrichIP.java ---
    @@ -208,6 +120,8 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
                 attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString());
             }
     
    +        attrs.put(new StringBuilder(ipAttributeName).append(".accuracy").toString(), response.getLocation().getAccuracyRadius().toString() );
    --- End diff --
    
    Makes sense 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by trixpan <gi...@git.apache.org>.
Github user trixpan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113428044
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/ISPEnrichIP.java ---
    @@ -0,0 +1,132 @@
    +/*
    + * 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.nifi.processors;
    +
    +import com.maxmind.geoip2.exception.GeoIp2Exception;
    +import com.maxmind.geoip2.model.IspResponse;
    +import org.apache.commons.lang3.StringUtils;
    +import org.apache.nifi.annotation.behavior.EventDriven;
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
    +import org.apache.nifi.annotation.behavior.SideEffectFree;
    +import org.apache.nifi.annotation.behavior.SupportsBatching;
    +import org.apache.nifi.annotation.behavior.WritesAttribute;
    +import org.apache.nifi.annotation.behavior.WritesAttributes;
    +import org.apache.nifi.annotation.documentation.CapabilityDescription;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.flowfile.FlowFile;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.exception.ProcessException;
    +import org.apache.nifi.processors.maxmind.DatabaseReader;
    +import org.apache.nifi.util.StopWatch;
    +
    +import java.io.IOException;
    +import java.net.InetAddress;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.concurrent.TimeUnit;
    +
    +@EventDriven
    +@SideEffectFree
    +@SupportsBatching
    +@Tags({"ISP", "enrich", "ip", "maxmind"})
    +@InputRequirement(Requirement.INPUT_REQUIRED)
    +@CapabilityDescription("Looks up ISP information for an IP address and adds the information to FlowFile attributes. The "
    +        + "ISP data is provided as a MaxMind database. The attribute that contains the IP address to lookup is provided by the "
    +        + "'IP Address Attribute' property. If the name of the attribute provided is 'X', then the the attributes added by enrichment "
    +        + "will take the form X.isp.<fieldName>")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "X.isp.lookup.micros", description = "The number of microseconds that the geo lookup took"),
    +    @WritesAttribute(attribute = "X.isp.asn", description = "The Autonomous System Number (ASN) identified for the IP address"),
    +    @WritesAttribute(attribute = "X.isp.asn.organization", description = "The Organization Associated with the ASN identified"),
    +    @WritesAttribute(attribute = "X.isp.name", description = "The name of the ISP associated with the IP address provided"),
    +    @WritesAttribute(attribute = "X.isp.organization", description = "The Organization associated with the IP address provided"),})
    +public class ISPEnrichIP extends AbstractEnrichIP {
    +
    +    @Override
    +    public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    +        FlowFile flowFile = session.get();
    +        if (flowFile == null) {
    +            return;
    +        }
    +
    +        final DatabaseReader dbReader = databaseReaderRef.get();
    +        final String ipAttributeName = context.getProperty(IP_ADDRESS_ATTRIBUTE).evaluateAttributeExpressions(flowFile).getValue();
    +        final String ipAttributeValue = flowFile.getAttribute(ipAttributeName);
    +        if (StringUtils.isEmpty(ipAttributeName)) { //TODO need to add additional validation - should look like an IPv4 or IPv6 addr for instance
    --- End diff --
    
    I was revisiting the code and to be honest that TODO should be simply removed. The validation is done just following that section when we call:
    
    ```
            try {
                inetAddress = InetAddress.getByName(ipAttributeValue);
            } catch (final IOException ioe) {
                session.transfer(flowFile, REL_NOT_FOUND);
                getLogger().warn("Could not resolve {} to ip address for {}", new Object[]{ipAttributeValue, flowFile}, ioe);
                return;
            }
    ```
    
    IMNSHO relying on `InetAddress.getByName(String)` to validate is far better than using something like Apache Commons InetAddressValidator as the very same object used for validation is then re-used within the processor logic itself.
    
    ```
            try {
                response = dbReader.city(inetAddress);
                stopWatch.stop();
            }
    ```
    
    I would guess that anything else would be validating the same input twice??
    
    So instead I did instead update the log messages raised by triggering the condition you pointed / the exception above.
    
    let me know what you think


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113245854
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/GeoEnrichIP.java ---
    @@ -208,6 +120,8 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
                 attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString());
             }
     
    +        attrs.put(new StringBuilder(ipAttributeName).append(".accuracy").toString(), response.getLocation().getAccuracyRadius().toString() );
    --- End diff --
    
    The javadoc for getAccuracyRadius() says "This attribute is only available from the Insights end point." Are we guaranteed for that to be the case? Perhaps add some defensive code here to only add the attribute if we can successfully get the radius (to avoid NPEs, e.g.)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by trixpan <gi...@git.apache.org>.
Github user trixpan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113431000
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestISPEnrichIP.java ---
    @@ -0,0 +1,310 @@
    +/*
    + * 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.nifi.processors;
    +
    +import com.fasterxml.jackson.databind.DeserializationFeature;
    +import com.fasterxml.jackson.databind.InjectableValues;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.maxmind.geoip2.exception.GeoIp2Exception;
    +import com.maxmind.geoip2.model.IspResponse;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.flowfile.FlowFile;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processors.maxmind.DatabaseReader;
    +import org.apache.nifi.util.MockFlowFile;
    +import org.apache.nifi.util.TestRunner;
    +import org.apache.nifi.util.TestRunners;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.powermock.core.classloader.annotations.PrepareForTest;
    +import org.powermock.modules.junit4.PowerMockRunner;
    +
    +import java.io.IOException;
    +import java.net.InetAddress;
    +import java.net.UnknownHostException;
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +
    +import static org.junit.Assert.*;
    --- End diff --
    
    just realised the intelliJ settings for import and import static are independent... :disappointed: 
    
    fixed


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113442378
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/GeoEnrichIP.java ---
    @@ -76,26 +76,36 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             final DatabaseReader dbReader = databaseReaderRef.get();
             final String ipAttributeName = context.getProperty(IP_ADDRESS_ATTRIBUTE).evaluateAttributeExpressions(flowFile).getValue();
             final String ipAttributeValue = flowFile.getAttribute(ipAttributeName);
    -        if (StringUtils.isEmpty(ipAttributeName)) { //TODO need to add additional validation - should look like an IPv4 or IPv6 addr for instance
    +
    +        if (StringUtils.isEmpty(ipAttributeName)) {
                 session.transfer(flowFile, REL_NOT_FOUND);
    -            getLogger().warn("Unable to find ip address for {}", new Object[]{flowFile});
    +            getLogger().warn("FlowFile '{}' aatribute '{}' was empty. Routing to failure",
    +                    new Object[]{flowFile, IP_ADDRESS_ATTRIBUTE.getDisplayName()});
                 return;
             }
    +
             InetAddress inetAddress = null;
             CityResponse response = null;
     
             try {
                 inetAddress = InetAddress.getByName(ipAttributeValue);
             } catch (final IOException ioe) {
                 session.transfer(flowFile, REL_NOT_FOUND);
    -            getLogger().warn("Could not resolve {} to ip address for {}", new Object[]{ipAttributeValue, flowFile}, ioe);
    +            getLogger().warn("Could not resolve the IP for value '{}', contained within the attribute '{}' in " +
    +                            "FlowFile '{}'. This is usually caused by issue resolving the appropriate DNS record or " +
    +                            "providing the processor with an invalid IP address ",
    +                            new Object[]{IP_ADDRESS_ATTRIBUTE.getDisplayName(), ipAttributeValue, flowFile}, ioe);
    --- End diff --
    
    The first two objects are reversed, I can fix this on merge


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:

    https://github.com/apache/nifi/pull/1650
  
    +1 LGTM, tested both processors, everything works well.  Thank you for the contribution! Merging to master


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113247007
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/ISPEnrichIP.java ---
    @@ -0,0 +1,132 @@
    +/*
    + * 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.nifi.processors;
    +
    +import com.maxmind.geoip2.exception.GeoIp2Exception;
    +import com.maxmind.geoip2.model.IspResponse;
    +import org.apache.commons.lang3.StringUtils;
    +import org.apache.nifi.annotation.behavior.EventDriven;
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
    +import org.apache.nifi.annotation.behavior.SideEffectFree;
    +import org.apache.nifi.annotation.behavior.SupportsBatching;
    +import org.apache.nifi.annotation.behavior.WritesAttribute;
    +import org.apache.nifi.annotation.behavior.WritesAttributes;
    +import org.apache.nifi.annotation.documentation.CapabilityDescription;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.flowfile.FlowFile;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.exception.ProcessException;
    +import org.apache.nifi.processors.maxmind.DatabaseReader;
    +import org.apache.nifi.util.StopWatch;
    +
    +import java.io.IOException;
    +import java.net.InetAddress;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.concurrent.TimeUnit;
    +
    +@EventDriven
    +@SideEffectFree
    +@SupportsBatching
    +@Tags({"ISP", "enrich", "ip", "maxmind"})
    +@InputRequirement(Requirement.INPUT_REQUIRED)
    +@CapabilityDescription("Looks up ISP information for an IP address and adds the information to FlowFile attributes. The "
    +        + "ISP data is provided as a MaxMind database. The attribute that contains the IP address to lookup is provided by the "
    +        + "'IP Address Attribute' property. If the name of the attribute provided is 'X', then the the attributes added by enrichment "
    +        + "will take the form X.isp.<fieldName>")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "X.isp.lookup.micros", description = "The number of microseconds that the geo lookup took"),
    +    @WritesAttribute(attribute = "X.isp.asn", description = "The Autonomous System Number (ASN) identified for the IP address"),
    +    @WritesAttribute(attribute = "X.isp.asn.organization", description = "The Organization Associated with the ASN identified"),
    +    @WritesAttribute(attribute = "X.isp.name", description = "The name of the ISP associated with the IP address provided"),
    +    @WritesAttribute(attribute = "X.isp.organization", description = "The Organization associated with the IP address provided"),})
    +public class ISPEnrichIP extends AbstractEnrichIP {
    +
    +    @Override
    +    public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    +        FlowFile flowFile = session.get();
    +        if (flowFile == null) {
    +            return;
    +        }
    +
    +        final DatabaseReader dbReader = databaseReaderRef.get();
    +        final String ipAttributeName = context.getProperty(IP_ADDRESS_ATTRIBUTE).evaluateAttributeExpressions(flowFile).getValue();
    +        final String ipAttributeValue = flowFile.getAttribute(ipAttributeName);
    +        if (StringUtils.isEmpty(ipAttributeName)) { //TODO need to add additional validation - should look like an IPv4 or IPv6 addr for instance
    --- End diff --
    
    Although this is a copy of the TODO from GeoEnrichIP, is this a good time to add additional validation?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113244694
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/GeoEnrichIP.java ---
    @@ -70,6 +55,7 @@
     @WritesAttributes({
         @WritesAttribute(attribute = "X.geo.lookup.micros", description = "The number of microseconds that the geo lookup took"),
         @WritesAttribute(attribute = "X.geo.city", description = "The city identified for the IP address"),
    +    @WritesAttribute(attribute = "X.geo.accuracy", description = "The accuracy radius if provided by the database"),
    --- End diff --
    
    For clarity, probably should include the units (kilometers) here


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/1650


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1650: NIFI-2661 - Abstract the GeoEnrichIP processor

Posted by trixpan <gi...@git.apache.org>.
Github user trixpan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1650#discussion_r113411154
  
    --- Diff: nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/GeoEnrichIP.java ---
    @@ -70,6 +55,7 @@
     @WritesAttributes({
         @WritesAttribute(attribute = "X.geo.lookup.micros", description = "The number of microseconds that the geo lookup took"),
         @WritesAttribute(attribute = "X.geo.city", description = "The city identified for the IP address"),
    +    @WritesAttribute(attribute = "X.geo.accuracy", description = "The accuracy radius if provided by the database"),
    --- End diff --
    
    fixed


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---