From 754a263328fe01cd2ce95b44440067c329a80771 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Thu, 21 Jun 2018 12:50:11 -0500 Subject: [PATCH] ARTEMIS-1951 allow queue's user to be updated --- .../management/ActiveMQServerControl.java | 25 ++++++++++++++++++- .../impl/ActiveMQServerControlImpl.java | 14 ++++++++++- .../artemis/core/postoffice/PostOffice.java | 3 ++- .../core/postoffice/impl/PostOfficeImpl.java | 7 +++++- .../artemis/core/server/ActiveMQServer.java | 7 ++++++ .../activemq/artemis/core/server/Queue.java | 7 +++++- .../core/server/impl/ActiveMQServerImpl.java | 17 +++++++++++-- .../artemis/core/server/impl/QueueImpl.java | 7 +++++- .../impl/ScheduledDeliveryHandlerTest.java | 6 +++++ .../integration/client/UpdateQueueTest.java | 12 ++++++--- .../ActiveMQServerControlUsingCoreTest.java | 11 ++++++++ .../unit/core/postoffice/impl/FakeQueue.java | 5 ++++ .../server/impl/fakes/FakePostOffice.java | 3 ++- 13 files changed, 112 insertions(+), 12 deletions(-) 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 83f66b7aea..234a2d514c 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 @@ -605,6 +605,7 @@ public interface ActiveMQServerControl { * @return a textual summary of the queue * @throws Exception */ + @Deprecated @Operation(desc = "Update a queue", impact = MBeanOperationInfo.ACTION) String updateQueue(@Parameter(name = "name", desc = "Name of the queue") String name, @Parameter(name = "routingType", desc = "The routing type used for this address, MULTICAST or ANYCAST") String routingType, @@ -618,15 +619,37 @@ public interface ActiveMQServerControl { * @param routingType the routing type used for this address, {@code MULTICAST} or {@code ANYCAST} * @param maxConsumers the maximum number of consumers allowed on this queue at any one time * @param purgeOnNoConsumers delete this queue when the last consumer disconnects + * @param exclusive if the queue should route exclusively to one consumer * @return a textual summary of the queue * @throws Exception */ + @Deprecated + @Operation(desc = "Update a queue", impact = MBeanOperationInfo.ACTION) + String updateQueue(@Parameter(name = "name", desc = "Name of the queue") String name, + @Parameter(name = "routingType", desc = "The routing type used for this address, MULTICAST or ANYCAST") String routingType, + @Parameter(name = "maxConsumers", desc = "The maximum number of consumers allowed on this queue at any one time") Integer maxConsumers, + @Parameter(name = "purgeOnNoConsumers", desc = "Delete this queue when the last consumer disconnects") Boolean purgeOnNoConsumers, + @Parameter(name = "exclusive", desc = "If the queue should route exclusively to one consumer") Boolean exclusive) throws Exception; + + /** + * Update a queue + * + * @param name name of the queue + * @param routingType the routing type used for this address, {@code MULTICAST} or {@code ANYCAST} + * @param maxConsumers the maximum number of consumers allowed on this queue at any one time + * @param purgeOnNoConsumers delete this queue when the last consumer disconnects + * @param exclusive if the queue should route exclusively to one consumer + * @param user the user associated with this queue + * @return + * @throws Exception + */ @Operation(desc = "Update a queue", impact = MBeanOperationInfo.ACTION) String updateQueue(@Parameter(name = "name", desc = "Name of the queue") String name, @Parameter(name = "routingType", desc = "The routing type used for this address, MULTICAST or ANYCAST") String routingType, @Parameter(name = "maxConsumers", desc = "The maximum number of consumers allowed on this queue at any one time") Integer maxConsumers, @Parameter(name = "purgeOnNoConsumers", desc = "Delete this queue when the last consumer disconnects") Boolean purgeOnNoConsumers, - @Parameter(name = "exclusive", desc = "If the queue should route exclusively to one consumer") Boolean exclusive) throws Exception; + @Parameter(name = "exclusive", desc = "If the queue should route exclusively to one consumer") Boolean exclusive, + @Parameter(name = "user", desc = "The user associated with this queue") String user) throws Exception; /** * Deploy a durable queue. 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 cabdc1050f..9ed7acdf3d 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 @@ -825,6 +825,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } } + @Deprecated @Override public String updateQueue(String name, String routingType, @@ -833,18 +834,29 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active return updateQueue(name, routingType, maxConsumers, purgeOnNoConsumers, null); } + @Deprecated @Override public String updateQueue(String name, String routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, Boolean exclusive) throws Exception { + return updateQueue(name, routingType, maxConsumers, purgeOnNoConsumers, exclusive, null); + } + + @Override + public String updateQueue(String name, + String routingType, + Integer maxConsumers, + Boolean purgeOnNoConsumers, + Boolean exclusive, + String user) throws Exception { checkStarted(); clearIO(); try { - final Queue queue = server.updateQueue(name, routingType != null ? RoutingType.valueOf(routingType) : null, maxConsumers, purgeOnNoConsumers, exclusive); + final Queue queue = server.updateQueue(name, routingType != null ? RoutingType.valueOf(routingType) : null, maxConsumers, purgeOnNoConsumers, exclusive, user); if (queue == null) { throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(new SimpleString(name)); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java index 19ddd94f39..024a80671d 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java @@ -68,7 +68,8 @@ public interface PostOffice extends ActiveMQComponent { RoutingType routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, - Boolean exclusive) throws Exception; + Boolean exclusive, + String user) throws Exception; List listQueuesForAddress(SimpleString address) throws Exception; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java index 5fbb2d8dc9..e3df0c4006 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java @@ -467,7 +467,8 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding RoutingType routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, - Boolean exclusive) throws Exception { + Boolean exclusive, + String user) throws Exception { synchronized (addressLock) { final QueueBinding queueBinding = (QueueBinding) addressManager.getBinding(name); if (queueBinding == null) { @@ -511,6 +512,10 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding changed = true; queue.setExclusive(exclusive); } + if ((user != null && !user.equals(queue.getUser()) || (user == null && queue.getUser() != null))) { + changed = true; + queue.setUser(SimpleString.toSimpleString(user)); + } if (changed) { final long txID = storageManager.generateID(); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java index 78ebbb710c..c2e4cbf2b1 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java @@ -445,6 +445,13 @@ public interface ActiveMQServer extends ServiceComponent { Boolean purgeOnNoConsumers, Boolean exclusive) throws Exception; + Queue updateQueue(String name, + RoutingType routingType, + Integer maxConsumers, + Boolean purgeOnNoConsumers, + Boolean exclusive, + String user) throws Exception; + /* * add a ProtocolManagerFactory to be used. Note if @see Configuration#isResolveProtocols is tur then this factory will * replace any factories with the same protocol diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/Queue.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/Queue.java index c549be9bf3..0e16718af6 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/Queue.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/Queue.java @@ -352,10 +352,15 @@ public interface Queue extends Bindable,CriticalComponent { float getRate(); /** - * @return the user who created this queue + * @return the user associated with this queue */ SimpleString getUser(); + /** + * @param user the user associated with this queue + */ + void setUser(SimpleString user); + /** This is to perform a check on the counter again */ void recheckRefCount(OperationContext context); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index ebe0401a1d..1e722aa00c 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -2546,7 +2546,8 @@ public class ActiveMQServerImpl implements ActiveMQServer { int maxConsumer = (config.isMaxConsumerConfigured()) ? maxConsumerQueueConfig : maxConsumerAddressSetting; if (locateQueue(queueName) != null && locateQueue(queueName).getAddress().toString().equals(config.getAddress())) { updateQueue(config.getName(), config.getRoutingType(), maxConsumer, config.getPurgeOnNoConsumers(), - config.isExclusive() == null ? as.isDefaultExclusiveQueue() : config.isExclusive()); + config.isExclusive() == null ? as.isDefaultExclusiveQueue() : config.isExclusive(), + config.getUser()); } else { // if the address::queue doesn't exist then create it try { @@ -2943,6 +2944,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { return queue; } + @Deprecated @Override public Queue updateQueue(String name, RoutingType routingType, @@ -2951,13 +2953,24 @@ public class ActiveMQServerImpl implements ActiveMQServer { return updateQueue(name, routingType, maxConsumers, purgeOnNoConsumers, null); } + @Deprecated @Override public Queue updateQueue(String name, RoutingType routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, Boolean exclusive) throws Exception { - final QueueBinding queueBinding = this.postOffice.updateQueue(new SimpleString(name), routingType, maxConsumers, purgeOnNoConsumers, exclusive); + return updateQueue(name, routingType, maxConsumers, purgeOnNoConsumers, null, null); + } + + @Override + public Queue updateQueue(String name, + RoutingType routingType, + Integer maxConsumers, + Boolean purgeOnNoConsumers, + Boolean exclusive, + String user) throws Exception { + final QueueBinding queueBinding = this.postOffice.updateQueue(new SimpleString(name), routingType, maxConsumers, purgeOnNoConsumers, exclusive, user); if (queueBinding != null) { final Queue queue = queueBinding.getQueue(); return queue; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java index 5da8dc1ef5..fdb0ddd84b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java @@ -136,7 +136,7 @@ public class QueueImpl extends CriticalComponentImpl implements Queue { private final SimpleString name; - private final SimpleString user; + private SimpleString user; private volatile Filter filter; @@ -491,6 +491,11 @@ public class QueueImpl extends CriticalComponentImpl implements Queue { return user; } + @Override + public void setUser(SimpleString user) { + this.user = user; + } + @Override public boolean isExclusive() { return exclusive; diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ScheduledDeliveryHandlerTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ScheduledDeliveryHandlerTest.java index 9005898a8f..f45a1ddce2 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ScheduledDeliveryHandlerTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ScheduledDeliveryHandlerTest.java @@ -1393,6 +1393,12 @@ public class ScheduledDeliveryHandlerTest extends Assert { public SimpleString getUser() { return null; } + + @Override + public void setUser(SimpleString user) { + + } + @Override public boolean isLastValue() { return false; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java index f5b6a001f9..9c8da67478 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java @@ -49,7 +49,11 @@ public class UpdateQueueTest extends ActiveMQTestBase { SimpleString ADDRESS = SimpleString.toSimpleString("queue.0"); - long originalID = server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, null, true, false).getID(); + Queue queue = server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, null, true, false); + + long originalID = queue.getID(); + + Assert.assertNull(queue.getUser()); Connection conn = factory.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -59,7 +63,7 @@ public class UpdateQueueTest extends ActiveMQTestBase { prod.send(session.createTextMessage("message " + i)); } - server.updateQueue(ADDRESS.toString(), RoutingType.ANYCAST, 1, false, false); + server.updateQueue(ADDRESS.toString(), RoutingType.ANYCAST, 1, false, false, "newUser"); conn.close(); factory.close(); @@ -69,10 +73,12 @@ public class UpdateQueueTest extends ActiveMQTestBase { validateBindingRecords(server, JournalRecordIds.QUEUE_BINDING_RECORD, 2); - Queue queue = server.locateQueue(ADDRESS); + queue = server.locateQueue(ADDRESS); Assert.assertNotNull("queue not found", queue); + Assert.assertEquals("newUser", queue.getUser().toString()); + factory = new ActiveMQConnectionFactory(); conn = factory.createConnection(); 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 35b46153be..ae24a45d2a 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 @@ -144,6 +144,17 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes return (String) proxy.invokeOperation("updateQueue", name, routingType, maxConsumers, purgeOnNoConsumers, exclusive); } + @Override + public String updateQueue(@Parameter(name = "name", desc = "Name of the queue") String name, + @Parameter(name = "routingType", desc = "The routing type used for this address, MULTICAST or ANYCAST") String routingType, + @Parameter(name = "maxConsumers", desc = "The maximum number of consumers allowed on this queue at any one time") Integer maxConsumers, + @Parameter(name = "purgeOnNoConsumers", desc = "Delete this queue when the last consumer disconnects") Boolean purgeOnNoConsumers, + @Parameter(name = "exclusive", desc = "If the queue should route exclusively to one consumer") Boolean exclusive, + @Parameter(name = "user", desc = "The user associated with this queue") String user) + throws Exception { + return (String) proxy.invokeOperation("updateQueue", name, routingType, maxConsumers, purgeOnNoConsumers, exclusive, user); + } + @Override public void deleteAddress(@Parameter(name = "name", desc = "The name of the address") String name) throws Exception { proxy.invokeOperation("deleteAddress", name); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java index 5c37aec355..192d7009d1 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java @@ -738,6 +738,11 @@ public class FakeQueue extends CriticalComponentImpl implements Queue { return null; } + @Override + public void setUser(SimpleString user) { + // no-op + } + @Override public long getDeliveringSize() { return 0; diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java index 6402bff2cf..b0560e3989 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java @@ -48,7 +48,8 @@ public class FakePostOffice implements PostOffice { RoutingType routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, - Boolean exclusive) throws Exception { + Boolean exclusive, + String user) throws Exception { return null; }