Author: eallen
Date: 2008-10-24 11:39:01 -0400 (Fri, 24 Oct 2008)
New Revision: 2684
Modified:
mgmt/trunk/cumin/python/cumin/negotiator.py
mgmt/trunk/cumin/python/cumin/negotiator.strings
Log:
Implemented ajax negotiator status updater.
Modified: mgmt/trunk/cumin/python/cumin/negotiator.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/negotiator.py 2008-10-24 15:37:34 UTC (rev 2683)
+++ mgmt/trunk/cumin/python/cumin/negotiator.py 2008-10-24 15:39:01 UTC (rev 2684)
@@ -39,9 +39,19 @@
self.__stop = self.StopButton(app, "stop")
self.add_child(self.__stop)
- def render_title(self, session):
- return "Negotiators %s" % fmt_count(Negotiator.select().count())
+ def get_args(self, session):
+ return self.frame.get_args(session)
+ def render_title(self, session, negotiator):
+ count = self.get_item_count(session, negotiator)
+ return "Negotiators %s" % fmt_count(count)
+
+ def render_sql_where(self, session, negotiator):
+ sql = "((c.rec_time is not null and " + \
+ "c.rec_time > now() - interval '10 minutes')" + \
+ " and deletion_time is null)"
+ return "where %s" % sql
+
class NameColumn(SqlTableColumn):
def render_title(self, session, data):
return "Name"
@@ -54,18 +64,29 @@
return fmt_olink(branch, neg, name=data["name"])
- class StartedColumn(SqlTableColumn):
+ class StartedColumn(SqlTableColumn, AjaxField):
def render_title(self, session, data):
- return "Started"
-
+ return "Status"
+
+ def get_url(self, session):
+ data = self.get_args(session)[0]
+ negotiator = Negotiator.get(data["id"])
+ if negotiator:
+ return "call.xml?class=negotiator;id=%i;method=GetLimitCount" %
negotiator.id
+
def render_content(self, session, data):
- value = data["rec_time"]
- expiry_time = datetime.now() - timedelta(minutes=2)
- if value and value > expiry_time:
- return "Yes"
- else:
- return "No"
+ id = self.elem_id(session)
+ return "<span id=\"%s\">Pending...%s</span>"
% \
+ (id, self.render_script(session))
+ def elem_id(self, session):
+ data = self.get_args(session)[0]
+ id = data["id"]
+ return "%s_%i" % (self.name, id)
+
+ def get_fn(self, session):
+ return self.elem_id(session)
+
class SystemColumn(SqlTableColumn):
def render_title(self, session, data):
return "System"
@@ -125,13 +146,37 @@
details = CuminDetails(app, "details")
self.__tabs.add_tab(details)
- def render_script(self, session, coll):
- data = "model.xml?class=negotiator;id=%i" % coll.id
- return "wooly.setIntervalUpdate('%s', updateNegotiator, 3000)"
% data
+class NegotiatorStatus(CuminStatus, AjaxField):
+ def render_negotiator_status(self, session, negotiator):
+ if self.expired(session, negotiator):
+ started = "Stopped"
+ else:
+ started = "Started"
+ return "<span id=\"%s\">%s</span>%s" % \
+ (self.name, started, self.render_script(session))
-class NegotiatorStatus(CuminStatus):
- pass
+ def render_color(self, session, negotiator):
+ if self.expired(session, negotiator):
+ return "red"
+ else:
+ return "green"
+
+ def expired(self, session, negotiator):
+ value = negotiator.statsCurr.recTime
+ expiry_time = datetime.now() - timedelta(minutes=2)
+ if value and value > expiry_time:
+ return False
+ else:
+ return True
+ def get_url(self, session):
+ negotiator = self.get_args(session)[0]
+ if negotiator:
+ return "call.xml?class=negotiator;id=%i;method=GetLimitCount" %
negotiator.id
+
+ def got_fn(self, session):
+ return "negotiator_status"
+
class NegStart(CuminBulkActionForm):
def render_title(self, session, *args):
return "Start Negotiator"
Modified: mgmt/trunk/cumin/python/cumin/negotiator.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/negotiator.strings 2008-10-24 15:37:34 UTC (rev 2683)
+++ mgmt/trunk/cumin/python/cumin/negotiator.strings 2008-10-24 15:39:01 UTC (rev 2684)
@@ -2,21 +2,18 @@
select
n.id,
n.name,
- n.daemon_start_time as started,
- c.monitor_self_age as age,
- c.rec_time,
y.id as system_id,
y.node_name as system_name
from negotiator as n
left outer join negotiator_stats as c on c.id = n.stats_curr_id
-left outer join negotiator_stats as p on p.id = n.stats_prev_id
inner join system as y on n.system = y.node_name
{sql_where}
{sql_orderby}
{sql_limit}
[NegotiatorSet.count_sql]
-select count(*) from negotiator as n
+select count(1) from negotiator as n
+left outer join negotiator_stats as c on c.id = n.stats_curr_id
{sql_where}
[NegotiatorView.javascript]
@@ -58,3 +55,40 @@
</table>
<div>{hidden_inputs}</div>
</form>
+
+[NegotiatorStatus.html]
+<div id="{id}" class="CuminStatus {color}">
+ <h2>Negotiator Status</h2>
+ {negotiator_status}
+</div>
+
+[StartedColumn.javascript]
+function got_started(obj, id) {
+ var elem = document.getElementById(id);
+ if (elem) {
+ var err = obj.error.value;
+ var started = "Started";
+ if (err == "True") {
+ started = "Stopped"
+ }
+ elem.innerHTML = started;
+ }
+}
+
+[NegotiatorStatus.javascript]
+function got_negotiator_status(obj, id) {
+ var elem = document.getElementById(id);
+ if (elem) {
+ var err = obj.error.value;
+ var started = "Started";
+ var color = "green";
+ if (err == "True") {
+ started = "Stopped"
+ color = "red"
+ }
+ elem.innerHTML = started;
+ elem.parentNode.className = "CuminStatus " + color;
+ setTimeout("get_status()", 1000)
+ }
+}
+