diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java index 3bd0eb8dde..ff5302f3b1 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java @@ -2770,7 +2770,6 @@ public interface AuditLogger extends BasicLogger { @Message(id = 601739, value = "User {0} is requesting to stop broker connection {1}", format = Message.Format.MESSAGE_FORMAT) void stopBrokerConnection(String user, String name); - static void startBrokerConnection(String name) { LOGGER.startBrokerConnection(getCaller(), name); } @@ -2779,4 +2778,19 @@ public interface AuditLogger extends BasicLogger { @Message(id = 601740, value = "User {0} is requesting to start broker connection {1}", format = Message.Format.MESSAGE_FORMAT) void startBrokerConnection(String user, String name); + static void getAddressCount(Object source) { + LOGGER.getAddressCount(getCaller(), source); + } + + @LogMessage(level = Logger.Level.INFO) + @Message(id = 601741, value = "User {0} is getting address count on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT) + void getAddressCount(String user, Object source, Object... args); + + static void getQueueCount(Object source) { + LOGGER.getQueueCount(getCaller(), source); + } + + @LogMessage(level = Logger.Level.INFO) + @Message(id = 601742, value = "User {0} is getting the queue count on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT) + void getQueueCount(String user, Object source, Object... args); } 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 94a69e7e7e..d3f4473215 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 @@ -394,11 +394,23 @@ public interface ActiveMQServerControl { String getConnectorsAsJSON() throws Exception; /** - * Returns the addresses created on this server. + * Returns the number of addresses created on this server. */ - @Attribute(desc = "Addresses created on this server") + @Attribute(desc = "Number of addresses created on this server") + int getAddressCount(); + + /** + * Returns the names of the addresses created on this server. + */ + @Attribute(desc = "Names of the addresses created on this server") String[] getAddressNames(); + /** + * Returns the number of queues created on this server. + */ + @Attribute(desc = "Number of queues created on this server") + int getQueueCount(); + /** * Returns the names of the queues created on this server. */ 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 f1e7218a25..2ad2206566 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 @@ -1395,6 +1395,22 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } } + @Override + public int getQueueCount() { + if (AuditLogger.isEnabled()) { + AuditLogger.getQueueCount(this.server); + } + checkStarted(); + + clearIO(); + try { + Object[] queueControls = server.getManagementService().getResources(QueueControl.class); + return queueControls.length; + } finally { + blockOnIO(); + } + } + @Override public String[] getQueueNames() { return getQueueNames(null); @@ -1493,6 +1509,22 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } } + @Override + public int getAddressCount() { + if (AuditLogger.isEnabled()) { + AuditLogger.getAddressCount(this.server); + } + checkStarted(); + + clearIO(); + try { + Object[] addresses = server.getManagementService().getResources(AddressControl.class); + return addresses.length; + } finally { + blockOnIO(); + } + } + @Override public String[] getAddressNames() { if (AuditLogger.isEnabled()) { 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 14037882b4..1f56b58520 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 @@ -661,6 +661,32 @@ public class ActiveMQServerControlTest extends ManagementTestBase { serverControl.destroyQueue(name.toString()); } + @Test + public void testGetQueueCount() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + SimpleString name = RandomUtil.randomSimpleString(); + + ActiveMQServerControl serverControl = createManagementControl(); + + // due to replication, there can be another queue created for replicating + // management operations + Assert.assertFalse(ActiveMQServerControlTest.contains(name.toString(), serverControl.getQueueNames())); + + int countBeforeCreate = serverControl.getQueueCount(); + + serverControl.createAddress(address.toString(), "ANYCAST"); + if (legacyCreateQueue) { + serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, true, -1, false, false); + } else { + serverControl.createQueue(new QueueConfiguration(name).setAddress(address).setRoutingType(RoutingType.ANYCAST).setDurable(true).setAutoCreateAddress(false).toJSON()); + } + + Assert.assertTrue(countBeforeCreate < serverControl.getQueueCount()); + + serverControl.destroyQueue(name.toString()); + Assert.assertFalse(ActiveMQServerControlTest.contains(name.toString(), serverControl.getQueueNames())); + } + @Test public void testGetQueueNames() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); @@ -741,6 +767,31 @@ public class ActiveMQServerControlTest extends ManagementTestBase { Assert.assertTrue(ActiveMQServerControlTest.contains(clusterConnection2, serverControl.getClusterConnectionNames())); } + @Test + public void testGetAddressCount() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + SimpleString name = RandomUtil.randomSimpleString(); + + ActiveMQServerControl serverControl = createManagementControl(); + + // due to replication, there can be another queue created for replicating + // management operations + Assert.assertFalse(ActiveMQServerControlTest.contains(address.toString(), serverControl.getAddressNames())); + + int countBeforeCreate = serverControl.getAddressCount(); + + if (legacyCreateQueue) { + serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, true, -1, false, true); + } else { + serverControl.createQueue(new QueueConfiguration(name).setAddress(address).setRoutingType(RoutingType.ANYCAST).toJSON()); + } + + Assert.assertTrue(countBeforeCreate < serverControl.getAddressCount()); + + serverControl.destroyQueue(name.toString(), true, true); + Assert.assertFalse(ActiveMQServerControlTest.contains(address.toString(), serverControl.getAddressNames())); + } + @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 28b02e045b..5d04f6c66f 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 @@ -375,11 +375,21 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes return (String) proxy.retrieveAttributeValue("connectorsAsJSON"); } + @Override + public int getAddressCount() { + return (Integer) proxy.retrieveAttributeValue("addressCount", Integer.class); + } + @Override public String[] getAddressNames() { return (String[]) proxy.retrieveAttributeValue("addressNames", String.class); } + @Override + public int getQueueCount() { + return (Integer) proxy.retrieveAttributeValue("queueCount", Integer.class); + } + @Override public String[] getQueueNames() { return (String[]) proxy.retrieveAttributeValue("queueNames", String.class);