REST clear cache: simple update to clear Manifold cache
authorLoic Baron <loic.baron@lip6.fr>
Fri, 23 Jan 2015 16:14:03 +0000 (17:14 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Fri, 23 Jan 2015 16:14:03 +0000 (17:14 +0100)
myslice/urls.py
rest/cache.py [new file with mode: 0644]

index c815148..da697cf 100644 (file)
@@ -92,6 +92,7 @@ urls = [
     (r'^create/(?P<object_type>[^/]+)/(?P<object_name>[^/]+)?/?$', 'rest.create.dispatch'),
     (r'^delete/(?P<object_type>[^/]+)/(?P<object_name>[^/]+)?/?$', 'rest.delete.dispatch'),
     (r'^credentials/(?P<action>[^/]+)/?$', 'rest.credentials.dispatch'),
+    (r'^cache/(?P<action>[^/]+)/?$', 'rest.cache.dispatch'),
     (r'^initscript/(?P<action>[^/]+)/?$', 'rest.initscript.dispatch'),
     #
     # REST monitoring
diff --git a/rest/cache.py b/rest/cache.py
new file mode 100644 (file)
index 0000000..3943946
--- /dev/null
@@ -0,0 +1,22 @@
+from django.http                import HttpResponse
+from portal.actions             import clear_user_creds
+
+from manifoldapi.manifoldapi    import execute_query
+from manifold.core.query        import Query
+
+import json
+
+def dispatch(request, action):
+    
+    if (action == 'clear') :
+        query = Query.update('myslice:user').filter_by('user_hrn', '==', '$user_hrn').set({'user_email':str(request.user)})
+        try:
+            res = execute_query(request, query)
+        except Exception, e:
+            ret = { "ret" : -1, "error" : "error clearing cache: %s" % e }
+            return HttpResponse(json.dumps(ret), content_type="application/json")
+    
+        ret = { "ret" : 1 }
+    else:
+        ret = { "ret" : 0, "error" : "action not supported" }
+    return HttpResponse(json.dumps(ret), content_type="application/json")