X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Flcm_utils.py;h=a83e788636c588b41c2d5ad31394c61e76cd4240;hb=refs%2Fchanges%2F66%2F8266%2F4;hp=2779a2560c1c09b15ca0e07cd70ad9a7ebd80aaa;hpb=e64f7fb3e0efd6fcc78ea322c90106c7403a8a62;p=osm%2FLCM.git diff --git a/osm_lcm/lcm_utils.py b/osm_lcm/lcm_utils.py index 2779a25..a83e788 100644 --- a/osm_lcm/lcm_utils.py +++ b/osm_lcm/lcm_utils.py @@ -18,6 +18,7 @@ import asyncio from collections import OrderedDict +from time import time # from osm_common.dbbase import DbException __author__ = "Alfonso Tierno" @@ -48,6 +49,21 @@ def versiontuple(v): return tuple(filled) +def deep_get(target_dict, key_list): + """ + Get a value from target_dict entering in the nested keys. If keys does not exist, it returns None + Example target_dict={a: {b: 5}}; key_list=[a,b] returns 5; both key_list=[a,b,c] and key_list=[f,h] return None + :param target_dict: dictionary to be read + :param key_list: list of keys to read from target_dict + :return: The wanted value if exist, None otherwise + """ + for key in key_list: + if not isinstance(target_dict, dict) or key not in target_dict: + return None + target_dict = target_dict[key] + return target_dict + + # LcmBase must be listed before TaskRegistry, as it is a dependency. class LcmBase: @@ -71,6 +87,8 @@ class LcmBase: """ if not _desc: return + now = time() + _desc["_admin.modified"] = now self.db.set_one(item, {"_id": _id}, _desc) _desc.clear() # except DbException as e: @@ -97,7 +115,7 @@ class TaskRegistry(LcmBase): # NS/NSI: "services" VIM/WIM/SDN: "accounts" topic_service_list = ['ns', 'nsi'] - topic_account_list = ['vim', 'wim', 'sdn'] + topic_account_list = ['vim', 'wim', 'sdn', 'k8scluster', 'k8srepo'] # Map topic to InstanceID topic2instid_dict = { @@ -110,7 +128,9 @@ class TaskRegistry(LcmBase): 'nsi': 'nsilcmops', 'vim': 'vim_accounts', 'wim': 'wim_accounts', - 'sdn': 'sdns'} + 'sdn': 'sdns', + 'k8scluster': 'k8sclusters', + 'k8srepo': 'k8srepos'} def __init__(self, worker_id=None, db=None, logger=None): self.task_registry = { @@ -119,6 +139,8 @@ class TaskRegistry(LcmBase): "vim_account": {}, "wim_account": {}, "sdn": {}, + "k8scluster": {}, + "k8srepo": {}, } self.worker_id = worker_id self.db = db @@ -232,7 +254,7 @@ class TaskRegistry(LcmBase): # NS/NSI: Use op_id as '_id' elif self._is_service_type_HA(topic): _id = op_id - # VIM/SDN/WIM: Split op_id to get Account ID and Operation Index, use Account ID as '_id' + # VIM/SDN/WIM/K8SCLUSTER: Split op_id to get Account ID and Operation Index, use Account ID as '_id' elif self._is_account_type_HA(topic): _id, _ = self._get_account_and_op_HA(op_id) return _id @@ -248,13 +270,16 @@ class TaskRegistry(LcmBase): else: # NS/NSI if self._is_service_type_HA(topic): + now = time() starttime_this_op = db_lcmop.get("startTime") instance_id_label = self.topic2instid_dict.get(topic) instance_id = db_lcmop.get(instance_id_label) _filter = {instance_id_label: instance_id, 'operationState': 'PROCESSING', - 'startTime.lt': starttime_this_op} - # VIM/WIM/SDN + 'startTime.lt': starttime_this_op, + "_admin.modified.gt": now - 2*3600, # ignore if tow hours of inactivity + } + # VIM/WIM/SDN/K8scluster elif self._is_account_type_HA(topic): _, op_index = self._get_account_and_op_HA(op_id) _ops = db_lcmop['_admin']['operations'] @@ -303,7 +328,7 @@ class TaskRegistry(LcmBase): the task in this instance of LCM, without querying the DB. """ - # Backward compatibility for VIM/WIM/SDN without op_id + # Backward compatibility for VIM/WIM/SDN/k8scluster without op_id if self._is_account_type_HA(topic) and op_id is None: return True