This is an automated email from the ASF dual-hosted git repository. ladyvader pushed a commit to branch feature/GEODE-3612 in repository https://gitbox.apache.org/repos/asf/geode.git
commit 559f279e2adeedd103d88a3bdb908dd2eb4d6954 Author: Lynn Hughes-Godfrey <[email protected]> AuthorDate: Thu Sep 21 16:45:06 2017 -0700 GEODE-3612: Add support for hostname-for-senders in gfsh create gateway-receiver command --- .../geode/internal/i18n/LocalizedStrings.java | 2 +- .../cli/commands/CreateGatewayReceiverCommand.java | 11 +- .../functions/GatewayReceiverCreateFunction.java | 5 + .../cli/functions/GatewayReceiverFunctionArgs.java | 10 +- .../management/internal/cli/i18n/CliStrings.java | 4 +- .../CreateGatewayReceiverCommandDUnitTest.java | 115 ++++++++++++++++----- .../cache/wan/wancommand/WANCommandTestBase.java | 33 +++++- 7 files changed, 149 insertions(+), 31 deletions(-) diff --git a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java index 3a32db8..4d40ea2 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java +++ b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java @@ -7213,7 +7213,7 @@ public class LocalizedStrings { new StringId(5305, "Exception occurred while handling call to {0}.afterAcknowledgement for event {1}:"); public static final StringId GatewayReceiverImpl_USING_LOCAL_HOST = - new StringId(5399, "No bind-address or hostname-for-sender is specified, Using local host "); + new StringId(5399, "No bind-address or hostname-for-senders specified, Using local host "); public static final StringId GatewayReceiverImpl_COULD_NOT_GET_HOST_NAME = new StringId(5400, "Could not get host name"); public static final StringId CqService_ERROR_SENDING_CQ_CONNECTION_STATUS = diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewayReceiverCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewayReceiverCommand.java index a07aee1..33b3ff5 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewayReceiverCommand.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateGatewayReceiverCommand.java @@ -73,15 +73,18 @@ public class CreateGatewayReceiverCommand implements GfshCommand { help = CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE__HELP) Integer socketBufferSize, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER, - help = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER__HELP) String[] gatewayTransportFilters) { + help = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER__HELP) String[] gatewayTransportFilters, + + @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__HOSTNAMEFORSENDERS, + help = CliStrings.CREATE_GATEWAYRECEIVER__HOSTNAMEFORSENDERS__HELP) String hostnameForSenders) { Result result; AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>(); try { - GatewayReceiverFunctionArgs gatewayReceiverFunctionArgs = - new GatewayReceiverFunctionArgs(manualStart, startPort, endPort, bindAddress, - socketBufferSize, maximumTimeBetweenPings, gatewayTransportFilters); + GatewayReceiverFunctionArgs gatewayReceiverFunctionArgs = new GatewayReceiverFunctionArgs( + manualStart, startPort, endPort, bindAddress, socketBufferSize, maximumTimeBetweenPings, + gatewayTransportFilters, hostnameForSenders); Set<DistributedMember> membersToCreateGatewayReceiverOn = CliUtil.findMembers(onGroups, onMember); diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java index a7dc7ea..c3da49a 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java @@ -157,6 +157,11 @@ public class GatewayReceiverCreateFunction extends FunctionAdapter implements In CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER)); } } + + String hostnameForSenders = gatewayReceiverCreateArgs.getHostnameForSenders(); + if (hostnameForSenders != null) { + gatewayReceiverFactory.setHostnameForSenders(hostnameForSenders); + } return gatewayReceiverFactory.create(); } diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverFunctionArgs.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverFunctionArgs.java index 2084af9..72bcb83 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverFunctionArgs.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverFunctionArgs.java @@ -36,9 +36,11 @@ public class GatewayReceiverFunctionArgs implements Serializable { private final String[] gatewayTransportFilters; + private final String hostnameForSenders; + public GatewayReceiverFunctionArgs(Boolean manualStart, Integer startPort, Integer endPort, String bindAddress, Integer socketBufferSize, Integer maximumTimeBetweenPings, - String[] gatewayTransportFilters) { + String[] gatewayTransportFilters, String hostnameForSenders) { this.manualStart = manualStart; this.startPort = startPort; this.endPort = endPort; @@ -46,6 +48,7 @@ public class GatewayReceiverFunctionArgs implements Serializable { this.socketBufferSize = socketBufferSize; this.maximumTimeBetweenPings = maximumTimeBetweenPings; this.gatewayTransportFilters = gatewayTransportFilters; + this.hostnameForSenders = hostnameForSenders; } public Boolean isManualStart() { @@ -75,4 +78,9 @@ public class GatewayReceiverFunctionArgs implements Serializable { public String[] getGatewayTransportFilters() { return this.gatewayTransportFilters; } + + public String getHostnameForSenders() { + return hostnameForSenders; + } + } diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java index 2492490..aa93e49 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java @@ -2122,7 +2122,9 @@ public class CliStrings { public static final String CREATE_GATEWAYRECEIVER__MANUALSTART = "manual-start"; public static final String CREATE_GATEWAYRECEIVER__MANUALSTART__HELP = "Whether manual start is to be enabled or the receiver will start automatically after creation."; - + public static final String CREATE_GATEWAYRECEIVER__HOSTNAMEFORSENDERS = "hostname-for-senders"; + public static final String CREATE_GATEWAYRECEIVER__HOSTNAMEFORSENDERS__HELP = + "The host name that server locators will tell GatewaySenders this GatewayReceiver is listening on."; /* start gateway-receiver */ public static final String START_GATEWAYRECEIVER = "start gateway-receiver"; diff --git a/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/CreateGatewayReceiverCommandDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/CreateGatewayReceiverCommandDUnitTest.java index af27a60..c4d548f 100644 --- a/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/CreateGatewayReceiverCommandDUnitTest.java +++ b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/CreateGatewayReceiverCommandDUnitTest.java @@ -19,9 +19,14 @@ import static org.apache.geode.test.dunit.Assert.assertTrue; import static org.apache.geode.test.dunit.Assert.fail; import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; +import org.apache.geode.internal.i18n.LocalizedStrings; +import org.apache.geode.internal.logging.log4j.LocalizedMessage; +import org.apache.geode.internal.net.SocketCreator; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -76,18 +81,26 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { fail("testCreateGatewayReceiver failed as did not get CommandResult"); } + String hostname; + try { + hostname = SocketCreator.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + throw new IllegalStateException( + LocalizedStrings.GatewayReceiverImpl_COULD_NOT_GET_HOST_NAME.toLocalizedString(), e); + } + vm3.invoke(() -> verifyReceiverCreationWithAttributes(!GatewayReceiver.DEFAULT_MANUAL_START, GatewayReceiver.DEFAULT_START_PORT, GatewayReceiver.DEFAULT_END_PORT, GatewayReceiver.DEFAULT_BIND_ADDRESS, GatewayReceiver.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, - GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE, null)); + GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE, null, hostname)); vm4.invoke(() -> verifyReceiverCreationWithAttributes(!GatewayReceiver.DEFAULT_MANUAL_START, GatewayReceiver.DEFAULT_START_PORT, GatewayReceiver.DEFAULT_END_PORT, GatewayReceiver.DEFAULT_BIND_ADDRESS, GatewayReceiver.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, - GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE, null)); + GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE, null, hostname)); vm5.invoke(() -> verifyReceiverCreationWithAttributes(!GatewayReceiver.DEFAULT_MANUAL_START, GatewayReceiver.DEFAULT_START_PORT, GatewayReceiver.DEFAULT_END_PORT, GatewayReceiver.DEFAULT_BIND_ADDRESS, GatewayReceiver.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, - GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE, null)); + GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE, null, hostname)); } /** @@ -128,13 +141,69 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { fail("testCreateGatewayReceiver failed as did not get CommandResult"); } vm3.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm4.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm5.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); + } + + /** + * GatewayReceiver with hostnameForSenders + */ + @Test + public void testCreateGatewayReceiverWithHostnameForSenders() throws UnknownHostException { + VM puneLocator = Host.getLocator(); + int dsIdPort = puneLocator.invoke(this::getLocatorPort); + propsSetUp(dsIdPort); + vm2.invoke(() -> createFirstRemoteLocator(2, dsIdPort)); + + vm3.invoke(() -> createCache(dsIdPort)); + vm4.invoke(() -> createCache(dsIdPort)); + vm5.invoke(() -> createCache(dsIdPort)); + + String hostnameForSenders = InetAddress.getLocalHost().getHostName(); + String command = + CliStrings.CREATE_GATEWAYRECEIVER + " --" + CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART + + "=false" + " --" + CliStrings.CREATE_GATEWAYRECEIVER__HOSTNAMEFORSENDERS + "=" + + hostnameForSenders + " --" + CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT + "=10000" + + " --" + CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT + "=11000" + " --" + + CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS + "=100000" + " --" + + CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE + "=512000"; + CommandResult cmdResult = executeCommand(command); + if (cmdResult != null) { + String strCmdResult = commandResultToString(cmdResult); + getLogWriter().info("testCreateGatewayReceiver stringResult : " + strCmdResult + ">>>>"); + assertEquals(Result.Status.OK, cmdResult.getStatus()); + + TabularResultData resultData = (TabularResultData) cmdResult.getResultData(); + List<String> status = resultData.retrieveAllValues("Status"); + assertEquals(4, status.size());// expected size 4 includes the manager node + // verify there is no error in the status + for (String stat : status) { + assertTrue("GatewayReceiver creation failed with: " + stat, !stat.contains("ERROR:")); + } + } else { + fail("testCreateGatewayReceiver failed as did not get CommandResult"); + } + + vm3.invoke(() -> verifyGatewayReceiverProfile(hostnameForSenders)); + vm4.invoke(() -> verifyGatewayReceiverProfile(hostnameForSenders)); + vm5.invoke(() -> verifyGatewayReceiverProfile(hostnameForSenders)); + + vm3.invoke(() -> verifyGatewayReceiverServerLocations(dsIdPort, hostnameForSenders)); + vm4.invoke(() -> verifyGatewayReceiverServerLocations(dsIdPort, hostnameForSenders)); + vm5.invoke(() -> verifyGatewayReceiverServerLocations(dsIdPort, hostnameForSenders)); + + vm3.invoke(() -> verifyReceiverCreationWithAttributes(true, 10000, 11000, "", 100000, 512000, + null, hostnameForSenders)); + vm4.invoke(() -> verifyReceiverCreationWithAttributes(true, 10000, 11000, "", 100000, 512000, + null, hostnameForSenders)); + vm5.invoke(() -> verifyReceiverCreationWithAttributes(true, 10000, 11000, "", 100000, 512000, + null, hostnameForSenders)); } + /** * GatewayReceiver with given attributes and a single GatewayTransportFilter. */ @@ -178,11 +247,11 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { transportFilters.add("org.apache.geode.cache30.MyGatewayTransportFilter1"); vm3.invoke(() -> verifyReceiverCreationWithAttributes(true, 10000, 11000, "localhost", 100000, - 512000, transportFilters)); + 512000, transportFilters, "localhost")); vm4.invoke(() -> verifyReceiverCreationWithAttributes(true, 10000, 11000, "localhost", 100000, - 512000, transportFilters)); + 512000, transportFilters, "localhost")); vm5.invoke(() -> verifyReceiverCreationWithAttributes(true, 10000, 11000, "localhost", 100000, - 512000, transportFilters)); + 512000, transportFilters, "localhost")); } /** @@ -228,11 +297,11 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { transportFilters.add("org.apache.geode.cache30.MyGatewayTransportFilter2"); vm3.invoke(() -> verifyReceiverCreationWithAttributes(!GatewayReceiver.DEFAULT_MANUAL_START, - 10000, 11000, "localhost", 100000, 512000, transportFilters)); + 10000, 11000, "localhost", 100000, 512000, transportFilters, "localhost")); vm4.invoke(() -> verifyReceiverCreationWithAttributes(!GatewayReceiver.DEFAULT_MANUAL_START, - 10000, 11000, "localhost", 100000, 512000, transportFilters)); + 10000, 11000, "localhost", 100000, 512000, transportFilters, "localhost")); vm5.invoke(() -> verifyReceiverCreationWithAttributes(!GatewayReceiver.DEFAULT_MANUAL_START, - 10000, 11000, "localhost", 100000, 512000, transportFilters)); + 10000, 11000, "localhost", 100000, 512000, transportFilters, "localhost")); } /** @@ -315,7 +384,7 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { fail("testCreateGatewayReceiver failed as did not get CommandResult"); } vm3.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); } /** @@ -361,9 +430,9 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { fail("testCreateGatewayReceiver failed as did not get CommandResult"); } vm3.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm4.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); } /** @@ -406,11 +475,11 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { } vm3.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm4.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm5.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); } /** @@ -453,9 +522,9 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { fail("testCreateGatewayReceiver failed as did not get CommandResult"); } vm3.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm4.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); } /** @@ -497,10 +566,10 @@ public class CreateGatewayReceiverCommandDUnitTest extends WANCommandTestBase { fail("testCreateGatewayReceiver failed as did not get CommandResult"); } vm3.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm4.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); vm5.invoke(() -> verifyReceiverCreationWithAttributes(false, 10000, 11000, "localhost", 100000, - 512000, null)); + 512000, null, "localhost")); } } diff --git a/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WANCommandTestBase.java b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WANCommandTestBase.java index 1e67093..55d9121 100644 --- a/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WANCommandTestBase.java +++ b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WANCommandTestBase.java @@ -37,6 +37,10 @@ import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.DiskStore; import org.apache.geode.cache.DiskStoreFactory; +import org.apache.geode.cache.client.PoolFactory; +import org.apache.geode.cache.client.PoolManager; +import org.apache.geode.cache.client.internal.ConnectionSource; +import org.apache.geode.cache.client.internal.PoolImpl; import org.apache.geode.cache.wan.GatewayEventFilter; import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewayReceiverFactory; @@ -47,8 +51,11 @@ import org.apache.geode.cache.wan.GatewayTransportFilter; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.distributed.Locator; import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.distributed.internal.ServerLocation; import org.apache.geode.internal.AvailablePort; import org.apache.geode.internal.AvailablePortHelper; +import org.apache.geode.internal.cache.CacheServerAdvisor; +import org.apache.geode.internal.cache.CacheServerImpl; import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.internal.cache.LocalRegion; import org.apache.geode.internal.cache.wan.AbstractGatewaySender; @@ -409,9 +416,32 @@ public abstract class WANCommandTestBase extends CliCommandTestBase { } } + protected void verifyGatewayReceiverServerLocations(int locatorPort, String hostname) { + PoolFactory pf = PoolManager.createFactory(); + pf.setServerGroup(GatewayReceiver.RECEIVER_GROUP); + pf.addLocator("localhost", locatorPort); + PoolImpl pool = (PoolImpl) pf.create("gateway-receiver-pool"); + ConnectionSource connectionSource = pool.getConnectionSource(); + List<ServerLocation> serverLocations = connectionSource.getAllServers(); + StringBuffer aStr = new StringBuffer(); + for (ServerLocation serverLocation : serverLocations) { + assertEquals(hostname, serverLocation.getHostName()); + } + } + + protected void verifyGatewayReceiverProfile(String hostname) { + Set<GatewayReceiver> receivers = ((Cache) this.cache).getGatewayReceivers(); + for (GatewayReceiver receiver : receivers) { + CacheServerImpl server = (CacheServerImpl) receiver.getServer(); + CacheServerAdvisor.CacheServerProfile profile = + (CacheServerAdvisor.CacheServerProfile) server.getProfile(); + assertEquals(hostname, profile.getHost()); + } + } + public void verifyReceiverCreationWithAttributes(boolean isRunning, int startPort, int endPort, String bindAddress, int maxTimeBetweenPings, int socketBufferSize, - List<String> expectedGatewayTransportFilters) { + List<String> expectedGatewayTransportFilters, String hostnameForSenders) { Set<GatewayReceiver> receivers = cache.getGatewayReceivers(); assertEquals("Number of receivers is incorrect", 1, receivers.size()); @@ -423,6 +453,7 @@ public abstract class WANCommandTestBase extends CliCommandTestBase { assertEquals("maximumTimeBetweenPings", maxTimeBetweenPings, receiver.getMaximumTimeBetweenPings()); assertEquals("socketBufferSize", socketBufferSize, receiver.getSocketBufferSize()); + assertEquals("hostnameForSenders", hostnameForSenders, receiver.getHost()); // verify GatewayTransportFilters if (expectedGatewayTransportFilters != null) { -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
