Repository: geode Updated Branches: refs/heads/develop 0fde215a1 -> b06f69f22
GEODE-3292: Embedded PULSE Connection Failure When jmx-manager-bind-address != localhost * ManagementAgent sets the 'pulse.host' system property whenever a 'jmx-manager-bind-address' is configured. * PULSE gets the hostname of the local JMX Manager through the 'pulse.host' system property, reverting to 'localhost' by default. * this closes #664 Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/b06f69f2 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/b06f69f2 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/b06f69f2 Branch: refs/heads/develop Commit: b06f69f226924c1c13096011bfe29fc3a0ce8401 Parents: 0fde215 Author: Juan Jose Ramos Cassella <jujora...@gmail.com> Authored: Fri Jul 28 10:55:20 2017 +0100 Committer: Jinmei Liao <jil...@pivotal.io> Committed: Wed Aug 9 11:04:52 2017 -0700 ---------------------------------------------------------------------- .../test/dunit/rules/EmbeddedPulseRule.java | 6 ++ .../tools/pulse/PulseConnectivityTest.java | 99 ++++++++++++++++++++ .../tools/pulse/PulseVerificationTest.java | 70 -------------- .../management/internal/ManagementAgent.java | 4 +- .../tools/pulse/internal/PulseAppListener.java | 7 +- .../pulse/internal/PulseAppListenerTest.java | 91 ++++++++++++++++++ 6 files changed, 203 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/b06f69f2/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/EmbeddedPulseRule.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/EmbeddedPulseRule.java b/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/EmbeddedPulseRule.java index f81d7f4..bbf4b94 100644 --- a/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/EmbeddedPulseRule.java +++ b/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/EmbeddedPulseRule.java @@ -38,6 +38,12 @@ public class EmbeddedPulseRule extends ExternalResource { repository.setHost("localhost"); } + public void useJmxManager(String jmxHost, int jmxPort) { + repository.setJmxUseLocator(false); + repository.setHost(jmxHost + ""); + repository.setPort(jmxPort + ""); + } + public void useJmxPort(int jmxPort) { repository.setJmxUseLocator(false); repository.setPort(jmxPort + ""); http://git-wip-us.apache.org/repos/asf/geode/blob/b06f69f2/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseConnectivityTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseConnectivityTest.java b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseConnectivityTest.java new file mode 100644 index 0000000..606864d --- /dev/null +++ b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseConnectivityTest.java @@ -0,0 +1,99 @@ +/* + * 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.tools.pulse; + +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS; +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.InetAddress; +import java.util.Arrays; +import java.util.Collection; +import java.util.Properties; + +import org.apache.http.HttpResponse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import org.apache.geode.test.dunit.rules.EmbeddedPulseRule; +import org.apache.geode.test.dunit.rules.HttpClientRule; +import org.apache.geode.test.dunit.rules.LocatorStarterRule; +import org.apache.geode.test.junit.categories.IntegrationTest; +import org.apache.geode.tools.pulse.internal.data.Cluster; + +@RunWith(Parameterized.class) +@Category(IntegrationTest.class) +public class PulseConnectivityTest { + @Rule + public LocatorStarterRule locator = new LocatorStarterRule().withJMXManager(); + + @Rule + public EmbeddedPulseRule pulse = new EmbeddedPulseRule(); + + @Rule + public HttpClientRule client = new HttpClientRule(locator::getHttpPort); + + @Parameterized.Parameter + public static String jmxBindAddress; + + @Parameterized.Parameters(name = "JMXBindAddress: {0}") + public static Collection<String> bindAddresses() throws Exception { + String nonDefaultJmxBindAddress = InetAddress.getLocalHost().getHostName(); + if ("localhost".equals(nonDefaultJmxBindAddress)) { + nonDefaultJmxBindAddress = InetAddress.getLocalHost().getHostAddress(); + } + + return Arrays.asList(new String[] {"localhost", nonDefaultJmxBindAddress}); + } + + @Before + public void setUp() throws Exception { + Properties locatorProperties = new Properties(); + if (!"localhost".equals(jmxBindAddress)) + locatorProperties.setProperty(JMX_MANAGER_BIND_ADDRESS, jmxBindAddress); + locator.withProperties(locatorProperties).startLocator(); + } + + @Test + public void testLogin() throws Exception { + HttpResponse response = client.loginToPulse("admin", "wrongPassword"); + assertThat(response.getStatusLine().getStatusCode()).isEqualTo(302); + assertThat(response.getFirstHeader("Location").getValue()) + .contains("/pulse/login.html?error=BAD_CREDS"); + client.loginToPulseAndVerify("admin", "admin"); + } + + @Test + public void testConnectToJmx() throws Exception { + pulse.useJmxManager(jmxBindAddress, locator.getJmxPort()); + Cluster cluster = pulse.getRepository().getCluster("admin", null); + assertThat(cluster.isConnectedFlag()).isTrue(); + assertThat(cluster.getServerCount()).isEqualTo(0); + } + + @Test + public void testConnectToLocator() throws Exception { + pulse.useLocatorPort(locator.getPort()); + Cluster cluster = pulse.getRepository().getCluster("admin", null); + assertThat(cluster.isConnectedFlag()).isTrue(); + assertThat(cluster.getServerCount()).isEqualTo(0); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/b06f69f2/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseVerificationTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseVerificationTest.java b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseVerificationTest.java deleted file mode 100644 index 44fadb6..0000000 --- a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseVerificationTest.java +++ /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. - */ - -package org.apache.geode.tools.pulse; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.geode.test.dunit.rules.EmbeddedPulseRule; -import org.apache.geode.test.dunit.rules.HttpClientRule; -import org.apache.geode.test.dunit.rules.LocatorStarterRule; -import org.apache.geode.test.junit.categories.IntegrationTest; -import org.apache.geode.tools.pulse.internal.data.Cluster; -import org.apache.http.HttpResponse; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(IntegrationTest.class) -public class PulseVerificationTest { - - @ClassRule - public static LocatorStarterRule locator = - new LocatorStarterRule().withJMXManager().withAutoStart(); - - @Rule - public EmbeddedPulseRule pulse = new EmbeddedPulseRule(); - - @Rule - public HttpClientRule client = new HttpClientRule(locator::getHttpPort); - - @Test - public void loginWithIncorrectPassword() throws Exception { - HttpResponse response = client.loginToPulse("admin", "wrongPassword"); - assertThat(response.getStatusLine().getStatusCode()).isEqualTo(302); - assertThat(response.getFirstHeader("Location").getValue()) - .contains("/pulse/login.html?error=BAD_CREDS"); - - client.loginToPulseAndVerify("admin", "admin"); - } - - @Test - public void testConnectToJmx() throws Exception { - pulse.useJmxPort(locator.getJmxPort()); - Cluster cluster = pulse.getRepository().getCluster("admin", null); - assertThat(cluster.isConnectedFlag()).isTrue(); - assertThat(cluster.getServerCount()).isEqualTo(0); - } - - @Test - public void testConnectToLocator() throws Exception { - pulse.useLocatorPort(locator.getPort()); - Cluster cluster = pulse.getRepository().getCluster("admin", null); - assertThat(cluster.isConnectedFlag()).isTrue(); - assertThat(cluster.getServerCount()).isEqualTo(0); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/b06f69f2/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java index 554dc66..11590cf 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java @@ -74,7 +74,7 @@ import javax.rmi.ssl.SslRMIClientSocketFactory; * <p> * The ManagementAgent could be used in a loner or GemFire client to define and control JMX server * end points for the Platform MBeanServer and the GemFire MBeans hosted within it. - * + * * @since GemFire 7.0 */ public class ManagementAgent { @@ -99,6 +99,7 @@ public class ManagementAgent { * embedded pulse webapp can use a local MBeanServer instead of a remote JMX connection. */ private static final String PULSE_EMBEDDED_PROP = "pulse.embedded"; + private static final String PULSE_HOST_PROP = "pulse.host"; private static final String PULSE_PORT_PROP = "pulse.port"; private static final String PULSE_USESSL_MANAGER = "pulse.useSSL.manager"; private static final String PULSE_USESSL_LOCATOR = "pulse.useSSL.locator"; @@ -270,6 +271,7 @@ public class ManagementAgent { } System.setProperty(PULSE_EMBEDDED_PROP, "true"); + System.setProperty(PULSE_HOST_PROP, "" + config.getJmxManagerBindAddress()); System.setProperty(PULSE_PORT_PROP, "" + config.getJmxManagerPort()); final SocketCreator jmxSocketCreator = http://git-wip-us.apache.org/repos/asf/geode/blob/b06f69f2/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/PulseAppListener.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/PulseAppListener.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/PulseAppListener.java index 34dbf2e..6aef34f 100644 --- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/PulseAppListener.java +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/PulseAppListener.java @@ -35,9 +35,9 @@ import javax.servlet.ServletContextListener; /** * This class is used for checking the application running mode i.e. Embedded or not - * + * * @since GemFire version 7.0.Beta 2012-09-23 - * + * */ // @WebListener public class PulseAppListener implements ServletContextListener { @@ -81,7 +81,8 @@ public class PulseAppListener implements ServletContextListener { // jmx connection parameters logger.info(resourceBundle.getString("LOG_MSG_APP_RUNNING_EMBEDDED_MODE")); repository.setJmxUseLocator(false); - repository.setHost(PulseConstants.GEMFIRE_DEFAULT_HOST); + repository.setHost(System.getProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_HOST, + PulseConstants.GEMFIRE_DEFAULT_HOST)); repository.setPort(System.getProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_PORT, PulseConstants.GEMFIRE_DEFAULT_PORT)); http://git-wip-us.apache.org/repos/asf/geode/blob/b06f69f2/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/PulseAppListenerTest.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/PulseAppListenerTest.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/PulseAppListenerTest.java new file mode 100644 index 0000000..644a991 --- /dev/null +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/internal/PulseAppListenerTest.java @@ -0,0 +1,91 @@ +/* + * 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.tools.pulse.internal; + +import javax.servlet.ServletContextEvent; +import static org.mockito.Mockito.*; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestRule; + +import org.apache.geode.test.junit.categories.UnitTest; +import org.apache.geode.tools.pulse.internal.data.PulseConstants; +import org.apache.geode.tools.pulse.internal.data.Repository; + +@Category(UnitTest.class) +public class PulseAppListenerTest { + private Repository repository; + private PulseAppListener appListener; + + @Rule + public final TestRule restoreSystemProperties = new RestoreSystemProperties(); + + @Before + public void setUp() { + repository = Repository.get(); + appListener = new PulseAppListener(); + } + + @Test + public void embeddedModeDefaultPropertiesRepositoryInitializationTest() { + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_EMBEDDED, "true"); + appListener.contextInitialized(mock(ServletContextEvent.class)); + + Assert.assertEquals(false, repository.getJmxUseLocator()); + Assert.assertEquals(false, repository.isUseSSLManager()); + Assert.assertEquals(false, repository.isUseSSLLocator()); + Assert.assertEquals(PulseConstants.GEMFIRE_DEFAULT_PORT, repository.getPort()); + Assert.assertEquals(PulseConstants.GEMFIRE_DEFAULT_HOST, repository.getHost()); + + } + + @Test + public void embeddedModeNonDefaultPropertiesRepositoryInitializationTest() { + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_EMBEDDED, "true"); + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_PORT, "9999"); + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_HOST, "nonDefaultBindAddress"); + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_USESSL_MANAGER, + Boolean.TRUE.toString()); + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_USESSL_LOCATOR, + Boolean.TRUE.toString()); + + appListener.contextInitialized(mock(ServletContextEvent.class)); + + Assert.assertEquals(false, repository.getJmxUseLocator()); + Assert.assertEquals(true, repository.isUseSSLManager()); + Assert.assertEquals(true, repository.isUseSSLLocator()); + Assert.assertEquals("9999", repository.getPort()); + Assert.assertEquals("nonDefaultBindAddress", repository.getHost()); + } + + @After + public void tearDown() { + if (repository != null) { + repository.setPort(null); + repository.setHost(null); + repository.setJmxUseLocator(false); + repository.setUseSSLManager(false); + repository.removeAllClusters(); + } + } +}