Author: croberts
Date: 2012-07-12 17:02:24 +0000 (Thu, 12 Jul 2012)
New Revision: 5430
Modified:
trunk/cumin/python/cumin/grid/dashboard.py
trunk/cumin/python/cumin/model.py
trunk/cumin/python/cumin/stat.py
trunk/cumin/python/cumin/stat.strings
Log:
Adding new plumage-based chart for pool usage by user (accounting group). (BZ:703859)
Modified: trunk/cumin/python/cumin/grid/dashboard.py
===================================================================
--- trunk/cumin/python/cumin/grid/dashboard.py 2012-07-12 15:06:02 UTC (rev 5429)
+++ trunk/cumin/python/cumin/grid/dashboard.py 2012-07-12 17:02:24 UTC (rev 5430)
@@ -6,6 +6,7 @@
from wooly.table import TableHeader
from wooly.widgets import RadioModeSet, WidgetSet
from wooly.template import WidgetTemplate
+from wooly.forms import StringInput
from parsley.stringex import rpartition
from rosemary.sqlquery import SqlQueryOptions
@@ -66,6 +67,15 @@
chart.duration.param.default = "3600"
charts.add_child(chart)
+ chart = self.UserUsageChart(app, "useruse",
app.model.com_redhat_grid_plumage.Accountant)
+ chart.stats = ["resused"]
+ chart.max_samples = 250
+ filter = ReportingChart.FilterInput(app, "namefilter",
app.model.com_redhat_grid_plumage.Accountant,
app.model.com_redhat_grid_plumage.Accountant.user.name, "userc", "Filter
user")
+ chart.filters.append(filter)
+ chart.add_child(filter)
+ chart.duration.param.default= "86400"
+ charts.add_child(chart)
+
def render_title(self, session):
return "History"
@@ -81,6 +91,14 @@
def render_title(self, session):
return "Pool efficiency"
+ class UserUsageChart(ReportingChart):
+ def render_title(self, session):
+ return "Pool usage by user"
+
+ class AccountingChart(ReportingChart):
+ def render_title(self, session):
+ return "Usage by parent accounting group"
+
class DashboardSummary(Widget):
def __init__(self, app, name, collector):
super(DashboardSummary, self).__init__(app, name)
Modified: trunk/cumin/python/cumin/model.py
===================================================================
--- trunk/cumin/python/cumin/model.py 2012-07-12 15:06:02 UTC (rev 5429)
+++ trunk/cumin/python/cumin/model.py 2012-07-12 17:02:24 UTC (rev 5430)
@@ -318,12 +318,16 @@
return retval
class SamplesSqlAdapter(SqlAdapter):
- def __init__(self, app, cls, sig, session):
+ def __init__(self, app, cls, sig, session, extra_filters=None):
super(SamplesSqlAdapter, self).__init__(app, cls.sql_samples_table)
filters = cls.get_sample_filters_by_signature(sig)
for f in filters:
self.query.add_filter(f)
+
+ if extra_filters is not None:
+ for ef in extra_filters:
+ self.query.add_filter(ef)
self.update_col = cls.get_timestamp_col()
Modified: trunk/cumin/python/cumin/stat.py
===================================================================
--- trunk/cumin/python/cumin/stat.py 2012-07-12 15:06:02 UTC (rev 5429)
+++ trunk/cumin/python/cumin/stat.py 2012-07-12 17:02:24 UTC (rev 5430)
@@ -18,6 +18,8 @@
from cumin.util import calc_rate, secs, nvl, xml_escape
from cumin.OpenFlashChart import Element, Chart
+from rosemary.sqlfilter import SqlFilter
+
strings = StringCatalog(__file__)
log = logging.getLogger("cumin.stat")
@@ -176,7 +178,7 @@
if self.chart_type:
params.append("type=%s" % self.chart_type)
-
+
return params
def render_href(self, session):
@@ -211,6 +213,7 @@
self.duration.add_state("2592000", "1 month")
self.duration.add_state("31557600", "1 year")
self.max_samples = 0
+ self.filters = list()
def get_href_params(self, session):
params = list()
@@ -302,8 +305,47 @@
return 120
def render_id_nodots(self, session):
- return self.render_id(session).replace(".", "_")
+ return self.render_id(session).replace(".", "_")
+
+ def render_filters(self, session):
+ filtertext = ""
+ for f in self.filters:
+ filtertext += f.do_render(session)
+
+ return filtertext
+
+ class FilterInput(Widget):
+ def __init__(self, app, name, cls, attr, param, title):
+ super(ReportingChart.FilterInput, self).__init__(app, name)
+ self.user_list = list()
+ self.cls = cls
+ self.attr = attr
+ self.param = param
+ self.title = title
+
+ def render_onclick(self, session):
+ return """onclick="updateFilter(this.getPrevious().value,
this, '%s')" """ % self.parent.path
+ def render_onchange(self, session):
+ return """onchange="updateFilter(this.value, this,
'%s', '%s')" """ % (self.parent.path, self.param)
+
+ def render_name(self, session):
+ return self.name
+
+ def do_process(self, session):
+ rows = self.cls.get_selection_samples(session.cursor)
+ self.user_list = sorted(list(set((getattr(x, self.attr)) for x in rows)))
+
+ def render_user_list(self, session):
+ options = ""
+ for u in self.user_list:
+ options += """<option
value="%s">%s</option>""" % (xml_escape(u),
xml_escape(u))
+
+ return options
+
+ def render_title(self, session):
+ return self.title
+
class ImageCache(object):
def __init__(self):
self.__files = dict() # {name: {"time": time_created, "file":
file object, "cookie": (cookie values)}}
@@ -476,10 +518,28 @@
stats = [getattr(rosemary_class, x) for x in self.stats.get(session)]
adapters = dict()
for stat in stats:
- adapters[stat] = SamplesSqlAdapter(self.app, rosemary_class, signature,
session)
+ filters = list()
+ if self.user_selection.get(session) is not None and
self.user_selection.get(session).lower() != "none" and
self.user_selection.get(session) != "":
+ filters.append(self.UserFilter(rosemary_class,
self.user_selection.get(session)))
+ if self.group_selection.get(session) is not None and
self.group_selection.get(session).lower() != "none" and
self.group_selection.get(session) != "":
+ filters.append(self.UserFilter(rosemary_class,
self.group_selection.get(session)))
+ adapters[stat] = SamplesSqlAdapter(self.app, rosemary_class, signature,
session, filters)
+
return (adapters, stats)
+ class UserFilter(SqlFilter):
+ def __init__(self, cls, value):
+
+ table = cls.sql_samples_table
+
+ fmt = "(%s like '%s')"
+ args = (table.user.identifier, value)
+
+ self.text = fmt % args
+
+ def emit(self):
+ return self.text
# builds an object that is similar to a RosemaryStatistic that can
# be used later in the chart rendering to give values to the chart items
class Pseudostat(object):
@@ -1242,6 +1302,14 @@
self.percent_property = Parameter(app, "tp")
self.add_parameter(self.percent_property)
+
+ self.user_selection = Parameter(app, "userc")
+ self.user_selection.default = None
+ self.add_parameter(self.user_selection)
+
+ self.group_selection = Parameter(app, "groupc")
+ self.group_selection.default = None
+ self.add_parameter(self.group_selection)
def get_content_type(self, session):
return "text/plain"
Modified: trunk/cumin/python/cumin/stat.strings
===================================================================
--- trunk/cumin/python/cumin/stat.strings 2012-07-12 15:06:02 UTC (rev 5429)
+++ trunk/cumin/python/cumin/stat.strings 2012-07-12 17:02:24 UTC (rev 5430)
@@ -132,6 +132,9 @@
top:49px;
}
+div.chartFilter {
+ margin-top:10px;
+}
[StatValueChart.css]
div.StatValueChart {
@@ -350,10 +353,79 @@
<div class="loading"
style="display:none;"><span>Loading...</span></div>
</div>
</div>
+ <div class="chartFilter">
+ {filters}
+ </div>
</div>
-
</div>
+
+[ReportingChart.javascript]
+function updateFilter(filter, a, id, param, attempt) {
+ var li = a.parentNode;
+ var ul = li.parentNode;
+ var as = ul.getElementsByTagName('a');
+ var hash = wooly.session.hash();
+ hash[id] = filter;
+ wooly.session.setHash(hash);
+
+ var oImg = document.images[id];
+ if (oImg) {
+ var src = oImg.src;
+ var branch = wooly.session.branch(src);
+ branch.userc = filter;
+ src = branch.marshal();
+ src = cumin.refreshTime(src);
+ oImg.src = src;
+
+ $(oImg).onerror = $(oImg).onload = function () {this.className = ""};
+ oImg.className = "Loading";
+
+ var loading = $(id).getElement(".loading");
+ if (loading) {
+ loading.loading = true;
+ setTimeout("showLoading('"+id+"')", 1000);
+ setTimeout("hideLoading('"+id+"')", 1000 * 60);
+ }
+
+ wooly.cancelIntervalUpdate();
+ wooly.resumeIntervalUpdate();
+ cumin.expireIntervalUpdate();
+ return false;
+ } else {
+ var chart = cumin.getChart(id);
+ if ((chart == null) || (typeof
$(chart).getParent().getElements('a')[chart_href] == "undefined")) {
+ if (typeof attempt == "undefined")
+ attempt = 1;
+ if (attempt < 10)
+ setTimeout(function () {updateFilter(filter, a, id, attempt+1);}, 100);
+ return false;
+ }
+ newurl = get_new_chart_url(id,
$(chart).getParent().getElements('a')[chart_href].get('href'), param,
filter);
+ $(chart).getParent().getElements('a')[chart_href].set('href',
newurl);
+ drawSingleChart(chart, true);
+ }
+ return false;
+}
+
+function get_new_chart_url(id, url, param, value) {
+ var chart = cumin.getChart(id);
+ if (chart == null)
+ return false;
+
+ var branch = wooly.session.branch(url);
+ var now = new Date().getTime();
+ branch['elapsed'] = now; // force an entire update
+ branch[param] = value;
+ url = branch.marshal();
+
+ return url;
+}
+
+[FilterInput.html]
+<!-- <input id="{id}" type="text"
name="{name}"></input><input type="button"
value="Update filter" {onclick}/> -->
+{title}: <select {onchange}>{user_list}</select>
+
[GenericChart.css]
div.FullpageChart {
margin: 1.5em;
@@ -366,7 +438,6 @@
<img id="{id}" src="{img_href}"
height="{height}" width="{width}" alt="stats" />
<div class="loading"
style="display:none;"><span>Loading...</span></div>
</div>
- YOU ARE HERE!
</div>
[PieFlashChart.html]