From 3c595f18d5dbd439f7230c53619160a01af8d183 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Tue, 20 Nov 2018 18:53:01 -0600 Subject: [PATCH] ARTEMIS-2179 mgmnt method to get cluster-cxn names --- .../management/ActiveMQServerControl.java | 6 +++++ .../impl/ActiveMQServerControlImpl.java | 18 +++++++++++++++ .../management/ActiveMQServerControlTest.java | 22 +++++++++++++++++++ .../ActiveMQServerControlUsingCoreTest.java | 11 ++++++++++ 4 files changed, 57 insertions(+) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java index 62a422f1f6..06819b2e76 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java @@ -1335,5 +1335,11 @@ public interface ActiveMQServerControl { */ @Operation(desc = "Names of the queues created on this server with the given routing-type (i.e. ANYCAST or MULTICAST)", impact = MBeanOperationInfo.INFO) String[] getQueueNames(@Parameter(name = "routingType", desc = "The routing type, MULTICAST or ANYCAST") String routingType); + + /** + * Returns the names of the cluster-connections deployed on this server. + */ + @Operation(desc = "Names of the cluster-connections deployed on this server", impact = MBeanOperationInfo.INFO) + String[] getClusterConnectionNames(); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index 716a733f4a..96f352e8fc 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -950,6 +950,24 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } } + @Override + public String[] getClusterConnectionNames() { + checkStarted(); + + clearIO(); + try { + List names = new ArrayList<>(); + for (ClusterConnection clusterConnection : server.getClusterManager().getClusterConnections()) { + names.add(clusterConnection.getName().toString()); + } + + String[] result = new String[names.size()]; + return names.toArray(result); + } finally { + blockOnIO(); + } + } + @Override public String getUptime() { checkStarted(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java index 931e6c3148..0e40041686 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java @@ -55,6 +55,7 @@ import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; import org.apache.activemq.artemis.api.jms.JMSFactoryType; import org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl; import org.apache.activemq.artemis.core.client.impl.ClientSessionImpl; +import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration; import org.apache.activemq.artemis.core.messagecounter.impl.MessageCounterManagerImpl; @@ -463,6 +464,27 @@ public class ActiveMQServerControlTest extends ManagementTestBase { Assert.assertFalse(ActiveMQServerControlTest.contains(multicastName.toString(), serverControl.getQueueNames())); } + @Test + public void testGetClusterConnectionNames() throws Exception { + String clusterConnection1 = RandomUtil.randomString(); + String clusterConnection2 = RandomUtil.randomString(); + + ActiveMQServerControl serverControl = createManagementControl(); + + Assert.assertFalse(ActiveMQServerControlTest.contains(clusterConnection1, serverControl.getClusterConnectionNames())); + Assert.assertFalse(ActiveMQServerControlTest.contains(clusterConnection2, serverControl.getClusterConnectionNames())); + + server.stop(); + server + .getConfiguration() + .addClusterConfiguration(new ClusterConnectionConfiguration().setName(clusterConnection1).setConnectorName(connectorConfig.getName())) + .addClusterConfiguration(new ClusterConnectionConfiguration().setName(clusterConnection2).setConnectorName(connectorConfig.getName())); + server.start(); + + Assert.assertTrue(ActiveMQServerControlTest.contains(clusterConnection1, serverControl.getClusterConnectionNames())); + Assert.assertTrue(ActiveMQServerControlTest.contains(clusterConnection2, serverControl.getClusterConnectionNames())); + } + @Test public void testGetAddressNames() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java index a20da2bf2e..716b5d0685 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java @@ -324,6 +324,17 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes return null; } + @Override + public String[] getClusterConnectionNames() { + try { + return (String[]) proxy.invokeOperation(String.class, "getClusterConnectionNames"); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + @Override public String getUptime() { return null;