From 20835fc7deb0d149293351f032af6e5d9e4a1952 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 20 Mar 2013 21:19:38 +0100 Subject: [PATCH] in query, 'method' is now called 'subject' --- manifold/js/manifold-query.js | 72 ++++++++++++++++++-------------- manifold/js/manifold.js | 2 +- manifold/manifoldapi.py | 4 +- manifold/manifoldproxy.py | 5 +++ manifold/manifoldquery.py | 73 ++++++++++++++++++--------------- plugins/querycode/querycode.css | 2 +- plugins/querycode/querycode.js | 4 +- trash/dashboard.py | 3 +- trash/haze.py | 2 +- unfold/js/metadata.js | 22 +++++----- unfold/page.py | 8 ++-- 11 files changed, 112 insertions(+), 85 deletions(-) diff --git a/manifold/js/manifold-query.js b/manifold/js/manifold-query.js index 4e146ada..41ab86fc 100644 --- a/manifold/js/manifold-query.js +++ b/manifold/js/manifold-query.js @@ -1,8 +1,8 @@ -function ManifoldQuery(action, method, timestamp, filters, params, fields, unique, query_uuid, aq, sq) { +function ManifoldQuery(action, subject, timestamp, filters, params, fields, unique, query_uuid, aq, sq) { // get, update, delete, create var action; // slice, user, network... - var method; + var subject; // timestamp, now, latest(cache) : date of the results queried var timestamp; // key(field),op(=<>),value @@ -23,12 +23,24 @@ function ManifoldQuery(action, method, timestamp, filters, params, fields, uniqu /*------------------------------------------------------------- Query properties are SQL like : --------------------------------------------------------------- -SELECT fields FROM method WHERE filter; -UPDATE method SET field=value WHERE filter; / returns SELECT -DELETE FROM method WHERE filter -INSERT INTO method VALUES(field=value) +SELECT fields FROM subject WHERE filter; +UPDATE subject SET field=value WHERE filter; / returns SELECT +DELETE FROM subject WHERE filter +INSERT INTO subject VALUES(field=value) -------------------------------------------------------------*/ + this.__repr = function (q) { + res = "ManyfoldQuery "; + res += " id=" + q.query_uuid; + res += " a=" + q.action; + res += " s=" + q.subject; + res += " ts=" + q.timestamp; + res += " flts=" + q.filters; + res += " flds=" + q.fields; + res += " prms=" + q.params; + return res; + } + this.clone = function() { q = new ManifoldQuery(); return jQuery.extend(true, q, this); @@ -86,7 +98,7 @@ INSERT INTO method VALUES(field=value) return {'added':added, 'removed':removed}; } this.to_hash = function() { - return {'action': this.action, 'method': this.method, 'timestamp': this.timestamp, + return {'action': this.action, 'subject': this.subject, 'timestamp': this.timestamp, 'filters': this.filters, 'params': this.params, 'fields': this.fields}; } this.analyze_subqueries = function() { @@ -94,7 +106,7 @@ INSERT INTO method VALUES(field=value) var q = new ManifoldQuery(); q.query_uuid = this.query_uuid; q.action = this.action; - q.method = this.method; + q.subject = this.subject; q.timestamp = this.timestamp; /* Filters */ @@ -104,15 +116,15 @@ INSERT INTO method VALUES(field=value) var v = filter[2]; var pos = k.indexOf('.'); if (pos != -1) { - var method = k.substr(0, pos); + var subject = k.substr(0, pos); var field = k.substr(pos+1); - if (jQuery.inArray(this.method, q.subqueries) == -1) { - q.subqueries[this.method] = new ManifoldQuery(); - q.subqueries[this.method].action = this.action; - q.subqueries[this.method].method = this.method; - q.subqueries[this.method].timestamp = this.timestamp; + if (jQuery.inArray(this.subject, q.subqueries) == -1) { + q.subqueries[this.subject] = new ManifoldQuery(); + q.subqueries[this.subject].action = this.action; + q.subqueries[this.subject].subject = this.subject; + q.subqueries[this.subject].timestamp = this.timestamp; } - q.subqueries[this.method].filters.push(Array(field, op, v)); + q.subqueries[this.subject].filters.push(Array(field, op, v)); } else { q.filters.push(this.filter); } @@ -122,15 +134,15 @@ INSERT INTO method VALUES(field=value) jQuery.each(this.params, function(param, value) { var pos = param.indexOf('.'); if (pos != -1) { - var method = param.substr(0, pos); + var subject = param.substr(0, pos); var field = param.substr(pos+1); - if (jQuery.inArray(this.method, q.subqueries) == -1) { - q.subqueries[this.method] = new ManifoldQuery(); - q.subqueries[this.method].action = this.action; - q.subqueries[this.method].method = this.method; - q.subqueries[this.method].timestamp = this.timestamp; + if (jQuery.inArray(this.subject, q.subqueries) == -1) { + q.subqueries[this.subject] = new ManifoldQuery(); + q.subqueries[this.subject].action = this.action; + q.subqueries[this.subject].subject = this.subject; + q.subqueries[this.subject].timestamp = this.timestamp; } - q.subqueries[this.method].params[field] = value; + q.subqueries[this.subject].params[field] = value; } else { q.params[field] = value; } @@ -140,15 +152,15 @@ INSERT INTO method VALUES(field=value) jQuery.each(this.fields, function(i, v) { var pos = v.indexOf('.'); if (pos != -1) { - var method = v.substr(0, pos); + var subject = v.substr(0, pos); var field = v.substr(pos+1); - if (jQuery.inArray(this.method, q.subqueries) == -1) { - q.subqueries[this.method] = new ManifoldQuery(); - q.subqueries[this.method].action = this.action; - q.subqueries[this.method].method = this.method; - q.subqueries[this.method].timestamp = this.timestamp; + if (jQuery.inArray(this.subject, q.subqueries) == -1) { + q.subqueries[this.subject] = new ManifoldQuery(); + q.subqueries[this.subject].action = this.action; + q.subqueries[this.subject].subject = this.subject; + q.subqueries[this.subject].timestamp = this.timestamp; } - q.subqueries[this.method].fields.push(field); + q.subqueries[this.subject].fields.push(field); } else { q.fields.push(v); } @@ -158,7 +170,7 @@ INSERT INTO method VALUES(field=value) /* constructor */ this.action = action; - this.method = method; + this.subject = subject; this.timestamp = timestamp; this.filters = filters; this.params = params; diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index 4508a9ee..6cd209b2 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -53,7 +53,7 @@ var manifold = { var query=manifold.find_query(tuple.query_uuid); var hash=query.to_hash(); if (manifold.asynchroneous_debug) - console.log ("sending POST on " + manifold.proxy_url + " iterating on " + tuple.query_uuid + " -> " + hash); + console.log ("sending POST on " + manifold.proxy_url + " with query= " + query.__repr(query)); jQuery.post(manifold.proxy_url, {'query': hash}, success_closure(query, tuple.id)); }) }, diff --git a/manifold/manifoldapi.py b/manifold/manifoldapi.py index e482c2dc..18c555ca 100644 --- a/manifold/manifoldapi.py +++ b/manifold/manifoldapi.py @@ -34,9 +34,9 @@ class ManifoldAPI: return func def send_manifold_query (self, manifold_query): - (action,method)= (manifold_query.action,manifold_query.method) + (action,subject)= (manifold_query.action,manifold_query.subject) if action=='get': - return self.server.Get(self.auth, method, manifold_query.filters, {}, manifold_query.fields) + return self.server.Get(self.auth, subject, manifold_query.filters, {}, manifold_query.fields) # xxx... else: print "WARNING: ManifoldAPI.send_manifold_query: only 'get' implemented for now" diff --git a/manifold/manifoldproxy.py b/manifold/manifoldproxy.py index 4bce287e..553dcfe9 100644 --- a/manifold/manifoldproxy.py +++ b/manifold/manifoldproxy.py @@ -6,6 +6,9 @@ from django.http import HttpResponse, HttpResponseForbidden from manifold.manifoldquery import ManifoldQuery from manifold.manifoldapi import ManifoldAPI +debug=False +debug=True + # add artificial delay in s debug_spin=0 #debug_spin=1 @@ -32,12 +35,14 @@ with the query passed using POST""" return try: # translate incoming POST request into a query object + if debug: print 'manifoldproxy.proxy: request.POST',request.POST manifold_query = ManifoldQuery() manifold_query.fill_from_dict(request.POST) # retrieve session for request manifold_api_session_auth = request.session['manifold']['auth'] # actually forward manifold_api= ManifoldAPI(auth=manifold_api_session_auth) + if debug: print 'manifoldproxy.proxy: sending to backend', manifold_query answer=manifold_api.send_manifold_query (manifold_query) if debug_spin: import time diff --git a/manifold/manifoldquery.py b/manifold/manifoldquery.py index ffd7c1f1..b7f88c4a 100644 --- a/manifold/manifoldquery.py +++ b/manifold/manifoldquery.py @@ -4,16 +4,19 @@ import uuid def uniqid (): return uuid.uuid4().hex +debug=False +debug=True + class ManifoldQuery: - def __init__ (self, action=None, method=None, timestamp='now', + def __init__ (self, action=None, subject=None, timestamp='now', filters=[], params=[], fields=[], sort=None, limit=None, offset=None, ): self.query_uuid=uniqid() # settable self.action=action - self.method=method + self.subject=subject self.timestamp=timestamp self.filters=filters self.params=params @@ -28,38 +31,41 @@ class ManifoldQuery: self.subqueries = {} def __repr__ (self): - result="Q: id=%(query_uuid)s - %(action)s on %(method)s "%self.__dict__ + result="Q: id=%(query_uuid)s - %(action)s on %(subject)s "%self.__dict__ result += " with %d filters, %d fields"%(len(self.filters),len(self.params)) return result def to_json (self): query_uuid=self.query_uuid a=self.action - m=self.method + s=self.subject t=self.timestamp f=json.dumps (self.filters) + print 'filters f=',f p=json.dumps (self.params) c=json.dumps (self.fields) # xxx unique can be removed, but for now we pad the js structure unique=0 aq = self.analyzed_query.to_json() if self.analyzed_query else 'null' - # subqueries is a dictionary method:query + # subqueries is a dictionary subject:query if not self.subqueries: sq="{}" else: - sq=", ".join ( [ "'%s':%s" % (method, subquery.to_json()) - for (method, subquery) in self.subqueries.iteritems()]) + sq=", ".join ( [ "'%s':%s" % (subject, subquery.to_json()) + for (subject, subquery) in self.subqueries.iteritems()]) sq="{%s}"%sq - return """ new ManifoldQuery('%(a)s', '%(m)s', '%(t)s', %(f)s, %(p)s, %(c)s, %(unique)s, '%(query_uuid)s', %(aq)s, %(sq)s)"""%locals() + result= """ new ManifoldQuery('%(a)s', '%(s)s', '%(t)s', %(f)s, %(p)s, %(c)s, %(unique)s, '%(query_uuid)s', %(aq)s, %(sq)s)"""%locals() + if debug: print 'ManifoldQuery.to_json:',result + return result # this builds a ManifoldQuery object from a dict as received from javascript through its ajax request # e.g. here's what I captured from the server's output - # incoming POST + # incoming POST def fill_from_dict (self, d): for key in d.keys(): - for arg in ['action', 'method', 'filters', 'fields', 'timestamp', 'params']: + for arg in ['action', 'subject', 'filters', 'fields', 'timestamp', 'params']: if arg in key: # dirty hack around fields; fields must be a list if arg == 'fields': @@ -73,7 +79,7 @@ class ManifoldQuery: analyzed_query = ManifoldQuery() analyzed_query.query_uuid = self.query_uuid analyzed_query.action = self.action - analyzed_query.method = self.method + analyzed_query.subject = self.subject analyzed_query.timestamp = self.timestamp # analyse query filters @@ -83,16 +89,17 @@ class ManifoldQuery: operation = filter[1] value = filter[2] if '.' in key: - method = key.split('.')[0] - field = key.split('.')[1] - if not analyzed_query.subqueries[method]: + parts=key.split('.') + subject = parts[0] + field = parts[1] + if not analyzed_query.subqueries[subject]: subquery = ManifoldQuery() subquery.action = self.action - subquery.method = method + subquery.subject = subject subquery.timestamp = self.timestamp - analyzed_query.subqueries[method] = subquery + analyzed_query.subqueries[subject] = subquery - analyzed_query.subqueries[method].filters.append([field, operation, value]) + analyzed_query.subqueries[subject].filters.append([field, operation, value]) else: analyzed_query.filters.append(filter) @@ -100,16 +107,17 @@ class ManifoldQuery: # params syntax : params = {'param1': value1, 'param2': value2, ...} for param in self.params.keys(): if '.' in param: - method = param.split('.')[0] - field = param.split('.')[1] - if not analyzed_query.subqueries[method]: + parts=param.split('.') + subject = parts[0] + field = parts[1] + if not analyzed_query.subqueries[subject]: subquery = ManifoldQuery() subquery.action = self.action - subquery.method = method + subquery.subject = subject subquery.timestamp = self.timestamp - analyzed_query.subqueries[method] = subquery + analyzed_query.subqueries[subject] = subquery - analyzed_query.subqueries[method].params[field] = self.params[param] + analyzed_query.subqueries[subject].params[field] = self.params[param] else: analyzed_query.params[param] = self.params[param] @@ -117,33 +125,34 @@ class ManifoldQuery: # fields syntax: fields = [element1, element2, ....] for element in self.fields: if '.' in element: - method = element.split('.')[0] - field = element.split('.')[1] - if not analyzed_query.subqueries[method]: + parts=element.split('.') + subject = parts[0] + field = parts[1] + if not analyzed_query.subqueries[subject]: subquery = ManifoldQuery() subquery.action = self.action - subquery.method = method + subquery.subject = subject subquery.timestamp = self.timestamp - analyzed_query.subqueries[method] = subquery + analyzed_query.subqueries[subject] = subquery - analyzed_query.subqueries[method].fields.append(field) + analyzed_query.subqueries[subject].fields.append(field) else: analyzed_query.fields.append(element) # default subqueries - if analyzed_query.method == 'slice': + if analyzed_query.subject == 'slice': if not analyzed_query.subqueries['resource']: subquery = ManifoldQuery() subquery.action = self.action - subquery.method = method + subquery.subject = subject subquery.timestamp = self.timestamp analyzed_query.subqueries['resource'] = subquery if not analyzed_query.subqueries['lease']: subquery = ManifoldQuery() subquery.action = self.action - subquery.method = method + subquery.subject = subject subquery.timestamp = self.timestamp analyzed_query.subqueries['lease'] = subquery diff --git a/plugins/querycode/querycode.css b/plugins/querycode/querycode.css index 7d6f86ed..1aa77da0 100644 --- a/plugins/querycode/querycode.css +++ b/plugins/querycode/querycode.css @@ -45,7 +45,7 @@ div.info:hover span{ /*the span will display just on :hover state*/ padding: 0em 0em 0em 1em; } -div.method { +div.subject { padding: 10px; background-color: #fafafa; border-top: solid 1px black; diff --git a/plugins/querycode/querycode.js b/plugins/querycode/querycode.js index eab1238e..3574b30e 100644 --- a/plugins/querycode/querycode.js +++ b/plugins/querycode/querycode.js @@ -126,7 +126,7 @@ }); ofs = '[' + ofs + ']'; - output += 'pp srv.call("' + mixed_case(query.action) +'", auth, "' + query.method + '", "' + query.timestamp + '", ' + ifs + ', ' + ofs + ')'; + output += 'pp srv.call("' + mixed_case(query.action) +'", auth, "' + query.subject + '", "' + query.timestamp + '", ' + ifs + ', ' + ofs + ')'; var output = '
' + output + "
"; return output; @@ -159,7 +159,7 @@ }); ofs = '[' + ofs + ']'; - output += 'srv.' + mixed_case(query.action) + '(auth, "' + query.method + '", ' + ifs + ', {}, ' + ofs + ')'; + output += 'srv.' + mixed_case(query.action) + '(auth, "' + query.subject + '", ' + ifs + ', {}, ' + ofs + ')'; var output = '
' + output + "
"; return output; } diff --git a/trash/dashboard.py b/trash/dashboard.py index 2dd417e7..cbe8bd4e 100644 --- a/trash/dashboard.py +++ b/trash/dashboard.py @@ -26,9 +26,10 @@ def dashboard_view (request): page = Page(request) slices_query = ManifoldQuery (action='get', - method='slice', + subject='slice', timestamp='latest', fields=['slice_hrn'], + filters=[], # xxx filter : should filter on the slices the logged user can see # we don't have the user's hrn yet # in addition this currently returns all slices anyways diff --git a/trash/haze.py b/trash/haze.py index b9f56a95..b373ea35 100644 --- a/trash/haze.py +++ b/trash/haze.py @@ -24,7 +24,7 @@ def hazelnut_view (request): page = Page(request) main_query = ManifoldQuery (action='get', - method='resource', + subject='resource', timestamp='latest', fields=['hrn','hostname'], filters= [ [ 'slice_hrn', '=', 'ple.inria.', ] ], diff --git a/unfold/js/metadata.js b/unfold/js/metadata.js index 57940b11..eefdcbfa 100644 --- a/unfold/js/metadata.js +++ b/unfold/js/metadata.js @@ -3,11 +3,11 @@ var metadata = { get : function () { return MANIFOLD_METADATA; }, - // returns all fields of a given method - fields : function (method) { + // returns all fields of a given subject + fields : function (subject) { var result=new Array(); - jQuery.each(MANIFOLD_METADATA, function(m,obj){ - if(m==method){ + jQuery.each(MANIFOLD_METADATA, function(s,obj){ + if(s==subject){ jQuery.each(obj['column'], function(i,f){ result.push(f); }); @@ -19,10 +19,10 @@ var metadata = { return result; }, // returns all properties of a given field - field : function (method, field) { + field : function (subject, field) { var result=new Array(); - jQuery.each(MANIFOLD_METADATA, function(m,obj){ - if(m==method){ + jQuery.each(MANIFOLD_METADATA, function(s,obj){ + if(s==subject){ jQuery.each(obj['column'], function(i,f){ if(f['column']==field){ result.push(f); @@ -34,11 +34,11 @@ var metadata = { }); return result[0]; }, - // returns the value of a property from a field within a method (type of object : resource,node,lease,slice...) - property : function (method, field, property) { + // returns the value of a property from a field within a subject (type of object : resource,node,lease,slice...) + property : function (subject, field, property) { var result=null; - jQuery.each(MANIFOLD_METADATA, function(m,obj){ - if(m==method){ + jQuery.each(MANIFOLD_METADATA, function(s,obj){ + if(s==subject){ jQuery.each(obj['column'], function(i,f){ if(f['column']==field){ result=f[property]; diff --git a/unfold/page.py b/unfold/page.py index 9c1c4123..bc8c01b2 100644 --- a/unfold/page.py +++ b/unfold/page.py @@ -93,16 +93,16 @@ class Page: results = manifold_api.Get('metadata:table', [], [], fields) for res in results: - method = res['table'] - self._metadata[method] = res + subject = res['table'] + self._metadata[subject] = res request.session['metadata'] = self._metadata javascript = "var MANIFOLD_METADATA =" + json.dumps(self._metadata) + ";" self.add_js_chunks(javascript) - def metadata_get_fields(self, method): - return self._metadata[method]['column'].sort() + def metadata_get_fields(self, subject): + return self._metadata[subject]['column'].sort() def expose_js_manifold_config (self): self.add_js_chunks(Config.manifold_js_export()) -- 2.43.0