You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/04/27 08:57:38 UTC

[GitHub] [ignite] atris opened a new pull request #9048: IGNITE-14607: Regex Based Filtering For IP Addresses During Discovery

atris opened a new pull request #9048:
URL: https://github.com/apache/ignite/pull/9048


   This commit introduces functionality to filter IP addresses during IP discovery using regexes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] asfgit closed pull request #9048: IGNITE-14607: Regex Based Filtering For IP Addresses During Discovery

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #9048:
URL: https://github.com/apache/ignite/pull/9048


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] atris commented on pull request #9048: IGNITE-14607: Regex Based Filtering For IP Addresses During Discovery

Posted by GitBox <gi...@apache.org>.
atris commented on pull request #9048:
URL: https://github.com/apache/ignite/pull/9048#issuecomment-828245008


   @alamar Updated, please see.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] alamar commented on a change in pull request #9048: IGNITE-14607: Regex Based Filtering For IP Addresses During Discovery

Posted by GitBox <gi...@apache.org>.
alamar commented on a change in pull request #9048:
URL: https://github.com/apache/ignite/pull/9048#discussion_r621277970



##########
File path: modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithAddressFilterTest.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.ignite.spi.discovery.tcp;
+
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.P1;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.junit.Test;
+
+/**
+ * Test discovery SPI with address filter present
+ */
+public class TcpDiscoveryWithAddressFilterTest extends TcpDiscoveryWithWrongServerTest {
+
+    IgnitePredicate<InetSocketAddress> addressFilter = new P1<InetSocketAddress>() {

Review comment:
       Javadoc is needed for all fields, please also specify access modifier.

##########
File path: modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithAddressFilterTest.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.ignite.spi.discovery.tcp;
+
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.P1;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.junit.Test;
+
+/**
+ * Test discovery SPI with address filter present
+ */
+public class TcpDiscoveryWithAddressFilterTest extends TcpDiscoveryWithWrongServerTest {
+
+    IgnitePredicate<InetSocketAddress> addressFilter = new P1<InetSocketAddress>() {
+        @Override public boolean apply(InetSocketAddress address) {
+            // Compile regular expression
+            Pattern pattern = Pattern.compile("^/127\\.0\\.0\\.1:47503$", Pattern.CASE_INSENSITIVE);
+            // Match regex against input
+            Matcher matcher = pattern.matcher(address.toString());
+            // Use results...
+            return !(matcher.matches());
+        }
+    };
+
+    /** {@inheritDoc} */
+   @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
+
+        ipFinder.setAddresses(Collections.singleton("127.0.0.1:" + Integer.toString(SERVER_PORT) + ".." +
+                Integer.toString(LAST_SERVER_PORT)));
+
+        cfg.setAddressFilter(addressFilter);
+
+        cfg.setDiscoverySpi(new TcpDiscoveryWithAddressFilter().setIpFinder(ipFinder));
+
+        return cfg;
+    }
+
+    /**
+     * Basic test
+     */
+    @Test
+    public void testBasic() throws Exception {
+        startTcpThread(new NoResponseWorker(), SERVER_PORT);
+        startTcpThread(new NoResponseWorker(), LAST_SERVER_PORT);
+
+        simpleTest();
+    }
+
+    /**
+     * Check for incoming addresses and check that the filter was applied
+     */
+    class TcpDiscoveryWithAddressFilter extends TcpDiscoverySpi {
+        /** {@inheritDoc} */
+        @Override protected Collection<InetSocketAddress> resolvedAddresses() throws IgniteSpiException {
+            Collection<InetSocketAddress> res = super.resolvedAddresses();
+
+            for (InetSocketAddress addr : res) {

Review comment:
       curly braces not needed for single-statement, one-line body.

##########
File path: modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithAddressFilterTest.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.ignite.spi.discovery.tcp;
+
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.P1;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.junit.Test;
+
+/**
+ * Test discovery SPI with address filter present
+ */
+public class TcpDiscoveryWithAddressFilterTest extends TcpDiscoveryWithWrongServerTest {

Review comment:
       You need to add this class to some test suite.

##########
File path: modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithAddressFilterTest.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.ignite.spi.discovery.tcp;
+
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.P1;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.junit.Test;
+
+/**
+ * Test discovery SPI with address filter present
+ */
+public class TcpDiscoveryWithAddressFilterTest extends TcpDiscoveryWithWrongServerTest {
+
+    IgnitePredicate<InetSocketAddress> addressFilter = new P1<InetSocketAddress>() {
+        @Override public boolean apply(InetSocketAddress address) {
+            // Compile regular expression
+            Pattern pattern = Pattern.compile("^/127\\.0\\.0\\.1:47503$", Pattern.CASE_INSENSITIVE);
+            // Match regex against input
+            Matcher matcher = pattern.matcher(address.toString());
+            // Use results...
+            return !(matcher.matches());
+        }
+    };
+
+    /** {@inheritDoc} */
+   @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
+
+        ipFinder.setAddresses(Collections.singleton("127.0.0.1:" + Integer.toString(SERVER_PORT) + ".." +
+                Integer.toString(LAST_SERVER_PORT)));
+
+        cfg.setAddressFilter(addressFilter);
+
+        cfg.setDiscoverySpi(new TcpDiscoveryWithAddressFilter().setIpFinder(ipFinder));
+
+        return cfg;
+    }
+
+    /**
+     * Basic test
+     */
+    @Test
+    public void testBasic() throws Exception {
+        startTcpThread(new NoResponseWorker(), SERVER_PORT);
+        startTcpThread(new NoResponseWorker(), LAST_SERVER_PORT);
+
+        simpleTest();
+    }
+
+    /**
+     * Check for incoming addresses and check that the filter was applied
+     */
+    class TcpDiscoveryWithAddressFilter extends TcpDiscoverySpi {

Review comment:
       please use protected or private modifier

##########
File path: modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java
##########
@@ -43,16 +43,16 @@
  */
 public class TcpDiscoveryWithWrongServerTest extends GridCommonAbstractTest {
     /** Non-Ignite Server port #1. */
-    private static final int SERVER_PORT = 47500;
+    static final int SERVER_PORT = 47500;

Review comment:
       please use protected here & for all fields, classes below




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org