diff --git a/flume-bom/pom.xml b/flume-bom/pom.xml index 774b2cab9b..97cf0ad7c2 100644 --- a/flume-bom/pom.xml +++ b/flume-bom/pom.xml @@ -217,6 +217,16 @@ flume-taildir-source ${flume-taildir.version} + + org.apache.flume.flume-ng-sources + flume-syslog-source + ${project.version} + + + org.apache.flume.flume-ng-sources + flume-netcat-source + ${project.version} + org.apache.flume flume-shared-kafka diff --git a/flume-ng-configuration/src/main/java/org/apache/flume/conf/source/SourceType.java b/flume-ng-configuration/src/main/java/org/apache/flume/conf/source/SourceType.java index f26bb59467..5792d8dcea 100644 --- a/flume-ng-configuration/src/main/java/org/apache/flume/conf/source/SourceType.java +++ b/flume-ng-configuration/src/main/java/org/apache/flume/conf/source/SourceType.java @@ -61,21 +61,21 @@ public enum SourceType implements ComponentWithClassName { * * @see org.apache.flume.source.SyslogTcpSource */ - SYSLOGTCP("org.apache.flume.source.SyslogTcpSource"), + SYSLOGTCP("org.apache.flume.source.syslog.SyslogTcpSource"), /** * MultiportSyslogTCPSource * * @see org.apache.flume.source.MultiportSyslogTCPSource */ - MULTIPORT_SYSLOGTCP("org.apache.flume.source.MultiportSyslogTCPSource"), + MULTIPORT_SYSLOGTCP("org.apache.flume.source.syslog.MultiportSyslogTCPSource"), /** * SyslogUDPSource * * @see org.apache.flume.source.SyslogUDPSource */ - SYSLOGUDP("org.apache.flume.source.SyslogUDPSource"), + SYSLOGUDP("org.apache.flume.source.syslog.SyslogUDPSource"), /** * Spool directory source @@ -117,7 +117,7 @@ public enum SourceType implements ComponentWithClassName { * * @see org.apache.flume.source.NetcatUdpSource */ - NETCATUDP("org.apache.flume.source.NetcatUdpSource"); + NETCATUDP("org.apache.flume.source.netcat.NetcatUdpSource"); private final String sourceClassName; diff --git a/flume-ng-core/pom.xml b/flume-ng-core/pom.xml index b33f5c71c5..33d269607c 100644 --- a/flume-ng-core/pom.xml +++ b/flume-ng-core/pom.xml @@ -32,8 +32,8 @@ - 199 - 121 + 152 + 64 org.apache.flume.core @@ -133,11 +133,6 @@ commons-lang - - io.netty - netty-all - - org.apache.httpcomponents httpclient @@ -156,11 +151,6 @@ test - - org.apache.mina - mina-core - - diff --git a/flume-ng-core/src/main/java/org/apache/flume/netty/filter/PatternRule.java b/flume-ng-core/src/main/java/org/apache/flume/netty/filter/PatternRule.java deleted file mode 100644 index 31cc2b67cd..0000000000 --- a/flume-ng-core/src/main/java/org/apache/flume/netty/filter/PatternRule.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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.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. - *
- * Rule Syntax: - *
- *
- * Rule ::= [n|i]:address          n stands for computer name, i for ip address
- * address ::= <regex> | localhost
- * regex is a regular expression with '*' as multi character and '?' as single character wild card
- * 
- *
- * Example: allow localhost: - *
- * new PatternRule(true, "n:localhost") - *
- * Example: allow local lan: - *
- * new PatternRule(true, "i:192.168.0.*") - *
- * Example: block all - *
- * new PatternRule(false, "n:*") - *
- *

- * 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-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java index df445b6ccb..08897f919c 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java +++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java @@ -60,11 +60,7 @@ private void verifySourceCreation(String name, String type, Class typeClass) 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("spooldir-src", "spooldir", SpoolDirectorySource.class); // verifySourceCreation("thrift-src", "thrift", ThriftSource.class); verifySourceCreation("custom-src", MockSource.class.getCanonicalName(), MockSource.class); diff --git a/flume-ng-core/src/test/resources/certs/gencerts.sh b/flume-ng-core/src/test/resources/certs/gencerts.sh deleted file mode 100755 index 0fb0263de8..0000000000 --- a/flume-ng-core/src/test/resources/certs/gencerts.sh +++ /dev/null @@ -1,31 +0,0 @@ -mkdir tmp -rm ../truststorefile.jks -rm ../keystorefile.jks -rm ../server.flume-keystore.p12 -# Create the CA key and certificate -openssl req -config rootca.conf -new -x509 -nodes -keyout tmp/flume-cacert.key -out tmp/flume-ca.crt -days 10960 -# Create the trust store and import the certificate -keytool -keystore ../truststorefile.jks -storetype jks -importcert -file 'tmp/flume-ca.crt' -keypass password -storepass password -alias flume-cacert -noprompt -#Import the root certificate -keytool -keystore ../keystorefile.jks -alias flume-ca -importcert -file tmp/flume-ca.crt -keypass password -storepass password -noprompt -# Create the client private key in the client key store -keytool -genkeypair -keyalg RSA -alias client -keystore ../keystorefile.jks -storepass password -keypass password -validity 10960 -keysize 2048 -dname "CN=client.flume, C=US" -# Create a signing request for the client # -keytool -keystore ../keystorefile.jks -alias client -certreq -file tmp/client.csr -keypass password -storepass password -# Sign the client certificate -openssl x509 -req -CA 'tmp/flume-ca.crt' -CAkey 'tmp/flume-cacert.key' -in tmp/client.csr -out tmp/client.crt_signed -days 10960 -CAcreateserial -passin pass:password -# Verify the signed certificate -openssl verify -CAfile 'tmp/flume-ca.crt' tmp/client.crt_signed -#Import the client's signed certificate -keytool -keystore ../keystorefile.jks -alias client -importcert -file tmp/client.crt_signed -keypass password -storepass password -noprompt -#Verify the keystore -keytool -list -v -keystore ../keystorefile.jks -storepass password -# Create the server private key in the server key store -keytool -genkeypair -keyalg RSA -alias server -keystore ../server.flume-keystore.p12 -storepass password -storetype PKCS12 -keypass password -validity 10960 -keysize 2048 -dname "CN=server.flume, C=US" -# Create a signing request for the server # -keytool -keystore ../server.flume-keystore.p12 -alias server -certreq -file tmp/server.csr -keypass password -storepass password -# Sign the server certificate -openssl x509 -req -CA 'tmp/flume-ca.crt' -CAkey 'tmp/flume-cacert.key' -in tmp/server.csr -out ../server.flume-crt.pem -days 10960 -CAcreateserial -passin pass:password -# Extract the private key -openssl pkcs12 -in ../server.flume-keystore.p12 -passin pass:password -nokeys -out ../server.flume.pem -rm -rf tmp diff --git a/flume-ng-core/src/test/resources/certs/rootca.conf b/flume-ng-core/src/test/resources/certs/rootca.conf deleted file mode 100644 index 722e9c39bc..0000000000 --- a/flume-ng-core/src/test/resources/certs/rootca.conf +++ /dev/null @@ -1,9 +0,0 @@ -[ req ] -distinguished_name = CA_DN -prompt = no -output_password = password -default_bits = 2048 - -[ CA_DN ] -C = US -CN = flume-ca diff --git a/flume-ng-core/src/test/resources/certs/server.conf b/flume-ng-core/src/test/resources/certs/server.conf deleted file mode 100644 index 7a9fb58356..0000000000 --- a/flume-ng-core/src/test/resources/certs/server.conf +++ /dev/null @@ -1,9 +0,0 @@ -[ req ] -distinguished_name = CA_DN -prompt = no -output_password = password -default_bits = 2048 - -[ CA_DN ] -C = US -CN = server.flume diff --git a/flume-ng-core/src/test/resources/keystorefile.jks b/flume-ng-core/src/test/resources/keystorefile.jks deleted file mode 100644 index d62e957925..0000000000 Binary files a/flume-ng-core/src/test/resources/keystorefile.jks and /dev/null differ diff --git a/flume-ng-core/src/test/resources/server.flume-crt.pem b/flume-ng-core/src/test/resources/server.flume-crt.pem deleted file mode 100644 index 9e3774427d..0000000000 --- a/flume-ng-core/src/test/resources/server.flume-crt.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICwjCCAaoCCQD8AQyla5FbDjANBgkqhkiG9w0BAQsFADAgMQswCQYDVQQGEwJV -UzERMA8GA1UEAwwIZmx1bWUtY2EwIBcNMjMwMzIyMDAyODM0WhgPMjA1MzAzMjQw -MDI4MzRaMCQxCzAJBgNVBAYTAlVTMRUwEwYDVQQDEwxzZXJ2ZXIuZmx1bWUwggEi -MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEEAUShlX2lWDYiEgcZL1JzWFw -auNkdxOGo1DtD3YaZdrU1GS2UwspLm0qcSFEF1Sx6uVTABdgjZGnxJLSTJkabVu/ -iMuP+EQrE/4AWJoyuuaYMSG0EGeP+mttTtLHYyt/k9NJkABYxFZkNqdDuo+lF/Vs -QdW3icym0vqMwiIvE+VKw9j3F+zFZizfx6MiBH0uuNrXHFCNUg52/cbeyiXO1mks -yruOV+PF8/44zAepjLWiJgp7Wo6ejXmLvR+k68RwB5V7fXrzPYueM9GQDmLffkdO -ZhrcafiRFGlzWSmC820Eb2b5+cVnm96XAlUXE5ao5o58oMmcufMnJ5k2UbFJAgMB -AAEwDQYJKoZIhvcNAQELBQADggEBAHBGpqraT39aw/HVrJdmpsw8CwSmdiir+NYk -5PprbIKAyf/P/9ObKcqesO8d8CQZVvzzm+Ok2rgcALDIl/TbbAVUPizIrN4AiH+Z -BPOqDFF4taWkw73iMDiq61QS8SpJIOxxmL8PsK5eefuABrpumnVgW5X9BT/uMIqW -NOwiyII3NVvtlErcdAL/ZTYWc3S8CEWVRc88ZpIBSLB4/tqQbPM+m+ZtYMSKi3Sh -ugOjonPuteeQqu6R7HRYOajepKdGe048Moq90v0IrDI8v+rbezLFpEWOnG0fUDEq -LfA9l7e/q1ukXRW4ccJWZWXLrZbEbX5hJeTlyYhHciwB5jfueMM= ------END CERTIFICATE----- diff --git a/flume-ng-core/src/test/resources/server.flume-keystore.p12 b/flume-ng-core/src/test/resources/server.flume-keystore.p12 deleted file mode 100644 index da51f355d1..0000000000 Binary files a/flume-ng-core/src/test/resources/server.flume-keystore.p12 and /dev/null differ diff --git a/flume-ng-core/src/test/resources/server.flume.pem b/flume-ng-core/src/test/resources/server.flume.pem deleted file mode 100644 index 6bc71ed797..0000000000 --- a/flume-ng-core/src/test/resources/server.flume.pem +++ /dev/null @@ -1,23 +0,0 @@ -Bag Attributes - friendlyName: server - localKeyID: 54 69 6D 65 20 31 36 37 39 34 34 34 39 31 33 33 33 39 -subject=/C=US/CN=server.flume -issuer=/C=US/CN=server.flume ------BEGIN CERTIFICATE----- -MIIC6TCCAdGgAwIBAgIEMlDgqzANBgkqhkiG9w0BAQsFADAkMQswCQYDVQQGEwJV -UzEVMBMGA1UEAxMMc2VydmVyLmZsdW1lMCAXDTIzMDMyMjAwMjgzM1oYDzIwNTMw -MzI0MDAyODMzWjAkMQswCQYDVQQGEwJVUzEVMBMGA1UEAxMMc2VydmVyLmZsdW1l -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxBAFEoZV9pVg2IhIHGS9 -Sc1hcGrjZHcThqNQ7Q92GmXa1NRktlMLKS5tKnEhRBdUserlUwAXYI2Rp8SS0kyZ -Gm1bv4jLj/hEKxP+AFiaMrrmmDEhtBBnj/prbU7Sx2Mrf5PTSZAAWMRWZDanQ7qP -pRf1bEHVt4nMptL6jMIiLxPlSsPY9xfsxWYs38ejIgR9Lrja1xxQjVIOdv3G3sol -ztZpLMq7jlfjxfP+OMwHqYy1oiYKe1qOno15i70fpOvEcAeVe3168z2LnjPRkA5i -335HTmYa3Gn4kRRpc1kpgvNtBG9m+fnFZ5velwJVFxOWqOaOfKDJnLnzJyeZNlGx -SQIDAQABoyEwHzAdBgNVHQ4EFgQUClD6FZ+qPIFrtBaz0swRTtWt1WEwDQYJKoZI -hvcNAQELBQADggEBALuX9E+tRWvvA9uULj9Iq+k9iUNMQzkmyzXGu7hY46ZU9lx+ -fNnLZq82zz9rHq8IhK4HsLIsPCLfNeXwG/TNR4zUHKI53lzkburxgu76soMUDbHX -8udyUgrs0YjQcppw6IOOmlZtgNeF2nu7jeoXrCaA07yXzehAqukHv7glWaV3oORc -rDkZvHfJ2G7hPbUYYIeouJsbG9rNukNPOY9JEYGFYzDxZ8hlFt7Lp/icbdpjFGDV -tkMtPpVz59B47j/Kk/k5zxaDLnD42svL8GByyM5UxvAqAlYnfMKiZqXfY0JbCpMC -e9Z5xOyt9F8NLFyjRsmBlJD61LuLb8hAZK/Ho70= ------END CERTIFICATE----- diff --git a/flume-ng-core/src/test/resources/server.p12 b/flume-ng-core/src/test/resources/server.p12 deleted file mode 100644 index 07eef5168f..0000000000 Binary files a/flume-ng-core/src/test/resources/server.p12 and /dev/null differ diff --git a/flume-ng-core/src/test/resources/truststore.jks b/flume-ng-core/src/test/resources/truststore.jks deleted file mode 100644 index 8c08349e0f..0000000000 Binary files a/flume-ng-core/src/test/resources/truststore.jks and /dev/null differ diff --git a/flume-ng-core/src/test/resources/truststorefile.jks b/flume-ng-core/src/test/resources/truststorefile.jks deleted file mode 100644 index a0c3a49ac1..0000000000 Binary files a/flume-ng-core/src/test/resources/truststorefile.jks and /dev/null differ diff --git a/flume-ng-dist/pom.xml b/flume-ng-dist/pom.xml index 7bfe274287..0f328cb819 100644 --- a/flume-ng-dist/pom.xml +++ b/flume-ng-dist/pom.xml @@ -150,6 +150,14 @@ org.apache.flume.flume-ng-sources flume-taildir-source + + org.apache.flume.flume-ng-sources + flume-syslog-source + + + org.apache.flume.flume-ng-sources + flume-netcat-source + org.apache.flume flume-ng-environment-variable-config-filter diff --git a/flume-ng-sdk/pom.xml b/flume-ng-sdk/pom.xml index dc47f42b1a..8ddc7e3c59 100644 --- a/flume-ng-sdk/pom.xml +++ b/flume-ng-sdk/pom.xml @@ -44,6 +44,19 @@ test + + + org.bouncycastle + bcpkix-jdk18on + test + + + + org.bouncycastle + bcprov-jdk18on + test + + org.slf4j slf4j-api @@ -93,6 +106,18 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + -Djava.net.preferIPv4Stack=true + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + + + diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/TestKeyStores.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/TestKeyStores.java new file mode 100644 index 0000000000..7be6500271 --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/TestKeyStores.java @@ -0,0 +1,77 @@ +/* + * 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.util; + +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.KeyStore; +import java.security.cert.X509Certificate; + +/** + * Test helper that builds key and trust stores backed by a single self-signed certificate, + * so SSL tests can generate their TLS material in memory instead of shipping keystore files. + */ +public final class TestKeyStores { + + private final KeyPair keyPair; + private final X509Certificate certificate; + + private TestKeyStores(KeyPair keyPair, X509Certificate certificate) { + this.keyPair = keyPair; + this.certificate = certificate; + } + + /** + * Generates a self-signed credential for the given distinguished name (for example {@code CN=localhost}). + */ + public static TestKeyStores selfSigned(String dname) throws Exception { + KeyPair keyPair = X509Certificates.generateKeyPair(); + X509Certificate certificate = X509Certificates.generateSelfSignedCertificate(keyPair, dname); + return new TestKeyStores(keyPair, certificate); + } + + public X509Certificate certificate() { + return certificate; + } + + /** A keystore of the given type holding the private key and certificate under alias {@code key}. */ + public KeyStore keyStore(String type, String password) throws Exception { + KeyStore ks = KeyStore.getInstance(type); + ks.load(null, null); + ks.setKeyEntry("key", keyPair.getPrivate(), password.toCharArray(), new X509Certificate[] {certificate}); + return ks; + } + + /** A truststore of the given type holding only the certificate under alias {@code cert}. */ + public KeyStore trustStore(String type) throws Exception { + KeyStore ts = KeyStore.getInstance(type); + ts.load(null, null); + ts.setCertificateEntry("cert", certificate); + return ts; + } + + /** Writes {@link #keyStore} to {@code file} and returns its path. */ + public Path writeKeyStore(Path file, String type, String password) throws Exception { + KeyStore ks = keyStore(type, password); + try (OutputStream out = Files.newOutputStream(file)) { + ks.store(out, password.toCharArray()); + } + return file; + } +} diff --git a/flume-ng-sources/flume-http-source/src/test/java/org/apache/flume/source/http/X509Certificates.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/X509Certificates.java similarity index 94% rename from flume-ng-sources/flume-http-source/src/test/java/org/apache/flume/source/http/X509Certificates.java rename to flume-ng-sdk/src/test/java/org/apache/flume/util/X509Certificates.java index c98ece50f3..ac38450025 100644 --- a/flume-ng-sources/flume-http-source/src/test/java/org/apache/flume/source/http/X509Certificates.java +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/X509Certificates.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source.http; +package org.apache.flume.util; import java.math.BigInteger; import java.security.KeyPair; @@ -37,7 +37,7 @@ /** * Utility class to generate X.509 certificates for testing purposes. */ -final class X509Certificates { +public final class X509Certificates { private static final long MINUTE_IN_MILLIS = 60_000L; private static final long YEAR_IN_MILLIS = 365L * 24 * 60 * MINUTE_IN_MILLIS; @@ -54,7 +54,7 @@ final class X509Certificates { } } - static KeyPair generateKeyPair() { + public static KeyPair generateKeyPair() { return RSA_GENERATOR.generateKeyPair(); } @@ -66,7 +66,7 @@ static KeyPair generateKeyPair() { * @return a self-signed X.509 server certificate * @throws Exception if certificate creation or signing fails */ - static X509Certificate generateSelfSignedCertificate(KeyPair keyPair, String subjectDn) throws Exception { + public static X509Certificate generateSelfSignedCertificate(KeyPair keyPair, String subjectDn) throws Exception { long now = System.currentTimeMillis(); Date notBefore = new Date(now - MINUTE_IN_MILLIS); Date notAfter = new Date(now + YEAR_IN_MILLIS); diff --git a/flume-ng-sources/flume-http-source/src/test/java/org/apache/flume/source/http/TestHTTPSource.java b/flume-ng-sources/flume-http-source/src/test/java/org/apache/flume/source/http/TestHTTPSource.java index fc950b8d76..9c674cbc87 100644 --- a/flume-ng-sources/flume-http-source/src/test/java/org/apache/flume/source/http/TestHTTPSource.java +++ b/flume-ng-sources/flume-http-source/src/test/java/org/apache/flume/source/http/TestHTTPSource.java @@ -24,8 +24,6 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import jakarta.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.reflect.Type; @@ -35,9 +33,7 @@ import java.net.Socket; import java.net.URL; import java.net.UnknownHostException; -import java.security.KeyPair; import java.security.KeyStore; -import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -65,6 +61,7 @@ import org.apache.flume.conf.Configurables; import org.apache.flume.event.JSONEvent; import org.apache.flume.instrumentation.SourceCounter; +import org.apache.flume.util.TestKeyStores; import org.apache.flume.util.Whitebox; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -147,23 +144,12 @@ private static Context getDefaultSecureContextGlobalKeystore(int port) throws IO private static KeyStore trustStore; private static void generateSslStores() throws Exception { - KeyPair keyPair = X509Certificates.generateKeyPair(); - X509Certificate certificate = X509Certificates.generateSelfSignedCertificate(keyPair, "CN=localhost"); - - KeyStore keyStore = KeyStore.getInstance("JKS"); - keyStore.load(null, null); - keyStore.setKeyEntry( - "jetty", keyPair.getPrivate(), KEYSTORE_PASSWORD.toCharArray(), new X509Certificate[] {certificate}); - File keystoreFile = TEMP_FOLDER.newFile("keystore.jks"); - try (FileOutputStream out = new FileOutputStream(keystoreFile)) { - keyStore.store(out, KEYSTORE_PASSWORD.toCharArray()); - } - serverKeystorePath = keystoreFile.getAbsolutePath(); - + TestKeyStores credentials = TestKeyStores.selfSigned("CN=localhost"); + serverKeystorePath = credentials + .writeKeyStore(TEMP_FOLDER.newFile("keystore.jks").toPath(), "JKS", KEYSTORE_PASSWORD) + .toString(); // The test client only needs to trust the self-signed server certificate. - trustStore = KeyStore.getInstance("JKS"); - trustStore.load(null, null); - trustStore.setCertificateEntry("server", certificate); + trustStore = credentials.trustStore("JKS"); } @BeforeClass diff --git a/flume-ng-sources/flume-netcat-source/pom.xml b/flume-ng-sources/flume-netcat-source/pom.xml new file mode 100644 index 0000000000..91aca106c4 --- /dev/null +++ b/flume-ng-sources/flume-netcat-source/pom.xml @@ -0,0 +1,60 @@ + + + + + 4.0.0 + + + org.apache.flume + flume-ng-sources + 2.0.0-SNAPSHOT + + + org.apache.flume.flume-ng-sources + flume-netcat-source + Flume Netcat Source + + + + 3 + org.apache.flume.source.netcat + + + + + org.apache.flume + flume-ng-sdk + + + org.apache.flume + flume-ng-core + + + + io.netty + netty-all + + + + junit + junit + test + + + + diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/NetcatUdpSource.java b/flume-ng-sources/flume-netcat-source/src/main/java/org/apache/flume/source/netcat/NetcatUdpSource.java similarity index 98% rename from flume-ng-core/src/main/java/org/apache/flume/source/NetcatUdpSource.java rename to flume-ng-sources/flume-netcat-source/src/main/java/org/apache/flume/source/netcat/NetcatUdpSource.java index be044b508e..f16c3ab8f9 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/NetcatUdpSource.java +++ b/flume-ng-sources/flume-netcat-source/src/main/java/org/apache/flume/source/netcat/NetcatUdpSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.netcat; import com.google.common.annotations.VisibleForTesting; import io.netty.bootstrap.Bootstrap; @@ -40,6 +40,7 @@ import org.apache.flume.conf.Configurables; import org.apache.flume.event.EventBuilder; import org.apache.flume.exception.ChannelException; +import org.apache.flume.source.AbstractSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatUdpSource.java b/flume-ng-sources/flume-netcat-source/src/test/java/org/apache/flume/source/netcat/TestNetcatUdpSource.java similarity index 99% rename from flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatUdpSource.java rename to flume-ng-sources/flume-netcat-source/src/test/java/org/apache/flume/source/netcat/TestNetcatUdpSource.java index 7266086a4f..3af5910dc9 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatUdpSource.java +++ b/flume-ng-sources/flume-netcat-source/src/test/java/org/apache/flume/source/netcat/TestNetcatUdpSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.netcat; import com.google.common.base.Charsets; import java.io.IOException; diff --git a/flume-ng-sources/flume-netcat-source/src/test/java/org/apache/flume/source/netcat/TestNetcatUdpSourceFactory.java b/flume-ng-sources/flume-netcat-source/src/test/java/org/apache/flume/source/netcat/TestNetcatUdpSourceFactory.java new file mode 100644 index 0000000000..855733ca10 --- /dev/null +++ b/flume-ng-sources/flume-netcat-source/src/test/java/org/apache/flume/source/netcat/TestNetcatUdpSourceFactory.java @@ -0,0 +1,41 @@ +/* + * 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.source.netcat; + +import org.apache.flume.Source; +import org.apache.flume.SourceFactory; +import org.apache.flume.source.DefaultSourceFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestNetcatUdpSourceFactory { + + private SourceFactory sourceFactory; + + @Before + public void setUp() { + sourceFactory = new DefaultSourceFactory(); + } + + @Test + public void testNetcatUdpSourceCreation() throws Exception { + Source src = sourceFactory.create("netcat-udp-src", "netcatudp"); + Assert.assertNotNull(src); + Assert.assertTrue(src instanceof NetcatUdpSource); + } +} diff --git a/flume-ng-sources/flume-syslog-source/pom.xml b/flume-ng-sources/flume-syslog-source/pom.xml new file mode 100644 index 0000000000..8f85d836f7 --- /dev/null +++ b/flume-ng-sources/flume-syslog-source/pom.xml @@ -0,0 +1,106 @@ + + + + + 4.0.0 + + + org.apache.flume + flume-ng-sources + 2.0.0-SNAPSHOT + + + org.apache.flume.flume-ng-sources + flume-syslog-source + Flume Syslog Source + + + + 8 + org.apache.flume.source.syslog + + + + + org.apache.flume + flume-ng-sdk + + + org.apache.flume + flume-ng-core + + + org.apache.flume + flume-ng-sdk + tests + test + + + + com.google.guava + guava + + + + io.netty + netty-all + + + + org.apache.mina + mina-core + + + + junit + junit + test + + + + org.mockito + mockito-core + test + + + + org.bouncycastle + bcpkix-jdk18on + test + + + + org.bouncycastle + bcprov-jdk18on + test + + + + org.apache.logging.log4j + log4j-core + test + + + + org.apache.logging.log4j + log4j-slf4j-impl + test + + + + diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/MultiportSyslogTCPSource.java b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/MultiportSyslogTCPSource.java similarity index 99% rename from flume-ng-core/src/main/java/org/apache/flume/source/MultiportSyslogTCPSource.java rename to flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/MultiportSyslogTCPSource.java index 8853857ccf..2a92c74686 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/MultiportSyslogTCPSource.java +++ b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/MultiportSyslogTCPSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import com.google.common.base.Preconditions; import com.google.common.base.Throwables; @@ -38,6 +38,7 @@ import org.apache.flume.conf.LogPrivacyUtil; import org.apache.flume.event.EventBuilder; import org.apache.flume.instrumentation.SourceCounter; +import org.apache.flume.source.SslContextAwareAbstractSource; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.service.IoHandlerAdapter; import org.apache.mina.core.session.IdleStatus; diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogParser.java b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogParser.java similarity index 99% rename from flume-ng-core/src/main/java/org/apache/flume/source/SyslogParser.java rename to flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogParser.java index 8e84a7cc82..97cd8af108 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogParser.java +++ b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogParser.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import com.google.common.base.Preconditions; import com.google.common.cache.CacheBuilder; diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogSourceConfigurationConstants.java b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogSourceConfigurationConstants.java similarity index 98% rename from flume-ng-core/src/main/java/org/apache/flume/source/SyslogSourceConfigurationConstants.java rename to flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogSourceConfigurationConstants.java index 8378f10568..e791a0162e 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogSourceConfigurationConstants.java +++ b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogSourceConfigurationConstants.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; public final class SyslogSourceConfigurationConstants { diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogTcpSource.java b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogTcpSource.java similarity index 98% rename from flume-ng-core/src/main/java/org/apache/flume/source/SyslogTcpSource.java rename to flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogTcpSource.java index 09bfa49522..48c587a7b5 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogTcpSource.java +++ b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogTcpSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import com.google.common.annotations.VisibleForTesting; import io.netty.bootstrap.ServerBootstrap; @@ -45,6 +45,7 @@ import org.apache.flume.conf.Configurables; import org.apache.flume.exception.ChannelException; import org.apache.flume.instrumentation.SourceCounter; +import org.apache.flume.source.SslContextAwareAbstractSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogUDPSource.java b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogUDPSource.java similarity index 98% rename from flume-ng-core/src/main/java/org/apache/flume/source/SyslogUDPSource.java rename to flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogUDPSource.java index d5d159b02e..cb4862d392 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogUDPSource.java +++ b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogUDPSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import com.google.common.annotations.VisibleForTesting; import io.netty.bootstrap.Bootstrap; @@ -37,6 +37,7 @@ import org.apache.flume.conf.Configurables; import org.apache.flume.exception.ChannelException; import org.apache.flume.instrumentation.SourceCounter; +import org.apache.flume.source.AbstractSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogUtils.java b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogUtils.java similarity index 99% rename from flume-ng-core/src/main/java/org/apache/flume/source/SyslogUtils.java rename to flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogUtils.java index 049020b4aa..ac65eea27a 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/SyslogUtils.java +++ b/flume-ng-sources/flume-syslog-source/src/main/java/org/apache/flume/source/syslog/SyslogUtils.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import io.netty.buffer.ByteBuf; import java.io.ByteArrayOutputStream; diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestMultiportSyslogTCPSource.java similarity index 97% rename from flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java rename to flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestMultiportSyslogTCPSource.java index 49c74421d6..8a63720de9 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java +++ b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestMultiportSyslogTCPSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -33,6 +33,8 @@ import java.net.UnknownHostException; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import java.security.cert.X509Certificate; import java.text.ParseException; import java.time.ZonedDateTime; @@ -59,10 +61,11 @@ import org.apache.flume.conf.Configurables; import org.apache.flume.exception.ChannelException; import org.apache.flume.instrumentation.SourceCounter; -import org.apache.flume.source.MultiportSyslogTCPSource.LineSplitter; -import org.apache.flume.source.MultiportSyslogTCPSource.MultiportSyslogHandler; -import org.apache.flume.source.MultiportSyslogTCPSource.ParsedBuffer; -import org.apache.flume.source.MultiportSyslogTCPSource.ThreadSafeDecoder; +import org.apache.flume.source.syslog.MultiportSyslogTCPSource.LineSplitter; +import org.apache.flume.source.syslog.MultiportSyslogTCPSource.MultiportSyslogHandler; +import org.apache.flume.source.syslog.MultiportSyslogTCPSource.ParsedBuffer; +import org.apache.flume.source.syslog.MultiportSyslogTCPSource.ThreadSafeDecoder; +import org.apache.flume.util.TestKeyStores; import org.apache.flume.util.Whitebox; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -231,9 +234,12 @@ public X509Certificate[] getAcceptedIssuers() { SocketFactory socketFactory = sslContext.getSocketFactory(); + Path keystore = TestKeyStores.selfSigned("CN=localhost") + .writeKeyStore(Files.createTempFile("server", ".p12"), "PKCS12", "password"); + Context context = new Context(); context.put("ssl", "true"); - context.put("keystore", "src/test/resources/server.flume-keystore.p12"); + context.put("keystore", keystore.toString()); context.put("keystore-password", "password"); context.put("keystore-type", "PKCS12"); diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogParser.java similarity index 99% rename from flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java rename to flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogParser.java index 07200383af..ca6e53ed74 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java +++ b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogParser.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import com.google.common.base.Charsets; import com.google.common.collect.Lists; diff --git a/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogSourceFactory.java b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogSourceFactory.java new file mode 100644 index 0000000000..1c559ac3b7 --- /dev/null +++ b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogSourceFactory.java @@ -0,0 +1,55 @@ +/* + * 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.source.syslog; + +import org.apache.flume.Source; +import org.apache.flume.SourceFactory; +import org.apache.flume.source.DefaultSourceFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestSyslogSourceFactory { + + private SourceFactory sourceFactory; + + @Before + public void setUp() { + sourceFactory = new DefaultSourceFactory(); + } + + @Test + public void testSyslogTcpSourceCreation() throws Exception { + Source src = sourceFactory.create("syslogtcp-src", "syslogtcp"); + Assert.assertNotNull(src); + Assert.assertTrue(src instanceof SyslogTcpSource); + } + + @Test + public void testMultiportSyslogTcpSourceCreation() throws Exception { + Source src = sourceFactory.create("multiport_syslogtcp-src", "multiport_syslogtcp"); + Assert.assertNotNull(src); + Assert.assertTrue(src instanceof MultiportSyslogTCPSource); + } + + @Test + public void testSyslogUdpSourceCreation() throws Exception { + Source src = sourceFactory.create("syslogudp-src", "syslogudp"); + Assert.assertNotNull(src); + Assert.assertTrue(src instanceof SyslogUDPSource); + } +} diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogTcpSource.java similarity index 94% rename from flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java rename to flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogTcpSource.java index feb955629d..fbfd874039 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java +++ b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogTcpSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -28,6 +28,7 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; +import java.nio.file.Path; import java.security.cert.X509Certificate; import java.time.LocalDateTime; import java.util.ArrayList; @@ -47,8 +48,12 @@ import org.apache.flume.channel.ReplicatingChannelSelector; import org.apache.flume.conf.Configurables; import org.apache.flume.exception.ChannelException; +import org.apache.flume.util.TestKeyStores; import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import org.slf4j.LoggerFactory; @@ -68,6 +73,17 @@ public class TestSyslogTcpSource { private final String bodyWithTimestamp = stamp1 + " " + data1; private final String bodyWithTandH = "<10>" + stamp1 + " " + host1 + " " + data1 + "\n"; + @ClassRule + public static final TemporaryFolder TEMP_FOLDER = new TemporaryFolder(); + + private static Path serverKeystore; + + @BeforeClass + public static void generateKeystore() throws Exception { + serverKeystore = TestKeyStores.selfSigned("CN=localhost") + .writeKeyStore(TEMP_FOLDER.newFile("server.p12").toPath(), "PKCS12", "password"); + } + private void init(String keepFields) { init(keepFields, new Context()); } @@ -96,7 +112,7 @@ private void init(String keepFields, Context context) { private void initSsl() { Context context = new Context(); context.put("ssl", "true"); - context.put("keystore", "src/test/resources/server.p12"); + context.put("keystore", serverKeystore.toString()); context.put("keystore-password", "password"); context.put("keystore-type", "PKCS12"); init("none", context); diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogUdpSource.java similarity index 99% rename from flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java rename to flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogUdpSource.java index 9979906cf7..7d8ce85a27 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java +++ b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogUdpSource.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogUtils.java similarity index 99% rename from flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java rename to flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogUtils.java index fd8206cddc..9834ca3ee5 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java +++ b/flume-ng-sources/flume-syslog-source/src/test/java/org/apache/flume/source/syslog/TestSyslogUtils.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.flume.source; +package org.apache.flume.source.syslog; import static io.netty.buffer.Unpooled.*; import static org.junit.Assert.assertEquals; diff --git a/flume-ng-sources/pom.xml b/flume-ng-sources/pom.xml index 683ea2a531..3318e3fd2e 100644 --- a/flume-ng-sources/pom.xml +++ b/flume-ng-sources/pom.xml @@ -34,6 +34,8 @@ flume-http-source flume-taildir-source + flume-syslog-source + flume-netcat-source