Author: tmckay Date: 2011-08-01 19:46:49 +0000 (Mon, 01 Aug 2011) New Revision: 4898
Modified: trunk/sage/python/sage/wallaby/wallabyoperations.py Log: Add get_nodes_by_tag()
Modified: trunk/sage/python/sage/wallaby/wallabyoperations.py =================================================================== --- trunk/sage/python/sage/wallaby/wallabyoperations.py 2011-08-01 13:39:46 UTC (rev 4897) +++ trunk/sage/python/sage/wallaby/wallabyoperations.py 2011-08-01 19:46:49 UTC (rev 4898) @@ -5,6 +5,8 @@ from sage.util import CallThread from threading import Lock, Condition
+#import cProfile + imports_ok = True try: import wallaby @@ -73,6 +75,7 @@ # takes time to filter the list so it is handled in a separate # thread when group data is received. self._tags = [] + self._nodes_by_tag = dict()
# Lock is used for synchronization with the caching thread and # for thread safety of any and all data that could be accessed @@ -151,9 +154,12 @@ # Wallaby API uses extensions to __getattr__ on # the Store to retrieve objects from the Broker # and return a list of proxy objects. + start = time.time() d = getattr(self._store, attr, []) except: d = [] + delta = time.time() - start + log.debug("WallabyOperations: %s seconds to refresh %s" % (delta, attr))
# If the data is empty, _set_cache will leave the # remaining field set to 0 for the attribute so we @@ -162,7 +168,7 @@ # interval for this attribute. self._set_cache(attr, d)
- log.debug("WallabyOperations: refresh processing time %s" \ + log.debug("WallabyOperations: total refresh processing time %s" \ % (time.time() - start_processing))
# Find out how long we should sleep for. @@ -204,6 +210,8 @@ return False
self._stop = False + +# self._maintain_cache = CallThread(cProfile.runctx('maintain_cache(self)', globals(), locals(), filename='sage.stats'), None) self._maintain_cache = CallThread(maintain_cache, None, self) self._maintain_cache.daemon = True self._maintain_cache.start() @@ -280,6 +288,19 @@ d = self._tags self._lock.release() return d + + def get_nodes_by_tag(self): + ''' + Return a list of node names associated with each tag. + + The return result is a dictionary with tag names as keys and + lists of node names as values. The nodes listed for each tag + are members of the tag group. + ''' + self._lock.acquire() + n = self._nodes_by_tag + self._lock.release() + return n
def set_interval(self, which, refresh): ''' @@ -327,23 +348,29 @@
# Filter groups for the subset of tags if attr == WBTypes.GROUPS: - self._get_tag_list(data) + self._generate_tag_list(data)
- def _get_tag_list(self, data): + def _generate_tag_list(self, data):
def process_tags(groups): - d = [] + + # get the tag list + tags = [] + nodes_by_tag = dict() for g in groups: if g.getConfig() == {} and not g.name.startswith("+++"): - d.append(g) - self._store_tag_list(d) + tags.append(g) + nodes = g.membership() + nodes_by_tag[g.name] = nodes + self._store_tag_list(tags, nodes_by_tag)
t = CallThread(process_tags, None, data) t.start()
- def _store_tag_list(self, tags): + def _store_tag_list(self, tags, nodes_by_tag): self._lock.acquire() self._tags = tags + self._nodes_by_tag = nodes_by_tag self._lock.release()
def _get_store(self):
cumin-developers@lists.fedorahosted.org