From fd11a1e079a1f8e3c1359300ad0ae2ed1a945972 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Tue, 26 May 2020 15:06:47 -0500 Subject: [PATCH] ARTEMIS-2781 return only local queue names for AddressControl.getQueueNames() --- .../api/core/management/AddressControl.java | 8 ++++++- .../management/impl/AddressControlImpl.java | 14 +++++++++-- .../management/AddressControlTest.java | 24 +++++++++++++++++++ .../AddressControlUsingCoreTest.java | 5 ++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java index e367685d21..d8a2bae6d1 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java @@ -74,7 +74,13 @@ public interface AddressControl { /** * Returns the names of the queues bound to this address. */ - @Attribute(desc = "names of the queue(s) bound to this address") + @Attribute(desc = "names of the remote queue(s) bound to this address") + String[] getRemoteQueueNames() throws Exception; + + /** + * Returns the names of the queues bound to this address. + */ + @Attribute(desc = "names of the local queue(s) bound to this address") String[] getQueueNames() throws Exception; /** diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java index c3c0a74a58..bc18864d8c 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java @@ -43,6 +43,7 @@ import org.apache.activemq.artemis.core.security.Role; import org.apache.activemq.artemis.core.security.SecurityStore; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; +import org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding; import org.apache.activemq.artemis.core.server.impl.AddressInfo; import org.apache.activemq.artemis.core.server.management.ManagementService; import org.apache.activemq.artemis.core.settings.HierarchicalRepository; @@ -130,10 +131,19 @@ public class AddressControlImpl extends AbstractControl implements AddressContro } } + @Override + public String[] getRemoteQueueNames() throws Exception { + return getQueueNames(false); + } + @Override public String[] getQueueNames() throws Exception { + return getQueueNames(true); + } + + private String[] getQueueNames(boolean local) throws Exception { if (AuditLogger.isEnabled()) { - AuditLogger.getQueueNames(this.addressInfo); + AuditLogger.getQueueNames(this.addressInfo, local); } clearIO(); try { @@ -141,7 +151,7 @@ public class AddressControlImpl extends AbstractControl implements AddressContro if (bindings != null) { List queueNames = new ArrayList<>(); for (Binding binding : bindings.getBindings()) { - if (binding instanceof QueueBinding) { + if ((local && binding.isLocal()) || (!local && binding instanceof RemoteQueueBinding)) { queueNames.add(binding.getUniqueName().toString()); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java index d07cc0b318..432ecf82ca 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java @@ -44,6 +44,9 @@ import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.security.CheckType; import org.apache.activemq.artemis.core.security.Role; import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding; +import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType; +import org.apache.activemq.artemis.core.server.cluster.impl.RemoteQueueBindingImpl; import org.apache.activemq.artemis.core.server.impl.QueueImpl; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.tests.util.Wait; @@ -106,6 +109,10 @@ public class AddressControlTest extends ManagementTestBase { session.createQueue(new QueueConfiguration(queue).setAddress(address)); + // add a fake RemoteQueueBinding to simulate being in a cluster; we don't want this binding to be returned by getQueueNames() + RemoteQueueBinding binding = new RemoteQueueBindingImpl(server.getStorageManager().generateID(), address, RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString(), RandomUtil.randomLong(), null, null, RandomUtil.randomSimpleString(), RandomUtil.randomInt() + 1, MessageLoadBalancingType.OFF); + server.getPostOffice().addBinding(binding); + AddressControl addressControl = createManagementControl(address); String[] queueNames = addressControl.getQueueNames(); Assert.assertEquals(1, queueNames.length); @@ -124,6 +131,23 @@ public class AddressControlTest extends ManagementTestBase { session.deleteQueue(anotherQueue); } + @Test + public void testGetRemoteQueueNames() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + SimpleString queue = RandomUtil.randomSimpleString(); + + session.createAddress(address, RoutingType.MULTICAST, false); + + // add a fake RemoteQueueBinding to simulate being in a cluster; this should be returned by getRemoteQueueNames() + RemoteQueueBinding binding = new RemoteQueueBindingImpl(server.getStorageManager().generateID(), address, queue, RandomUtil.randomSimpleString(), RandomUtil.randomLong(), null, null, RandomUtil.randomSimpleString(), RandomUtil.randomInt() + 1, MessageLoadBalancingType.OFF); + server.getPostOffice().addBinding(binding); + + AddressControl addressControl = createManagementControl(address); + String[] queueNames = addressControl.getRemoteQueueNames(); + Assert.assertEquals(1, queueNames.length); + Assert.assertEquals(queue.toString(), queueNames[0]); + } + @Test public void testGetBindingNames() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java index 31355fde5e..cd7354c83c 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java @@ -73,6 +73,11 @@ public class AddressControlUsingCoreTest extends AddressControlTest { return (long) proxy.retrieveAttributeValue("numberOfMessages"); } + @Override + public String[] getRemoteQueueNames() throws Exception { + return (String[]) proxy.retrieveAttributeValue("remoteQueueNames", String.class); + } + @Override public String[] getQueueNames() throws Exception { return (String[]) proxy.retrieveAttributeValue("queueNames", String.class);