Author: tmckay
Date: 2013-02-25 16:30:30 +0000 (Mon, 25 Feb 2013)
New Revision: 5723
Modified:
branches/tmckay/cumin/python/cumin/grid/tags.py
branches/tmckay/sage/python/sage/wallaby/wallabyoperations.py
Log:
Fix up wallaby operations methods so there is no need to recache after
Cumin operations. Instead, fix up our own data structures by hand.
Modified: branches/tmckay/cumin/python/cumin/grid/tags.py
===================================================================
--- branches/tmckay/cumin/python/cumin/grid/tags.py 2013-02-21 22:11:06 UTC (rev 5722)
+++ branches/tmckay/cumin/python/cumin/grid/tags.py 2013-02-25 16:30:30 UTC (rev 5723)
@@ -1001,7 +1001,6 @@
self.invoc = invoc
try:
self.app.wallaroo.edit_tags(node_name, *tags, callback=callback,
refresh=True)
- #call_async(self.callback, self.app.wallaroo.edit_tags, node_name, *tags)
except:
invoc.status = invoc.FAILED
log.debug("Edit node failed", exc_info=True)
@@ -1068,19 +1067,13 @@
current_tags = self.app.wallaroo.get_tag_names(node)
current_tags.append(tag_name)
self.call_count += 1
- self.app.wallaroo.edit_tags(node, *current_tags,
callback=self.callback, refresh=False)
- #call_async(self.callback, self.app.wallaroo.edit_tags, node,
*current_tags)
+ self.app.wallaroo.edit_tags(node, *current_tags,
callback=self.callback, refresh=False)
for node in current_nodes:
if node not in chosen_nodes:
current_tags = self.app.wallaroo.get_tag_names(node)
current_tags.remove(tag_name)
self.call_count += 1
self.app.wallaroo.edit_tags(node, *current_tags,
callback=self.callback, refresh=False)
- #call_async(self.callback, self.app.wallaroo.edit_tags, node,
*current_tags)
-
- # These calls have been serialized so we can just queue the refresh here
- self.app.wallaroo.refresh(WBTypes.GROUPS,WBTypes.TAGS)
-
except:
self.call_count = 0
invoc.status = invoc.FAILED
Modified: branches/tmckay/sage/python/sage/wallaby/wallabyoperations.py
===================================================================
--- branches/tmckay/sage/python/sage/wallaby/wallabyoperations.py 2013-02-21 22:11:06 UTC
(rev 5722)
+++ branches/tmckay/sage/python/sage/wallaby/wallabyoperations.py 2013-02-25 16:30:30 UTC
(rev 5723)
@@ -306,6 +306,10 @@
try:
if node_name in self._cache[WBTypes.NODES].data:
names = self._cache[WBTypes.NODES].data[node_name].getLabels()
+ # This is a hack until remove group works
+ names = [n for n in names \
+ if n in self._nodes_by_tag and \
+ node_name in self._nodes_by_tag[n]]
finally:
self._lock.release()
return names
@@ -317,23 +321,29 @@
Refresh the cached lists of groups and tags.
'''
- created = False
+ tags = []
try:
for name in names:
start = time.time()
self._store.addLabel(name)
- created = True
+ tags.append(self._store.getGroupByName(name))
delta = time.time() - start
log.debug("WallabyOperations: store.addLabel %s" % delta)
except Exception, e:
log.debug("WallabyOperations: create_tag, exception suppressed,
%s" % str(e))
- # if we actually created tags then we must update the cache
- if created:
- self._mark_refresh("groups", "tags", must=True)
-
+ # If we actually created tags then we must add them to the cache
+ # Each tag must go in the groups and tags cache, and the tag has
+ # no nodes yet because we just made it.
+ self._lock.acquire()
+ for tag in tags:
+ self._nodes_by_tag[tag.name] = []
+ self._cache["tags"].data[tag.name] = tag
+ self._cache["groups"].data[tag.name] = tag
+ self._lock.release()
+
if callback and not self._replaying:
- callback(created)
+ callback(len(tags) > 0)
@_queued
def remove_tags(self, names, callback=None):
@@ -344,20 +354,34 @@
tag name first. Refresh cached lists of
groups, tags, and nodes.
'''
- removed = False
+ tags = []
for name in names:
if name in self._cache["tags"].data:
try:
- self._store.removeGroup(name)
- removed = True
+ # This handler here is a hack to allow remove group
+ # when it really doesn't work yet
+ try:
+ self._store.removeGroup(name)
+ except:
+ pass
+ tags.append(name)
except Exception, e:
log.debug("WallabyOperations: remove_tag, exception
suppressed, %s" % str(e))
# if we actually created tags then we must update the cache
- if removed:
- self._mark_refresh("nodes", "groups",
"tags", must=True)
+
+ # If we removed tags then we must remove them from the cache
+ self._lock.acquire()
+ for tag in tags:
+ #for n in self._nodes_by_tag[tag]:
+ # n.refresh()
+ del self._nodes_by_tag[tag]
+ del self._cache["tags"].data[tag]
+ del self._cache["groups"].data[tag]
+ self._lock.release()
+
if callback and not self._replaying:
- callback(removed)
+ callback(len(tags) > 0)
@_queued
def edit_tags(self, node, *tags, **kwargs):
@@ -370,12 +394,8 @@
list or tuple of strings
'''
status = False
- if type(node) in (str, unicode):
- n = node
- else:
- n = node.name
- n = n in self._cache[WBTypes.NODES].data and \
- self._cache[WBTypes.NODES].data[n] or None
+ n = node in self._cache[WBTypes.NODES].data and \
+ self._cache[WBTypes.NODES].data[node] or None
if n is None:
log.debug("WallabyOperations: edit_tags, node not found %s" %
str(n))
else:
@@ -391,10 +411,18 @@
except Exception, e:
log.debug("WallabyOperations: edit_tags, exception suppressed,
%s" % str(e))
- # Go ahead and default refresh to True
- refresh = "refresh" in kwargs and kwargs["refresh"] or
True
- if refresh and status:
- self._mark_refresh("groups", "tags")
+ if status:
+ self._lock.acquire()
+ for key,val in self._nodes_by_tag.iteritems():
+ if key in tags:
+ if not node in val:
+ val.append(node)
+ else:
+ try:
+ val.remove(node)
+ except:
+ pass
+ self._lock.release()
callback = "callback" in kwargs and kwargs["callback"] or
None
if callback and not self._replaying:
@@ -403,20 +431,15 @@
@_queued
def edit_features(self, group, *features, **kwargs):
'''
- Replace existing features in a group with the specified features.
-
+ Replace existing features in a group with the specified features
group -- a wallaby.Group object or the name of a wallaby.Group object
features -- the new set of features for the group,
list or tuple of strings
'''
status = False
- if type(group) in (str, unicode):
- g = group
- else:
- g = group.name
- g = g in self._cache[WBTypes.GROUPS].data and \
- self._cache[WBTypes.GROUPS].data[g] or None
+ g = group in self._cache[WBTypes.GROUPS].data and \
+ self._cache[WBTypes.GROUPS].data[group] or None
if g is None:
log.debug("WallabyOperations: edit_features, group not found
%s" % str(g))
else:
@@ -429,7 +452,7 @@
except Exception, e:
log.debug("WallabyOperations: edit_features, exception
suppressed, %s" % str(e))
- # we don't need a refresh because we have no mapping of features to
nodes
+ # no other data to update here because we don't have
callback = "callback" in kwargs and kwargs["callback"] or
None
if callback and not self._replaying: