Author: tross Date: Wed Mar 13 18:34:58 2013 New Revision: 1456081 URL: http://svn.apache.org/r1456081 Log: QPID-4559 - Added handling of the queue-delete preconditions in the qmf broker method. Patch contributed by Ernie Allen.
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h qpid/trunk/qpid/cpp/src/tests/cli_tests.py qpid/trunk/qpid/tools/src/py/qpid-config qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?rev=1456081&r1=1456080&r2=1456081&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Wed Mar 13 18:34:58 2013 @@ -624,6 +624,10 @@ const std::string SRC_IS_QUEUE("srcIsQue const std::string SRC_IS_LOCAL("srcIsLocal"); const std::string DYNAMIC("dynamic"); const std::string SYNC("sync"); + +// parameters for deleting a Queue object +const std::string IF_EMPTY("if_empty"); +const std::string IF_UNUSED("if_unused"); } struct InvalidBindingIdentifier : public qpid::Exception @@ -890,7 +894,14 @@ void Broker::deleteObject(const std::str } QPID_LOG (debug, "Broker::delete(" << type << ", " << name << "," << options << ")"); if (type == TYPE_QUEUE) { - deleteQueue(name, userId, connectionId); + // extract ifEmpty and ifUnused from options + bool ifUnused = false, ifEmpty = false; + for (Variant::Map::const_iterator i = options.begin(); i != options.end(); ++i) { + if (i->first == IF_UNUSED) ifUnused = i->second.asBool(); + else if (i->first == IF_EMPTY) ifEmpty = i->second.asBool(); + } + deleteQueue(name, userId, connectionId, + boost::bind(&Broker::checkDeleteQueue, this, _1, ifUnused, ifEmpty)); } else if (type == TYPE_EXCHANGE || type == TYPE_TOPIC) { deleteExchange(name, userId, connectionId); } else if (type == TYPE_BINDING) { @@ -909,7 +920,17 @@ void Broker::deleteObject(const std::str } else { throw UnknownObjectType(type); } +} +void Broker::checkDeleteQueue(Queue::shared_ptr queue, bool ifUnused, bool ifEmpty) +{ + if(ifEmpty && queue->getMessageCount() > 0) { + throw qpid::framing::PreconditionFailedException(QPID_MSG("Cannot delete queue " + << queue->getName() << "; queue not empty")); + } else if(ifUnused && queue->getConsumerCount() > 0) { + throw qpid::framing::PreconditionFailedException(QPID_MSG("Cannot delete queue " + << queue->getName() << "; queue in use")); + } } Manageable::status_t Broker::queryObject(const std::string& type, Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h?rev=1456081&r1=1456080&r2=1456081&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h Wed Mar 13 18:34:58 2013 @@ -152,6 +152,7 @@ class Broker : public sys::Runnable, pub const qpid::types::Variant::Map& properties, bool strict, const ConnectionState* context); void deleteObject(const std::string& type, const std::string& name, const qpid::types::Variant::Map& options, const ConnectionState* context); + void checkDeleteQueue(boost::shared_ptr<Queue> queue, bool ifUnused, bool ifEmpty); Manageable::status_t queryObject(const std::string& type, const std::string& name, qpid::types::Variant::Map& results, const ConnectionState* context); Manageable::status_t queryQueue( const std::string& name, Modified: qpid/trunk/qpid/cpp/src/tests/cli_tests.py URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/cli_tests.py?rev=1456081&r1=1456080&r2=1456081&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/tests/cli_tests.py (original) +++ qpid/trunk/qpid/cpp/src/tests/cli_tests.py Wed Mar 13 18:34:58 2013 @@ -135,6 +135,44 @@ class CliTests(TestBase010): found = True self.assertEqual(found, False) + def test_qpid_config_del_nonempty_queue(self): + self.startBrokerAccess(); + qname = "test_qpid_config_del" + + ret = os.system(self.qpid_config_command(" add queue " + qname)) + self.assertEqual(ret, 0) + queues = self.broker_access.getAllQueues() + found = False + for queue in queues: + if queue.name == qname: + self.assertEqual(queue.durable, False) + found = True + self.assertEqual(found, True) + + self.startBrokerAccess() + + sess = self.broker_conn.session() + tx = sess.sender(qname) + tx.send("MESSAGE") + + ret = os.system(self.qpid_config_command(" del queue " + qname)) + queues = self.broker_access.getAllQueues() + found = False + for queue in queues: + if queue.name == qname: + found = True + self.assertEqual(found, True) + + ret = os.system(self.qpid_config_command(" del queue " + qname + " --force")) + self.assertEqual(ret, 0) + queues = self.broker_access.getAllQueues() + found = False + for queue in queues: + if queue.name == qname: + found = True + self.assertEqual(found, False) + + def test_qpid_config_api(self): self.startBrokerAccess(); qname = "test_qpid_config_api" @@ -222,7 +260,6 @@ class CliTests(TestBase010): self.assertEqual(ret, 0) self.helper_find_queue(qname, False) - # test the bind-queue-to-header-exchange functionality def test_qpid_config_headers(self): self.startBrokerAccess(); Modified: qpid/trunk/qpid/tools/src/py/qpid-config URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-config?rev=1456081&r1=1456080&r2=1456081&view=diff ============================================================================== --- qpid/trunk/qpid/tools/src/py/qpid-config (original) +++ qpid/trunk/qpid/tools/src/py/qpid-config Wed Mar 13 18:34:58 2013 @@ -624,7 +624,8 @@ class BrokerManager: if len(args) < 1: Usage() qname = args[0] - self.broker.delQueue(qname) + self.broker.delQueue(qname, if_empty=config._if_empty, if_unused=config._if_unused) + def Bind(self, args): Modified: qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py?rev=1456081&r1=1456080&r2=1456081&view=diff ============================================================================== --- qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py (original) +++ qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py Wed Mar 13 18:34:58 2013 @@ -250,8 +250,13 @@ class BrokerAgent(object): 'strict': True} self._method('create', args) - def delQueue(self, name): - args = {'type': 'queue', 'name': name} + def delQueue(self, name, if_empty=True, if_unused=True): + options = {'if_empty': if_empty, + 'if_unused': if_unused} + + args = {'type': 'queue', + 'name': name, + 'options': options} self._method('delete', args) def bind(self, exchange, queue, key, options={}, **kwargs): --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org