Repository: activemq-artemis Updated Branches: refs/heads/2.6.x 10a4e90dc -> 049381679
ARTEMIS-1951 allow queue's user to be updated (cherry picked from commit 754a263328fe01cd2ce95b44440067c329a80771) Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/0f7d3d51 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/0f7d3d51 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/0f7d3d51 Branch: refs/heads/2.6.x Commit: 0f7d3d5109c326bdbfe8d74ac0c6a20b7eb964d6 Parents: 10a4e90 Author: Justin Bertram <[email protected]> Authored: Thu Jun 21 12:50:11 2018 -0500 Committer: Justin Bertram <[email protected]> Committed: Mon Oct 1 13:03:14 2018 -0500 ---------------------------------------------------------------------- .../core/management/ActiveMQServerControl.java | 23 ++++++++++++++++++++ .../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 +++++ .../core/server/impl/fakes/FakePostOffice.java | 3 ++- 13 files changed, 111 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java ---------------------------------------------------------------------- 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 83f66b7..234a2d5 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,9 +619,11 @@ 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, @@ -629,6 +632,26 @@ public interface ActiveMQServerControl { @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, + @Parameter(name = "user", desc = "The user associated with this queue") String user) throws Exception; + + /** * Deploy a durable queue. * <br> * If {@code address} is {@code null} it will be defaulted to {@code name}. http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java ---------------------------------------------------------------------- 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 5cb0c56..a005907 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)); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java ---------------------------------------------------------------------- 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 19ddd94..024a806 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<Queue> listQueuesForAddress(SimpleString address) throws Exception; http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java ---------------------------------------------------------------------- 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 68df53d..4c78a79 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(); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java ---------------------------------------------------------------------- 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 130ce22..cfc5bb9 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 @@ -447,6 +447,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 http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/Queue.java ---------------------------------------------------------------------- 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 c549be9..0e16718 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); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java ---------------------------------------------------------------------- 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 87aafdc..1e5343c 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 @@ -2568,7 +2568,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 { @@ -2970,6 +2971,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { return queue; } + @Deprecated @Override public Queue updateQueue(String name, RoutingType routingType, @@ -2978,13 +2980,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; http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java ---------------------------------------------------------------------- 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 c80d4f3..624d8ce 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; @@ -490,6 +490,11 @@ public class QueueImpl extends CriticalComponentImpl implements Queue { } @Override + public void setUser(SimpleString user) { + this.user = user; + } + + @Override public boolean isExclusive() { return exclusive; } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/ScheduledDeliveryHandlerTest.java ---------------------------------------------------------------------- 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 9005898..f45a1dd 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; http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java ---------------------------------------------------------------------- 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 f5b6a00..9c8da67 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(); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java ---------------------------------------------------------------------- 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 35b4615..ae24a45 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 @@ -145,6 +145,17 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes } @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); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/postoffice/impl/FakeQueue.java ---------------------------------------------------------------------- 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 5c37aec..192d700 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 @@ -739,6 +739,11 @@ public class FakeQueue extends CriticalComponentImpl implements Queue { } @Override + public void setUser(SimpleString user) { + // no-op + } + + @Override public long getDeliveringSize() { return 0; } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/0f7d3d51/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java ---------------------------------------------------------------------- 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 6402bff..b0560e3 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; }
