Author: justi9
Date: 2007-11-08 15:46:05 -0500 (Thu, 08 Nov 2007)
New Revision: 1273
Modified:
mgmt/cumin/python/cumin/__init__.py
mgmt/cumin/python/cumin/demo.py
mgmt/cumin/python/cumin/exchange.py
mgmt/cumin/python/cumin/exchange.strings
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/page.strings
mgmt/cumin/python/cumin/queue.strings
Log:
Part 1 of 2 of ajaxification of exchange status. This part is mostly
model improvements to export measurements and errors/warnings in xml.
Modified: mgmt/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/cumin/python/cumin/__init__.py 2007-11-08 20:13:16 UTC (rev 1272)
+++ mgmt/cumin/python/cumin/__init__.py 2007-11-08 20:46:05 UTC (rev 1273)
@@ -11,7 +11,7 @@
from demo import DemoData
from page import CuminPage
from queue import QueueXmlPage, QueueChartPage
-from exchange import ExchangeChartPage
+from exchange import ExchangeXmlPage, ExchangeChartPage
from client import ClientChartPage
class Cumin(Application):
@@ -36,6 +36,7 @@
self.add_page(DevelPage(self, "devel.html"))
self.add_page(QueueXmlPage(self, "queue.xml"))
self.add_page(QueueChartPage(self, "queue.png"))
+ self.add_page(ExchangeXmlPage(self, "exchange.xml"))
self.add_page(ExchangeChartPage(self, "exchange.png"))
self.add_page(ClientChartPage(self, "client.png"))
Modified: mgmt/cumin/python/cumin/demo.py
===================================================================
--- mgmt/cumin/python/cumin/demo.py 2007-11-08 20:13:16 UTC (rev 1272)
+++ mgmt/cumin/python/cumin/demo.py 2007-11-08 20:46:05 UTC (rev 1273)
@@ -174,7 +174,7 @@
def frob(self, mobject):
mobject.lock()
try:
- if isinstance(mobject, MeasuredModelObject):
+ if isinstance(mobject, CuminModelObject):
for measure in mobject.measurements:
self.frob_measure(measure)
Modified: mgmt/cumin/python/cumin/exchange.py
===================================================================
--- mgmt/cumin/python/cumin/exchange.py 2007-11-08 20:13:16 UTC (rev 1272)
+++ mgmt/cumin/python/cumin/exchange.py 2007-11-08 20:46:05 UTC (rev 1273)
@@ -116,6 +116,9 @@
return "Exchange '%s'" % exchange.name
class ExchangeStatus(CuminStatus):
+ def render_xml_url(self, session, exchange):
+ return "exchange.xml?id=%i" % exchange.id
+
def render_messages_received(self, session, exchange):
value = exchange.get_measurement("msgReceives").get_rate()
return fmt_rate(value, "msg", "sec")
@@ -383,6 +386,24 @@
value = producer.get_measurement("bytesProduced").get_rate()
return fmt_rate(value, "byte", "sec")
+class ExchangeXmlPage(Page):
+ def __init__(self, app, name):
+ super(ExchangeXmlPage, self).__init__(app, name)
+
+ self.exchange = ExchangeParameter(app, "id")
+ self.add_parameter(self.exchange)
+
+ def get_content_type(self, session):
+ return Page.xml_content_type
+
+ def do_render(self, session, object):
+ writer = Writer()
+
+ writer.write(Page.xml_1_0_declaration)
+ self.exchange.get(session).write_xml(writer)
+
+ return writer.to_string()
+
class ExchangeChartPage(CuminChartPage):
def __init__(self, app, name):
super(ExchangeChartPage, self).__init__(app, name)
Modified: mgmt/cumin/python/cumin/exchange.strings
===================================================================
--- mgmt/cumin/python/cumin/exchange.strings 2007-11-08 20:13:16 UTC (rev 1272)
+++ mgmt/cumin/python/cumin/exchange.strings 2007-11-08 20:46:05 UTC (rev 1273)
@@ -83,6 +83,11 @@
}())
</script>
+[ExchangeStatus.javascript]
+function updateExchangeStatus(xml, elem) {
+ updateStatus(xml, elem);
+}
+
[ExchangeStatus.html]
<div id="{id}" class="{class}">
<h2>Exchange Status</h2>
@@ -112,6 +117,9 @@
</tr>
</table>
</div>
+<script>
+ wooly.setIntervalUpdate("{id}", "{xml_url}", updateExchangeStatus,
3000);
+</script>
[ExchangeView.html]
{status}
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2007-11-08 20:13:16 UTC (rev 1272)
+++ mgmt/cumin/python/cumin/model.py 2007-11-08 20:46:05 UTC (rev 1273)
@@ -175,10 +175,12 @@
def get_realm(self, id):
return self.get_index(self.realm).get(id)
-class MeasuredModelObject(ModelObject):
+class CuminModelObject(ModelObject):
def __init__(self, model, mclass):
- super(MeasuredModelObject, self).__init__(model, mclass)
+ super(CuminModelObject, self).__init__(model, mclass)
+ self.errors = list()
+ self.warnings = list()
self.measurements = list()
def get_measurement(self, name):
@@ -186,45 +188,50 @@
if measure.name == name:
return measure
-class BrokerCluster(ModelObject):
+ def write_error_xml(self, writer):
+ writer.write("<error-count>%i</error-count>" %
len(self.errors))
+ writer.write("<warning-count>%i</warning-count>" %
len(self.warnings))
+
+ def write_measurement_xml(self, writer):
+ writer.write("<measurements>")
+
+ for measure in self.measurements:
+ measure.write_xml(writer)
+
+ writer.write("</measurements>")
+
+class BrokerCluster(CuminModelObject):
def __init__(self, model):
super(BrokerCluster, self).__init__(model, model.broker_cluster)
self.name = None
- self.errors = list()
- self.warnings = list()
-
-class Broker(ModelObject):
+class Broker(CuminModelObject):
def __init__(self, model):
super(Broker, self).__init__(model, model.broker)
self.name = None
self.default_virtual_host = None
- self.errors = list()
- self.warnings = list()
-
def write_xml(self, writer):
writer.write("<broker id=\"broker-%i\">" % self.id)
writer.write("<name>" + self.name + "</name>")
writer.write("<default-virtual-host
ref=\"virtual-host-%i\"/>" \
% self.default_virtual_host.id)
+ self.write_error_xml(writer)
+
for vhost in self.virtual_host_items():
vhost.write_xml(writer)
writer.write("</broker>")
-class BrokerProfile(ModelObject):
+class BrokerProfile(CuminModelObject):
def __init__(self, model):
super(BrokerProfile, self).__init__(model, model.broker_profile)
self.name = None
- self.errors = list()
- self.warnings = list()
-
class ConfigProperty(ModelObject):
def __init__(self, model):
super(ConfigProperty, self).__init__(model, model.config_property)
@@ -234,22 +241,19 @@
self.broker_value = None
self.type = None # ("boolean", "integer",
"string")
-class BrokerGroup(ModelObject):
+class BrokerGroup(CuminModelObject):
def __init__(self, model):
super(BrokerGroup, self).__init__(model, model.broker_group)
self.name = None
- self.errors = list()
- self.warnings = list()
-
class BrokerGroupType(ModelObject):
def __init__(self, model):
super(BrokerGroupType, self).__init__(model, model.broker_group_type)
self.name = None
-class VirtualHost(ModelObject):
+class VirtualHost(CuminModelObject):
def __init__(self, model):
super(VirtualHost, self).__init__(model, model.virtual_host)
@@ -278,6 +282,8 @@
writer.write("<default-exchange ref=\"exchange-%i\"/>"
\
% self.default_exchange.id)
+ self.write_error_xml(writer)
+
for queue in self.queue_items():
queue.write_xml(writer)
@@ -295,20 +301,18 @@
self.name = None
-class Realm(ModelObject):
+class Realm(CuminModelObject):
def __init__(self, model):
- model.lock()
-
super(Realm, self).__init__(model, model.realm)
self.name = None
- model.unlock()
-
def write_xml(self, writer):
writer.write("<realm id=\"realm-%i\">" % self.id)
writer.write("<name>%s</name>" % self.name)
+ self.write_error_xml(writer)
+
for queue in self.queue_items():
writer.write("<queue ref=\"queue-%i\"/>" %
queue.id)
@@ -386,7 +390,7 @@
writer.write("<%s><v>%i</v><r>%i</r></%s>" %
\
(self.name, self.get_value(), self.get_rate(), self.name))
-class Queue(MeasuredModelObject):
+class Queue(CuminModelObject):
def __init__(self, model):
super(Queue, self).__init__(model, model.queue)
@@ -397,9 +401,6 @@
self.is_auto_delete = False
self.latency_priority = "m" # h, m, or l
- self.errors = list()
- self.warnings = list()
-
# General
measure = Measurement("consumers", "int")
@@ -594,25 +595,20 @@
writer.write("<name>%s</name>" % self.name)
writer.write("<latency-priority>%s</latency-priority>" \
% self.latency_priority)
- writer.write("<error-count>%i</error-count>" %
len(self.errors))
- writer.write("<warning-count>%i</warning-count>" %
len(self.warnings))
+ self.write_error_xml(writer)
+
for realm in self.realm_items():
writer.write("<realm ref=\"realm-%i\"/>" %
realm.id)
for binding in self.binding_items():
binding.write_xml(writer)
- writer.write("<measurements>")
-
- for measure in self.measurements:
- measure.write_xml(writer)
-
- writer.write("</measurements>")
+ self.write_measurement_xml(writer)
writer.write("</queue>")
-class Consumer(MeasuredModelObject):
+class Consumer(CuminModelObject):
def __init__(self, model):
super(Consumer, self).__init__(model, model.consumer)
@@ -637,7 +633,7 @@
measure.highlow = True
self.measurements.append(measure)
-class Exchange(MeasuredModelObject):
+class Exchange(CuminModelObject):
def __init__(self, model):
super(Exchange, self).__init__(model, model.exchange)
@@ -648,9 +644,6 @@
self.is_auto_delete = False
self.is_internal = False
- self.errors = list()
- self.warnings = list()
-
measure = Measurement("producers", "int")
measure.title = "Producers"
measure.unit = "producer"
@@ -710,18 +703,20 @@
def write_xml(self, writer):
writer.write("<exchange id=\"exchange-%i\">" %
self.id)
writer.write("<name>%s</name>" % self.name)
- #writer.write("<error-count>%i</error-count>" %
self.error_count)
- #writer.write("<warning-count>%i</warning-count>" %
self.warning_count)
+ self.write_error_xml(writer)
+
for realm in self.realm_items():
writer.write("<realm ref=\"realm-%i\"/>" %
realm.id)
for binding in self.binding_items():
binding.write_xml(writer)
+
+ self.write_measurement_xml(writer)
writer.write("</exchange>")
-class Producer(MeasuredModelObject):
+class Producer(CuminModelObject):
def __init__(self, model):
super(Producer, self).__init__(model, model.producer)
@@ -737,7 +732,7 @@
measure.categories = ("byte", "general")
self.measurements.append(measure)
-class Binding(MeasuredModelObject):
+class Binding(CuminModelObject):
def __init__(self, model):
super(Binding, self).__init__(model, model.binding)
@@ -753,17 +748,18 @@
writer.write("<exchange ref=\"exchange-%i\"/>" %
self.exchange.id)
writer.write("<queue ref=\"queue-%i\"/>" %
self.queue.id)
writer.write("<binding-key>%s</binding-key>" %
self.binding_key)
+
+ self.write_error_xml(writer)
+ self.write_measurement_xml(writer)
+
writer.write("</binding>")
-class Client(MeasuredModelObject):
+class Client(CuminModelObject):
def __init__(self, model):
super(Client, self).__init__(model, model.client)
self.address = None
- self.errors = list()
- self.warnings = list()
-
measure = Measurement("msgsProduced", "int")
measure.title = "Msgs. Produced"
measure.categories = ("message", "general")
@@ -784,15 +780,12 @@
measure.categories = ("byte", "general")
self.measurements.append(measure)
-class Session(MeasuredModelObject):
+class Session(CuminModelObject):
def __init__(self, model):
super(Session, self).__init__(model, model.session)
self.name = None
- self.errors = list()
- self.warnings = list()
-
measure = Measurement("attached", "bool")
measure.title = "Attached"
measure.categories = ("general")
Modified: mgmt/cumin/python/cumin/page.strings
===================================================================
--- mgmt/cumin/python/cumin/page.strings 2007-11-08 20:13:16 UTC (rev 1272)
+++ mgmt/cumin/python/cumin/page.strings 2007-11-08 20:46:05 UTC (rev 1273)
@@ -546,6 +546,25 @@
color: #999;
}
+[CuminPage.javascript]
+function updateStatus(xml, elem) {
+ var ecount = xml.elem("error-count").text().get();
+ var errors = ecount + " " + (ecount == "1" &&
"error" || "errors");
+
+ var wcount = xml.elem("warning-count").text().get();
+ var warnings = wcount + " " + (wcount == "1" &&
"warning" || "warnings");
+
+ if (ecount != "0") {
+ elem.node.className = "mstatus red";
+ } else if (wcount != "0") {
+ elem.node.className = "mstatus yellow";
+ } else {
+ elem.node.className = "mstatus green";
+ }
+
+ elem.elem("div").set(errors + ", " + warnings);
+}
+
[CuminPage.html]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Modified: mgmt/cumin/python/cumin/queue.strings
===================================================================
--- mgmt/cumin/python/cumin/queue.strings 2007-11-08 20:13:16 UTC (rev 1272)
+++ mgmt/cumin/python/cumin/queue.strings 2007-11-08 20:46:05 UTC (rev 1273)
@@ -90,22 +90,8 @@
[QueueStatus.javascript]
function updateQueueStatus(xml, elem) {
- var ecount = xml.elem("error-count").text().get();
- var errors = ecount + " " + (ecount == "1" &&
"error" || "errors");
+ updateStatus(xml, elem);
- var wcount = xml.elem("warning-count").text().get();
- var warnings = wcount + " " + (wcount == "1" &&
"warning" || "warnings");
-
- if (ecount != "0") {
- elem.node.className = "mstatus red";
- } else if (wcount != "0") {
- elem.node.className = "mstatus yellow";
- } else {
- elem.node.className = "mstatus green";
- }
-
- elem.elem("div").set(errors + ", " + warnings);
-
var ms = xml.elems("measurements").next();
var menq = ms.elem("msgtotalenqueues").elem("r").text().get();