+ # Input: op_id, example: 'abc123def:3' Output: account_id='abc123def', op_index=3
+ def _get_account_and_op_HA(self, op_id):
+ if not op_id:
+ return (None, None)
+ account_id, _, op_index = op_id.rpartition(':')
+ if not account_id:
+ return (None, None)
+ if not op_index.isdigit():
+ return (None, None)
+ return account_id, op_index
+
+ # Get '_id' for any topic and operation
+ def _get_instance_id_HA(self, topic, op_type, op_id):
+ _id = None
+ # Special operation 'ANY', for SDN account associated to a VIM account: op_id as '_id'
+ if op_type == 'ANY':
+ _id = op_id
+ # NS/NSI: Use op_id as '_id'
+ elif self._is_service_type_HA(topic):
+ _id = op_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
+
+ # Set DB _filter for querying any related process state
+ def _get_waitfor_filter_HA(self, db_lcmop, topic, op_type, op_id):
+ _filter = {}
+ # Special operation 'ANY', for SDN account associated to a VIM account: op_id as '_id'
+ # In this special case, the timestamp is ignored
+ if op_type == 'ANY':
+ _filter = {'operationState': 'PROCESSING'}
+ # Otherwise, get 'startTime' timestamp for this operation
+ 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,
+ "_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']
+ _this_op = _ops[int(op_index)]
+ starttime_this_op = _this_op.get('startTime', None)
+ _filter = {'operationState': 'PROCESSING',
+ 'startTime.lt': starttime_this_op}
+ return _filter
+
+ # Get DB params for any topic and operation
+ def _get_dbparams_for_lock_HA(self, topic, op_type, op_id):
+ q_filter = {}
+ update_dict = {}
+ # NS/NSI
+ if self._is_service_type_HA(topic):
+ q_filter = {'_id': op_id, '_admin.worker': None}
+ update_dict = {'_admin.worker': self.worker_id}
+ # VIM/WIM/SDN
+ elif self._is_account_type_HA(topic):
+ account_id, op_index = self._get_account_and_op_HA(op_id)
+ if not account_id:
+ return None, None
+ if op_type == 'create':
+ # Creating a VIM/WIM/SDN account implies setting '_admin.current_operation' = 0
+ op_index = 0
+ q_filter = {'_id': account_id, "_admin.operations.{}.worker".format(op_index): None}
+ update_dict = {'_admin.operations.{}.worker'.format(op_index): self.worker_id,
+ '_admin.current_operation': op_index}
+ return q_filter, update_dict
+
+ def lock_HA(self, topic, op_type, op_id):