summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/vesagent
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2018-05-15 09:43:35 +0000
committerBin Yang <bin.yang@windriver.com>2018-05-15 09:43:35 +0000
commit520570b61f080547a654f44e2764b24881cf1ed1 (patch)
tree03de37408bcbc4a55759ae8e286e3ba2f71eda4d /windriver/titanium_cloud/vesagent
parent786e42a71518a44e7ba71feb42faad1f1dae55a4 (diff)
Add DELETE API to remove all backlogs of a VIM
And this will bring down the vesagent workers whenever there is no backlogs of any VIM any more Change-Id: I21d2229727d7bf6af119c072e9ca7ce9ce252c8d Issue-ID: MULTICLOUD-230 Signed-off-by: Bin Yang <bin.yang@windriver.com>
Diffstat (limited to 'windriver/titanium_cloud/vesagent')
-rw-r--r--windriver/titanium_cloud/vesagent/vesagent_ctrl.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/windriver/titanium_cloud/vesagent/vesagent_ctrl.py b/windriver/titanium_cloud/vesagent/vesagent_ctrl.py
index e7094aa4..fdc9f71a 100644
--- a/windriver/titanium_cloud/vesagent/vesagent_ctrl.py
+++ b/windriver/titanium_cloud/vesagent/vesagent_ctrl.py
@@ -241,6 +241,13 @@ class VesAgentCtrl(APIView):
'''
self._logger.info("vimid: %s" % vimid)
self._logger.debug("with META: %s" % request.META)
+ try:
+ # tbd
+ self.clearBacklogsOneVIM(vimid)
+ except Exception as e:
+ self._logger.error("exception:%s" % str(e))
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(status=status.HTTP_200_OK)
@@ -275,6 +282,52 @@ class VesAgentCtrl(APIView):
self._logger.info("return")
return vesAgentConfig
+ def clearBacklogsOneVIM(self, vimid):
+ '''
+ remove the specified backlogs for a VIM
+ :param vimid:
+ :param vesagent_config:
+ :return:
+ '''
+ self._logger.info("vimid: %s" % vimid)
+
+ try:
+ # remove vimid from "VesAgentBacklogs.vimlist"
+ VesAgentBacklogsVimListStr = cache.get("VesAgentBacklogs.vimlist")
+ VesAgentBacklogsVimList = []
+ if VesAgentBacklogsVimListStr is not None:
+ VesAgentBacklogsVimList = json.loads(VesAgentBacklogsVimListStr)
+ VesAgentBacklogsVimList = [v for v in VesAgentBacklogsVimList if v != vimid]
+
+ logger.info("VesAgentBacklogs.vimlist is %s" % VesAgentBacklogsVimList)
+
+ # cache forever
+ cache.set("VesAgentBacklogs.vimlist", json.dumps(VesAgentBacklogsVimList), None)
+
+ # retrieve the backlogs
+ vesAgentConfigStr = cache.get("VesAgentBacklogs.config.%s" % (vimid))
+ if vesAgentConfigStr is None:
+ logger.warn("VesAgentBacklogs.config.%s cannot be found in cache" % (vimid))
+ return 0
+
+ logger.debug("VesAgentBacklogs.config.%s: %s" % (vimid, vesAgentConfigStr))
+
+ vesAgentConfig = json.loads(vesAgentConfigStr)
+ if vesAgentConfig is None:
+ logger.warn("VesAgentBacklogs.config.%s corrupts" % (vimid))
+ return 0
+
+ # iterate all backlog and remove the associate state!
+ # tbd
+
+ # clear the whole backlogs for a VIM
+ cache.set("VesAgentBacklogs.config.%s" % vimid, "deleting the backlogs", 1)
+
+ except Exception as e:
+ self._logger.error("exception:%s" % str(e))
+
+ self._logger.info("return")
+ return 0
def buildBacklogsOneVIM(self, vimid, vesagent_config = None):
'''