diff --git a/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/ClientSNICQAcceptanceTest.java b/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/ClientSNICQAcceptanceTest.java index dfe19519a6ca..e1943d5f0cb8 100644 --- a/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/ClientSNICQAcceptanceTest.java +++ b/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/ClientSNICQAcceptanceTest.java @@ -115,19 +115,11 @@ public static void beforeClass() throws IOException, InterruptedException { } @AfterClass - public static void afterClass() { - printlog("locator-maeve"); - printlog("server-dolores"); - } - - private static void printlog(String name) { - try { - String output = - docker.get().exec(options("-T"), "geode", - arguments("cat", name + "/" + name + ".log")); - System.out.println(name + " log file--------------------------------\n" + output); - } catch (Throwable ignore) { - } + public static void afterClass() throws Exception { + String output = + docker.get().exec(options("-T"), "geode", + arguments("cat", "server-dolores/server-dolores.log")); + System.out.println("Server log file--------------------------------\n" + output); } @Before diff --git a/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/DualServerSNIAcceptanceTest.java b/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/DualServerSNIAcceptanceTest.java index 7423b9573906..7b08be2b0429 100644 --- a/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/DualServerSNIAcceptanceTest.java +++ b/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/DualServerSNIAcceptanceTest.java @@ -31,7 +31,6 @@ import com.palantir.docker.compose.DockerComposeRule; import org.junit.After; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; @@ -61,7 +60,7 @@ public class DualServerSNIAcceptanceTest { private static final URL DOCKER_COMPOSE_PATH = - DualServerSNIAcceptanceTest.class.getResource("dual-server-docker-compose.yml"); + SingleServerSNIAcceptanceTest.class.getResource("docker-compose.yml"); // Docker compose does not work on windows in CI. Ignore this test on windows // Using a RuleChain to make sure we ignore the test before the rule comes into play @@ -75,17 +74,8 @@ public class DualServerSNIAcceptanceTest { @BeforeClass public static void beforeClass() throws Exception { - docker.get().exec(options("-T"), "locator-maeve", - arguments("gfsh", "run", "--file=/geode/scripts/locator-maeve.gfsh")); - - docker.get().exec(options("-T"), "server-dolores", - arguments("gfsh", "run", "--file=/geode/scripts/server-dolores.gfsh")); - - docker.get().exec(options("-T"), "server-clementine", - arguments("gfsh", "run", "--file=/geode/scripts/server-clementine.gfsh")); - - docker.get().exec(options("-T"), "locator-maeve", - arguments("gfsh", "run", "--file=/geode/scripts/create-regions.gfsh")); + docker.get().exec(options("-T"), "geode", + arguments("gfsh", "run", "--file=/geode/scripts/geode-starter-2.gfsh")); final String trustStorePath = createTempFileFromResource(SingleServerSNIAcceptanceTest.class, @@ -107,18 +97,6 @@ public void after() { ensureCacheClosed(); } - @AfterClass - public static void afterClass() throws Exception { - // if you need to capture logs for one of the processes use this pattern: - // try { - // String output = - // docker.get().exec(options("-T"), "locator-maeve", - // arguments("cat", "locator-maeve/locator-maeve.log")); - // System.out.println("Locator log file--------------------------------\n" + output); - // } catch (Throwable ignore) { - // } - } - @Test public void successfulRoutingTest() { verifyPutAndGet("group-dolores", "region-dolores"); diff --git a/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/GenerateSNIKeyAndTrustStores.java b/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/GenerateSNIKeyAndTrustStores.java index b48054afae36..1e5168ccefff 100644 --- a/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/GenerateSNIKeyAndTrustStores.java +++ b/geode-assembly/src/acceptanceTest/java/org/apache/geode/client/sni/GenerateSNIKeyAndTrustStores.java @@ -15,6 +15,7 @@ package org.apache.geode.client.sni; import java.io.File; +import java.net.InetAddress; import java.net.URL; import org.apache.geode.cache.ssl.CertStores; @@ -50,8 +51,10 @@ public void generateStores() throws Exception { CertificateMaterial certificate = new CertificateBuilder(365 * 100, "SHA256withRSA") .commonName(certName) .issuedBy(ca) - .sanDnsName(certName) - .sanDnsName("geode") + .sanDnsName("geode") // for inside the docker container + .sanDnsName("localhost") // for inside the docker container + .sanIpAddress(InetAddress.getByName("0.0.0.0")) // for inside the docker container + .sanDnsName(certName) // for client endpoint validation .generate(); CertStores store = new CertStores(certName); diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/dual-server-docker-compose.yml b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/dual-server-docker-compose.yml deleted file mode 100644 index f22e60a424f9..000000000000 --- a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/dual-server-docker-compose.yml +++ /dev/null @@ -1,70 +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. -# -version: '3.5' -services: - locator-maeve: - container_name: 'locator-maeve' - image: 'geode:develop' - hostname: locator-maeve - expose: - - '10334' - entrypoint: 'sh' - command: '-c /geode/scripts/forever' - networks: - geode-sni-test: - volumes: - - ./geode-config:/geode/config:ro - - ./scripts:/geode/scripts - server-clementine: - container_name: 'server-clementine' - image: 'geode:develop' - hostname: server-clementine - expose: - - '8501' - entrypoint: 'sh' - command: '-c /geode/scripts/forever' - networks: - geode-sni-test: - volumes: - - ./geode-config:/geode/config:ro - - ./scripts:/geode/scripts - server-dolores: - container_name: 'server-dolores' - image: 'geode:develop' - hostname: server-dolores - expose: - - '8502' - entrypoint: 'sh' - command: '-c /geode/scripts/forever' - networks: - geode-sni-test: - volumes: - - ./geode-config:/geode/config:ro - - ./scripts:/geode/scripts - haproxy: - container_name: 'haproxy' - image: 'haproxy:2.1' - ports: - - "15443" - networks: - geode-sni-test: - volumes: - - ./dual-server-haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro -networks: - geode-sni-test: - name: geode-sni-test - diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/dual-server-haproxy.cfg b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/dual-server-haproxy.cfg deleted file mode 100644 index 130f8049f40e..000000000000 --- a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/dual-server-haproxy.cfg +++ /dev/null @@ -1,44 +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. -# - -defaults - timeout client 1000 - timeout connect 1000 - timeout server 1000 - -frontend sniproxy - bind *:15443 - mode tcp - tcp-request inspect-delay 5s - tcp-request content accept if { req_ssl_hello_type 1 } - use_backend locators-maeve if { req.ssl_sni -i locator-maeve } - use_backend servers-dolores if { req.ssl_sni -i server-dolores } - use_backend servers-clementine if { req.ssl_sni -i server-clementine } - default_backend locators-maeve - log stdout format raw local0 debug - -backend locators-maeve - mode tcp - server locator1 locator-maeve:10334 - -backend servers-dolores - mode tcp - server server1 server-dolores:8501 - -backend servers-clementine - mode tcp - server server1 server-clementine:8502 diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/locator-maeve-keystore.jks b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/locator-maeve-keystore.jks index cce17bd30a2e..ec2feb85baa0 100644 Binary files a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/locator-maeve-keystore.jks and b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/locator-maeve-keystore.jks differ diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-clementine-keystore.jks b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-clementine-keystore.jks index 5eb5b8881d08..626269da26f2 100644 Binary files a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-clementine-keystore.jks and b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-clementine-keystore.jks differ diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-dolores-keystore.jks b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-dolores-keystore.jks index 490c75af8b48..54de8d6b0abb 100644 Binary files a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-dolores-keystore.jks and b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/server-dolores-keystore.jks differ diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/truststore.jks b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/truststore.jks index 69b434607380..a381a9a1b4bc 100644 Binary files a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/truststore.jks and b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/geode-config/truststore.jks differ diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/create-regions.gfsh b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/create-regions.gfsh deleted file mode 100644 index 53b601dc0c3e..000000000000 --- a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/create-regions.gfsh +++ /dev/null @@ -1,20 +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. -# - -connect --locator=locator-maeve[10334] --use-ssl=true --security-properties-file=/geode/config/gfsecurity.properties -create region --name=region-dolores --group=group-dolores --type=REPLICATE -create region --name=region-clementine --group=group-clementine --type=REPLICATE diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/geode-starter-2.gfsh b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/geode-starter-2.gfsh new file mode 100644 index 000000000000..d640a77c00da --- /dev/null +++ b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/geode-starter-2.gfsh @@ -0,0 +1,23 @@ +# +# 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. +# + +start locator --name=locator-maeve --connect=false --redirect-output --hostname-for-clients=locator-maeve --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/locator-maeve-keystore.jks +start server --name=server-dolores --group=group-dolores --hostname-for-clients=server-dolores --locators=geode[10334] --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/server-dolores-keystore.jks +start server --name=server-clementine --group=group-clementine --hostname-for-clients=server-clementine --server-port=40405 --locators=geode[10334] --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/server-clementine-keystore.jks +connect --locator=geode[10334] --use-ssl=true --security-properties-file=/geode/config/gfsecurity.properties +create region --name=region-dolores --group=group-dolores --type=REPLICATE +create region --name=region-clementine --group=group-clementine --type=REPLICATE diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/geode-starter.gfsh b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/geode-starter.gfsh index fa2c0d42cdc8..bd89a37da61e 100644 --- a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/geode-starter.gfsh +++ b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/geode-starter.gfsh @@ -15,7 +15,7 @@ # limitations under the License. # -start locator --name=locator-maeve --connect=false --hostname-for-clients=locator-maeve --jmx-manager-hostname-for-clients=geode --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/locator-maeve-keystore.jks +start locator --name=locator-maeve --connect=false --hostname-for-clients=locator-maeve --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/locator-maeve-keystore.jks start server --name=server-dolores --max-heap=256m --hostname-for-clients=server-dolores --locators=geode[10334] --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/server-dolores-keystore.jks connect --locator=geode[10334] --use-ssl=true --security-properties-file=/geode/config/gfsecurity.properties create region --name=jellyfish --type=REPLICATE diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/locator-maeve.gfsh b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/locator-maeve.gfsh deleted file mode 100644 index bcf32246395d..000000000000 --- a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/locator-maeve.gfsh +++ /dev/null @@ -1,18 +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. -# - -start locator --name=locator-maeve --connect=false --redirect-output --bind-address=locator-maeve --http-service-bind-address=locator-maeve --jmx-manager-hostname-for-clients=locator-maeve --hostname-for-clients=locator-maeve --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/locator-maeve-keystore.jks --J=-Dgemfire.forceDnsUse=true --J=-Djdk.tls.trustNameService=true diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/server-clementine.gfsh b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/server-clementine.gfsh deleted file mode 100644 index 09224452e37f..000000000000 --- a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/server-clementine.gfsh +++ /dev/null @@ -1,18 +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. -# - -start server --name=server-clementine --group=group-clementine --bind-address=server-clementine --http-service-bind-address=server-clementine --hostname-for-clients=server-clementine --server-port=8502 --locators=locator-maeve[10334] --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/server-clementine-keystore.jks --J=-Dgemfire.forceDnsUse=true --J=-Djdk.tls.trustNameService=true diff --git a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/server-dolores.gfsh b/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/server-dolores.gfsh deleted file mode 100644 index 4f128f5bcdf0..000000000000 --- a/geode-assembly/src/acceptanceTest/resources/org/apache/geode/client/sni/scripts/server-dolores.gfsh +++ /dev/null @@ -1,18 +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. -# - -start server --name=server-dolores --group=group-dolores --bind-address=server-dolores --http-service-bind-address=server-dolores --hostname-for-clients=server-dolores --server-port=8501 --locators=locator-maeve[10334] --properties-file=/geode/config/gemfire.properties --security-properties-file=/geode/config/gfsecurity.properties --J=-Dgemfire.ssl-keystore=/geode/config/server-dolores-keystore.jks --J=-Dgemfire.forceDnsUse=true --J=-Djdk.tls.trustNameService=true diff --git a/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java b/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java index b81625e8779f..59aaa805af08 100644 --- a/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java +++ b/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandIntegrationTest.java @@ -22,8 +22,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import java.io.InputStream; -import java.io.OutputStream; import java.util.Properties; import org.junit.Before; @@ -81,11 +79,7 @@ public void startLocatorRespectsJmxManagerHostnameForClients() throws Exception @Test public void startWithBindAddress() throws Exception { - final Process mockProcess = mock(Process.class); - doReturn(mock(InputStream.class)).when(mockProcess).getInputStream(); - doReturn(mock(InputStream.class)).when(mockProcess).getErrorStream(); - doReturn(mock(OutputStream.class)).when(mockProcess).getOutputStream(); - doReturn(mockProcess).when(spy).getProcess(any(), any()); + doReturn(mock(Process.class)).when(spy).getProcess(any(), any()); commandRule.executeAndAssertThat(spy, "start locator --bind-address=127.0.0.1"); ArgumentCaptor commandLines = ArgumentCaptor.forClass(String[].class); diff --git a/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectWithClusterConfigurationDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectWithClusterConfigurationDUnitTest.java index 8288ac21d6d5..d2c6d950bfcf 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectWithClusterConfigurationDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectWithClusterConfigurationDUnitTest.java @@ -31,8 +31,6 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; -import java.net.UnknownHostException; -import java.nio.file.Paths; import java.util.List; import java.util.Properties; import java.util.concurrent.TimeUnit; @@ -41,18 +39,16 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.distributed.Locator; +import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService; import org.apache.geode.distributed.internal.InternalLocator; import org.apache.geode.distributed.internal.membership.api.MembershipManagerHelper; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.internal.AvailablePort; import org.apache.geode.internal.AvailablePortHelper; -import org.apache.geode.internal.inet.LocalHostUtil; import org.apache.geode.test.awaitility.GeodeAwaitility; import org.apache.geode.test.dunit.Assert; import org.apache.geode.test.dunit.AsyncInvocation; @@ -72,14 +68,10 @@ public class ReconnectWithClusterConfigurationDUnitTest implements Serializable static Properties dsProperties; @Rule - public transient DistributedRule distributedRule = - DistributedRule.builder().withVMCount(NUM_VMS).build(); - - @Rule - public transient TemporaryFolder temporaryFolder = new TemporaryFolder(); + public DistributedRule distributedRule = DistributedRule.builder().withVMCount(NUM_VMS).build(); @Before - public void setup() throws IOException { + public void setup() { List randomAvailableTCPPortKeepers = AvailablePortHelper.getRandomAvailableTCPPortKeepers(NUM_LOCATORS); for (int i = 0; i < NUM_LOCATORS; i++) { @@ -89,7 +81,6 @@ public void setup() throws IOException { final int[] locPorts = locatorPorts; Invoke.invokeInEveryVM("set locator ports", () -> locatorPorts = locPorts); for (int i = 0; i < NUM_LOCATORS; i++) { - final String workingDir = temporaryFolder.newFolder().getAbsolutePath(); final int locatorNumber = i; randomAvailableTCPPortKeepers.get(locatorNumber).release(); VM.getVM(i).invoke("start locator", () -> { @@ -97,9 +88,7 @@ public void setup() throws IOException { Disconnect.disconnectFromDS(); dsProperties = null; Properties props = getDistributedSystemProperties(); - locator = InternalLocator.startLocator(locatorPorts[locatorNumber], new File(""), - null, null, new HostAddress(LocalHostUtil.getLocalHost()), true, - props, null, Paths.get(workingDir)); + locator = Locator.startLocatorAndDS(locatorPorts[locatorNumber], new File(""), props); system = locator.getDistributedSystem(); cache = ((InternalLocator) locator).getCache(); IgnoredException.addIgnoredException( @@ -117,8 +106,10 @@ public void teardown() { VM.getVM(i).invoke(() -> { InternalLocator locator = InternalLocator.getLocator(); if (locator != null) { - if (cache != null && cache.isReconnecting()) { - cache.stopReconnecting(); + InternalConfigurationPersistenceService sharedConfig = + locator.getConfigurationPersistenceService(); + if (sharedConfig != null) { + sharedConfig.destroySharedConfiguration(); } locator.stop(); } @@ -133,7 +124,7 @@ public void teardown() { }); } - public Properties getDistributedSystemProperties() throws UnknownHostException { + public Properties getDistributedSystemProperties() { dsProperties = new Properties(); dsProperties.put(MAX_WAIT_TIME_RECONNECT, "" + (5000 * NUM_VMS)); dsProperties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true"); @@ -142,13 +133,12 @@ public Properties getDistributedSystemProperties() throws UnknownHostException { dsProperties.put(USE_CLUSTER_CONFIGURATION, "true"); dsProperties.put(HTTP_SERVICE_PORT, "0"); StringBuilder stringBuilder = new StringBuilder(); - final String localHostName = LocalHostUtil.getLocalHostName(); - stringBuilder.append(localHostName + "[") + stringBuilder.append("localHost[") .append(locatorPorts[0]) .append(']'); for (int i = 1; i < NUM_LOCATORS; i++) { - stringBuilder.append("," + localHostName + "[") - .append(locatorPorts[i]) + stringBuilder.append(",localHost[") + .append(locatorPorts[0]) .append(']'); } dsProperties.put(LOCATORS, stringBuilder.toString()); diff --git a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java index e0f8966c281d..d3c17332f4ae 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/distributed/LocatorDUnitTest.java @@ -1002,8 +1002,7 @@ public void testNoLocator() { } catch (GemFireConfigException ex) { String s = ex.getMessage(); - assertThat(s.contains("Could not contact any of the locators")) - .isTrue(); + assertThat(s.contains("Locator does not exist")).isTrue(); } } diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorClusterManagementServiceIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorClusterManagementServiceIntegrationTest.java index 58598c0a87e7..0e0226ee6606 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorClusterManagementServiceIntegrationTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorClusterManagementServiceIntegrationTest.java @@ -28,12 +28,10 @@ import java.util.Optional; import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.internal.HttpService; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.internal.AvailablePortHelper; import org.apache.geode.internal.cache.InternalCacheForClientAccess; import org.apache.geode.internal.cache.InternalRegionFactory; @@ -45,40 +43,11 @@ public class InternalLocatorClusterManagementServiceIntegrationTest { private InternalLocator internalLocator; // the instance under test - private DistributionConfigImpl distributionConfig; - private InternalCacheForClientAccess cache; - private BaseManagementService managementService; - private AgentUtil agentUtil; - private HttpService httpService; - - @Before - public void setup() throws URISyntaxException { - distributionConfig = mock(DistributionConfigImpl.class); - cache = mock(InternalCacheForClientAccess.class); - managementService = mock(BaseManagementService.class); - agentUtil = mock(AgentUtil.class); - httpService = mock(HttpService.class); - InternalRegionFactory regionFactory = mock(InternalRegionFactory.class); - LoggingSession loggingSession = mock(LoggingSession.class); - URI uri = new URI("file", "/management.war", null); - - when(distributionConfig.getJmxManager()).thenReturn(true); - when(distributionConfig.getJmxManagerPort()) - .thenReturn(AvailablePortHelper.getRandomAvailableTCPPort()); - when(distributionConfig.getLocators()).thenReturn(""); - when(distributionConfig.getSecurableCommunicationChannels()) - .thenReturn(new SecurableCommunicationChannel[] {}); - when(distributionConfig.getSecurityAuthTokenEnabledComponents()).thenReturn(new String[] {}); - when(cache.createInternalRegionFactory(RegionShortcut.REPLICATE)).thenReturn(regionFactory); - when(cache.getOptionalService(HttpService.class)) - .thenReturn(Optional.of(httpService)); - when(cache.getCacheForProcessingClientRequests()).thenReturn(cache); - when(agentUtil.findWarLocation("geode-web-management")).thenReturn(uri); - BaseManagementService.setManagementService(cache, managementService); - - internalLocator = new InternalLocator(0, loggingSession, null, null, null, (HostAddress) null, - null, null, distributionConfig, null); - } + private DistributionConfigImpl distributionConfig = mock(DistributionConfigImpl.class); + private InternalCacheForClientAccess cache = mock(InternalCacheForClientAccess.class); + private BaseManagementService managementService = mock(BaseManagementService.class); + private AgentUtil agentUtil = mock(AgentUtil.class); + private HttpService httpService = mock(HttpService.class); @After public void tearDown() { diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java index f5041d42a0ae..09efe36b3596 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; +import java.net.InetAddress; import java.nio.file.Path; import java.util.Properties; @@ -36,7 +37,6 @@ import org.mockito.quality.Strictness; import org.apache.geode.distributed.Locator; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.internal.logging.InternalLogWriter; import org.apache.geode.internal.security.SecurableCommunicationChannel; import org.apache.geode.logging.internal.LoggingSession; @@ -58,7 +58,7 @@ public class InternalLocatorIntegrationTest { private InternalLogWriter logWriter; @Mock private InternalLogWriter securityLogWriter; - private HostAddress bindAddress; + private InetAddress bindAddress; private String hostnameForClients; @Mock private Properties distributedSystemProperties; @@ -98,9 +98,7 @@ public void constructs() { assertThatCode(() -> { internalLocator = new InternalLocator(port, loggingSession, logFile, logWriter, securityLogWriter, - bindAddress, - hostnameForClients, - distributedSystemProperties, distributionConfig, + bindAddress, hostnameForClients, distributedSystemProperties, distributionConfig, workingDirectory); }).doesNotThrowAnyException(); } diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java index 08f4fe1f7b1a..cb3c19a370c2 100755 --- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java @@ -31,6 +31,7 @@ import static org.mockito.Mockito.when; import java.io.File; +import java.net.InetAddress; import java.util.Comparator; import java.util.List; import java.util.Properties; @@ -65,7 +66,6 @@ import org.apache.geode.distributed.internal.membership.api.MembershipLocator; import org.apache.geode.distributed.internal.membership.api.MembershipView; import org.apache.geode.distributed.internal.membership.api.MessageListener; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.TcpClient; import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreator; import org.apache.geode.distributed.internal.tcpserver.TcpSocketFactory; @@ -137,7 +137,7 @@ private List doTestMultipleManagersInSameProcessWithGroups(String groups // boot up a locator int port = AvailablePortHelper.getRandomAvailableTCPPort(); - HostAddress localHost = new HostAddress(LocalHostUtil.getLocalHost()); + InetAddress localHost = LocalHostUtil.getLocalHost(); // this locator will hook itself up with the first Membership // to be created @@ -328,14 +328,13 @@ public void testLocatorAndTwoServersJoinUsingDiffeHellman() throws Exception { // boot up a locator int port = AvailablePortHelper.getRandomAvailableTCPPort(); - HostAddress localHost = new HostAddress(LocalHostUtil.getLocalHost()); + InetAddress localHost = LocalHostUtil.getLocalHost(); Properties p = new Properties(); p.setProperty(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128"); // this locator will hook itself up with the first Membership // to be created internalLocator = - InternalLocator.startLocator(port, new File(""), null, null, localHost, false, p, - null, + InternalLocator.startLocator(port, new File(""), null, null, localHost, false, p, null, temporaryFolder.getRoot().toPath()); // create configuration objects diff --git a/geode-core/src/main/java/org/apache/geode/distributed/Locator.java b/geode-core/src/main/java/org/apache/geode/distributed/Locator.java index 0a62382e5dcc..e4b2c9883319 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/Locator.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/Locator.java @@ -22,7 +22,6 @@ import java.util.Properties; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.internal.inet.LocalHostUtil; /** @@ -64,11 +63,8 @@ public abstract class Locator { /** The file to which this locator logs */ protected File logFile; - /** no longer used but kept for binary compatibility */ - protected InetAddress bindAddress; - /** The bind address for this locator */ - protected HostAddress hostAddress; + protected InetAddress bindAddress; /** * the hostname to give to clients so they can connect to this locator. @@ -105,7 +101,7 @@ public abstract class Locator { */ public static Locator startLocator(int port, File logFile) throws IOException { - return startLocator(port, logFile, false, null, null, true, true, + return startLocator(port, logFile, false, (InetAddress) null, (Properties) null, true, true, null); } @@ -140,7 +136,7 @@ public static Locator startLocator(int port, File logFile) throws IOException { public static Locator startLocatorAndDS(int port, File logFile, Properties distributedSystemProperties) throws IOException { - return startLocator(port, logFile, null, distributedSystemProperties, true, true, + return startLocator(port, logFile, (InetAddress) null, distributedSystemProperties, true, true, null); } @@ -169,9 +165,8 @@ public static Locator startLocatorAndDS(int port, File logFile, */ public static Locator startLocator(int port, File logFile, InetAddress bindAddress) throws IOException { - HostAddress hostAddress = bindAddress == null ? null : new HostAddress(bindAddress); - return startLocator(port, logFile, false, hostAddress, null, true, - true, null); + + return startLocator(port, logFile, false, bindAddress, (Properties) null, true, true, null); } @@ -203,9 +198,7 @@ public static Locator startLocator(int port, File logFile, InetAddress bindAddre */ public static Locator startLocatorAndDS(int port, File logFile, InetAddress bindAddress, java.util.Properties dsProperties) throws IOException { - HostAddress hostAddress = bindAddress == null ? null : new HostAddress(bindAddress); - return startLocator(port, logFile, hostAddress, dsProperties, true, true, - null); + return startLocator(port, logFile, bindAddress, dsProperties, true, true, null); } /** @@ -246,16 +239,14 @@ public static Locator startLocatorAndDS(int port, File logFile, InetAddress bind public static Locator startLocatorAndDS(int port, File logFile, InetAddress bindAddress, java.util.Properties dsProperties, boolean peerLocator, boolean serverLocator, String hostnameForClients) throws IOException { - HostAddress hostAddress = bindAddress == null ? null : new HostAddress(bindAddress); - return startLocator(port, logFile, hostAddress, dsProperties, true, true, - hostnameForClients); + return startLocator(port, logFile, bindAddress, dsProperties, true, true, hostnameForClients); } /** * all Locator methods that start locators should use this method to start the locator and its * distributed system */ - private static Locator startLocator(int port, File logFile, HostAddress bindAddress, + private static Locator startLocator(int port, File logFile, InetAddress bindAddress, java.util.Properties dsProperties, boolean peerLocator, boolean serverLocator, String hostnameForClients) throws IOException { return InternalLocator.startLocator(port, logFile, null, null, bindAddress, true, dsProperties, @@ -267,7 +258,7 @@ private static Locator startLocator(int port, File logFile, HostAddress bindAddr * peerLocator, serverLocator, hostnameForClients) instead. */ private static Locator startLocator(int port, File logFile, boolean startDistributedSystem, - HostAddress bindAddress, java.util.Properties dsProperties, boolean peerLocator, + InetAddress bindAddress, java.util.Properties dsProperties, boolean peerLocator, boolean serverLocator, String hostnameForClients) throws IOException { return InternalLocator.startLocator(port, logFile, null, null, bindAddress, startDistributedSystem, dsProperties, hostnameForClients); @@ -341,7 +332,7 @@ public File getLogFile() { * Returns the IP address to which this locator's listening socket is bound. */ public InetAddress getBindAddress() { - return bindAddress; + return this.bindAddress; } /** @@ -391,16 +382,14 @@ public String toString() { * Get the string representation of this Locator in host[port] format. */ public String asString() { - String bindAddressString = null; - if (hostAddress == null) { + Object ba = this.bindAddress; + if (ba == null) { try { - bindAddressString = LocalHostUtil.getLocalHostName(); + ba = LocalHostUtil.getLocalHostName(); } catch (java.net.UnknownHostException uh) { } - } else { - bindAddressString = hostAddress.getHostName(); } - StringBuilder locatorString = new StringBuilder(String.valueOf(bindAddressString)); + StringBuilder locatorString = new StringBuilder(String.valueOf(ba)); Integer port = getPort(); if (port != null && port.intValue() > 0) { locatorString.append('[').append(this.getPort()).append(']'); diff --git a/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java index bab4a14c1ece..0cd015e27ece 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/LocatorLauncher.java @@ -60,7 +60,6 @@ import org.apache.geode.cache.client.internal.locator.LocatorStatusRequest; import org.apache.geode.cache.client.internal.locator.LocatorStatusResponse; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.HostAndPort; import org.apache.geode.distributed.internal.tcpserver.TcpClient; import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreator; @@ -188,7 +187,7 @@ public class LocatorLauncher extends AbstractLauncher { private final boolean portSpecified; private final boolean workingDirectorySpecified; - private final HostAddress bindAddress; + private final InetAddress bindAddress; private final Integer pid; private final Integer port; @@ -260,7 +259,7 @@ private LocatorLauncher(final Builder builder) { this.command = builder.getCommand(); this.help = Boolean.TRUE.equals(builder.getHelp()); this.bindAddressSpecified = builder.isBindAddressSpecified(); - this.bindAddress = builder.getHostAddress(); + this.bindAddress = builder.getBindAddress(); setDebug(Boolean.TRUE.equals(builder.getDebug())); this.deletePidFileOnStop = Boolean.TRUE.equals(builder.getDeletePidFileOnStop()); this.distributedSystemProperties = builder.getDistributedSystemProperties(); @@ -298,31 +297,19 @@ public ServiceState handleStatus() { @Deprecated public static LocatorStatusResponse statusLocator(int port, InetAddress bindAddress) throws IOException { - return statusLocator(port, bindAddress == null ? null : bindAddress.getCanonicalHostName(), - new Properties()); - } - - /** - * Returns the status of the locator on the given host & port. If you have endpoint - * identification enabled the preferred method is statusForLocator(int, String), which - * lets you specify the locator's name that the locator has stored in its TLS certificate - */ - public LocatorStatusResponse statusForLocator(int port, InetAddress bindAddress) - throws IOException { - return statusLocator(port, bindAddress == null ? null : bindAddress.getCanonicalHostName(), - getProperties()); + return statusLocator(port, bindAddress, new Properties()); } /** * Returns the status of the locator on the given host & port */ - public LocatorStatusResponse statusForLocator(int port, String hostname) + public LocatorStatusResponse statusForLocator(int port, InetAddress bindAddress) throws IOException { - return statusLocator(port, hostname, getProperties()); + return statusLocator(port, bindAddress, getProperties()); } private static LocatorStatusResponse statusLocator( - final int port, String bindAddress, + final int port, InetAddress bindAddress, final Properties properties) throws IOException { @@ -341,7 +328,7 @@ private static LocatorStatusResponse statusLocator( TcpSocketFactory.DEFAULT); return (LocatorStatusResponse) client.requestToServer( - new HostAndPort(bindAddress == null ? HostUtils.getLocalHost() : bindAddress, port), + new HostAndPort(bindAddress == null ? null : bindAddress.getCanonicalHostName(), port), new LocatorStatusRequest(), timeout, true); } catch (ClassNotFoundException e) { throw new RuntimeException(e); @@ -442,7 +429,7 @@ public boolean isRedirectingOutput() { * @see java.net.InetAddress */ public InetAddress getBindAddress() { - return bindAddress == null ? null : bindAddress.getAddress(); + return this.bindAddress; } /** @@ -461,9 +448,10 @@ public InetAddress getBindAddress() { */ protected String getBindAddressAsString() { try { - if (bindAddress != null) { - return bindAddress.getHostName(); + if (getBindAddress() != null) { + return getBindAddress().getCanonicalHostName(); } + return LocalHostUtil.getCanonicalLocalHostName(); } catch (UnknownHostException handled) { // Returning localhost/127.0.0.1 implies the bindAddress was null and no IP address for @@ -726,8 +714,7 @@ public LocatorState start() { try { this.locator = InternalLocator.startLocator(getPort(), getLogFile(), null, null, - bindAddress, true, getDistributedSystemProperties(), - getHostnameForClients(), + getBindAddress(), true, getDistributedSystemProperties(), getHostnameForClients(), Paths.get(workingDirectory)); } finally { ProcessLauncherContext.remove(); @@ -873,7 +860,7 @@ public LocatorState waitOnStatusResponse(final long timeout, final long interval while (System.currentTimeMillis() < endTimeInMilliseconds) { try { - LocatorStatusResponse response = statusForLocator(getPort(), getBindAddressString()); + LocatorStatusResponse response = statusForLocator(getPort(), getBindAddress()); return new LocatorState(this, Status.ONLINE, response); } catch (Exception handled) { timedWait(interval, timeUnit); @@ -998,7 +985,7 @@ private LocatorState statusWithPid() { private LocatorState statusWithPort() { try { - LocatorStatusResponse response = statusForLocator(getPort(), getBindAddressString()); + LocatorStatusResponse response = statusForLocator(getPort(), getBindAddress()); return new LocatorState(this, Status.ONLINE, response); } catch (Exception handled) { return createNoResponseState(handled, @@ -1199,10 +1186,6 @@ private Properties getOverriddenDefaults() throws IOException { return overriddenDefaults; } - public String getBindAddressString() { - return bindAddress == null ? null : bindAddress.getHostName(); - } - private class LocatorControllerParameters implements ProcessControllerParameters { @Override public File getPidFile() { @@ -1277,7 +1260,7 @@ public static class Builder { private Boolean loadSharedConfigFromDir; private Command command; - private HostAddress bindAddress; + private InetAddress bindAddress; private Integer pid; private Integer port; @@ -1588,18 +1571,14 @@ boolean isBindAddressSpecified() { * @see java.net.InetAddress */ public InetAddress getBindAddress() { - return bindAddress == null ? null : bindAddress.getAddress(); - } - - HostAddress getHostAddress() { - return bindAddress; + return this.bindAddress; } /** * Sets the IP address as an java.net.InetAddress to which the Locator has bound itself * listening for client requests. * - * @param addressString the InetAddress with the IP address or hostname on which the Locator is + * @param bindAddress the InetAddress with the IP address or hostname on which the Locator is * bound and listening. * @return this Builder instance. * @throws IllegalArgumentException wrapping the UnknownHostException if the IP address or @@ -1607,23 +1586,24 @@ HostAddress getHostAddress() { * @see #getBindAddress() * @see java.net.InetAddress */ - public Builder setBindAddress(final String addressString) { - if (isBlank(addressString)) { + public Builder setBindAddress(final String bindAddress) { + if (isBlank(bindAddress)) { this.bindAddress = null; return this; } else { try { - InetAddress address = InetAddress.getByName(addressString); + InetAddress address = InetAddress.getByName(bindAddress); if (LocalHostUtil.isLocalHost(address)) { - this.bindAddress = new HostAddress(addressString); + this.bindAddress = address; return this; } else { throw new IllegalArgumentException( - addressString + " is not an address for this machine."); + bindAddress + " is not an address for this machine."); } } catch (UnknownHostException e) { - throw new IllegalArgumentException("The hostname/IP address (" + addressString - + ") to which the Locator will be bound is unknown.", + throw new IllegalArgumentException( + String.format("The hostname/IP address to which the %s will be bound is unknown.", + "Locator"), e); } } @@ -2150,9 +2130,11 @@ private static String getLocatorLocation(LocatorLauncher launcher) { private static String getBindAddressAsString(LocatorLauncher launcher) { if (InternalLocator.hasLocator()) { final InternalLocator locator = InternalLocator.getLocator(); - String bindAddress = locator.getBindAddressString(); - if (bindAddress != null && !bindAddress.isEmpty()) { - return bindAddress; + final InetAddress bindAddress = locator.getBindAddress(); + if (bindAddress != null) { + if (isNotBlank(bindAddress.getHostAddress())) { + return bindAddress.getHostAddress(); + } } } return launcher.getBindAddressAsString(); diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalDistributedSystem.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalDistributedSystem.java index 847e581e70cb..d45df2e0e154 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalDistributedSystem.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalDistributedSystem.java @@ -79,7 +79,6 @@ import org.apache.geode.distributed.internal.membership.api.MembershipInformation; import org.apache.geode.distributed.internal.membership.api.MembershipLocator; import org.apache.geode.distributed.internal.membership.api.QuorumChecker; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.internal.Assert; import org.apache.geode.internal.InternalDataSerializer; import org.apache.geode.internal.InternalInstantiator; @@ -915,9 +914,8 @@ private void startInitLocator( try { startedLocator = InternalLocator.createLocator(locId.getPort(), NullLoggingSession.create(), null, - logWriter, securityLogWriter, new HostAddress(locId.getHost()), - locId.getHostnameForClients(), originalConfig.toProperties(), - false); + logWriter, securityLogWriter, locId.getHost().getAddress(), + locId.getHostnameForClients(), originalConfig.toProperties(), false); // if locator is started this way, cluster config is not enabled, set the flag correctly startedLocator.getConfig().setEnableClusterConfiguration(false); diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java index 543e1e36fff4..52dad50b8367 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; +import java.net.InetAddress; import java.net.URI; import java.net.UnknownHostException; import java.nio.file.Path; @@ -68,7 +69,6 @@ import org.apache.geode.distributed.internal.membership.api.MembershipLocator; import org.apache.geode.distributed.internal.membership.api.MembershipLocatorBuilder; import org.apache.geode.distributed.internal.membership.api.QuorumChecker; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.InfoRequest; import org.apache.geode.distributed.internal.tcpserver.TcpHandler; import org.apache.geode.distributed.internal.tcpserver.TcpServer; @@ -258,16 +258,13 @@ private static void removeLocator(InternalLocator locator) { * @param startDistributedSystem if true then this locator will also start its own ds * * @deprecated Please use - * {@link #createLocator(int, LoggingSession, File, InternalLogWriter, InternalLogWriter, HostAddress, String, Properties, Path)} + * {@link #createLocator(int, LoggingSession, File, InternalLogWriter, InternalLogWriter, InetAddress, String, Properties, Path)} * instead. */ @Deprecated public static InternalLocator createLocator(int port, LoggingSession loggingSession, File logFile, - InternalLogWriter logWriter, - InternalLogWriter securityLogWriter, - HostAddress bindAddress, - String hostnameForClients, - Properties distributedSystemProperties, + InternalLogWriter logWriter, InternalLogWriter securityLogWriter, InetAddress bindAddress, + String hostnameForClients, Properties distributedSystemProperties, boolean startDistributedSystem) { return createLocator(port, loggingSession, logFile, logWriter, securityLogWriter, bindAddress, hostnameForClients, distributedSystemProperties, @@ -285,18 +282,13 @@ public static InternalLocator createLocator(int port, LoggingSession loggingSess * @param logFile the file that log messages should be written to * @param logWriter a log writer that should be used (logFile parameter is ignored) * @param securityLogWriter the logWriter to be used for security related log messages - * @param bindAddress the bind address for the locator * @param distributedSystemProperties optional properties to configure the distributed system * (e.g., mcast addr/port, other locators) * @param workingDirectory the working directory to use for any files */ public static InternalLocator createLocator(int port, LoggingSession loggingSession, File logFile, - InternalLogWriter logWriter, - InternalLogWriter securityLogWriter, - HostAddress bindAddress, - String hostnameForClients, - Properties distributedSystemProperties, - Path workingDirectory) { + InternalLogWriter logWriter, InternalLogWriter securityLogWriter, InetAddress bindAddress, + String hostnameForClients, Properties distributedSystemProperties, Path workingDirectory) { synchronized (locatorLock) { if (hasLocator()) { throw new IllegalStateException( @@ -340,7 +332,7 @@ private static void setLocator(InternalLocator locator) { * @param hostnameForClients the name to give to clients for connecting to this locator */ public static InternalLocator startLocator(int port, File logFile, InternalLogWriter logWriter, - InternalLogWriter securityLogWriter, HostAddress bindAddress, boolean startDistributedSystem, + InternalLogWriter securityLogWriter, InetAddress bindAddress, boolean startDistributedSystem, Properties distributedSystemProperties, String hostnameForClients) throws IOException { return startLocator(port, logFile, logWriter, securityLogWriter, bindAddress, @@ -359,7 +351,6 @@ public static InternalLocator startLocator(int port, File logFile, InternalLogWr * @param logFile the file that log messages should be written to * @param logWriter a log writer that should be used (logFile parameter is ignored) * @param securityLogWriter the logWriter to be used for security related log messages - * @param bindAddress the bind address for the locator * @param startDistributedSystem if true, a distributed system is started * @param distributedSystemProperties optional properties to configure the distributed system * (e.g., mcast @@ -368,11 +359,8 @@ public static InternalLocator startLocator(int port, File logFile, InternalLogWr * @param workingDirectory the working directory to use for any files */ public static InternalLocator startLocator(int port, File logFile, InternalLogWriter logWriter, - InternalLogWriter securityLogWriter, - HostAddress bindAddress, - boolean startDistributedSystem, - Properties distributedSystemProperties, - String hostnameForClients, Path workingDirectory) + InternalLogWriter securityLogWriter, InetAddress bindAddress, boolean startDistributedSystem, + Properties distributedSystemProperties, String hostnameForClients, Path workingDirectory) throws IOException { System.setProperty(FORCE_LOCATOR_DM_TYPE, "true"); InternalLocator newLocator = null; @@ -477,17 +465,11 @@ public static boolean isDedicatedLocator() { */ @VisibleForTesting InternalLocator(int port, LoggingSession loggingSession, File logFile, - InternalLogWriter logWriter, InternalLogWriter securityLogWriter, - HostAddress hostAddress, String hostnameForClients, - Properties distributedSystemProperties, + InternalLogWriter logWriter, InternalLogWriter securityLogWriter, InetAddress bindAddress, + String hostnameForClients, Properties distributedSystemProperties, DistributionConfigImpl distributionConfig, Path workingDirectory) { this.logFile = logFile; - this.hostAddress = hostAddress; - // bindAddress is superceded by hostAddress but must be kept for Locator API backward - // compatibility - if (hostAddress != null) { - this.bindAddress = hostAddress.getAddress(); - } + this.bindAddress = bindAddress; this.hostnameForClients = hostnameForClients; this.workingDirectory = workingDirectory; @@ -497,8 +479,8 @@ public static boolean isDedicatedLocator() { // set bind-address explicitly only if not wildcard and let any explicit // value in distributedSystemProperties take precedence - if (hostAddress != null) { - env.setProperty(BIND_ADDRESS, hostAddress.getHostName()); + if (bindAddress != null && !bindAddress.isAnyLocalAddress()) { + env.setProperty(BIND_ADDRESS, bindAddress.getHostAddress()); } if (distributedSystemProperties != null) { @@ -573,7 +555,7 @@ MAX_POOL_SIZE, new DelayedPoolStatHelper(), executor) .setConfig(config) .setPort(port) - .setBindAddress(hostAddress) + .setBindAddress(bindAddress) .setProtocolChecker(new ProtocolCheckerImpl(this, new ClientProtocolServiceLoader())) .setFallbackHandler(handler) .setLocatorsAreCoordinators(shouldLocatorsBeCoordinators()) @@ -693,7 +675,7 @@ public MembershipLocator getMembershipLocator() { */ @Deprecated public static InternalLocator startLocator(int locatorPort, File logFile, - InternalLogWriter logWriter, InternalLogWriter securityLogWriter, HostAddress bindAddress, + InternalLogWriter logWriter, InternalLogWriter securityLogWriter, InetAddress bindAddress, Properties distributedSystemProperties, boolean peerLocator, boolean serverLocator, String hostnameForClients, boolean b1) throws IOException { return startLocator(locatorPort, logFile, logWriter, securityLogWriter, bindAddress, true, @@ -716,8 +698,8 @@ private void startDistributedSystem() throws IOException { } else { StringBuilder sb = new StringBuilder(100); - if (hostAddress != null && !StringUtils.isEmpty(hostAddress.getHostName())) { - sb.append(hostAddress.getHostName()); + if (bindAddress != null) { + sb.append(bindAddress.getHostAddress()); } else { sb.append(LocalHostUtil.getLocalHost().getCanonicalHostName()); } @@ -906,9 +888,8 @@ void startServerLocation(InternalDistributedSystem distributedSystem) throws IOE } } - ServerLocator serverLocator = - new ServerLocator(getPort(), getBindAddressString(), hostnameForClients, - logFile, productUseLog, getConfig().getName(), distributedSystem, locatorStats); + ServerLocator serverLocator = new ServerLocator(getPort(), bindAddress, hostnameForClients, + logFile, productUseLog, getConfig().getName(), distributedSystem, locatorStats); restartHandlers.add(serverLocator); membershipLocator.addHandler(LocatorListRequest.class, serverLocator); membershipLocator.addHandler(ClientConnectionRequest.class, serverLocator); @@ -1440,13 +1421,6 @@ public boolean hasHandlerForClass(Class messageClass) { return membershipLocator.isHandled(messageClass); } - public String getBindAddressString() { - if (hostAddress != null) { - return hostAddress.getHostName(); - } - return null; - } - class FetchSharedConfigStatus implements Callable { @Override diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java index 5064d99dba9d..075489fefe5a 100755 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.IOException; +import java.net.InetAddress; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -107,15 +108,15 @@ public LocatorLoadSnapshot getLoadSnapshot() { return loadSnapshot; } - public ServerLocator(int port, String bindAddress, String hostNameForClients, File logFile, + public ServerLocator(int port, InetAddress bindAddress, String hostNameForClients, File logFile, ProductUseLog productUseLogWriter, String memberName, InternalDistributedSystem ds, LocatorStats stats) throws IOException { this.port = port; - if (bindAddress == null || bindAddress.isEmpty()) { + if (bindAddress == null) { this.hostName = LocalHostUtil.getCanonicalLocalHostName(); } else { - this.hostName = bindAddress; + this.hostName = bindAddress.getHostAddress(); } if (hostNameForClients != null && !hostNameForClients.equals("")) { diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/adapter/ServiceConfig.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/adapter/ServiceConfig.java index de568821fe9f..8788f3412a37 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/adapter/ServiceConfig.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/adapter/ServiceConfig.java @@ -66,9 +66,10 @@ public ServiceConfig(RemoteTransportConfig transport, DistributionConfig theConf joinTimeout = Long.getLong("p2p.joinTimeout", defaultJoinTimeout).longValue(); + // if network partition detection is enabled, we must connect to the locators + // more frequently in order to make sure we're not isolated from them SocketCreator.resolve_dns = true; - if (theConfig.getEnableNetworkPartitionDetection() && - !theConfig.getSSLEndPointIdentificationEnabled()) { + if (theConfig.getEnableNetworkPartitionDetection()) { if (!SocketCreator.FORCE_DNS_USE) { SocketCreator.resolve_dns = false; } diff --git a/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java b/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java index 8815a6aa1627..731459cd329c 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java +++ b/geode-core/src/main/java/org/apache/geode/internal/DistributionLocator.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.net.InetAddress; +import java.util.Properties; import org.apache.logging.log4j.Logger; @@ -25,7 +26,6 @@ import org.apache.geode.annotations.internal.MakeNotStatic; import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.logging.internal.executors.LoggingThread; import org.apache.geode.logging.internal.log4j.api.LogService; import org.apache.geode.util.internal.GeodeGlossary; @@ -109,7 +109,9 @@ public static void main(String args[]) { SystemFailure.loadEmergencyClasses(); final int port = parsePort(args[0]); - HostAddress hostAddress = null; + InetAddress address = null; + boolean peerLocator = true; + boolean serverLocator = true; String hostnameForClients = null; try { if (args.length > 1 && !args[1].equals("")) { @@ -119,37 +121,43 @@ public static void main(String args[]) { args[1])); ExitCode.FATAL.doSystemExit(); } - hostAddress = new HostAddress(args[1]); - // do a look-up to ensure that the name can be resolved to an address - InetAddress.getByName(args[1]); + address = InetAddress.getByName(args[1]); } else { // address = null; // was InetAddress.getLocalHost(); (redundant assignment) } + if (args.length > 2) { + peerLocator = "true".equalsIgnoreCase(args[2]); + } + if (args.length > 3) { + serverLocator = "true".equalsIgnoreCase(args[3]); + } if (args.length > 4) { hostnameForClients = args[4]; } - final InetAddress inetAddress = hostAddress == null ? null : hostAddress.getAddress(); if (!Boolean.getBoolean(InternalDistributedSystem.DISABLE_SHUTDOWN_HOOK_PROPERTY)) { + final InetAddress faddress = address; Runtime.getRuntime() .addShutdownHook(new LoggingThread("LocatorShutdownThread", false, () -> { try { - DistributionLocator.shutdown(port, inetAddress); + DistributionLocator.shutdown(port, faddress); } catch (IOException e) { e.printStackTrace(); } })); } - lockFile = ManagerInfo.setLocatorStarting(directory, port, inetAddress); + lockFile = ManagerInfo.setLocatorStarting(directory, port, address); lockFile.deleteOnExit(); - InetAddress address = hostAddress == null ? null : hostAddress.getAddress(); try { + InternalLocator locator = InternalLocator.startLocator(port, new File(DEFAULT_LOG_FILE), - null, null, hostAddress, true, null, hostnameForClients); + null, null, address, true, (Properties) null, hostnameForClients); + ManagerInfo.setLocatorStarted(directory, port, address); locator.waitToStop(); + } finally { shutdown(port, address); } @@ -160,7 +168,7 @@ public static void main(String args[]) { } catch (java.net.BindException ex) { logger.fatal("Could not bind locator to {}[{}]", - new Object[] {hostAddress, port}); + new Object[] {address, port}); ExitCode.FATAL.doSystemExit(); } catch (Exception ex) { diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java index b5572a824336..c4ecb46b964d 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java @@ -26,7 +26,6 @@ import org.apache.geode.InternalGemFireException; import org.apache.geode.distributed.Locator; import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.distributed.internal.InternalLocator; import org.apache.geode.distributed.internal.tcpserver.HostAndPort; import org.apache.geode.internal.inet.LocalHostUtil; import org.apache.geode.internal.net.SSLConfig; @@ -174,11 +173,7 @@ public DistributionLocatorId(String marshalled) { public DistributionLocatorId(InetAddress address, Locator locator) { this(address, locator.getPort(), - (((InternalLocator) locator).getBindAddressString() != null - ? ((InternalLocator) locator).getBindAddressString() - : (locator.getBindAddress() != null ? locator.getBindAddress().getHostAddress() - : null)), - null, + locator.getBindAddress() == null ? null : locator.getBindAddress().getHostAddress(), null, locator.getHostnameForClients()); } diff --git a/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java b/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java index 4ac863b3dd96..22f2e96a690f 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java +++ b/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java @@ -62,6 +62,7 @@ import javax.net.ssl.X509ExtendedKeyManager; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.validator.routines.InetAddressValidator; import org.apache.logging.log4j.Logger; import org.apache.geode.GemFireConfigException; @@ -833,6 +834,17 @@ private boolean setServerNames(SSLParameters modifiedParams, HostAndPort addr) { } String hostName = addr.getHostName(); + if (this.sslConfig.doEndpointIdentification() + && InetAddressValidator.getInstance().isValid(hostName)) { + // endpoint validation typically uses a hostname in the sniServer parameter that the handshake + // will compare against the subject alternative addresses in the server's certificate. Here + // we attempt to get a hostname instead of the proffered numeric address + try { + hostName = InetAddress.getByName(hostName).getCanonicalHostName(); + } catch (UnknownHostException e) { + // ignore - we'll see what happens with endpoint validation using a numeric address... + } + } serverNames.add(new SNIHostName(hostName)); modifiedParams.setServerNames(serverNames); return true; diff --git a/geode-core/src/main/java/org/apache/geode/internal/tcp/Connection.java b/geode-core/src/main/java/org/apache/geode/internal/tcp/Connection.java index 9e0e96e03a99..24b1d7f07d4a 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/tcp/Connection.java +++ b/geode-core/src/main/java/org/apache/geode/internal/tcp/Connection.java @@ -1725,14 +1725,8 @@ private void readMessages() { private void createIoFilter(SocketChannel channel, boolean clientSocket) throws IOException { if (getConduit().useSSL() && channel != null) { InetSocketAddress address = (InetSocketAddress) channel.getRemoteAddress(); - String hostName; - if (remoteAddr != null) { - hostName = remoteAddr.getHostName(); - } else { - hostName = SocketCreator.getHostName(address.getAddress()); - } SSLEngine engine = - getConduit().getSocketCreator().createSSLEngine(hostName, + getConduit().getSocketCreator().createSSLEngine(address.getHostString(), address.getPort(), clientSocket); int packetBufferSize = engine.getSession().getPacketBufferSize(); diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java index 7180a9d8bf35..5a98dcaa9557 100644 --- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java +++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; +import java.net.InetAddress; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -315,9 +316,9 @@ ResultModel doStartLocator( infoResult.addLine(locatorState.toString()); String locatorHostName; - String bindAddr = locatorLauncher.getBindAddressString(); + InetAddress bindAddr = locatorLauncher.getBindAddress(); if (bindAddr != null) { - locatorHostName = bindAddr; + locatorHostName = bindAddr.getCanonicalHostName(); } else { locatorHostName = StringUtils.defaultIfBlank(locatorLauncher.getHostnameForClients(), HostUtils.getLocalHost()); @@ -482,8 +483,8 @@ String[] createStartLocatorCommandLine(final LocatorLauncher launcher, commandLine.add(launcher.getMemberName()); } - if (launcher.getBindAddressString() != null) { - commandLine.add("--bind-address=" + launcher.getBindAddressString()); + if (launcher.getBindAddress() != null) { + commandLine.add("--bind-address=" + launcher.getBindAddress().getHostAddress()); } if (launcher.isDebugging() || isDebugging()) { diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java index ee7759bf6317..2433387fa43e 100644 --- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java +++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java @@ -130,9 +130,8 @@ public JmxOperationInvoker(final String host, final int port, Properties gfPrope env.put("com.sun.jndi.rmi.factory.socket", new ContextAwareSSLRMIClientSocketFactory()); } - final String hostName = checkAndConvertToCompatibleIPv6Syntax(host); this.url = new JMXServiceURL(MessageFormat.format(JMX_URL_FORMAT, - hostName, String.valueOf(port))); + checkAndConvertToCompatibleIPv6Syntax(host), String.valueOf(port))); this.connector = JMXConnectorFactory.connect(url, env); this.mbsc = connector.getMBeanServerConnection(); this.connector.addConnectionNotificationListener(new JMXConnectionListener(this), null, null); diff --git a/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryIntegrationTest.java b/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryIntegrationTest.java index bfe48191cc78..16b09e6a2325 100644 --- a/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryIntegrationTest.java +++ b/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryIntegrationTest.java @@ -49,7 +49,6 @@ import org.apache.geode.distributed.internal.membership.gms.MembershipLocatorStatisticsNoOp; import org.apache.geode.distributed.internal.membership.gms.Services; import org.apache.geode.distributed.internal.membership.gms.util.MemberIdentifierUtil; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.TcpClient; import org.apache.geode.distributed.internal.tcpserver.TcpServer; import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreatorImpl; @@ -155,7 +154,7 @@ public void testRecoverFromOther() throws Exception { final TcpSocketCreatorImpl socketCreator = new TcpSocketCreatorImpl(); locator = MembershipLocatorBuilder.newLocatorBuilder(socketCreator, serializer, temporaryFolder.getRoot().toPath(), executorServiceSupplier) - .setBindAddress(new HostAddress(localHost)).create(); + .setBindAddress(localHost).create(); final int port = locator.start(); try { @@ -183,7 +182,7 @@ public String getLocators() { // now create a peer location handler that should recover from our real locator and know // that real locator's identifier - GMSLocator gmsLocator = new GMSLocator(new HostAddress(localHost), + GMSLocator gmsLocator = new GMSLocator(localHost, membership.getLocalMember().getHost() + "[" + port + "]", true, true, new MembershipLocatorStatisticsNoOp(), "", temporaryFolder.getRoot().toPath(), locatorClient, diff --git a/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java b/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java index 47ec0ffaede1..3a86a1e5a320 100644 --- a/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java +++ b/geode-membership/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java @@ -22,14 +22,12 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -117,18 +115,11 @@ public void initMocks(boolean enableNetworkPartition) throws Exception { public void initMocks(boolean enableNetworkPartition, boolean useTestGMSJoinLeave) throws Exception { - String locator = "localhost[12345]"; - initMocks(enableNetworkPartition, useTestGMSJoinLeave, locator, locator); - } - - public void initMocks(boolean enableNetworkPartition, boolean useTestGMSJoinLeave, - String locators, String startLocator) - throws Exception { mockConfig = mock(MembershipConfig.class); when(mockConfig.isNetworkPartitionDetectionEnabled()).thenReturn(enableNetworkPartition); when(mockConfig.getSecurityUDPDHAlgo()).thenReturn(""); - when(mockConfig.getStartLocator()).thenReturn(startLocator); - when(mockConfig.getLocators()).thenReturn(locators); + when(mockConfig.getStartLocator()).thenReturn("localhost[12345]"); + when(mockConfig.getLocators()).thenReturn("localhost[12345]"); when(mockConfig.getMcastPort()).thenReturn(0); when(mockConfig.getMemberTimeout()).thenReturn(2000L); @@ -1432,7 +1423,14 @@ private GMSMembershipView createView() { @Test public void testCoordinatorFindRequestSuccess() throws Exception { initMocks(false); - mockRequestToServer(isA(HostAndPort.class)); + HashSet registrants = new HashSet<>(); + registrants.add(mockMembers[0]); + FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, + null, registrants, false, true, null); + + when(locatorClient.requestToServer(isA(HostAndPort.class), + isA(FindCoordinatorRequest.class), anyInt(), anyBoolean())) + .thenReturn(fcr); boolean foundCoordinator = gmsJoinLeave.findCoordinator(); assertTrue(gmsJoinLeave.searchState.toString(), foundCoordinator); @@ -1443,80 +1441,22 @@ public void testCoordinatorFindRequestSuccess() throws Exception { public void testCoordinatorFindRequestFailure() throws Exception { try { initMocks(false); - mockRequestToServer(eq(new HostAndPort("localhost", 12346))); + HashSet registrants = new HashSet<>(); + registrants.add(mockMembers[0]); + FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], + false, null, registrants, false, true, null); GMSMembershipView view = createView(); JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0); gmsJoinLeave.setJoinResponseMessage(jrm); - assertThatThrownBy(gmsJoinLeave::join) - .isInstanceOf(MembershipConfigurationException.class); - } finally { - } - } - - @Test - public void testJoinFailureWhenSleepInterrupted() throws Exception { - initMocks(false); - mockRequestToServer(isA(HostAndPort.class)); - - when(mockConfig.getMemberTimeout()).thenReturn(100L); - when(mockConfig.getJoinTimeout()).thenReturn(1000L); - - GMSJoinLeave spyGmsJoinLeave = spy(gmsJoinLeave); - when(spyGmsJoinLeave.pauseIfThereIsNoCoordinator(-1, GMSJoinLeave.JOIN_RETRY_SLEEP)) - .thenThrow(new InterruptedException()); - - assertThatThrownBy(spyGmsJoinLeave::join) - .isInstanceOf(MembershipConfigurationException.class) - .hasMessageContaining("Retry sleep interrupted"); - } - - @Test - public void testJoinFailureWhenTimeout() throws Exception { - initMocks(false); - mockRequestToServer(isA(HostAndPort.class)); - - assertThatThrownBy(() -> gmsJoinLeave.join()) - .isInstanceOf(MembershipConfigurationException.class) - .hasMessageContaining("Operation timed out"); - } - - @Test - public void testPauseIfThereIsNoCoordinator() throws InterruptedException { - locatorClient = mock(TcpClient.class); - gmsJoinLeave = new GMSJoinLeave(locatorClient); - assertThat(gmsJoinLeave.pauseIfThereIsNoCoordinator(-1, GMSJoinLeave.JOIN_RETRY_SLEEP)) - .isFalse(); - assertThat(gmsJoinLeave.pauseIfThereIsNoCoordinator(1, GMSJoinLeave.JOIN_RETRY_SLEEP)).isTrue(); - } - - @Test - public void testJoinFailureWhenNoLocator() throws Exception { - final String locator1 = "locator1[12345]"; - final String locator2 = "locator2[54321]"; - locatorClient = mock(TcpClient.class); + when(locatorClient.requestToServer(eq(new HostAndPort("localhost", 12346)), + isA(FindCoordinatorRequest.class), anyInt(), anyBoolean())) + .thenReturn(fcr); - initMocks(false, false, locator1 + ',' + locator2, locator1); - when(locatorClient.requestToServer(any(), any(), anyInt(), anyBoolean())) - .thenThrow(IOException.class); - - assertThatThrownBy(gmsJoinLeave::join) - .isInstanceOf(MembershipConfigurationException.class) - .hasMessageContaining( - "Could not contact any of the locators: [locator1:12345, locator2:54321]") - .hasCauseInstanceOf(IOException.class); - } - - private void mockRequestToServer(HostAndPort hostAndPort) - throws IOException, ClassNotFoundException { - HashSet registrants = new HashSet<>(); - registrants.add(mockMembers[0]); + assertFalse("Should not be able to join ", gmsJoinLeave.join()); + } finally { - FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, - null, registrants, false, true, null); - when(locatorClient.requestToServer(hostAndPort, - isA(FindCoordinatorRequest.class), anyInt(), anyBoolean())) - .thenReturn(fcr); + } } private void waitForViewAndFinalCheckInProgress(int viewId) throws InterruptedException { diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/api/MembershipLocatorBuilder.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/api/MembershipLocatorBuilder.java index 131e1ebd418a..3c7704c70592 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/api/MembershipLocatorBuilder.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/api/MembershipLocatorBuilder.java @@ -14,13 +14,13 @@ */ package org.apache.geode.distributed.internal.membership.api; +import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.file.Path; import java.util.concurrent.ExecutorService; import java.util.function.Supplier; import org.apache.geode.distributed.internal.membership.gms.MembershipLocatorBuilderImpl; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.ProtocolChecker; import org.apache.geode.distributed.internal.tcpserver.TcpHandler; import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreator; @@ -29,7 +29,7 @@ public interface MembershipLocatorBuilder { MembershipLocatorBuilder setPort(int port); - MembershipLocatorBuilder setBindAddress(HostAddress bindAddress); + MembershipLocatorBuilder setBindAddress(InetAddress bindAddress); MembershipLocatorBuilder setConfig(MembershipConfig membershipConfig); diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMemberData.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMemberData.java index 250a64086b94..55aba28b9327 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMemberData.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMemberData.java @@ -595,6 +595,8 @@ public void readEssentialData(DataInput in, this.inetAddr = StaticSerialization.readInetAddress(in); if (this.inetAddr != null) { + // use address as hostname at this level. getHostName() will do a reverse-dns lookup, + // which is very expensive this.hostName = inetAddr.getHostAddress(); } this.udpPort = in.readInt(); diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java index 2d88312dbd32..e1d1b5573de6 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java @@ -571,7 +571,12 @@ private void join() throws MemberStartupException { this.isJoining = true; // added for bug #44373 // connect - services.getJoinLeave().join(); + boolean ok = services.getJoinLeave().join(); + + if (!ok) { + throw new MembershipConfigurationException("Unable to join the distributed system. " + + "Operation either timed out, was stopped or Locator does not exist."); + } MembershipView initialView = createGeodeView(services.getJoinLeave().getView()); latestView = new MembershipView<>(initialView, initialView.getViewId()); diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/MembershipLocatorBuilderImpl.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/MembershipLocatorBuilderImpl.java index 98be6b46f556..4ee88472fdbf 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/MembershipLocatorBuilderImpl.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/MembershipLocatorBuilderImpl.java @@ -14,6 +14,7 @@ */ package org.apache.geode.distributed.internal.membership.gms; +import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.file.Path; import java.util.concurrent.ExecutorService; @@ -26,7 +27,6 @@ import org.apache.geode.distributed.internal.membership.api.MembershipLocatorBuilder; import org.apache.geode.distributed.internal.membership.api.MembershipLocatorStatistics; import org.apache.geode.distributed.internal.membership.gms.locator.MembershipLocatorImpl; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.ProtocolChecker; import org.apache.geode.distributed.internal.tcpserver.TcpHandler; import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreator; @@ -37,7 +37,7 @@ public final class MembershipLocatorBuilderImpl imp MembershipLocatorBuilder { private final DSFIDSerializer serializer; private int port = 0; - private HostAddress bindAddress = null; + private InetAddress bindAddress = null; private ProtocolChecker protocolChecker = (socket, input, firstByte) -> false; private TcpHandler fallbackHandler = new TcpHandlerNoOp(); private MembershipLocatorStatistics locatorStats = new MembershipLocatorStatisticsNoOp(); @@ -65,7 +65,7 @@ public MembershipLocatorBuilder setPort(int port) { } @Override - public MembershipLocatorBuilder setBindAddress(HostAddress bindAddress) { + public MembershipLocatorBuilder setBindAddress(InetAddress bindAddress) { this.bindAddress = bindAddress; return this; } diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/interfaces/JoinLeave.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/interfaces/JoinLeave.java index 1880a2679e7d..722816277e94 100755 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/interfaces/JoinLeave.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/interfaces/JoinLeave.java @@ -16,7 +16,6 @@ import org.apache.geode.distributed.internal.membership.api.MemberIdentifier; import org.apache.geode.distributed.internal.membership.api.MemberStartupException; -import org.apache.geode.distributed.internal.membership.api.MembershipConfigurationException; import org.apache.geode.distributed.internal.membership.gms.GMSMembershipView; /** @@ -27,15 +26,10 @@ public interface JoinLeave extends Service { /** - * joins the distributed system. - * - * @throws MemberStartupException if there was a problem joining the cluster after membership - * configuration has - * completed. - * @throws MembershipConfigurationException if operation either timed out, was stopped or locator - * does not exist. + * joins the distributed system and returns true if successful, false if not. Throws + * MemberStartupException and MemberConfigurationException */ - void join() throws MemberStartupException; + boolean join() throws MemberStartupException; /** * leaves the distributed system. Should be invoked before stop() diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java index c87fcf8b554a..3cc10eb7a783 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.net.InetAddress; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -44,7 +45,6 @@ import org.apache.geode.distributed.internal.membership.gms.Services; import org.apache.geode.distributed.internal.membership.gms.interfaces.Locator; import org.apache.geode.distributed.internal.membership.gms.messenger.GMSMemberWrapper; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.HostAndPort; import org.apache.geode.distributed.internal.tcpserver.TcpClient; import org.apache.geode.distributed.internal.tcpserver.TcpHandler; @@ -107,7 +107,7 @@ public class GMSLocator implements Locator, Tcp * @param objectSerializer a serializer used to persist the membership view * @param objectDeserializer a deserializer used to recover the membership view */ - public GMSLocator(HostAddress bindAddress, String locatorString, boolean usePreferredCoordinators, + public GMSLocator(InetAddress bindAddress, String locatorString, boolean usePreferredCoordinators, boolean networkPartitionDetectionEnabled, MembershipLocatorStatistics locatorStats, String securityUDPDHAlgo, Path workingDirectory, final TcpClient locatorClient, ObjectSerializer objectSerializer, @@ -120,8 +120,7 @@ public GMSLocator(HostAddress bindAddress, String locatorString, boolean usePref if (this.locatorString == null || this.locatorString.isEmpty()) { locators = new ArrayList<>(0); } else { - locators = GMSUtil.parseLocators(locatorString, - bindAddress == null ? null : bindAddress.getAddress()); + locators = GMSUtil.parseLocators(locatorString, bindAddress); } this.locatorStats = locatorStats; this.workingDirectory = workingDirectory; diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/MembershipLocatorImpl.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/MembershipLocatorImpl.java index 3f86f2aa9594..c4d2333d15fb 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/MembershipLocatorImpl.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/MembershipLocatorImpl.java @@ -38,7 +38,6 @@ import org.apache.geode.distributed.internal.membership.api.MembershipLocatorStatistics; import org.apache.geode.distributed.internal.membership.gms.GMSMembership; import org.apache.geode.distributed.internal.membership.gms.Services; -import org.apache.geode.distributed.internal.tcpserver.HostAddress; import org.apache.geode.distributed.internal.tcpserver.HostAndPort; import org.apache.geode.distributed.internal.tcpserver.ProtocolChecker; import org.apache.geode.distributed.internal.tcpserver.TcpClient; @@ -62,7 +61,7 @@ public class MembershipLocatorImpl implements Membe private final GMSLocator gmsLocator; private final TcpClient locatorClient; - public MembershipLocatorImpl(int port, HostAddress bindAddress, + public MembershipLocatorImpl(int port, InetAddress bindAddress, ProtocolChecker protocolChecker, Supplier executorServiceSupplier, TcpSocketCreator socketCreator, @@ -76,10 +75,9 @@ public MembershipLocatorImpl(int port, HostAddress bindAddress, handler = new PrimaryHandler(fallbackHandler, config.getLocatorWaitTime()); String host = bindAddress == null ? LocalHostUtil.getLocalHostName() : bindAddress.getHostName(); - InetAddress inetAddress = bindAddress == null ? null : bindAddress.getAddress(); String threadName = "Distribution Locator on " + host + ": " + port; - this.server = new TcpServer(port, inetAddress, handler, + this.server = new TcpServer(port, bindAddress, handler, threadName, protocolChecker, locatorStats::getStatTime, executorServiceSupplier, @@ -93,7 +91,7 @@ public MembershipLocatorImpl(int port, HostAddress bindAddress, objectSerializer, objectDeserializer, Socket::new); gmsLocator = - new GMSLocator(bindAddress, config.getLocators(), locatorsAreCoordinators, + new GMSLocator<>(bindAddress, config.getLocators(), locatorsAreCoordinators, config.isNetworkPartitionDetectionEnabled(), locatorStats, config.getSecurityUDPDHAlgo(), workingDirectory, locatorClient, objectSerializer, diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeave.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeave.java index 7328ae358428..ff5c619b49a1 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeave.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/membership/GMSJoinLeave.java @@ -273,13 +273,11 @@ static class SearchState { int lastFindCoordinatorInViewId = -1000; final Set> responses = new HashSet<>(); public int responsesExpected; - Exception lastLocatorException; void cleanup() { alreadyTried.clear(); possibleCoordinator = null; view = null; - lastLocatorException = null; synchronized (responses) { responses.clear(); } @@ -317,14 +315,14 @@ public static int getMinimumRetriesBeforeBecomingCoordinator(int locatorsSize) { * @return true if successful, false if not */ @Override - public void join() throws MemberStartupException { + public boolean join() throws MemberStartupException { try { if (Boolean.getBoolean(BYPASS_DISCOVERY_PROPERTY)) { synchronized (viewInstallationLock) { becomeCoordinator(); } - return; + return true; } SearchState state = searchState; @@ -357,11 +355,11 @@ public void join() throws MemberStartupException { synchronized (viewInstallationLock) { becomeCoordinator(); } - return; + return true; } } else { if (attemptToJoin()) { - return; + return true; } if (this.isStopping) { break; @@ -385,45 +383,40 @@ public void join() throws MemberStartupException { break; } } - if (found && !state.hasContactedAJoinedLocator) { - try { - if (pauseIfThereIsNoCoordinator(state.possibleCoordinator.getVmViewId(), retrySleep)) { + try { + if (found && !state.hasContactedAJoinedLocator) { + // if locators are restarting they may be handing out IDs from a stale view that + // we should go through quickly. Otherwise we should sleep a bit to let failure + // detection select a new coordinator + if (state.possibleCoordinator.getVmViewId() < 0) { + logger.debug("sleeping for {} before making another attempt to find the coordinator", + retrySleep); + Thread.sleep(retrySleep); + } else { // since we were given a coordinator that couldn't be used we should keep trying tries = 0; giveupTime = System.currentTimeMillis() + timeout; } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new MembershipConfigurationException( - "Retry sleep interrupted. Giving up on joining the distributed system."); } + } catch (InterruptedException e) { + logger.debug("retry sleep interrupted - giving up on joining the distributed system"); + return false; } } // for if (!this.isJoined) { logger.debug("giving up attempting to join the distributed system after " + (System.currentTimeMillis() - startTime) + "ms"); + } - // to preserve old behavior we need to throw a MemberStartupException if - // unable to contact any of the locators - if (state.hasContactedAJoinedLocator) { - throw new MemberStartupException("Unable to join the distributed system in " - + (System.currentTimeMillis() - startTime) + "ms"); - } - - if (state.locatorsContacted == 0) { - throw new MembershipConfigurationException( - "Unable to join the distributed system. Could not contact any of the locators: " - + locators, - state.lastLocatorException); - } - - if (System.currentTimeMillis() > giveupTime) { - throw new MembershipConfigurationException( - "Unable to join the distributed system. Operation timed out"); - } + // to preserve old behavior we need to throw a MemberStartupException if + // unable to contact any of the locators + if (!this.isJoined && state.hasContactedAJoinedLocator) { + throw new MemberStartupException("Unable to join the distributed system in " + + (System.currentTimeMillis() - startTime) + "ms"); } - return; + + return this.isJoined; } finally { // notify anyone waiting on the address to be completed if (this.isJoined) { @@ -435,24 +428,6 @@ public void join() throws MemberStartupException { } } - boolean pauseIfThereIsNoCoordinator(int viewId, long retrySleep) - throws InterruptedException { - // if locators are restarting they may be handing out IDs from a stale view that - // we should go through quickly. Otherwise we should sleep a bit to let failure - // detection select a new coordinator - if (viewId < 0) { - // the process hasn't finished joining the cluster. - logger.debug("sleeping for {} before making another attempt to find the coordinator", - retrySleep); - Thread.sleep(retrySleep); - } else { - // the member has joined the cluster. - return true; - } - - return false; - } - /** * send a join request and wait for a reply. Process the reply. This may throw a * MemberStartupException or an exception from the authenticator, if present. @@ -1224,7 +1199,6 @@ boolean findCoordinator() throws MemberStartupException { } catch (IOException | ClassNotFoundException problem) { logger.info("Unable to contact locator " + laddr + ": " + problem); logger.debug("Exception thrown when contacting a locator", problem); - state.lastLocatorException = problem; if (state.locatorsContacted == 0 && System.currentTimeMillis() < giveUpTime) { try { Thread.sleep(FIND_LOCATOR_RETRY_SLEEP); diff --git a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessenger.java b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessenger.java index 8da3f2fecdc9..a695a2dce27c 100644 --- a/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessenger.java +++ b/geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessenger.java @@ -556,10 +556,9 @@ private void establishLocalAddress() throws MemberStartupException { || !config.getStartLocator().isEmpty(); // establish the DistributedSystem's address - String hostname = config.getBindAddress(); - if (hostname == null || hostname.isEmpty()) { - hostname = jgAddress.getInetAddress().getHostName(); - } + String hostname = + !config.isNetworkPartitionDetectionEnabled() ? jgAddress.getInetAddress().getHostName() + : jgAddress.getInetAddress().getHostAddress(); GMSMemberData gmsMember = new GMSMemberData(jgAddress.getInetAddress(), hostname, jgAddress.getPort(), OSProcess.getId(), (byte) services.getConfig().getVmKind(), diff --git a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/HostAddress.java b/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/HostAddress.java deleted file mode 100644 index 9f32dfd1e1ac..000000000000 --- a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/HostAddress.java +++ /dev/null @@ -1,56 +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.geode.distributed.internal.tcpserver; - -import java.net.InetAddress; -import java.net.InetSocketAddress; - - -/** - * HostAddress is a holder of a host name/address. It is the primary - * way to specify a host address that may or may not be resolvable to an InetAddress. - *

- * This class preserves the hostName string passed in to its constructor that takes a - * hostName string and will respond with that string when asked for a hostName. - * - * @See HostAndPort which can hold both a host name and a port - */ -public class HostAddress extends InetSocketWrapper { - - public HostAddress(String hostName) { - super(hostName, 0); - } - - public HostAddress(InetAddress address) { - if (address == null) { - throw new IllegalArgumentException("null parameters are not allowed"); - } - inetSocketAddress = new InetSocketAddress(address, 0); - } - - public HostAddress(HostAndPort hostAndPort) { - hostName = hostAndPort.hostName; - inetSocketAddress = hostAndPort.inetSocketAddress; - } - - @Override - public String toString() { - if (hostName != null) { - return hostName; - } else { - return inetSocketAddress.getAddress().toString(); - } - } -} diff --git a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/HostAndPort.java b/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/HostAndPort.java index 73ae77580e78..f7d6805c0528 100644 --- a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/HostAndPort.java +++ b/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/HostAndPort.java @@ -19,6 +19,9 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.util.Objects; + +import org.apache.commons.validator.routines.InetAddressValidator; import org.apache.geode.internal.serialization.DataSerializableFixedID; import org.apache.geode.internal.serialization.DeserializationContext; @@ -30,9 +33,6 @@ * HostAndPort is a holder of a host name/address and a port. It is the primary * way to specify a connection endpoint in the socket-creator methods. *

- * This class preserves the hostName string passed in to its constructor that takes a - * hostName string and will respond with that string when asked for a hostName. - *

* Note: This class is serializable for testing. A number of client/server and WAN tests * transmit PoolAttributes between unit test JVMs using RMI. PoolAttributes are * Externalizable for this purpose and use Geode serialization to transmit HostAndPort @@ -43,20 +43,73 @@ * @see ClientSocketCreator * @see AdvancedSocketCreator * @see TcpClient - * @see HostAddress */ -public class HostAndPort extends InetSocketWrapper implements DataSerializableFixedID { +public class HostAndPort implements DataSerializableFixedID { + + private InetSocketAddress socketInetAddress; public HostAndPort() { // serialization constructor } public HostAndPort(String hostName, int port) { - super(hostName, port); + if (hostName == null) { + socketInetAddress = new InetSocketAddress(port); + } else if (InetAddressValidator.getInstance().isValid(hostName)) { + // numeric address - use as-is + socketInetAddress = new InetSocketAddress(hostName, port); + } else { + // non-numeric address - resolve hostname when needed + socketInetAddress = InetSocketAddress.createUnresolved(hostName, port); + } + } + + /** + * Returns an InetSocketAddress for this host and port. An attempt is made to resolve the + * host name but if resolution fails an unresolved InetSocketAddress is returned. This return + * value will not hold an InetAddress, so calling getAddress() on it will return null. + */ + public InetSocketAddress getSocketInetAddress() { + if (socketInetAddress.isUnresolved()) { + // note that this leaves the InetAddress null if the hostname isn't resolvable + return new InetSocketAddress(socketInetAddress.getHostString(), socketInetAddress.getPort()); + } else { + return this.socketInetAddress; + } + } + + public String getHostName() { + return socketInetAddress.getHostString(); } public int getPort() { - return inetSocketAddress.getPort(); + return socketInetAddress.getPort(); + } + + @Override + public int hashCode() { + return socketInetAddress.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + HostAndPort that = (HostAndPort) o; + return Objects.equals(socketInetAddress, that.socketInetAddress); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[" + socketInetAddress + "]"; + } + + public InetAddress getAddress() { + return getSocketInetAddress().getAddress(); } @Override @@ -66,13 +119,13 @@ public int getDSFID() { @Override public void toData(DataOutput out, SerializationContext context) throws IOException { - if (inetSocketAddress.isUnresolved()) { + if (socketInetAddress.isUnresolved()) { out.writeByte(0); StaticSerialization.writeString(getHostName(), out); out.writeInt(getPort()); } else { out.writeByte(1); - StaticSerialization.writeInetAddress(inetSocketAddress.getAddress(), out); + StaticSerialization.writeInetAddress(socketInetAddress.getAddress(), out); out.writeInt(getPort()); } } @@ -80,20 +133,20 @@ public void toData(DataOutput out, SerializationContext context) throws IOExcept @Override public void fromData(DataInput in, DeserializationContext context) throws IOException, ClassNotFoundException { - InetAddress address; + InetAddress address = null; byte flags = in.readByte(); if ((flags & 1) == 0) { String hostName = StaticSerialization.readString(in); int port = in.readInt(); if (hostName == null || hostName.isEmpty()) { - inetSocketAddress = new InetSocketAddress(port); + socketInetAddress = new InetSocketAddress(port); } else { - inetSocketAddress = InetSocketAddress.createUnresolved(hostName, port); + socketInetAddress = InetSocketAddress.createUnresolved(hostName, port); } } else { address = StaticSerialization.readInetAddress(in); int port = in.readInt(); - inetSocketAddress = new InetSocketAddress(address, port); + socketInetAddress = new InetSocketAddress(address, port); } } @@ -101,4 +154,6 @@ public void fromData(DataInput in, DeserializationContext context) public Version[] getSerializationVersions() { return null; } + + } diff --git a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/InetSocketWrapper.java b/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/InetSocketWrapper.java deleted file mode 100644 index 168fc3f4cabf..000000000000 --- a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/InetSocketWrapper.java +++ /dev/null @@ -1,100 +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.geode.distributed.internal.tcpserver; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Objects; - -import org.apache.commons.validator.routines.InetAddressValidator; - -class InetSocketWrapper { - String hostName; - protected InetSocketAddress inetSocketAddress; - private InetSocketAddress attemptedToResolve; - - protected InetSocketWrapper() {} - - protected InetSocketWrapper(String hostName, int port) { - // preserve the hostName string since InetSocketAddress will throw it away if it's a numeric - // address. Invoking getHostName on the InetSocketAddress would possibly return a different - // string. - this.hostName = hostName; - if (hostName == null) { - inetSocketAddress = new InetSocketAddress(port); - } else if (InetAddressValidator.getInstance().isValid(hostName)) { - // numeric address - use as-is - inetSocketAddress = new InetSocketAddress(hostName, port); - } else { - // non-numeric address - resolve hostname when needed - inetSocketAddress = InetSocketAddress.createUnresolved(hostName, port); - } - } - - public String getHostName() { - if (hostName != null) { - return hostName; - } - return inetSocketAddress.getHostName(); - } - - public InetAddress getAddress() { - return getSocketInetAddress().getAddress(); - } - - @Override - public int hashCode() { - return inetSocketAddress.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - InetSocketWrapper that = (InetSocketWrapper) o; - return Objects.equals(inetSocketAddress, that.inetSocketAddress); - } - - /** - * Returns an InetSocketAddress for this host and port. An attempt is made to resolve the - * host name but if resolution fails an unresolved InetSocketAddress is returned. This return - * value will not hold an InetAddress, so calling getAddress() on it will return null. - */ - public InetSocketAddress getSocketInetAddress() { - if (attemptedToResolve == null) { - attemptedToResolve = basicGetInetSocketAddress(); - } - return attemptedToResolve; - } - - private InetSocketAddress basicGetInetSocketAddress() { - if (inetSocketAddress.isUnresolved()) { - // note that this leaves the InetAddress null if the hostname isn't resolvable - return new InetSocketAddress(inetSocketAddress.getHostString(), inetSocketAddress.getPort()); - } else { - return inetSocketAddress; - } - } - - @Override - public String toString() { - return inetSocketAddress.toString(); - } - -} diff --git a/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/WANTestBase.java b/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/WANTestBase.java index 655926b45e4f..ab6933a13f43 100644 --- a/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/WANTestBase.java +++ b/geode-wan/src/distributedTest/java/org/apache/geode/internal/cache/wan/WANTestBase.java @@ -52,6 +52,7 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Arrays; @@ -380,7 +381,7 @@ public static Integer createSecondRemoteLocatorWithAPI(int dsId, int localPort, props.setProperty(DISTRIBUTED_SYSTEM_ID, "" + dsId); props.setProperty(LOCATORS, "localhost[" + localPort + "]"); props.setProperty(REMOTE_LOCATORS, "localhost[" + remoteLocPort + "]"); - Locator locator = Locator.startLocatorAndDS(0, null, null, props, + Locator locator = Locator.startLocatorAndDS(0, null, InetAddress.getByName("0.0.0.0"), props, true, true, hostnameForClients); return locator.getPort(); }