[rhmessaging-commits] rhmessaging commits: r3937 - mgmt/newdata/cumin/python/cumin/messaging.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Apr 26 16:17:26 EDT 2010


Author: eallen
Date: 2010-04-26 16:17:25 -0400 (Mon, 26 Apr 2010)
New Revision: 3937

Modified:
   mgmt/newdata/cumin/python/cumin/messaging/broker.py
Log:
Broker Engroup

Modified: mgmt/newdata/cumin/python/cumin/messaging/broker.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/broker.py	2010-04-26 20:16:39 UTC (rev 3936)
+++ mgmt/newdata/cumin/python/cumin/messaging/broker.py	2010-04-26 20:17:25 UTC (rev 3937)
@@ -70,8 +70,6 @@
         self.add_attribute_column(broker.port)
         self.add_attribute_column(cluster.clusterName)
 
-        #self.add_selection_task(app.messaging.BrokerEngroup)
-
     def get_data_values(self, session):
         values = super(BrokerSelector, self).get_data_values(session)
 
@@ -129,7 +127,10 @@
         self.exchange_add = ExchangeAdd(app, self)
         self.brokerlink_add = BrokerLinkAdd(app, self)
         self.move_messages = MoveMessages(app, self)
+        self.engroup = BrokerEngroup(app, self)
+        #self.add_selection_task(app.messaging.BrokerEngroup)
 
+
     def get_object(self, session, id):
         # self.object is Vhost, and we stick Broker in self.broker
 
@@ -147,54 +148,8 @@
 
     def get_title(self, session):
         obj = self.broker.get(session)
-        
         return "%s '%s'" % (obj._class._title, obj.get_title())
 
-class MoveMessages(ObjectTask):
-    def __init__(self, app, frame):
-        super(MoveMessages, self).__init__(app, frame)
-
-        self.form = MoveMessagesForm(app, self.name, self)
-
-    def get_title(self, session):
-        return "Move messages"
-
-    def do_invoke(self, invoc, vhost, src, dst, count):
-        self.qmf_call(invoc, vhost, src, dst, count)
-
-class MoveMessagesForm(ObjectTaskForm):
-    def __init__(self, app, name, task):
-        super(MoveMessagesForm, self).__init__(app, name, task)
-
-        self.queue = QueueParameter(app, "queue")
-        self.add_parameter(self.queue)
-
-        self.dest_queue = QueueSelectField(app, "dest", self)
-        self.add_field(self.dest_queue)
-
-        self.count = MultiplicityField(app, "count")
-        self.add_field(self.count)
-
-    def process_submit(self, session):
-        self.validate(session)
-
-        if not self.errors.get(session):
-            queue = self.queue.get(session)
-            dest_queue = self.dest_queue.get(session)
-            scount = self.count.get(session)
-
-            if scount == "all":
-                count = 0
-            elif scount == "top":
-                count = 1
-            elif scount == "N":
-                count = self.count.top_n.get_n_value(session)
-            else:
-                raise Exception("Wrong Value")
-
-            self.task.invoke(session, queue, dest_queue, count)
-            self.task.exit_with_redirect(session)
-
 class ModuleNotEnabled(Widget):
     def do_render(self, session):
         return "This module is not enabled"
@@ -393,3 +348,77 @@
             reg = Identifiable(data["id"])
             href = self.page.main.messaging.broker.get_href(session, reg)
             return fmt_link(href, fmt_shorten(data["name"]))
+
+class BrokerEngroupTaskForm(ObjectTaskForm):
+    def __init__(self, app, name, task):
+        super(BrokerEngroupTaskForm, self).__init__(app, name, task)
+
+        group = NewBrokerGroupParameter(app, "group")
+        self.groups = self.Groups(app, "groups", group)
+        self.add_field(self.groups)
+
+    def do_process(self, session):
+        super(BrokerEngroupTaskForm, self).do_process(session)
+
+        vhost = self.object.get(session)
+
+        cls = self.app.rosemary.com_redhat_cumin.BrokerGroupMapping
+        mappings = cls.get_selection(session.cursor, _broker_id=vhost._brokerRef_id)
+        checked_groups = [x._group_id for x in mappings]
+        self.groups.inputs.set(session, checked_groups)
+
+    def process_submit(self, session):
+        vhost = self.object.get(session)
+        cls = self.app.rosemary.org_apache_qpid_broker.Broker
+        broker = cls.get_object(session.cursor, vhost._brokerRef_id)
+        groups = self.groups.get(session)
+
+        self.task.invoke(session, broker, groups)
+        self.task.exit_with_redirect(session)
+
+    class Groups(CheckboxItemSetField):
+        def render_title(self, session):
+            return "Groups"
+
+        def do_get_items(self, session):
+            cls = self.app.rosemary.com_redhat_cumin.BrokerGroup
+            groups = cls.get_selection(session.cursor)
+            return (FormInputItem(x._id, title=x.name) for x in groups)
+
+class BrokerEngroup(ObjectTask):
+    def __init__(self, app, selector):
+        super(BrokerEngroup, self).__init__(app, selector)
+
+        self.form = BrokerEngroupTaskForm(app, "engroup", self)
+
+    def get_title(self, session):
+        return "Add to groups"
+
+    def do_invoke(self, invoc, broker, groups):
+        conn = self.app.model.get_sql_connection()
+        cursor = conn.cursor()
+
+        cls = self.app.rosemary.com_redhat_cumin.BrokerGroup
+        all_groups = cls.get_selection(cursor)
+        selected_ids = [x._id for x in groups]
+
+        cls = self.app.rosemary.com_redhat_cumin.BrokerGroupMapping
+        try:
+            for group in all_groups:
+                existing_mapping = cls.get_selection(cursor, _broker_id=broker._id, _group_id=group._id)
+                if not group._id in selected_ids:
+                    if len(existing_mapping) > 0:
+                        existing_mapping[0].delete(cursor)
+                else:
+                    if len(existing_mapping) == 0:
+                        new_mapping = cls.create_object(cursor)
+                        new_mapping._broker_id = broker._id
+                        new_mapping._group_id = group._id
+                        new_mapping.fake_qmf_values()
+                        new_mapping.save(cursor)
+        finally:
+            cursor.close()
+
+        conn.commit()
+
+        invoc.end()



More information about the rhmessaging-commits mailing list