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/01/14 11:03:23 UTC

[GitHub] nifi pull request #1418: NIFI-3238 - Introduce ListenBeat processor and depr...

GitHub user trixpan opened a pull request:

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

    NIFI-3238 - Introduce ListenBeat processor and deprecates ListenLumbe\u2026

    \u2026rjack 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:
    - [ ] 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-3238

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

    https://github.com/apache/nifi/pull/1418.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 #1418
    
----
commit 50c6742a36deb1879bbc615f7b5354b084c592a8
Author: Andre F de Miranda <tr...@users.noreply.github.com>
Date:   2017-01-04T16:14:59Z

    NIFI-3238 - Introduce ListenBeat processor and deprecates ListenLumberjack 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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103595838
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/frame/BeatsDecoder.java ---
    @@ -0,0 +1,330 @@
    +/*
    + * 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.beats.frame;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.zip.InflaterInputStream;
    +
    +import org.apache.nifi.stream.io.ByteArrayInputStream;
    +import org.apache.nifi.stream.io.ByteArrayOutputStream;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * Decodes a Beats frame by maintaining a state based on each byte that has been processed. This class
    + * should not be shared by multiple threads.
    + */
    +public class BeatsDecoder {
    +
    +
    +    static final Logger logger = LoggerFactory.getLogger(BeatsDecoder.class);
    +
    +    private BeatsFrame.Builder frameBuilder;
    +    private BeatsState currState = BeatsState.VERSION;
    +    private byte decodedFrameType;
    +
    +    private byte[] unprocessedData;
    +
    +    private final Charset charset;
    +    private final ByteArrayOutputStream currBytes;
    +
    +    private long windowSize;
    +
    +    static final int MIN_FRAME_HEADER_LENGTH = 2; // Version + Type
    +    static final int WINDOWSIZE_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32bit unsigned window size
    +    static final int COMPRESSED_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32 bit unsigned + payload
    +    static final int JSON_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 8; // 32 bit unsigned sequence number + 32 bit unsigned payload length
    +
    +    public static final byte FRAME_WINDOWSIZE = 0x57, FRAME_DATA = 0x44, FRAME_COMPRESSED = 0x43, FRAME_ACK = 0x41, FRAME_JSON = 0x4a;
    +
    +    /**
    +     * @param charset the charset to decode bytes from the frame
    +     */
    +    public BeatsDecoder(final Charset charset) {
    +        this(charset, new ByteArrayOutputStream(4096));
    --- End diff --
    
    Is 4K ok as a default size? Should it be passed in here and perhaps default somewhere else in case it needs to be configurable?


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103595712
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/frame/BeatsDecoder.java ---
    @@ -0,0 +1,330 @@
    +/*
    + * 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.beats.frame;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.zip.InflaterInputStream;
    +
    +import org.apache.nifi.stream.io.ByteArrayInputStream;
    +import org.apache.nifi.stream.io.ByteArrayOutputStream;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * Decodes a Beats frame by maintaining a state based on each byte that has been processed. This class
    + * should not be shared by multiple threads.
    + */
    +public class BeatsDecoder {
    +
    +
    +    static final Logger logger = LoggerFactory.getLogger(BeatsDecoder.class);
    --- End diff --
    
    Should we instead pass in a reference to the ComponentLog rather than depend on SLF4J as the implementation? I realize SLF4J is itself a facade, but this couples the logging directly to it rather than using the NiFi logging "framework"


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103599241
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/frame/BeatsDecoder.java ---
    @@ -0,0 +1,330 @@
    +/*
    + * 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.beats.frame;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.zip.InflaterInputStream;
    +
    +import org.apache.nifi.stream.io.ByteArrayInputStream;
    +import org.apache.nifi.stream.io.ByteArrayOutputStream;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * Decodes a Beats frame by maintaining a state based on each byte that has been processed. This class
    + * should not be shared by multiple threads.
    + */
    +public class BeatsDecoder {
    +
    +
    +    static final Logger logger = LoggerFactory.getLogger(BeatsDecoder.class);
    --- End diff --
    
    sure. Will adjust.


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103648185
  
    --- Diff: nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/src/main/java/org/apache/nifi/processors/lumberjack/ListenLumberjack.java ---
    @@ -62,12 +62,13 @@
     
     import com.google.gson.Gson;
     
    +@Deprecated
     @InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
     @Tags({"listen", "lumberjack", "tcp", "logs"})
    -@CapabilityDescription("Listens for Lumberjack messages being sent to a given port over TCP. Each message will be " +
    +@CapabilityDescription("This processor is deprecated and will be removed in the near future. Listens for Lumberjack messages being sent to a given port over TCP. Each message will be " +
    --- 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.
---

[GitHub] nifi pull request #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103649158
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/ListenBeats.java ---
    @@ -0,0 +1,216 @@
    +/*
    + * 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.beats;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.BlockingQueue;
    +
    +import javax.net.ssl.SSLContext;
    +
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +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.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey;
    +import org.apache.nifi.processor.DataUnit;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.util.listen.AbstractListenEventBatchingProcessor;
    +import org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.ChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.event.EventFactory;
    +import org.apache.nifi.processor.util.listen.handler.ChannelHandlerFactory;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponder;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponse;
    +import org.apache.nifi.processors.beats.event.BeatsEvent;
    +import org.apache.nifi.processors.beats.event.BeatsEventFactory;
    +import org.apache.nifi.processors.beats.frame.BeatsEncoder;
    +import org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory;
    +import org.apache.nifi.processors.beats.response.BeatsChannelResponse;
    +import org.apache.nifi.processors.beats.response.BeatsResponse;
    +import org.apache.nifi.ssl.SSLContextService;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
    +@Tags({"listen", "beats", "tcp", "logs"})
    +@CapabilityDescription("Listens for messages sent by libbeat compatible clients (e.g. filebeats, metricbeats, etc) being sent to a given port over TCP, writing its contents in" +
    +        "JSON format to the content of the message to a FlowFile." +
    +        "This processor replaces the now deprecated ListenLumberjack")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "beats.sender", description = "The sending host of the messages."),
    +    @WritesAttribute(attribute = "beats.port", description = "The sending port the messages were received over."),
    +    @WritesAttribute(attribute = "beats.sequencenumber", description = "The sequence number of the message. Only included if <Batch Size> is 1."),
    +    @WritesAttribute(attribute = "mime.type", description = "The mime.type of the content which is application/json")
    +})
    +@SeeAlso(classNames = {"org.apache.nifi.processors.standard.ParseSyslog"})
    +public class ListenBeats extends AbstractListenEventBatchingProcessor<BeatsEvent> {
    +
    +    public static final PropertyDescriptor SSL_CONTEXT_SERVICE = new PropertyDescriptor.Builder()
    +        .name("SSL Context Service")
    +        .description("The Controller Service to use in order to obtain an SSL Context. If this property is set, " +
    +            "messages will be received over a secure connection.")
    +        // Nearly all Lumberjack v1 implementations require TLS to work. v2 implementations (i.e. beats) have TLS as optional
    +        .required(false)
    +        .identifiesControllerService(SSLContextService.class)
    +        .build();
    +
    +    @Override
    +    protected List<PropertyDescriptor> getAdditionalProperties() {
    +        return Arrays.asList(
    +            MAX_CONNECTIONS,
    +            SSL_CONTEXT_SERVICE
    +        );
    +    }
    +
    +    @Override
    +    protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    +        final List<ValidationResult> results = new ArrayList<>();
    +
    +        final SSLContextService sslContextService = validationContext.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +
    +        if (sslContextService != null && sslContextService.isTrustStoreConfigured() == false) {
    +            results.add(new ValidationResult.Builder()
    +                .explanation("The context service must have a truststore  configured for the beats forwarder client to work correctly")
    +                .valid(false).subject(SSL_CONTEXT_SERVICE.getName()).build());
    +        }
    +
    +        return results;
    +    }
    +
    +    private volatile BeatsEncoder beatsEncoder;
    +
    +
    +    @Override
    +    @OnScheduled
    +    public void onScheduled(ProcessContext context) throws IOException {
    +        super.onScheduled(context);
    +        // wanted to ensure charset was already populated here
    +        beatsEncoder = new BeatsEncoder();
    +    }
    +
    +    @Override
    +    protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<BeatsEvent> events) throws IOException {
    +        final EventFactory<BeatsEvent> eventFactory = new BeatsEventFactory();
    +        final ChannelHandlerFactory<BeatsEvent, AsyncChannelDispatcher> handlerFactory = new BeatsSocketChannelHandlerFactory<>();
    +
    +        final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    +        final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    +        final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    +
    +        // initialize the buffer pool based on max number of connections and the buffer size
    +        final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    +
    +        // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    +        SSLContext sslContext = null;
    +        final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +        if (sslContextService != null) {
    +            sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    +        }
    +
    +        // if we decide to support SSL then get the context and pass it in here
    +        return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events,
    +            getLogger(), maxConnections, sslContext, charSet);
    +    }
    +
    +
    +    @Override
    +    protected String getBatchKey(BeatsEvent event) {
    +        return event.getSender();
    +    }
    +
    +    protected void respond(final BeatsEvent event, final BeatsResponse beatsResponse) {
    +        final ChannelResponse response = new BeatsChannelResponse(beatsEncoder, beatsResponse);
    +
    +        final ChannelResponder responder = event.getResponder();
    +        responder.addResponse(response);
    +        try {
    +            responder.respond();
    +        } catch (IOException e) {
    +            getLogger().error("Error sending response for transaction {} due to {}",
    +                new Object[]{event.getSeqNumber(), e.getMessage()}, e);
    +        }
    +    }
    +
    +    protected void postProcess(final ProcessContext context, final ProcessSession session, final List<BeatsEvent> events) {
    +        // first commit the session so we guarantee we have all the events successfully
    +        // written to FlowFiles and transferred to the success relationship
    +        session.commit();
    +        // respond to each event to acknowledge successful receipt
    +        for (final BeatsEvent event : events) {
    +            respond(event, BeatsResponse.ok(event.getSeqNumber()));
    +        }
    +    }
    +
    +    @Override
    +    protected String getTransitUri(FlowFileEventBatch batch) {
    +        final String sender = batch.getEvents().get(0).getSender();
    +        final String senderHost = sender.startsWith("/") && sender.length() > 1 ? sender.substring(1) : sender;
    +        final String transitUri = new StringBuilder().append("beats").append("://").append(senderHost).append(":")
    +            .append(port).toString();
    +        return transitUri;
    +    }
    +
    +    @Override
    +    protected Map<String, String> getAttributes(FlowFileEventBatch batch) {
    +        final List<BeatsEvent> events = batch.getEvents();
    +        // the sender and command will be the same for all events based on the batch key
    +        final String sender = events.get(0).getSender();
    +        final int numAttributes = events.size() == 1 ? 5 : 4;
    +        final Map<String, String> attributes = new HashMap<>(numAttributes);
    +        attributes.put(beatsAttributes.SENDER.key(), sender);
    +        attributes.put(beatsAttributes.PORT.key(), String.valueOf(port));
    +        attributes.put(CoreAttributes.MIME_TYPE.key(), "application/json");
    +        // if there was only one event then we can pass on the transaction
    +        // NOTE: we could pass on all the transaction ids joined together
    --- End diff --
    
    wait a second. it is already there:
    
    @WritesAttribute(attribute = "beats.sequencenumber", description = "The sequence number of the message. Only included if <Batch Size> is 1."),


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103597193
  
    --- Diff: nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/src/main/java/org/apache/nifi/processors/lumberjack/ListenLumberjack.java ---
    @@ -62,12 +62,13 @@
     
     import com.google.gson.Gson;
     
    +@Deprecated
     @InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
     @Tags({"listen", "lumberjack", "tcp", "logs"})
    -@CapabilityDescription("Listens for Lumberjack messages being sent to a given port over TCP. Each message will be " +
    +@CapabilityDescription("This processor is deprecated and will be removed in the near future. Listens for Lumberjack messages being sent to a given port over TCP. Each message will be " +
    --- End diff --
    
    maybe rephrase to "may be removed from the distribution". Deprecated things have a tendency to linger ;)


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    I've been playing with this branch locally for a few days and I haven't experienced any issues yet.


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    +1 LGTM, ran tests and tried with a live NiFi using metricbeat and filebeat. Thanks very much for the great 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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103597456
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml ---
    @@ -0,0 +1,76 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    +  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.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <parent>
    +        <groupId>org.apache.nifi</groupId>
    +        <artifactId>nifi-beats-bundle</artifactId>
    +        <version>1.2.0-SNAPSHOT</version>
    +    </parent>
    +
    +    <artifactId>nifi-beats-processors</artifactId>
    +    <packaging>jar</packaging>
    +
    +    <dependencies>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-api</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-processor-utils</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-mock</artifactId>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-socket-utils</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-utils</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-flowfile-packager</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-ssl-context-service-api</artifactId>
    +            <scope>provided</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.slf4j</groupId>
    +            <artifactId>slf4j-simple</artifactId>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>junit</groupId>
    +            <artifactId>junit</artifactId>
    +            <version>4.11</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>com.google.code.gson</groupId>
    --- End diff --
    
    if this is a compile dependency and "you're already in there", please move this up above the "test" and "provided" dependencies. Not a requirement but a suggestion :)


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103599499
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-nar/src/main/resources/META-INF/LICENSE ---
    @@ -0,0 +1,233 @@
    +
    +                                 Apache License
    +                           Version 2.0, January 2004
    +                        http://www.apache.org/licenses/
    +
    +   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
    +
    +   1. Definitions.
    +
    +      "License" shall mean the terms and conditions for use, reproduction,
    +      and distribution as defined by Sections 1 through 9 of this document.
    +
    +      "Licensor" shall mean the copyright owner or entity authorized by
    +      the copyright owner that is granting the License.
    +
    +      "Legal Entity" shall mean the union of the acting entity and all
    +      other entities that control, are controlled by, or are under common
    +      control with that entity. For the purposes of this definition,
    +      "control" means (i) the power, direct or indirect, to cause the
    +      direction or management of such entity, whether by contract or
    +      otherwise, or (ii) ownership of fifty percent (50%) or more of the
    +      outstanding shares, or (iii) beneficial ownership of such entity.
    +
    +      "You" (or "Your") shall mean an individual or Legal Entity
    +      exercising permissions granted by this License.
    +
    +      "Source" form shall mean the preferred form for making modifications,
    +      including but not limited to software source code, documentation
    +      source, and configuration files.
    +
    +      "Object" form shall mean any form resulting from mechanical
    +      transformation or translation of a Source form, including but
    +      not limited to compiled object code, generated documentation,
    +      and conversions to other media types.
    +
    +      "Work" shall mean the work of authorship, whether in Source or
    +      Object form, made available under the License, as indicated by a
    +      copyright notice that is included in or attached to the work
    +      (an example is provided in the Appendix below).
    +
    +      "Derivative Works" shall mean any work, whether in Source or Object
    +      form, that is based on (or derived from) the Work and for which the
    +      editorial revisions, annotations, elaborations, or other modifications
    +      represent, as a whole, an original work of authorship. For the purposes
    +      of this License, Derivative Works shall not include works that remain
    +      separable from, or merely link (or bind by name) to the interfaces of,
    +      the Work and Derivative Works thereof.
    +
    +      "Contribution" shall mean any work of authorship, including
    +      the original version of the Work and any modifications or additions
    +      to that Work or Derivative Works thereof, that is intentionally
    +      submitted to Licensor for inclusion in the Work by the copyright owner
    +      or by an individual or Legal Entity authorized to submit on behalf of
    +      the copyright owner. For the purposes of this definition, "submitted"
    +      means any form of electronic, verbal, or written communication sent
    +      to the Licensor or its representatives, including but not limited to
    +      communication on electronic mailing lists, source code control systems,
    +      and issue tracking systems that are managed by, or on behalf of, the
    +      Licensor for the purpose of discussing and improving the Work, but
    +      excluding communication that is conspicuously marked or otherwise
    +      designated in writing by the copyright owner as "Not a Contribution."
    +
    +      "Contributor" shall mean Licensor and any individual or Legal Entity
    +      on behalf of whom a Contribution has been received by Licensor and
    +      subsequently incorporated within the Work.
    +
    +   2. Grant of Copyright License. Subject to the terms and conditions of
    +      this License, each Contributor hereby grants to You a perpetual,
    +      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    +      copyright license to reproduce, prepare Derivative Works of,
    +      publicly display, publicly perform, sublicense, and distribute the
    +      Work and such Derivative Works in Source or Object form.
    +
    +   3. Grant of Patent License. Subject to the terms and conditions of
    +      this License, each Contributor hereby grants to You a perpetual,
    +      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    +      (except as stated in this section) patent license to make, have made,
    +      use, offer to sell, sell, import, and otherwise transfer the Work,
    +      where such license applies only to those patent claims licensable
    +      by such Contributor that are necessarily infringed by their
    +      Contribution(s) alone or by combination of their Contribution(s)
    +      with the Work to which such Contribution(s) was submitted. If You
    +      institute patent litigation against any entity (including a
    +      cross-claim or counterclaim in a lawsuit) alleging that the Work
    +      or a Contribution incorporated within the Work constitutes direct
    +      or contributory patent infringement, then any patent licenses
    +      granted to You under this License for that Work shall terminate
    +      as of the date such litigation is filed.
    +
    +   4. Redistribution. You may reproduce and distribute copies of the
    +      Work or Derivative Works thereof in any medium, with or without
    +      modifications, and in Source or Object form, provided that You
    +      meet the following conditions:
    +
    +      (a) You must give any other recipients of the Work or
    +          Derivative Works a copy of this License; and
    +
    +      (b) You must cause any modified files to carry prominent notices
    +          stating that You changed the files; and
    +
    +      (c) You must retain, in the Source form of any Derivative Works
    +          that You distribute, all copyright, patent, trademark, and
    +          attribution notices from the Source form of the Work,
    +          excluding those notices that do not pertain to any part of
    +          the Derivative Works; and
    +
    +      (d) If the Work includes a "NOTICE" text file as part of its
    +          distribution, then any Derivative Works that You distribute must
    +          include a readable copy of the attribution notices contained
    +          within such NOTICE file, excluding those notices that do not
    +          pertain to any part of the Derivative Works, in at least one
    +          of the following places: within a NOTICE text file distributed
    +          as part of the Derivative Works; within the Source form or
    +          documentation, if provided along with the Derivative Works; or,
    +          within a display generated by the Derivative Works, if and
    +          wherever such third-party notices normally appear. The contents
    +          of the NOTICE file are for informational purposes only and
    +          do not modify the License. You may add Your own attribution
    +          notices within Derivative Works that You distribute, alongside
    +          or as an addendum to the NOTICE text from the Work, provided
    +          that such additional attribution notices cannot be construed
    +          as modifying the License.
    +
    +      You may add Your own copyright statement to Your modifications and
    +      may provide additional or different license terms and conditions
    +      for use, reproduction, or distribution of Your modifications, or
    +      for any such Derivative Works as a whole, provided Your use,
    +      reproduction, and distribution of the Work otherwise complies with
    +      the conditions stated in this License.
    +
    +   5. Submission of Contributions. Unless You explicitly state otherwise,
    +      any Contribution intentionally submitted for inclusion in the Work
    +      by You to the Licensor shall be under the terms and conditions of
    +      this License, without any additional terms or conditions.
    +      Notwithstanding the above, nothing herein shall supersede or modify
    +      the terms of any separate license agreement you may have executed
    +      with Licensor regarding such Contributions.
    +
    +   6. Trademarks. This License does not grant permission to use the trade
    +      names, trademarks, service marks, or product names of the Licensor,
    +      except as required for reasonable and customary use in describing the
    +      origin of the Work and reproducing the content of the NOTICE file.
    +
    +   7. Disclaimer of Warranty. Unless required by applicable law or
    +      agreed to in writing, Licensor provides the Work (and each
    +      Contributor provides its Contributions) on an "AS IS" BASIS,
    +      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    +      implied, including, without limitation, any warranties or conditions
    +      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
    +      PARTICULAR PURPOSE. You are solely responsible for determining the
    +      appropriateness of using or redistributing the Work and assume any
    +      risks associated with Your exercise of permissions under this License.
    +
    +   8. Limitation of Liability. In no event and under no legal theory,
    +      whether in tort (including negligence), contract, or otherwise,
    +      unless required by applicable law (such as deliberate and grossly
    +      negligent acts) or agreed to in writing, shall any Contributor be
    +      liable to You for damages, including any direct, indirect, special,
    +      incidental, or consequential damages of any character arising as a
    +      result of this License or out of the use or inability to use the
    +      Work (including but not limited to damages for loss of goodwill,
    +      work stoppage, computer failure or malfunction, or any and all
    +      other commercial damages or losses), even if such Contributor
    +      has been advised of the possibility of such damages.
    +
    +   9. Accepting Warranty or Additional Liability. While redistributing
    +      the Work or Derivative Works thereof, You may choose to offer,
    +      and charge a fee for, acceptance of support, warranty, indemnity,
    +      or other liability obligations and/or rights consistent with this
    +      License. However, in accepting such obligations, You may act only
    +      on Your own behalf and on Your sole responsibility, not on behalf
    +      of any other Contributor, and only if You agree to indemnify,
    +      defend, and hold each Contributor harmless for any liability
    +      incurred by, or claims asserted against, such Contributor by reason
    +      of your accepting any such warranty or additional liability.
    +
    +   END OF TERMS AND CONDITIONS
    +
    +   APPENDIX: How to apply the Apache License to your work.
    +
    +      To apply the Apache License to your work, attach the following
    +      boilerplate notice, with the fields enclosed by brackets "[]"
    +      replaced with your own identifying information. (Don't include
    +      the brackets!)  The text should be enclosed in the appropriate
    +      comment syntax for the file format. We also recommend that a
    +      file or class name and description of purpose be included on the
    +      same "printed page" as the copyright notice for easier
    +      identification within third-party archives.
    +
    +   Copyright [yyyy] [name of copyright owner]
    +
    +   Licensed 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.  
    +
    +APACHE NIFI SUBCOMPONENTS:
    +
    +The Apache NiFi project contains subcomponents with separate copyright
    +notices and license terms. Your use of the source code for the these
    +subcomponents is subject to the terms and conditions of the following
    +licenses. 
    +
    +  The binary distribution of this product bundles 'Bouncy Castle JDK 1.5'
    --- End diff --
    
    I missed that JIRA. Will help with other of my PRs as well. :-)


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103651066
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/frame/BeatsDecoder.java ---
    @@ -0,0 +1,330 @@
    +/*
    + * 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.beats.frame;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.zip.InflaterInputStream;
    +
    +import org.apache.nifi.stream.io.ByteArrayInputStream;
    +import org.apache.nifi.stream.io.ByteArrayOutputStream;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * Decodes a Beats frame by maintaining a state based on each byte that has been processed. This class
    + * should not be shared by multiple threads.
    + */
    +public class BeatsDecoder {
    +
    +
    +    static final Logger logger = LoggerFactory.getLogger(BeatsDecoder.class);
    +
    +    private BeatsFrame.Builder frameBuilder;
    +    private BeatsState currState = BeatsState.VERSION;
    +    private byte decodedFrameType;
    +
    +    private byte[] unprocessedData;
    +
    +    private final Charset charset;
    +    private final ByteArrayOutputStream currBytes;
    +
    +    private long windowSize;
    +
    +    static final int MIN_FRAME_HEADER_LENGTH = 2; // Version + Type
    +    static final int WINDOWSIZE_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32bit unsigned window size
    +    static final int COMPRESSED_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32 bit unsigned + payload
    +    static final int JSON_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 8; // 32 bit unsigned sequence number + 32 bit unsigned payload length
    +
    +    public static final byte FRAME_WINDOWSIZE = 0x57, FRAME_DATA = 0x44, FRAME_COMPRESSED = 0x43, FRAME_ACK = 0x41, FRAME_JSON = 0x4a;
    +
    +    /**
    +     * @param charset the charset to decode bytes from the frame
    +     */
    +    public BeatsDecoder(final Charset charset) {
    +        this(charset, new ByteArrayOutputStream(4096));
    --- End diff --
    
    I suspect so. I tested with both smaller and larger values and they all work ok. Happy to convert into a property tho so it can be adjusted.


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    @scottcrespo thanks for the message. 
    
    the work around here is fairly simple in nature: to allow any beat (filebeat, metricbeat, etc) to send their data directly into NiFi, allowing people currently using logstash to seamlessly migrate data pipelines into NiFi.
    
    When you read any beats doco you will note they have a few different outputs: Kafka, ES and Logstash. This processor allows NiFi to act as a destination of _*beats_ logstash output.
    
    So in theory, your Metricbeat module could still use metricbeat as underlying agent, but instead of shipping it directly into ES as I believe you are planning to do, ship it to NiFi (so it can be further processed, persisted in HDFS, etc)


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103653787
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/ListenBeats.java ---
    @@ -0,0 +1,216 @@
    +/*
    + * 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.beats;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.BlockingQueue;
    +
    +import javax.net.ssl.SSLContext;
    +
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +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.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey;
    +import org.apache.nifi.processor.DataUnit;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.util.listen.AbstractListenEventBatchingProcessor;
    +import org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.ChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.event.EventFactory;
    +import org.apache.nifi.processor.util.listen.handler.ChannelHandlerFactory;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponder;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponse;
    +import org.apache.nifi.processors.beats.event.BeatsEvent;
    +import org.apache.nifi.processors.beats.event.BeatsEventFactory;
    +import org.apache.nifi.processors.beats.frame.BeatsEncoder;
    +import org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory;
    +import org.apache.nifi.processors.beats.response.BeatsChannelResponse;
    +import org.apache.nifi.processors.beats.response.BeatsResponse;
    +import org.apache.nifi.ssl.SSLContextService;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
    +@Tags({"listen", "beats", "tcp", "logs"})
    +@CapabilityDescription("Listens for messages sent by libbeat compatible clients (e.g. filebeats, metricbeats, etc) being sent to a given port over TCP, writing its contents in" +
    +        "JSON format to the content of the message to a FlowFile." +
    +        "This processor replaces the now deprecated ListenLumberjack")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "beats.sender", description = "The sending host of the messages."),
    +    @WritesAttribute(attribute = "beats.port", description = "The sending port the messages were received over."),
    +    @WritesAttribute(attribute = "beats.sequencenumber", description = "The sequence number of the message. Only included if <Batch Size> is 1."),
    +    @WritesAttribute(attribute = "mime.type", description = "The mime.type of the content which is application/json")
    +})
    +@SeeAlso(classNames = {"org.apache.nifi.processors.standard.ParseSyslog"})
    +public class ListenBeats extends AbstractListenEventBatchingProcessor<BeatsEvent> {
    +
    +    public static final PropertyDescriptor SSL_CONTEXT_SERVICE = new PropertyDescriptor.Builder()
    +        .name("SSL Context Service")
    +        .description("The Controller Service to use in order to obtain an SSL Context. If this property is set, " +
    +            "messages will be received over a secure connection.")
    +        // Nearly all Lumberjack v1 implementations require TLS to work. v2 implementations (i.e. beats) have TLS as optional
    +        .required(false)
    +        .identifiesControllerService(SSLContextService.class)
    +        .build();
    +
    +    @Override
    +    protected List<PropertyDescriptor> getAdditionalProperties() {
    +        return Arrays.asList(
    +            MAX_CONNECTIONS,
    +            SSL_CONTEXT_SERVICE
    +        );
    +    }
    +
    +    @Override
    +    protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    +        final List<ValidationResult> results = new ArrayList<>();
    +
    +        final SSLContextService sslContextService = validationContext.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +
    +        if (sslContextService != null && sslContextService.isTrustStoreConfigured() == false) {
    +            results.add(new ValidationResult.Builder()
    +                .explanation("The context service must have a truststore  configured for the beats forwarder client to work correctly")
    +                .valid(false).subject(SSL_CONTEXT_SERVICE.getName()).build());
    +        }
    +
    +        return results;
    +    }
    +
    +    private volatile BeatsEncoder beatsEncoder;
    +
    +
    +    @Override
    +    @OnScheduled
    +    public void onScheduled(ProcessContext context) throws IOException {
    +        super.onScheduled(context);
    +        // wanted to ensure charset was already populated here
    +        beatsEncoder = new BeatsEncoder();
    +    }
    +
    +    @Override
    +    protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<BeatsEvent> events) throws IOException {
    +        final EventFactory<BeatsEvent> eventFactory = new BeatsEventFactory();
    +        final ChannelHandlerFactory<BeatsEvent, AsyncChannelDispatcher> handlerFactory = new BeatsSocketChannelHandlerFactory<>();
    +
    +        final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    +        final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    +        final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    +
    +        // initialize the buffer pool based on max number of connections and the buffer size
    +        final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    +
    +        // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    +        SSLContext sslContext = null;
    +        final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +        if (sslContextService != null) {
    +            sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    +        }
    +
    +        // if we decide to support SSL then get the context and pass it in here
    +        return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events,
    +            getLogger(), maxConnections, sslContext, charSet);
    +    }
    +
    +
    +    @Override
    +    protected String getBatchKey(BeatsEvent event) {
    +        return event.getSender();
    +    }
    +
    +    protected void respond(final BeatsEvent event, final BeatsResponse beatsResponse) {
    +        final ChannelResponse response = new BeatsChannelResponse(beatsEncoder, beatsResponse);
    +
    +        final ChannelResponder responder = event.getResponder();
    +        responder.addResponse(response);
    +        try {
    +            responder.respond();
    +        } catch (IOException e) {
    +            getLogger().error("Error sending response for transaction {} due to {}",
    +                new Object[]{event.getSeqNumber(), e.getMessage()}, e);
    +        }
    +    }
    +
    +    protected void postProcess(final ProcessContext context, final ProcessSession session, final List<BeatsEvent> events) {
    +        // first commit the session so we guarantee we have all the events successfully
    +        // written to FlowFiles and transferred to the success relationship
    +        session.commit();
    +        // respond to each event to acknowledge successful receipt
    +        for (final BeatsEvent event : events) {
    +            respond(event, BeatsResponse.ok(event.getSeqNumber()));
    +        }
    +    }
    +
    +    @Override
    +    protected String getTransitUri(FlowFileEventBatch batch) {
    +        final String sender = batch.getEvents().get(0).getSender();
    --- End diff --
    
    I would say not:
    
    final InetAddress sender = socketChannel.socket().getInetAddress();
    
    But some people also assumed the Titanic was unsinkable... :ship:


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    Hey @trixpan 
    
    @mattyb149 linked me to this PR since I'm an [Elastic Beats](https://github.com/elastic/beats) contributor and NiFi fan boy. 
    
    I just started working on a [Metricbeat module](https://github.com/elastic/beats/pull/3374) to monitor NiFi via its REST API. I'd love to talk with you to better understand your work here, and discuss an implementation for Metricbeat. 
    
    You can email me at: sccrespo@gmail.com
    Event better, hit me up on skype: scott.crespo
    
    
    Happy Coding!


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    @mattyb149 - hopefully addressed your feedback. 


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    For future reference:
    
    https://discuss.elastic.co/t/testers-wanted-beat-integration-with-apache-nifi/73671/


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    Reviewing...


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103599675
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/ListenBeats.java ---
    @@ -0,0 +1,216 @@
    +/*
    + * 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.beats;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.BlockingQueue;
    +
    +import javax.net.ssl.SSLContext;
    +
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +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.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey;
    +import org.apache.nifi.processor.DataUnit;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.util.listen.AbstractListenEventBatchingProcessor;
    +import org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.ChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.event.EventFactory;
    +import org.apache.nifi.processor.util.listen.handler.ChannelHandlerFactory;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponder;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponse;
    +import org.apache.nifi.processors.beats.event.BeatsEvent;
    +import org.apache.nifi.processors.beats.event.BeatsEventFactory;
    +import org.apache.nifi.processors.beats.frame.BeatsEncoder;
    +import org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory;
    +import org.apache.nifi.processors.beats.response.BeatsChannelResponse;
    +import org.apache.nifi.processors.beats.response.BeatsResponse;
    +import org.apache.nifi.ssl.SSLContextService;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
    +@Tags({"listen", "beats", "tcp", "logs"})
    +@CapabilityDescription("Listens for messages sent by libbeat compatible clients (e.g. filebeats, metricbeats, etc) being sent to a given port over TCP, writing its contents in" +
    +        "JSON format to the content of the message to a FlowFile." +
    +        "This processor replaces the now deprecated ListenLumberjack")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "beats.sender", description = "The sending host of the messages."),
    +    @WritesAttribute(attribute = "beats.port", description = "The sending port the messages were received over."),
    +    @WritesAttribute(attribute = "beats.sequencenumber", description = "The sequence number of the message. Only included if <Batch Size> is 1."),
    +    @WritesAttribute(attribute = "mime.type", description = "The mime.type of the content which is application/json")
    +})
    +@SeeAlso(classNames = {"org.apache.nifi.processors.standard.ParseSyslog"})
    +public class ListenBeats extends AbstractListenEventBatchingProcessor<BeatsEvent> {
    +
    +    public static final PropertyDescriptor SSL_CONTEXT_SERVICE = new PropertyDescriptor.Builder()
    +        .name("SSL Context Service")
    +        .description("The Controller Service to use in order to obtain an SSL Context. If this property is set, " +
    +            "messages will be received over a secure connection.")
    +        // Nearly all Lumberjack v1 implementations require TLS to work. v2 implementations (i.e. beats) have TLS as optional
    +        .required(false)
    +        .identifiesControllerService(SSLContextService.class)
    +        .build();
    +
    +    @Override
    +    protected List<PropertyDescriptor> getAdditionalProperties() {
    +        return Arrays.asList(
    +            MAX_CONNECTIONS,
    +            SSL_CONTEXT_SERVICE
    +        );
    +    }
    +
    +    @Override
    +    protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    +        final List<ValidationResult> results = new ArrayList<>();
    +
    +        final SSLContextService sslContextService = validationContext.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +
    +        if (sslContextService != null && sslContextService.isTrustStoreConfigured() == false) {
    +            results.add(new ValidationResult.Builder()
    +                .explanation("The context service must have a truststore  configured for the beats forwarder client to work correctly")
    +                .valid(false).subject(SSL_CONTEXT_SERVICE.getName()).build());
    +        }
    +
    +        return results;
    +    }
    +
    +    private volatile BeatsEncoder beatsEncoder;
    +
    +
    +    @Override
    +    @OnScheduled
    +    public void onScheduled(ProcessContext context) throws IOException {
    +        super.onScheduled(context);
    +        // wanted to ensure charset was already populated here
    +        beatsEncoder = new BeatsEncoder();
    +    }
    +
    +    @Override
    +    protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<BeatsEvent> events) throws IOException {
    +        final EventFactory<BeatsEvent> eventFactory = new BeatsEventFactory();
    +        final ChannelHandlerFactory<BeatsEvent, AsyncChannelDispatcher> handlerFactory = new BeatsSocketChannelHandlerFactory<>();
    +
    +        final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    +        final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    +        final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    +
    +        // initialize the buffer pool based on max number of connections and the buffer size
    +        final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    +
    +        // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    +        SSLContext sslContext = null;
    +        final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +        if (sslContextService != null) {
    +            sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    +        }
    +
    +        // if we decide to support SSL then get the context and pass it in here
    +        return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events,
    +            getLogger(), maxConnections, sslContext, charSet);
    +    }
    +
    +
    +    @Override
    +    protected String getBatchKey(BeatsEvent event) {
    +        return event.getSender();
    +    }
    +
    +    protected void respond(final BeatsEvent event, final BeatsResponse beatsResponse) {
    +        final ChannelResponse response = new BeatsChannelResponse(beatsEncoder, beatsResponse);
    +
    +        final ChannelResponder responder = event.getResponder();
    +        responder.addResponse(response);
    +        try {
    +            responder.respond();
    +        } catch (IOException e) {
    +            getLogger().error("Error sending response for transaction {} due to {}",
    +                new Object[]{event.getSeqNumber(), e.getMessage()}, e);
    +        }
    +    }
    +
    +    protected void postProcess(final ProcessContext context, final ProcessSession session, final List<BeatsEvent> events) {
    +        // first commit the session so we guarantee we have all the events successfully
    +        // written to FlowFiles and transferred to the success relationship
    +        session.commit();
    +        // respond to each event to acknowledge successful receipt
    +        for (final BeatsEvent event : events) {
    +            respond(event, BeatsResponse.ok(event.getSeqNumber()));
    +        }
    +    }
    +
    +    @Override
    +    protected String getTransitUri(FlowFileEventBatch batch) {
    +        final String sender = batch.getEvents().get(0).getSender();
    +        final String senderHost = sender.startsWith("/") && sender.length() > 1 ? sender.substring(1) : sender;
    +        final String transitUri = new StringBuilder().append("beats").append("://").append(senderHost).append(":")
    +            .append(port).toString();
    +        return transitUri;
    +    }
    +
    +    @Override
    +    protected Map<String, String> getAttributes(FlowFileEventBatch batch) {
    +        final List<BeatsEvent> events = batch.getEvents();
    +        // the sender and command will be the same for all events based on the batch key
    +        final String sender = events.get(0).getSender();
    +        final int numAttributes = events.size() == 1 ? 5 : 4;
    +        final Map<String, String> attributes = new HashMap<>(numAttributes);
    +        attributes.put(beatsAttributes.SENDER.key(), sender);
    +        attributes.put(beatsAttributes.PORT.key(), String.valueOf(port));
    +        attributes.put(CoreAttributes.MIME_TYPE.key(), "application/json");
    +        // if there was only one event then we can pass on the transaction
    +        // NOTE: we could pass on all the transaction ids joined together
    --- End diff --
    
    fair enough.


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103597989
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-nar/src/main/resources/META-INF/LICENSE ---
    @@ -0,0 +1,233 @@
    +
    +                                 Apache License
    +                           Version 2.0, January 2004
    +                        http://www.apache.org/licenses/
    +
    +   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
    +
    +   1. Definitions.
    +
    +      "License" shall mean the terms and conditions for use, reproduction,
    +      and distribution as defined by Sections 1 through 9 of this document.
    +
    +      "Licensor" shall mean the copyright owner or entity authorized by
    +      the copyright owner that is granting the License.
    +
    +      "Legal Entity" shall mean the union of the acting entity and all
    +      other entities that control, are controlled by, or are under common
    +      control with that entity. For the purposes of this definition,
    +      "control" means (i) the power, direct or indirect, to cause the
    +      direction or management of such entity, whether by contract or
    +      otherwise, or (ii) ownership of fifty percent (50%) or more of the
    +      outstanding shares, or (iii) beneficial ownership of such entity.
    +
    +      "You" (or "Your") shall mean an individual or Legal Entity
    +      exercising permissions granted by this License.
    +
    +      "Source" form shall mean the preferred form for making modifications,
    +      including but not limited to software source code, documentation
    +      source, and configuration files.
    +
    +      "Object" form shall mean any form resulting from mechanical
    +      transformation or translation of a Source form, including but
    +      not limited to compiled object code, generated documentation,
    +      and conversions to other media types.
    +
    +      "Work" shall mean the work of authorship, whether in Source or
    +      Object form, made available under the License, as indicated by a
    +      copyright notice that is included in or attached to the work
    +      (an example is provided in the Appendix below).
    +
    +      "Derivative Works" shall mean any work, whether in Source or Object
    +      form, that is based on (or derived from) the Work and for which the
    +      editorial revisions, annotations, elaborations, or other modifications
    +      represent, as a whole, an original work of authorship. For the purposes
    +      of this License, Derivative Works shall not include works that remain
    +      separable from, or merely link (or bind by name) to the interfaces of,
    +      the Work and Derivative Works thereof.
    +
    +      "Contribution" shall mean any work of authorship, including
    +      the original version of the Work and any modifications or additions
    +      to that Work or Derivative Works thereof, that is intentionally
    +      submitted to Licensor for inclusion in the Work by the copyright owner
    +      or by an individual or Legal Entity authorized to submit on behalf of
    +      the copyright owner. For the purposes of this definition, "submitted"
    +      means any form of electronic, verbal, or written communication sent
    +      to the Licensor or its representatives, including but not limited to
    +      communication on electronic mailing lists, source code control systems,
    +      and issue tracking systems that are managed by, or on behalf of, the
    +      Licensor for the purpose of discussing and improving the Work, but
    +      excluding communication that is conspicuously marked or otherwise
    +      designated in writing by the copyright owner as "Not a Contribution."
    +
    +      "Contributor" shall mean Licensor and any individual or Legal Entity
    +      on behalf of whom a Contribution has been received by Licensor and
    +      subsequently incorporated within the Work.
    +
    +   2. Grant of Copyright License. Subject to the terms and conditions of
    +      this License, each Contributor hereby grants to You a perpetual,
    +      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    +      copyright license to reproduce, prepare Derivative Works of,
    +      publicly display, publicly perform, sublicense, and distribute the
    +      Work and such Derivative Works in Source or Object form.
    +
    +   3. Grant of Patent License. Subject to the terms and conditions of
    +      this License, each Contributor hereby grants to You a perpetual,
    +      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    +      (except as stated in this section) patent license to make, have made,
    +      use, offer to sell, sell, import, and otherwise transfer the Work,
    +      where such license applies only to those patent claims licensable
    +      by such Contributor that are necessarily infringed by their
    +      Contribution(s) alone or by combination of their Contribution(s)
    +      with the Work to which such Contribution(s) was submitted. If You
    +      institute patent litigation against any entity (including a
    +      cross-claim or counterclaim in a lawsuit) alleging that the Work
    +      or a Contribution incorporated within the Work constitutes direct
    +      or contributory patent infringement, then any patent licenses
    +      granted to You under this License for that Work shall terminate
    +      as of the date such litigation is filed.
    +
    +   4. Redistribution. You may reproduce and distribute copies of the
    +      Work or Derivative Works thereof in any medium, with or without
    +      modifications, and in Source or Object form, provided that You
    +      meet the following conditions:
    +
    +      (a) You must give any other recipients of the Work or
    +          Derivative Works a copy of this License; and
    +
    +      (b) You must cause any modified files to carry prominent notices
    +          stating that You changed the files; and
    +
    +      (c) You must retain, in the Source form of any Derivative Works
    +          that You distribute, all copyright, patent, trademark, and
    +          attribution notices from the Source form of the Work,
    +          excluding those notices that do not pertain to any part of
    +          the Derivative Works; and
    +
    +      (d) If the Work includes a "NOTICE" text file as part of its
    +          distribution, then any Derivative Works that You distribute must
    +          include a readable copy of the attribution notices contained
    +          within such NOTICE file, excluding those notices that do not
    +          pertain to any part of the Derivative Works, in at least one
    +          of the following places: within a NOTICE text file distributed
    +          as part of the Derivative Works; within the Source form or
    +          documentation, if provided along with the Derivative Works; or,
    +          within a display generated by the Derivative Works, if and
    +          wherever such third-party notices normally appear. The contents
    +          of the NOTICE file are for informational purposes only and
    +          do not modify the License. You may add Your own attribution
    +          notices within Derivative Works that You distribute, alongside
    +          or as an addendum to the NOTICE text from the Work, provided
    +          that such additional attribution notices cannot be construed
    +          as modifying the License.
    +
    +      You may add Your own copyright statement to Your modifications and
    +      may provide additional or different license terms and conditions
    +      for use, reproduction, or distribution of Your modifications, or
    +      for any such Derivative Works as a whole, provided Your use,
    +      reproduction, and distribution of the Work otherwise complies with
    +      the conditions stated in this License.
    +
    +   5. Submission of Contributions. Unless You explicitly state otherwise,
    +      any Contribution intentionally submitted for inclusion in the Work
    +      by You to the Licensor shall be under the terms and conditions of
    +      this License, without any additional terms or conditions.
    +      Notwithstanding the above, nothing herein shall supersede or modify
    +      the terms of any separate license agreement you may have executed
    +      with Licensor regarding such Contributions.
    +
    +   6. Trademarks. This License does not grant permission to use the trade
    +      names, trademarks, service marks, or product names of the Licensor,
    +      except as required for reasonable and customary use in describing the
    +      origin of the Work and reproducing the content of the NOTICE file.
    +
    +   7. Disclaimer of Warranty. Unless required by applicable law or
    +      agreed to in writing, Licensor provides the Work (and each
    +      Contributor provides its Contributions) on an "AS IS" BASIS,
    +      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    +      implied, including, without limitation, any warranties or conditions
    +      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
    +      PARTICULAR PURPOSE. You are solely responsible for determining the
    +      appropriateness of using or redistributing the Work and assume any
    +      risks associated with Your exercise of permissions under this License.
    +
    +   8. Limitation of Liability. In no event and under no legal theory,
    +      whether in tort (including negligence), contract, or otherwise,
    +      unless required by applicable law (such as deliberate and grossly
    +      negligent acts) or agreed to in writing, shall any Contributor be
    +      liable to You for damages, including any direct, indirect, special,
    +      incidental, or consequential damages of any character arising as a
    +      result of this License or out of the use or inability to use the
    +      Work (including but not limited to damages for loss of goodwill,
    +      work stoppage, computer failure or malfunction, or any and all
    +      other commercial damages or losses), even if such Contributor
    +      has been advised of the possibility of such damages.
    +
    +   9. Accepting Warranty or Additional Liability. While redistributing
    +      the Work or Derivative Works thereof, You may choose to offer,
    +      and charge a fee for, acceptance of support, warranty, indemnity,
    +      or other liability obligations and/or rights consistent with this
    +      License. However, in accepting such obligations, You may act only
    +      on Your own behalf and on Your sole responsibility, not on behalf
    +      of any other Contributor, and only if You agree to indemnify,
    +      defend, and hold each Contributor harmless for any liability
    +      incurred by, or claims asserted against, such Contributor by reason
    +      of your accepting any such warranty or additional liability.
    +
    +   END OF TERMS AND CONDITIONS
    +
    +   APPENDIX: How to apply the Apache License to your work.
    +
    +      To apply the Apache License to your work, attach the following
    +      boilerplate notice, with the fields enclosed by brackets "[]"
    +      replaced with your own identifying information. (Don't include
    +      the brackets!)  The text should be enclosed in the appropriate
    +      comment syntax for the file format. We also recommend that a
    +      file or class name and description of purpose be included on the
    +      same "printed page" as the copyright notice for easier
    +      identification within third-party archives.
    +
    +   Copyright [yyyy] [name of copyright owner]
    +
    +   Licensed 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.  
    +
    +APACHE NIFI SUBCOMPONENTS:
    +
    +The Apache NiFi project contains subcomponents with separate copyright
    +notices and license terms. Your use of the source code for the these
    +subcomponents is subject to the terms and conditions of the following
    +licenses. 
    +
    +  The binary distribution of this product bundles 'Bouncy Castle JDK 1.5'
    --- End diff --
    
    Please double-check [NIFI-2954](https://issues.apache.org/jira/browse/NIFI-2954) with respect to what needs to go in the L&N as well as what can be specified as "provided" by the parent NAR(s) / framework. I couldn't immediately tell if all was well so I thought I'd point it out just to be sure.


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103599319
  
    --- Diff: nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/src/main/java/org/apache/nifi/processors/lumberjack/ListenLumberjack.java ---
    @@ -62,12 +62,13 @@
     
     import com.google.gson.Gson;
     
    +@Deprecated
     @InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
     @Tags({"listen", "lumberjack", "tcp", "logs"})
    -@CapabilityDescription("Listens for Lumberjack messages being sent to a given port over TCP. Each message will be " +
    +@CapabilityDescription("This processor is deprecated and will be removed in the near future. Listens for Lumberjack messages being sent to a given port over TCP. Each message will be " +
    --- End diff --
    
    will rephrase 


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103596699
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/ListenBeats.java ---
    @@ -0,0 +1,216 @@
    +/*
    + * 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.beats;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.BlockingQueue;
    +
    +import javax.net.ssl.SSLContext;
    +
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +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.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey;
    +import org.apache.nifi.processor.DataUnit;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.util.listen.AbstractListenEventBatchingProcessor;
    +import org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.ChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.event.EventFactory;
    +import org.apache.nifi.processor.util.listen.handler.ChannelHandlerFactory;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponder;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponse;
    +import org.apache.nifi.processors.beats.event.BeatsEvent;
    +import org.apache.nifi.processors.beats.event.BeatsEventFactory;
    +import org.apache.nifi.processors.beats.frame.BeatsEncoder;
    +import org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory;
    +import org.apache.nifi.processors.beats.response.BeatsChannelResponse;
    +import org.apache.nifi.processors.beats.response.BeatsResponse;
    +import org.apache.nifi.ssl.SSLContextService;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
    +@Tags({"listen", "beats", "tcp", "logs"})
    +@CapabilityDescription("Listens for messages sent by libbeat compatible clients (e.g. filebeats, metricbeats, etc) being sent to a given port over TCP, writing its contents in" +
    +        "JSON format to the content of the message to a FlowFile." +
    +        "This processor replaces the now deprecated ListenLumberjack")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "beats.sender", description = "The sending host of the messages."),
    +    @WritesAttribute(attribute = "beats.port", description = "The sending port the messages were received over."),
    +    @WritesAttribute(attribute = "beats.sequencenumber", description = "The sequence number of the message. Only included if <Batch Size> is 1."),
    +    @WritesAttribute(attribute = "mime.type", description = "The mime.type of the content which is application/json")
    +})
    +@SeeAlso(classNames = {"org.apache.nifi.processors.standard.ParseSyslog"})
    +public class ListenBeats extends AbstractListenEventBatchingProcessor<BeatsEvent> {
    +
    +    public static final PropertyDescriptor SSL_CONTEXT_SERVICE = new PropertyDescriptor.Builder()
    +        .name("SSL Context Service")
    +        .description("The Controller Service to use in order to obtain an SSL Context. If this property is set, " +
    +            "messages will be received over a secure connection.")
    +        // Nearly all Lumberjack v1 implementations require TLS to work. v2 implementations (i.e. beats) have TLS as optional
    +        .required(false)
    +        .identifiesControllerService(SSLContextService.class)
    +        .build();
    +
    +    @Override
    +    protected List<PropertyDescriptor> getAdditionalProperties() {
    +        return Arrays.asList(
    +            MAX_CONNECTIONS,
    +            SSL_CONTEXT_SERVICE
    +        );
    +    }
    +
    +    @Override
    +    protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    +        final List<ValidationResult> results = new ArrayList<>();
    +
    +        final SSLContextService sslContextService = validationContext.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +
    +        if (sslContextService != null && sslContextService.isTrustStoreConfigured() == false) {
    +            results.add(new ValidationResult.Builder()
    +                .explanation("The context service must have a truststore  configured for the beats forwarder client to work correctly")
    +                .valid(false).subject(SSL_CONTEXT_SERVICE.getName()).build());
    +        }
    +
    +        return results;
    +    }
    +
    +    private volatile BeatsEncoder beatsEncoder;
    +
    +
    +    @Override
    +    @OnScheduled
    +    public void onScheduled(ProcessContext context) throws IOException {
    +        super.onScheduled(context);
    +        // wanted to ensure charset was already populated here
    +        beatsEncoder = new BeatsEncoder();
    +    }
    +
    +    @Override
    +    protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<BeatsEvent> events) throws IOException {
    +        final EventFactory<BeatsEvent> eventFactory = new BeatsEventFactory();
    +        final ChannelHandlerFactory<BeatsEvent, AsyncChannelDispatcher> handlerFactory = new BeatsSocketChannelHandlerFactory<>();
    +
    +        final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    +        final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    +        final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    +
    +        // initialize the buffer pool based on max number of connections and the buffer size
    +        final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    +
    +        // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    +        SSLContext sslContext = null;
    +        final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +        if (sslContextService != null) {
    +            sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    +        }
    +
    +        // if we decide to support SSL then get the context and pass it in here
    +        return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events,
    +            getLogger(), maxConnections, sslContext, charSet);
    +    }
    +
    +
    +    @Override
    +    protected String getBatchKey(BeatsEvent event) {
    +        return event.getSender();
    +    }
    +
    +    protected void respond(final BeatsEvent event, final BeatsResponse beatsResponse) {
    +        final ChannelResponse response = new BeatsChannelResponse(beatsEncoder, beatsResponse);
    +
    +        final ChannelResponder responder = event.getResponder();
    +        responder.addResponse(response);
    +        try {
    +            responder.respond();
    +        } catch (IOException e) {
    +            getLogger().error("Error sending response for transaction {} due to {}",
    +                new Object[]{event.getSeqNumber(), e.getMessage()}, e);
    +        }
    +    }
    +
    +    protected void postProcess(final ProcessContext context, final ProcessSession session, final List<BeatsEvent> events) {
    +        // first commit the session so we guarantee we have all the events successfully
    +        // written to FlowFiles and transferred to the success relationship
    +        session.commit();
    +        // respond to each event to acknowledge successful receipt
    +        for (final BeatsEvent event : events) {
    +            respond(event, BeatsResponse.ok(event.getSeqNumber()));
    +        }
    +    }
    +
    +    @Override
    +    protected String getTransitUri(FlowFileEventBatch batch) {
    +        final String sender = batch.getEvents().get(0).getSender();
    +        final String senderHost = sender.startsWith("/") && sender.length() > 1 ? sender.substring(1) : sender;
    +        final String transitUri = new StringBuilder().append("beats").append("://").append(senderHost).append(":")
    +            .append(port).toString();
    +        return transitUri;
    +    }
    +
    +    @Override
    +    protected Map<String, String> getAttributes(FlowFileEventBatch batch) {
    +        final List<BeatsEvent> events = batch.getEvents();
    +        // the sender and command will be the same for all events based on the batch key
    +        final String sender = events.get(0).getSender();
    +        final int numAttributes = events.size() == 1 ? 5 : 4;
    +        final Map<String, String> attributes = new HashMap<>(numAttributes);
    +        attributes.put(beatsAttributes.SENDER.key(), sender);
    +        attributes.put(beatsAttributes.PORT.key(), String.valueOf(port));
    +        attributes.put(CoreAttributes.MIME_TYPE.key(), "application/json");
    +        // if there was only one event then we can pass on the transaction
    +        // NOTE: we could pass on all the transaction ids joined together
    --- End diff --
    
    maybe move this comment up to the def of numAttributes, to explain why there might be an extra one


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103652588
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/frame/BeatsDecoder.java ---
    @@ -0,0 +1,330 @@
    +/*
    + * 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.beats.frame;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.zip.InflaterInputStream;
    +
    +import org.apache.nifi.stream.io.ByteArrayInputStream;
    +import org.apache.nifi.stream.io.ByteArrayOutputStream;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * Decodes a Beats frame by maintaining a state based on each byte that has been processed. This class
    + * should not be shared by multiple threads.
    + */
    +public class BeatsDecoder {
    +
    +
    +    static final Logger logger = LoggerFactory.getLogger(BeatsDecoder.class);
    +
    +    private BeatsFrame.Builder frameBuilder;
    +    private BeatsState currState = BeatsState.VERSION;
    +    private byte decodedFrameType;
    +
    +    private byte[] unprocessedData;
    +
    +    private final Charset charset;
    +    private final ByteArrayOutputStream currBytes;
    +
    +    private long windowSize;
    +
    +    static final int MIN_FRAME_HEADER_LENGTH = 2; // Version + Type
    +    static final int WINDOWSIZE_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32bit unsigned window size
    +    static final int COMPRESSED_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32 bit unsigned + payload
    +    static final int JSON_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 8; // 32 bit unsigned sequence number + 32 bit unsigned payload length
    +
    +    public static final byte FRAME_WINDOWSIZE = 0x57, FRAME_DATA = 0x44, FRAME_COMPRESSED = 0x43, FRAME_ACK = 0x41, FRAME_JSON = 0x4a;
    +
    +    /**
    +     * @param charset the charset to decode bytes from the frame
    +     */
    +    public BeatsDecoder(final Charset charset) {
    +        this(charset, new ByteArrayOutputStream(4096));
    --- End diff --
    
    correction: passing as attribute will be painful. 4096 seems to be the value of choice around NiFi. Small values also work so I would reckon except for performance, no significant issue should be cause by the default


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103597308
  
    --- Diff: nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/src/main/java/org/apache/nifi/processors/lumberjack/event/LumberjackEvent.java ---
    @@ -24,6 +24,7 @@
     /**
      * A Lumberjack event which adds the transaction number and command to the StandardEvent.
      */
    +@Deprecated
    --- End diff --
    
    For all @Deprecated tags, please provide @deprecated Javadoc for why it is being deprecated and what they should switch to


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    @mattyb149 - this isn't ready yet but I suspect it may be functional. So far I have been testing with filebeat but it should work with metricbeat as well.
    
    Of note:
    
    - the processor performs partial ACKs, more precisely it replies to EVERY sequence number with an ACK, completely ignoring the window size. This may change prior to merging.
    
    - Given ListenLumberjack has been my first attempt in coding, while migrating from ListenLumberjack to ListenBeats I tried to clean the code a bit, I think there still space for improvement.
    
    To test the processor all it is needed is to:
    
    1. Download filebeat and unzip it
    2. use the following config:
    
    ```
    filebeat.prospectors:
    - input_type: log
      paths:
        - logsource/*.log
    
    output.logstash:
      hosts: ["localhost:5044"]
      compression_level: 0
      timeout: 600
      bulk_max_size: 1
    
    ```



---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and deprecates...

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

    https://github.com/apache/nifi/pull/1418
  
    @nickcarenza thanks for the feedback


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103834515
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/ListenBeats.java ---
    @@ -0,0 +1,217 @@
    +/*
    + * 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.beats;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.BlockingQueue;
    +
    +import javax.net.ssl.SSLContext;
    +
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +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.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey;
    +import org.apache.nifi.processor.DataUnit;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.util.listen.AbstractListenEventBatchingProcessor;
    +import org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.ChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.event.EventFactory;
    +import org.apache.nifi.processor.util.listen.handler.ChannelHandlerFactory;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponder;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponse;
    +import org.apache.nifi.processors.beats.event.BeatsEvent;
    +import org.apache.nifi.processors.beats.event.BeatsEventFactory;
    +import org.apache.nifi.processors.beats.frame.BeatsEncoder;
    +import org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory;
    +import org.apache.nifi.processors.beats.response.BeatsChannelResponse;
    +import org.apache.nifi.processors.beats.response.BeatsResponse;
    +import org.apache.nifi.ssl.SSLContextService;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
    +@Tags({"listen", "beats", "tcp", "logs"})
    +@CapabilityDescription("Listens for messages sent by libbeat compatible clients (e.g. filebeats, metricbeats, etc) being sent to a given port over TCP, writing its contents in" +
    --- End diff --
    
    Can you mention here (just for completeness) that the processor wants the "logstash" type output vs the Elasticsearch output? Might be a nod to those who have forgotten to configure their beats correctly.


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103596545
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/ListenBeats.java ---
    @@ -0,0 +1,216 @@
    +/*
    + * 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.beats;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.BlockingQueue;
    +
    +import javax.net.ssl.SSLContext;
    +
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +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.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey;
    +import org.apache.nifi.processor.DataUnit;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.util.listen.AbstractListenEventBatchingProcessor;
    +import org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.ChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.event.EventFactory;
    +import org.apache.nifi.processor.util.listen.handler.ChannelHandlerFactory;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponder;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponse;
    +import org.apache.nifi.processors.beats.event.BeatsEvent;
    +import org.apache.nifi.processors.beats.event.BeatsEventFactory;
    +import org.apache.nifi.processors.beats.frame.BeatsEncoder;
    +import org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory;
    +import org.apache.nifi.processors.beats.response.BeatsChannelResponse;
    +import org.apache.nifi.processors.beats.response.BeatsResponse;
    +import org.apache.nifi.ssl.SSLContextService;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
    +@Tags({"listen", "beats", "tcp", "logs"})
    +@CapabilityDescription("Listens for messages sent by libbeat compatible clients (e.g. filebeats, metricbeats, etc) being sent to a given port over TCP, writing its contents in" +
    +        "JSON format to the content of the message to a FlowFile." +
    +        "This processor replaces the now deprecated ListenLumberjack")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "beats.sender", description = "The sending host of the messages."),
    +    @WritesAttribute(attribute = "beats.port", description = "The sending port the messages were received over."),
    +    @WritesAttribute(attribute = "beats.sequencenumber", description = "The sequence number of the message. Only included if <Batch Size> is 1."),
    +    @WritesAttribute(attribute = "mime.type", description = "The mime.type of the content which is application/json")
    +})
    +@SeeAlso(classNames = {"org.apache.nifi.processors.standard.ParseSyslog"})
    +public class ListenBeats extends AbstractListenEventBatchingProcessor<BeatsEvent> {
    --- End diff --
    
    Inheriting the RECV_BUFFER_SIZE property from the other "AbstractListenEventProcessor" properties might be a little confusing here as it is not a "round" number like a power of 2. @bbende any thoughts 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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

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


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103650361
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/frame/BeatsDecoder.java ---
    @@ -0,0 +1,330 @@
    +/*
    + * 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.beats.frame;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.zip.InflaterInputStream;
    +
    +import org.apache.nifi.stream.io.ByteArrayInputStream;
    +import org.apache.nifi.stream.io.ByteArrayOutputStream;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * Decodes a Beats frame by maintaining a state based on each byte that has been processed. This class
    + * should not be shared by multiple threads.
    + */
    +public class BeatsDecoder {
    +
    +
    +    static final Logger logger = LoggerFactory.getLogger(BeatsDecoder.class);
    --- 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.
---

[GitHub] nifi pull request #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103645596
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-nar/src/main/resources/META-INF/LICENSE ---
    @@ -0,0 +1,233 @@
    +
    +                                 Apache License
    +                           Version 2.0, January 2004
    +                        http://www.apache.org/licenses/
    +
    +   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
    +
    +   1. Definitions.
    +
    +      "License" shall mean the terms and conditions for use, reproduction,
    +      and distribution as defined by Sections 1 through 9 of this document.
    +
    +      "Licensor" shall mean the copyright owner or entity authorized by
    +      the copyright owner that is granting the License.
    +
    +      "Legal Entity" shall mean the union of the acting entity and all
    +      other entities that control, are controlled by, or are under common
    +      control with that entity. For the purposes of this definition,
    +      "control" means (i) the power, direct or indirect, to cause the
    +      direction or management of such entity, whether by contract or
    +      otherwise, or (ii) ownership of fifty percent (50%) or more of the
    +      outstanding shares, or (iii) beneficial ownership of such entity.
    +
    +      "You" (or "Your") shall mean an individual or Legal Entity
    +      exercising permissions granted by this License.
    +
    +      "Source" form shall mean the preferred form for making modifications,
    +      including but not limited to software source code, documentation
    +      source, and configuration files.
    +
    +      "Object" form shall mean any form resulting from mechanical
    +      transformation or translation of a Source form, including but
    +      not limited to compiled object code, generated documentation,
    +      and conversions to other media types.
    +
    +      "Work" shall mean the work of authorship, whether in Source or
    +      Object form, made available under the License, as indicated by a
    +      copyright notice that is included in or attached to the work
    +      (an example is provided in the Appendix below).
    +
    +      "Derivative Works" shall mean any work, whether in Source or Object
    +      form, that is based on (or derived from) the Work and for which the
    +      editorial revisions, annotations, elaborations, or other modifications
    +      represent, as a whole, an original work of authorship. For the purposes
    +      of this License, Derivative Works shall not include works that remain
    +      separable from, or merely link (or bind by name) to the interfaces of,
    +      the Work and Derivative Works thereof.
    +
    +      "Contribution" shall mean any work of authorship, including
    +      the original version of the Work and any modifications or additions
    +      to that Work or Derivative Works thereof, that is intentionally
    +      submitted to Licensor for inclusion in the Work by the copyright owner
    +      or by an individual or Legal Entity authorized to submit on behalf of
    +      the copyright owner. For the purposes of this definition, "submitted"
    +      means any form of electronic, verbal, or written communication sent
    +      to the Licensor or its representatives, including but not limited to
    +      communication on electronic mailing lists, source code control systems,
    +      and issue tracking systems that are managed by, or on behalf of, the
    +      Licensor for the purpose of discussing and improving the Work, but
    +      excluding communication that is conspicuously marked or otherwise
    +      designated in writing by the copyright owner as "Not a Contribution."
    +
    +      "Contributor" shall mean Licensor and any individual or Legal Entity
    +      on behalf of whom a Contribution has been received by Licensor and
    +      subsequently incorporated within the Work.
    +
    +   2. Grant of Copyright License. Subject to the terms and conditions of
    +      this License, each Contributor hereby grants to You a perpetual,
    +      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    +      copyright license to reproduce, prepare Derivative Works of,
    +      publicly display, publicly perform, sublicense, and distribute the
    +      Work and such Derivative Works in Source or Object form.
    +
    +   3. Grant of Patent License. Subject to the terms and conditions of
    +      this License, each Contributor hereby grants to You a perpetual,
    +      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
    +      (except as stated in this section) patent license to make, have made,
    +      use, offer to sell, sell, import, and otherwise transfer the Work,
    +      where such license applies only to those patent claims licensable
    +      by such Contributor that are necessarily infringed by their
    +      Contribution(s) alone or by combination of their Contribution(s)
    +      with the Work to which such Contribution(s) was submitted. If You
    +      institute patent litigation against any entity (including a
    +      cross-claim or counterclaim in a lawsuit) alleging that the Work
    +      or a Contribution incorporated within the Work constitutes direct
    +      or contributory patent infringement, then any patent licenses
    +      granted to You under this License for that Work shall terminate
    +      as of the date such litigation is filed.
    +
    +   4. Redistribution. You may reproduce and distribute copies of the
    +      Work or Derivative Works thereof in any medium, with or without
    +      modifications, and in Source or Object form, provided that You
    +      meet the following conditions:
    +
    +      (a) You must give any other recipients of the Work or
    +          Derivative Works a copy of this License; and
    +
    +      (b) You must cause any modified files to carry prominent notices
    +          stating that You changed the files; and
    +
    +      (c) You must retain, in the Source form of any Derivative Works
    +          that You distribute, all copyright, patent, trademark, and
    +          attribution notices from the Source form of the Work,
    +          excluding those notices that do not pertain to any part of
    +          the Derivative Works; and
    +
    +      (d) If the Work includes a "NOTICE" text file as part of its
    +          distribution, then any Derivative Works that You distribute must
    +          include a readable copy of the attribution notices contained
    +          within such NOTICE file, excluding those notices that do not
    +          pertain to any part of the Derivative Works, in at least one
    +          of the following places: within a NOTICE text file distributed
    +          as part of the Derivative Works; within the Source form or
    +          documentation, if provided along with the Derivative Works; or,
    +          within a display generated by the Derivative Works, if and
    +          wherever such third-party notices normally appear. The contents
    +          of the NOTICE file are for informational purposes only and
    +          do not modify the License. You may add Your own attribution
    +          notices within Derivative Works that You distribute, alongside
    +          or as an addendum to the NOTICE text from the Work, provided
    +          that such additional attribution notices cannot be construed
    +          as modifying the License.
    +
    +      You may add Your own copyright statement to Your modifications and
    +      may provide additional or different license terms and conditions
    +      for use, reproduction, or distribution of Your modifications, or
    +      for any such Derivative Works as a whole, provided Your use,
    +      reproduction, and distribution of the Work otherwise complies with
    +      the conditions stated in this License.
    +
    +   5. Submission of Contributions. Unless You explicitly state otherwise,
    +      any Contribution intentionally submitted for inclusion in the Work
    +      by You to the Licensor shall be under the terms and conditions of
    +      this License, without any additional terms or conditions.
    +      Notwithstanding the above, nothing herein shall supersede or modify
    +      the terms of any separate license agreement you may have executed
    +      with Licensor regarding such Contributions.
    +
    +   6. Trademarks. This License does not grant permission to use the trade
    +      names, trademarks, service marks, or product names of the Licensor,
    +      except as required for reasonable and customary use in describing the
    +      origin of the Work and reproducing the content of the NOTICE file.
    +
    +   7. Disclaimer of Warranty. Unless required by applicable law or
    +      agreed to in writing, Licensor provides the Work (and each
    +      Contributor provides its Contributions) on an "AS IS" BASIS,
    +      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    +      implied, including, without limitation, any warranties or conditions
    +      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
    +      PARTICULAR PURPOSE. You are solely responsible for determining the
    +      appropriateness of using or redistributing the Work and assume any
    +      risks associated with Your exercise of permissions under this License.
    +
    +   8. Limitation of Liability. In no event and under no legal theory,
    +      whether in tort (including negligence), contract, or otherwise,
    +      unless required by applicable law (such as deliberate and grossly
    +      negligent acts) or agreed to in writing, shall any Contributor be
    +      liable to You for damages, including any direct, indirect, special,
    +      incidental, or consequential damages of any character arising as a
    +      result of this License or out of the use or inability to use the
    +      Work (including but not limited to damages for loss of goodwill,
    +      work stoppage, computer failure or malfunction, or any and all
    +      other commercial damages or losses), even if such Contributor
    +      has been advised of the possibility of such damages.
    +
    +   9. Accepting Warranty or Additional Liability. While redistributing
    +      the Work or Derivative Works thereof, You may choose to offer,
    +      and charge a fee for, acceptance of support, warranty, indemnity,
    +      or other liability obligations and/or rights consistent with this
    +      License. However, in accepting such obligations, You may act only
    +      on Your own behalf and on Your sole responsibility, not on behalf
    +      of any other Contributor, and only if You agree to indemnify,
    +      defend, and hold each Contributor harmless for any liability
    +      incurred by, or claims asserted against, such Contributor by reason
    +      of your accepting any such warranty or additional liability.
    +
    +   END OF TERMS AND CONDITIONS
    +
    +   APPENDIX: How to apply the Apache License to your work.
    +
    +      To apply the Apache License to your work, attach the following
    +      boilerplate notice, with the fields enclosed by brackets "[]"
    +      replaced with your own identifying information. (Don't include
    +      the brackets!)  The text should be enclosed in the appropriate
    +      comment syntax for the file format. We also recommend that a
    +      file or class name and description of purpose be included on the
    +      same "printed page" as the copyright notice for easier
    +      identification within third-party archives.
    +
    +   Copyright [yyyy] [name of copyright owner]
    +
    +   Licensed 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.  
    +
    +APACHE NIFI SUBCOMPONENTS:
    +
    +The Apache NiFi project contains subcomponents with separate copyright
    +notices and license terms. Your use of the source code for the these
    +subcomponents is subject to the terms and conditions of the following
    +licenses. 
    +
    +  The binary distribution of this product bundles 'Bouncy Castle JDK 1.5'
    --- End diff --
    
    Ok. Double checked, the LICENSE file follows the same line added by Joe as part of NIFI-2954, so I reckon it is ok as it is.


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103647459
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml ---
    @@ -0,0 +1,76 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<!--
    +  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.
    +-->
    +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <parent>
    +        <groupId>org.apache.nifi</groupId>
    +        <artifactId>nifi-beats-bundle</artifactId>
    +        <version>1.2.0-SNAPSHOT</version>
    +    </parent>
    +
    +    <artifactId>nifi-beats-processors</artifactId>
    +    <packaging>jar</packaging>
    +
    +    <dependencies>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-api</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-processor-utils</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-mock</artifactId>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-socket-utils</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-utils</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-flowfile-packager</artifactId>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.nifi</groupId>
    +            <artifactId>nifi-ssl-context-service-api</artifactId>
    +            <scope>provided</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.slf4j</groupId>
    +            <artifactId>slf4j-simple</artifactId>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>junit</groupId>
    +            <artifactId>junit</artifactId>
    +            <version>4.11</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>com.google.code.gson</groupId>
    --- 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.
---

[GitHub] nifi pull request #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103595420
  
    --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/ListenBeats.java ---
    @@ -0,0 +1,216 @@
    +/*
    + * 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.beats;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.nio.charset.Charset;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.BlockingQueue;
    +
    +import javax.net.ssl.SSLContext;
    +
    +import org.apache.nifi.annotation.behavior.InputRequirement;
    +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.SeeAlso;
    +import org.apache.nifi.annotation.documentation.Tags;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey;
    +import org.apache.nifi.processor.DataUnit;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.util.listen.AbstractListenEventBatchingProcessor;
    +import org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.ChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher;
    +import org.apache.nifi.processor.util.listen.event.EventFactory;
    +import org.apache.nifi.processor.util.listen.handler.ChannelHandlerFactory;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponder;
    +import org.apache.nifi.processor.util.listen.response.ChannelResponse;
    +import org.apache.nifi.processors.beats.event.BeatsEvent;
    +import org.apache.nifi.processors.beats.event.BeatsEventFactory;
    +import org.apache.nifi.processors.beats.frame.BeatsEncoder;
    +import org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory;
    +import org.apache.nifi.processors.beats.response.BeatsChannelResponse;
    +import org.apache.nifi.processors.beats.response.BeatsResponse;
    +import org.apache.nifi.ssl.SSLContextService;
    +
    +@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
    +@Tags({"listen", "beats", "tcp", "logs"})
    +@CapabilityDescription("Listens for messages sent by libbeat compatible clients (e.g. filebeats, metricbeats, etc) being sent to a given port over TCP, writing its contents in" +
    +        "JSON format to the content of the message to a FlowFile." +
    +        "This processor replaces the now deprecated ListenLumberjack")
    +@WritesAttributes({
    +    @WritesAttribute(attribute = "beats.sender", description = "The sending host of the messages."),
    +    @WritesAttribute(attribute = "beats.port", description = "The sending port the messages were received over."),
    +    @WritesAttribute(attribute = "beats.sequencenumber", description = "The sequence number of the message. Only included if <Batch Size> is 1."),
    +    @WritesAttribute(attribute = "mime.type", description = "The mime.type of the content which is application/json")
    +})
    +@SeeAlso(classNames = {"org.apache.nifi.processors.standard.ParseSyslog"})
    +public class ListenBeats extends AbstractListenEventBatchingProcessor<BeatsEvent> {
    +
    +    public static final PropertyDescriptor SSL_CONTEXT_SERVICE = new PropertyDescriptor.Builder()
    +        .name("SSL Context Service")
    +        .description("The Controller Service to use in order to obtain an SSL Context. If this property is set, " +
    +            "messages will be received over a secure connection.")
    +        // Nearly all Lumberjack v1 implementations require TLS to work. v2 implementations (i.e. beats) have TLS as optional
    +        .required(false)
    +        .identifiesControllerService(SSLContextService.class)
    +        .build();
    +
    +    @Override
    +    protected List<PropertyDescriptor> getAdditionalProperties() {
    +        return Arrays.asList(
    +            MAX_CONNECTIONS,
    +            SSL_CONTEXT_SERVICE
    +        );
    +    }
    +
    +    @Override
    +    protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    +        final List<ValidationResult> results = new ArrayList<>();
    +
    +        final SSLContextService sslContextService = validationContext.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +
    +        if (sslContextService != null && sslContextService.isTrustStoreConfigured() == false) {
    +            results.add(new ValidationResult.Builder()
    +                .explanation("The context service must have a truststore  configured for the beats forwarder client to work correctly")
    +                .valid(false).subject(SSL_CONTEXT_SERVICE.getName()).build());
    +        }
    +
    +        return results;
    +    }
    +
    +    private volatile BeatsEncoder beatsEncoder;
    +
    +
    +    @Override
    +    @OnScheduled
    +    public void onScheduled(ProcessContext context) throws IOException {
    +        super.onScheduled(context);
    +        // wanted to ensure charset was already populated here
    +        beatsEncoder = new BeatsEncoder();
    +    }
    +
    +    @Override
    +    protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<BeatsEvent> events) throws IOException {
    +        final EventFactory<BeatsEvent> eventFactory = new BeatsEventFactory();
    +        final ChannelHandlerFactory<BeatsEvent, AsyncChannelDispatcher> handlerFactory = new BeatsSocketChannelHandlerFactory<>();
    +
    +        final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    +        final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    +        final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    +
    +        // initialize the buffer pool based on max number of connections and the buffer size
    +        final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    +
    +        // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    +        SSLContext sslContext = null;
    +        final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    +        if (sslContextService != null) {
    +            sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    +        }
    +
    +        // if we decide to support SSL then get the context and pass it in here
    +        return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events,
    +            getLogger(), maxConnections, sslContext, charSet);
    +    }
    +
    +
    +    @Override
    +    protected String getBatchKey(BeatsEvent event) {
    +        return event.getSender();
    +    }
    +
    +    protected void respond(final BeatsEvent event, final BeatsResponse beatsResponse) {
    +        final ChannelResponse response = new BeatsChannelResponse(beatsEncoder, beatsResponse);
    +
    +        final ChannelResponder responder = event.getResponder();
    +        responder.addResponse(response);
    +        try {
    +            responder.respond();
    +        } catch (IOException e) {
    +            getLogger().error("Error sending response for transaction {} due to {}",
    +                new Object[]{event.getSeqNumber(), e.getMessage()}, e);
    +        }
    +    }
    +
    +    protected void postProcess(final ProcessContext context, final ProcessSession session, final List<BeatsEvent> events) {
    +        // first commit the session so we guarantee we have all the events successfully
    +        // written to FlowFiles and transferred to the success relationship
    +        session.commit();
    +        // respond to each event to acknowledge successful receipt
    +        for (final BeatsEvent event : events) {
    +            respond(event, BeatsResponse.ok(event.getSeqNumber()));
    +        }
    +    }
    +
    +    @Override
    +    protected String getTransitUri(FlowFileEventBatch batch) {
    +        final String sender = batch.getEvents().get(0).getSender();
    --- End diff --
    
    Any chance this can return null?


---
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 #1418: NIFI-3238 - Introduce ListenBeats processor and dep...

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

    https://github.com/apache/nifi/pull/1418#discussion_r103648209
  
    --- Diff: nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/src/main/java/org/apache/nifi/processors/lumberjack/event/LumberjackEvent.java ---
    @@ -24,6 +24,7 @@
     /**
      * A Lumberjack event which adds the transaction number and command to the StandardEvent.
      */
    +@Deprecated
    --- End diff --
    
    hopefully addressed


---
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.
---