Author: eallen
Date: 2010-04-26 16:16:10 -0400 (Mon, 26 Apr 2010)
New Revision: 3935
Modified:
mgmt/newdata/cumin/python/cumin/grid/negotiator.py
mgmt/newdata/cumin/python/cumin/grid/submission.py
mgmt/newdata/cumin/python/cumin/main.py
mgmt/newdata/cumin/python/cumin/messaging/queue.py
mgmt/newdata/cumin/python/cumin/widgets.py
mgmt/newdata/cumin/python/cumin/widgets.strings
Log:
TopQueue, TopSystems, TopSubmissions
Modified: mgmt/newdata/cumin/python/cumin/grid/negotiator.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/negotiator.py 2010-04-26 20:11:31 UTC (rev 3934)
+++ mgmt/newdata/cumin/python/cumin/grid/negotiator.py 2010-04-26 20:16:10 UTC (rev 3935)
@@ -63,7 +63,7 @@
def __init__(self, app, name, getter, negotiator, task):
super(QmfGroupColumn, self).__init__(app, name)
- self.header_class = TopTableColumnHeader
+ self.header_class = ItemTableColumnHeader
self.title = None
self.getter = getter
@@ -125,7 +125,7 @@
self.buttons.add_child(button)
col = self.ExpandColumn(app, "expand_col")
- col.header_class = TopTableColumnHeader
+ col.header_class = ItemTableColumnHeader
self.add_column(col)
col = self.GroupColumn(app, "group")
Modified: mgmt/newdata/cumin/python/cumin/grid/submission.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/submission.py 2010-04-26 20:11:31 UTC (rev 3934)
+++ mgmt/newdata/cumin/python/cumin/grid/submission.py 2010-04-26 20:16:10 UTC (rev 3935)
@@ -256,40 +256,3 @@
class AttributesField(MultilineStringField):
def render_title(self, session):
return "Extra attributes"
-
-class TopSubmissionSet(TopTable):
- def __init__(self, app, name):
- super(TopSubmissionSet, self).__init__(app, name)
-
- col = self.NameColumn(app, "name")
- col.width = "60%"
- self.add_column(col)
-
- self.set_default_column(col)
-
- col = self.DurationColumn(app, "name")
- col.width = "35%"
- col.align = "right"
- self.add_column(col)
-
- class NameColumn(TopTableColumn):
- def render_title(self, session):
- return "Name"
-
- def render_content(self, session, data):
- pool = Identifiable(data["pool"])
- submission = Identifiable(data["id"])
-
- branch = session.branch()
- self.page.main.grid.pool.object.set(session, pool)
- self.page.main.grid.pool.submission.object.set(session, submission)
- self.page.main.grid.pool.submission.show(session)
- return fmt_link(branch.marshal(), data["name"],
link_title=data["name"])
-
- class DurationColumn(TopTableColumn):
- def render_title(self, session):
- return "Duration"
-
- def render_content(self, session, data):
- since = data["qmf_create_time"]
- return fmt_duration(time() - secs(since))
Modified: mgmt/newdata/cumin/python/cumin/main.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/main.py 2010-04-26 20:11:31 UTC (rev 3934)
+++ mgmt/newdata/cumin/python/cumin/main.py 2010-04-26 20:16:10 UTC (rev 3935)
@@ -171,6 +171,12 @@
queues = TopQueueTable(app, "queues")
self.add_child(queues)
+ systems = TopSystemTable(app, "systems")
+ self.add_child(systems)
+
+ submissions = TopSubmissionTable(app, "submissions")
+ self.add_child(submissions)
+
# XXX
#queues = messaging.queue.TopQueueSet(app, "queues")
@@ -197,26 +203,6 @@
super(TopQueueAdapter, self).__init__(app, cls.sql_table)
self.cls = cls
- """
-select
- "Queue"."name",
- ((sum("Queue"."msgTotalEnqueues") -
- sum(s."msgTotalEnqueues")) / (count(1)-1)) / 30 as avg_60,
- "Vhost"."_brokerRef_id",
- "Queue"."_id"
-from "org.apache.qpid.broker"."Queue"
-inner join (
- select
- "Queue_samples"."_parent_id",
- "Queue_samples"."msgTotalEnqueues"
- from "org.apache.qpid.broker"."Queue_samples"
- where "Queue_samples"."_qmf_update_time" >= now() - interval
'60 seconds') as s on "Queue"."_id" = s._parent_id
-inner join "org.apache.qpid.broker"."Vhost" on
"Queue"."_vhostRef_id" = "Vhost"."_id"
-group by "Queue".name, "Queue"._id,
"Vhost"."_brokerRef_id" having count(1) > 1
-order by avg_60 desc
-limit 5 offset 0
- """
-
def init(self):
super(TopQueueAdapter, self).init()
@@ -274,7 +260,7 @@
def get_sql_options(self, options):
return options
-class TopQueueTable(DataTable, Form):
+class TopQueueTable(TopTable):
def __init__(self, app, name):
cls = app.rosemary.org_apache_qpid_broker.Queue
adapter = TopQueueAdapter(app, cls)
@@ -288,26 +274,6 @@
cls.msgTotalEnqueues)
self.add_column(col)
- self.header = TopTableHeader(app, "header")
- self.replace_child(self.header)
-
- self.footer = TopTableFooter(app, "footer")
- self.replace_child(self.footer)
-
- self.update_enabled = True
-
- def get_data_options(self, session):
- options = SqlQueryOptions()
-
- options.limit = 5
- options.offset = 0
-
- return options
-
- def get_count(self, session):
- # avoid extra sql call since we don't show the record count
- return 0
-
class MsgEnqueuesColumn(DataTableColumn):
def render_header_content(self, session):
return "Recent Enqueues / sec"
@@ -334,14 +300,62 @@
def render_cell_content(self, session, record):
return record[0]
-class TopTableHeader(TableHeader):
+class TopSystemTable(TopObjectTable):
def __init__(self, app, name):
- super(TopTableHeader, self).__init__(app, name)
+ cls = app.rosemary.com_redhat_sesame.Sysimage
- self.font = Attribute(app, "font")
- self.font.default = 0.9
- self.add_attribute(self.font)
+ super(TopSystemTable, self).__init__(app, name, cls)
-class TopTableFooter(Widget):
- def render(self, session):
- return ""
+ frame = "main.inventory.system"
+ col = ObjectLinkColumn(app, "name", cls.nodeName, cls._id, frame)
+ self.add_column(col)
+
+ self.add_attribute_column(cls.loadAverage1Min)
+ self.sort_col = cls.loadAverage1Min.name
+
+ self.header = TopTableHeader(app, "header")
+ self.replace_child(self.header)
+
+class TopSubmissionTable(TopObjectTable):
+ def __init__(self, app, name):
+ cls = app.rosemary.mrg_grid.Submission
+
+ super(TopSubmissionTable, self).__init__(app, name, cls)
+
+ col = self.NameColumn(app, cls.Name.name, cls.Name, cls._id, None)
+ self.add_column(col)
+
+ col = self.DurationColumn(app, cls._qmf_create_time.name, cls._qmf_create_time)
+ self.add_column(col)
+ self.sort_col = cls._qmf_create_time.name
+
+ running_col = self.adapter.table._columns_by_name["Running"]
+ SqlComparisonFilter(self.adapter.query,
+ running_col, "0", ">")
+
+ update_col = self.adapter.table._columns_by_name["_qmf_update_time"]
+ SqlComparisonFilter(self.adapter.query,
+ update_col, "now() - interval '60 seconds'",
">=")
+
+ class NameColumn(ObjectLinkColumn):
+ def render_cell_href(self, session, record):
+ # XXX fix this when submission has collector ref
+ pool = 1
+ submission = record[0]
+
+ branch = session.branch()
+ self.page.main.grid.pool.id.set(session, pool)
+ self.page.main.grid.pool.submission.id.set(session, submission)
+ self.page.main.grid.pool.submission.view.show(session)
+ return branch.marshal()
+
+ class DurationColumn(ObjectAttributeColumn):
+ def render_header_content(self, session):
+ return "Duration"
+
+ def render_cell_content(self, session, record):
+ created = self.field.get_content(session, record)
+ return fmt_duration(time() - secs(created))
+
+ def render_text_align(self, session):
+ return "right"
Modified: mgmt/newdata/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/queue.py 2010-04-26 20:11:31 UTC (rev 3934)
+++ mgmt/newdata/cumin/python/cumin/messaging/queue.py 2010-04-26 20:16:10 UTC (rev 3935)
@@ -44,6 +44,7 @@
self.remove = QueueRemove(app, self)
self.purge = QueuePurge(app, self)
+ self.move_messages = MoveQueueMessages(app, self)
class QueueRemove(ObjectTask):
def get_title(self, session):
@@ -636,47 +637,139 @@
def __init__(self, app, name, form):
super(QueueSelectField, self).__init__(app, name)
- self.queue_set = self.QueueSearchInputSet(app, "queue_set")
- self.add_child(self.queue_set)
+ self.param = self.QueueSearchInputSet(app, "queue_set")
+ self.add_child(self.param)
- self.param = self.QueueStringParameter(app, "param", self.queue_set)
- self.add_parameter(self.param)
-
def get(self, session):
return self.param.get(session)
def render_title(self, session):
- return "Select the destination queue"
+ return "Queue"
def render_inputs(self, session):
- return self.queue_set.render(session)
+ return self.param.render(session)
+ def validate(self, session):
+ if self.required:
+ val = self.get(session)
+ if not val:
+ error = FormError("The %s is required" %
self.render_title(session))
+ self.form.errors.add(session, error)
+
class QueueSearchInputSet(IncrementalSearchInput):
def do_get_items(self, session):
- queue = self.form.queue.get(session) # XXX
- queue_list_full = sorted_by(list(queue.vhost.queues))
+ cls = self.app.rosemary.org_apache_qpid_broker.Queue
+ vhost = self.form.get_object(session)
+ vhostid = vhost._id
+ queues = cls.get_selection(session.cursor, _vhostRef_id=vhostid)
+ queue_list_full = sorted_by(list(queues))
delta = timedelta(minutes=10)
queue_list = []
for _queue in queue_list_full:
- if (_queue.qmfUpdateTime > (datetime.now() - delta)) \
- and (_queue.name != queue.name):
+ if _queue._qmf_update_time > (datetime.now() - delta):
queue_list.append(_queue)
return queue_list
def render_item_content(self, session, queue):
return queue.name or "<em>Default</em>"
- class QueueStringParameter(Parameter):
- def __init__(self, app, name, queue_string):
- super(QueueSelectField.QueueStringParameter, self).__init__(app, name)
+class MoveMessagesBase(ObjectTask):
+ def get_title(self, session):
+ return "Move messages"
- self.queue_string = queue_string
+ def do_invoke(self, invoc, vhost, src, dst, count):
+ cls = self.app.rosemary.org_apache_qpid_broker.Broker
+ conn = self.app.model.get_sql_connection()
+ cursor = conn.cursor()
+ try:
+ broker = cls.get_object(cursor, vhost._brokerRef_id)
+ finally:
+ cursor.close()
+ self.qmf_call(invoc, broker, "queueMoveMessages", src, dst, count)
+class MoveQueueMessages(MoveMessagesBase):
+ def __init__(self, app, frame):
+ super(MoveQueueMessages, self).__init__(app, frame)
+
+ self.form = MoveQueueMessagesForm(app, self.name, self)
+
+class MoveMessages(MoveMessagesBase):
+ def __init__(self, app, frame):
+ super(MoveMessages, self).__init__(app, frame)
+
+ self.form = MoveMessagesForm(app, self.name, self)
+
+class MoveMessagesFormBase(ObjectTaskForm):
+ def __init__(self, app, name, task, src_queue):
+ super(MoveMessagesFormBase, self).__init__(app, name, task)
+
+ self.src_queue = src_queue
+ self.add_field(src_queue)
+
+ self.dest_queue = self.QueueDestField(app, "dest", self)
+ self.dest_queue.required = True
+ 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):
+ src_queue = self.src_queue.get(session)
+ dest_queue = self.dest_queue.get(session)
+ object = self.get_object(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, object, src_queue, dest_queue, count)
+ self.task.exit_with_redirect(session)
+
+ def get_object(self, session):
+ return self.object.get(session)
+
+ class QueueDestField(QueueSelectField):
+ def render_title(self, session):
+ return "Destination Queue"
+
+class MoveMessagesForm(MoveMessagesFormBase):
+ def __init__(self, app, name, task):
+ src_queue = self.QueueSrctField(app, "src", self)
+ src_queue.required = True
+ super(MoveMessagesForm, self).__init__(app, name, task, src_queue)
+
+ class QueueSrctField(QueueSelectField):
+ def render_title(self, session):
+ return "Source Queue"
+
+class MoveQueueMessagesForm(MoveMessagesFormBase):
+ def __init__(self, app, name, task):
+ src_queue = self.QueueSrcField(app, "src")
+ super(MoveQueueMessagesForm, self).__init__(app, name, task, src_queue)
+
+ def get_object(self, session):
+ # task expects a vhost object
+ queue = self.object.get(session)
+ cls = self.app.rosemary.org_apache_qpid_broker.Vhost
+ vhost = cls.get_object(session.cursor, queue._vhostRef_id)
+ return vhost
+
+ class QueueSrcField(FormField):
+ def render_title(self, session):
+ return "Source Queue"
+
+ def render_inputs(self, session):
+ return self.get(session)
+
def get(self, session):
- queue_string = self.queue_string.get(session)
- queue_where = "name = '%s'" % queue_string
- try:
- return Queue.select(queue_where)[0]
- except IndexError:
- return None
-
+ queue = self.form.object.get(session)
+ return queue.name
Modified: mgmt/newdata/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/widgets.py 2010-04-26 20:11:31 UTC (rev 3934)
+++ mgmt/newdata/cumin/python/cumin/widgets.py 2010-04-26 20:16:10 UTC (rev 3935)
@@ -730,41 +730,6 @@
return fmt_link("", title, class_, link_title=hover, bm=bm,
click=click)
-class TopTableColumn(SqlTableColumn):
- def __init__(self, app, name):
- super(TopTableColumn, self).__init__(app, name)
-
- self.header_class = TopTableColumnHeader
-
-class TopTableColumnHeader(ItemTableColumnHeader):
- pass
-
-class TopTable(SqlTable):
- def __init__(self, app, name):
- super(TopTable, self).__init__(app, name)
-
- self.html_class = TopTable.__name__
-
- col = self.CountColumn(app, "name")
- col.width = "5%"
- col.align = "right"
- self.add_column(col)
-
- self.update_enabled = True
-
- self.count = Attribute(app, "count")
- self.count.default = 1
- self.add_attribute(self.count)
-
- def get_connection(self, session):
- return self.app.model.get_sql_connection()
-
- class CountColumn(TopTableColumn):
- def render_content(self, session, data):
- count = self.parent.count.get(session)
- self.parent.count.set(session, count + 1)
- return count
-
class CuminItemTable(ItemTable):
def __init__(self, app, name):
super(CuminItemTable, self).__init__(app, name)
@@ -1480,3 +1445,85 @@
def render_item_class(self, session, item):
return "list_item"
+
+class TopTable(DataTable):
+ def __init__(self, app, name, adapter):
+ super(TopTable, self).__init__(app, name, adapter)
+
+ self.header = TopTableHeader(app, "header")
+ self.replace_child(self.header)
+
+ self.footer = TopTableFooter(app, "footer")
+ self.replace_child(self.footer)
+
+ self.update_enabled = True
+
+ def get_count(self, session):
+ # avoid extra sql call since we don't show the record count
+ return 0
+
+ def get_data_options(self, session):
+ options = SqlQueryOptions()
+
+ options.limit = 5
+ options.offset = 0
+
+ return options
+
+class TopObjectTable(ObjectTable):
+ def __init__(self, app, name, cls):
+ super(TopObjectTable, self).__init__(app, name, cls)
+
+ col = ObjectAttributeColumn(app, cls._id.name, cls._id)
+ col.visible = False
+ self.add_column(col)
+
+ self.header = TopTableHeader(app, "header")
+ self.replace_child(self.header)
+
+ self.footer = TopTableFooter(app, "footer")
+ self.replace_child(self.footer)
+
+ self.sort_col = None
+
+ def get_count(self, session):
+ # avoid extra sql call since we don't show the record count
+ return 0
+
+ def get_data_options(self, session):
+ sort_col = self.sort_col or self.cls._id.name
+ self.sort.set(session, sort_col)
+ self.ascending.set(session, False)
+ return super(TopObjectTable, self).get_data_options(session)
+
+class TopTableHeader(TableHeader):
+ def __init__(self, app, name):
+ super(TopTableHeader, self).__init__(app, name)
+
+ self.font = Attribute(app, "font")
+ self.font.default = 0.9
+ self.add_attribute(self.font)
+
+ self.limit = Attribute(app, "limit")
+ self.limit.default = 5
+ self.add_attribute(self.limit)
+
+ self.offset = Attribute(app, "offset")
+ self.offset.default = 0
+ self.add_attribute(self.offset)
+
+ def init(self):
+ super(TopTableHeader, self).init()
+
+ for column in self.table.columns:
+ column.header = TopTableColumnHeader(self.app, "header")
+ column.replace_child(column.header)
+ column.header.init()
+
+class TopTableColumnHeader(TableColumnHeader):
+ def render_class(self, session):
+ return self.parent.name
+
+class TopTableFooter(Widget):
+ def render(self, session):
+ return ""
Modified: mgmt/newdata/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/newdata/cumin/python/cumin/widgets.strings 2010-04-26 20:11:31 UTC (rev 3934)
+++ mgmt/newdata/cumin/python/cumin/widgets.strings 2010-04-26 20:16:10 UTC (rev 3935)
@@ -465,47 +465,8 @@
[EditablePropertyRenderer.orig_html]
<input type="hidden" name="{porig_name}"
value="{porig_value}"/>
-[TopTable.css]
-table.TopTable {
- width: 100%;
- border-collapse: collapse;
- margin: 0;
- table-layout: fixed;
-}
-
-table.TopTable tr {
- border-top: 1px dotted #ccc;
- vertical-align: top;
-}
-
-table.TopTable td {
- padding: 0.35em 0.5em;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
-}
-
-table.TopTable th {
- padding: 0.35em 0.5em;
- text-align: left;
- font-weight: normal;
- font-style: italic;
- color: #444;
- font-size: 0.9em;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
-}
-
-[TopTable.html]
-<table id="{id}" class="{class}">
- {columns}
- <thead><tr>{headers}</tr></thead>
- <tbody>{items}</tbody>
-</table>
-
[TopTableColumnHeader.html]
-<th {attrs}>{content}</th>
+<th class="{class}">{content}</th>
[CuminTable.css]
div.CuminTable table,