This is an automated email from the ASF dual-hosted git repository.

ppkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-flume-rpc.git


The following commit(s) were added to refs/heads/main by this push:
     new c309af3  Adapt RPC modules to modularized Flume and updated 
dependencies (#1)
c309af3 is described below

commit c309af338eb8b624a2538378c8c0d9bdeede44e3
Author: Ralph Goers <[email protected]>
AuthorDate: Fri Jun 26 08:29:36 2026 -0700

    Adapt RPC modules to modularized Flume and updated dependencies (#1)
    
    Align the Avro and Thrift RPC modules with the newer Flume module layout 
and dependency stack used on the spring-boot4 line.
    
    * Migrate from commons-lang to commons-lang3 (StringUtils, SystemUtils, 
MutableLong) in NettyAvroRpcClient and the spooling file reader test.
    * Vendor a local PatternRule under org.apache.flume.rpc.avro.netty.filter, 
since Netty 4 no longer provides the Netty 3 pattern-based IP filter rule, and 
point AvroSource at it.
    * Update SyslogUtils imports to org.apache.flume.source.syslog and add 
flume-syslog-source as a test dependency.
    * Switch the test logging bridge from log4j-slf4j-impl to log4j-slf4j2-impl.
    * Correct dependency scopes (test scope for log4j-jcl and junit), comment 
out the unused dropwizard metrics-core dependency, and drop the test-only 
log4j-1.2-api from flume-embedded-agent.
    * Trim TestDefaultSourceFactory (Avro and Thrift) to the sources still 
available, removing syslog, HTTP, netcat-udp and spooldir cases.
---
 flume-embedded-agent/pom.xml                       |   7 -
 flume-rpc-avro/pom.xml                             |  11 +-
 .../flume/rpc/avro/client/NettyAvroRpcClient.java  |   2 +-
 .../flume/rpc/avro/netty/filter/PatternRule.java   | 160 +++++++++++++++++++++
 .../apache/flume/rpc/avro/source/AvroSource.java   |   2 +-
 .../serialization/SyslogAvroEventSerializer.java   |   2 +-
 .../TestReliableSpoolingFileEventReader.java       |   4 +-
 .../TestSyslogAvroEventSerializer.java             |   2 +-
 .../rpc/avro/source/TestDefaultSourceFactory.java  |  11 --
 .../thrift/source/TestDefaultSourceFactory.java    |  10 --
 10 files changed, 176 insertions(+), 35 deletions(-)

diff --git a/flume-embedded-agent/pom.xml b/flume-embedded-agent/pom.xml
index ce9bbe2..0ab5674 100644
--- a/flume-embedded-agent/pom.xml
+++ b/flume-embedded-agent/pom.xml
@@ -81,13 +81,6 @@
       <optional>true</optional>
     </dependency>
 
-    <dependency>
-      <groupId>org.apache.logging.log4j</groupId>
-      <artifactId>log4j-1.2-api</artifactId>
-      <!-- only used for tests -->
-      <optional>true</optional>
-    </dependency>
-
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
diff --git a/flume-rpc-avro/pom.xml b/flume-rpc-avro/pom.xml
index 769e4a5..3dfdfb9 100644
--- a/flume-rpc-avro/pom.xml
+++ b/flume-rpc-avro/pom.xml
@@ -72,11 +72,18 @@
       <artifactId>flume-ng-node</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.flume.flume-ng-sources</groupId>
+      <artifactId>flume-syslog-source</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <!--
     <dependency>
       <groupId>io.dropwizard.metrics</groupId>
       <artifactId>metrics-core</artifactId>
       <version>${dropwizard-metrics.version}</version>
     </dependency>
+    -->
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-api</artifactId>
@@ -90,13 +97,14 @@
 
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>
-      <artifactId>log4j-slf4j-impl</artifactId>
+      <artifactId>log4j-slf4j2-impl</artifactId>
       <scope>test</scope>
     </dependency>
 
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-jcl</artifactId>
+      <scope>test</scope>
     </dependency>
 
     <dependency>
@@ -117,6 +125,7 @@
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>${junit.version}</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
diff --git 
a/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/client/NettyAvroRpcClient.java
 
b/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/client/NettyAvroRpcClient.java
index 798c89a..d83a876 100644
--- 
a/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/client/NettyAvroRpcClient.java
+++ 
b/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/client/NettyAvroRpcClient.java
@@ -58,7 +58,7 @@ import org.apache.avro.ipc.CallFuture;
 import org.apache.avro.ipc.Transceiver;
 import org.apache.avro.ipc.netty.NettyTransceiver;
 import org.apache.avro.ipc.specific.SpecificRequestor;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.flume.Event;
 import org.apache.flume.EventDeliveryException;
 import org.apache.flume.FlumeException;
diff --git 
a/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/netty/filter/PatternRule.java
 
b/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/netty/filter/PatternRule.java
new file mode 100644
index 0000000..34922a9
--- /dev/null
+++ 
b/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/netty/filter/PatternRule.java
@@ -0,0 +1,160 @@
+/*
+ * 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.flume.rpc.avro.netty.filter;
+
+import io.netty.handler.ipfilter.IpFilterRule;
+import io.netty.handler.ipfilter.IpFilterRuleType;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class PatternRule represents an IP filter rule using string patterns.
+ * <br>
+ * Rule Syntax:
+ * <br>
+ * <pre>
+ * Rule ::= [n|i]:address          n stands for computer name, i for ip address
+ * address ::= &lt;regex&gt; | localhost
+ * regex is a regular expression with '*' as multi character and '?' as single 
character wild card
+ * </pre>
+ * <br>
+ * Example: allow localhost:
+ * <br>
+ * new PatternRule(true, "n:localhost")
+ * <br>
+ * Example: allow local lan:
+ * <br>
+ * new PatternRule(true, "i:192.168.0.*")
+ * <br>
+ * Example: block all
+ * <br>
+ * new PatternRule(false, "n:*")
+ * <br>
+ * <p>
+ * For some reason Netty 4 didn't copy this from Netty 3. The code was copied 
from the Netty 3 PatternRule
+ * and modifed as required to match the new version of IpFilterRule.
+ */
+public class PatternRule implements IpFilterRule {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(PatternRule.class);
+    private static final String LOCALHOST = "127.0.0.1";
+    private final IpFilterRuleType ruleType;
+    private Pattern ipPattern;
+    private Pattern namePattern;
+    private boolean localhost;
+
+    /**
+     * Construct the IpFilterRule from a pattern.
+     *
+     * @param ruleType The RuleType (accept or deny)
+     * @param pattern  The pattern.
+     */
+    public PatternRule(IpFilterRuleType ruleType, String pattern) {
+        this.ruleType = ruleType;
+        parse(pattern);
+    }
+
+    private static String addRule(String pattern, String rule) {
+        if (rule == null || rule.length() == 0) {
+            return pattern;
+        }
+        if (pattern.length() != 0) {
+            pattern += "|";
+        }
+        rule = rule.replaceAll("\\.", "\\\\.");
+        rule = rule.replaceAll("\\*", ".*");
+        rule = rule.replaceAll("\\?", ".");
+        pattern += '(' + rule + ')';
+        return pattern;
+    }
+
+    private static boolean isLocalhost(InetAddress address) {
+        try {
+            if (address.equals(InetAddress.getLocalHost())) {
+                return true;
+            }
+        } catch (UnknownHostException e) {
+            if (logger.isInfoEnabled()) {
+                logger.info("error getting ip of localhost", e);
+            }
+        }
+        try {
+            InetAddress[] addrs = InetAddress.getAllByName(LOCALHOST);
+            for (InetAddress addr : addrs) {
+                if (addr.equals(address)) {
+                    return true;
+                }
+            }
+        } catch (UnknownHostException e) {
+            if (logger.isInfoEnabled()) {
+                logger.info("error getting ip of localhost", e);
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean matches(InetSocketAddress inetSocketAddress) {
+        InetAddress inetAddress = inetSocketAddress.getAddress();
+        if (localhost && isLocalhost(inetAddress)) {
+            return true;
+        }
+        if (ipPattern != null && 
ipPattern.matcher(inetAddress.getHostAddress()).matches()) {
+            return true;
+        }
+        if (namePattern != null) {
+            return namePattern.matcher(inetAddress.getHostName()).matches();
+        }
+        return false;
+    }
+
+    @Override
+    public IpFilterRuleType ruleType() {
+        return ruleType;
+    }
+
+    private void parse(String pattern) {
+        if (pattern == null) {
+            return;
+        }
+
+        String[] acls = pattern.split(",");
+
+        String ip = "";
+        String name = "";
+        for (String c : acls) {
+            c = c.trim();
+            if ("n:localhost".equals(c)) {
+                localhost = true;
+            } else if (c.startsWith("n:")) {
+                name = addRule(name, c.substring(2));
+            } else if (c.startsWith("i:")) {
+                ip = addRule(ip, c.substring(2));
+            }
+        }
+        if (ip.length() != 0) {
+            ipPattern = Pattern.compile(ip);
+        }
+        if (name.length() != 0) {
+            namePattern = Pattern.compile(name);
+        }
+    }
+}
diff --git 
a/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/source/AvroSource.java 
b/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/source/AvroSource.java
index a46411c..a909224 100644
--- 
a/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/source/AvroSource.java
+++ 
b/flume-rpc-avro/src/main/java/org/apache/flume/rpc/avro/source/AvroSource.java
@@ -50,7 +50,7 @@ import org.apache.flume.conf.LogPrivacyUtil;
 import org.apache.flume.event.EventBuilder;
 import org.apache.flume.exception.ChannelException;
 import org.apache.flume.instrumentation.SourceCounter;
-import org.apache.flume.netty.filter.PatternRule;
+import org.apache.flume.rpc.avro.netty.filter.PatternRule;
 import org.apache.flume.source.SslContextAwareAbstractSource;
 import org.apache.flume.source.avro.AvroFlumeEvent;
 import org.apache.flume.source.avro.AvroSourceProtocol;
diff --git 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/SyslogAvroEventSerializer.java
 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/SyslogAvroEventSerializer.java
index 6955561..02f1ed6 100644
--- 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/SyslogAvroEventSerializer.java
+++ 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/SyslogAvroEventSerializer.java
@@ -31,7 +31,7 @@ import org.apache.flume.Event;
 import org.apache.flume.conf.LogPrivacyUtil;
 import 
org.apache.flume.rpc.avro.serialization.SyslogAvroEventSerializer.SyslogEvent;
 import org.apache.flume.serialization.EventSerializer;
-import org.apache.flume.source.SyslogUtils;
+import org.apache.flume.source.syslog.SyslogUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
diff --git 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestReliableSpoolingFileEventReader.java
 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestReliableSpoolingFileEventReader.java
index ba999b7..153d787 100644
--- 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestReliableSpoolingFileEventReader.java
+++ 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestReliableSpoolingFileEventReader.java
@@ -41,8 +41,8 @@ import java.util.concurrent.Future;
 import java.util.concurrent.Semaphore;
 import junit.framework.Assert;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.SystemUtils;
-import org.apache.commons.lang.mutable.MutableLong;
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.commons.lang3.mutable.MutableLong;
 import org.apache.flume.Event;
 import org.apache.flume.FlumeException;
 import org.apache.flume.event.ReliableEventReader;
diff --git 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestSyslogAvroEventSerializer.java
 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestSyslogAvroEventSerializer.java
index d7b4d84..d5bc34a 100644
--- 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestSyslogAvroEventSerializer.java
+++ 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/serialization/TestSyslogAvroEventSerializer.java
@@ -35,7 +35,7 @@ import org.apache.flume.Event;
 import org.apache.flume.event.EventBuilder;
 import org.apache.flume.serialization.EventSerializer;
 import org.apache.flume.serialization.EventSerializerFactory;
-import org.apache.flume.source.SyslogUtils;
+import org.apache.flume.source.syslog.SyslogUtils;
 import org.junit.Assert;
 import org.junit.Assume;
 import org.junit.Test;
diff --git 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/source/TestDefaultSourceFactory.java
 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/source/TestDefaultSourceFactory.java
index 3dada90..62f4bea 100644
--- 
a/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/source/TestDefaultSourceFactory.java
+++ 
b/flume-rpc-avro/src/test/java/org/apache/flume/rpc/avro/source/TestDefaultSourceFactory.java
@@ -20,13 +20,8 @@ import org.apache.flume.Source;
 import org.apache.flume.SourceFactory;
 import org.apache.flume.source.DefaultSourceFactory;
 import org.apache.flume.source.ExecSource;
-import org.apache.flume.source.MultiportSyslogTCPSource;
 import org.apache.flume.source.NetcatSource;
-import org.apache.flume.source.NetcatUdpSource;
 import org.apache.flume.source.SequenceGeneratorSource;
-import org.apache.flume.source.SyslogTcpSource;
-import org.apache.flume.source.SyslogUDPSource;
-import org.apache.flume.source.http.HTTPSource;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -69,14 +64,8 @@ public class TestDefaultSourceFactory {
     public void testSourceCreation() throws Exception {
         verifySourceCreation("seq-src", "seq", SequenceGeneratorSource.class);
         verifySourceCreation("netcat-src", "netcat", NetcatSource.class);
-        verifySourceCreation("netcat-udp-src", "netcatudp", 
NetcatUdpSource.class);
         verifySourceCreation("exec-src", "exec", ExecSource.class);
         verifySourceCreation("avro-src", "avro", AvroSource.class);
-        verifySourceCreation("syslogtcp-src", "syslogtcp", 
SyslogTcpSource.class);
-        verifySourceCreation("multiport_syslogtcp-src", "multiport_syslogtcp", 
MultiportSyslogTCPSource.class);
-        verifySourceCreation("syslogudp-src", "syslogudp", 
SyslogUDPSource.class);
-        verifySourceCreation("spooldir-src", "spooldir", 
SpoolDirectorySource.class);
-        verifySourceCreation("http-src", "http", HTTPSource.class);
         verifySourceCreation("custom-src", 
MockSource.class.getCanonicalName(), MockSource.class);
     }
 }
diff --git 
a/flume-rpc-thrift/src/test/java/org/apache/flume/rpc/thrift/source/TestDefaultSourceFactory.java
 
b/flume-rpc-thrift/src/test/java/org/apache/flume/rpc/thrift/source/TestDefaultSourceFactory.java
index c6bd258..a809ec4 100644
--- 
a/flume-rpc-thrift/src/test/java/org/apache/flume/rpc/thrift/source/TestDefaultSourceFactory.java
+++ 
b/flume-rpc-thrift/src/test/java/org/apache/flume/rpc/thrift/source/TestDefaultSourceFactory.java
@@ -20,13 +20,8 @@ import org.apache.flume.Source;
 import org.apache.flume.SourceFactory;
 import org.apache.flume.source.DefaultSourceFactory;
 import org.apache.flume.source.ExecSource;
-import org.apache.flume.source.MultiportSyslogTCPSource;
 import org.apache.flume.source.NetcatSource;
-import org.apache.flume.source.NetcatUdpSource;
 import org.apache.flume.source.SequenceGeneratorSource;
-import org.apache.flume.source.SyslogTcpSource;
-import org.apache.flume.source.SyslogUDPSource;
-import org.apache.flume.source.http.HTTPSource;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -69,12 +64,7 @@ public class TestDefaultSourceFactory {
     public void testSourceCreation() throws Exception {
         verifySourceCreation("seq-src", "seq", SequenceGeneratorSource.class);
         verifySourceCreation("netcat-src", "netcat", NetcatSource.class);
-        verifySourceCreation("netcat-udp-src", "netcatudp", 
NetcatUdpSource.class);
         verifySourceCreation("exec-src", "exec", ExecSource.class);
-        verifySourceCreation("syslogtcp-src", "syslogtcp", 
SyslogTcpSource.class);
-        verifySourceCreation("multiport_syslogtcp-src", "multiport_syslogtcp", 
MultiportSyslogTCPSource.class);
-        verifySourceCreation("syslogudp-src", "syslogudp", 
SyslogUDPSource.class);
-        verifySourceCreation("http-src", "http", HTTPSource.class);
         verifySourceCreation("thrift-src", "thrift", ThriftSource.class);
         verifySourceCreation("custom-src", 
MockSource.class.getCanonicalName(), MockSource.class);
     }

Reply via email to