+ # self.logger.debug('_on_update_ro_db(nsrs_id={}'.format(nsrs_id))
+
+ try:
+ # TODO filter RO descriptor fields...
+
+ # write to database
+ db_dict = dict()
+ # db_dict['deploymentStatus'] = yaml.dump(ro_descriptor, default_flow_style=False, indent=2)
+ db_dict['deploymentStatus'] = ro_descriptor
+ self.update_db_2("nsrs", nsrs_id, db_dict)
+
+ except Exception as e:
+ self.logger.warn('Cannot write database RO deployment for ns={} -> {}'.format(nsrs_id, e))
+
+ async def _on_update_n2vc_db(self, table, filter, path, updated_data):
+
+ # self.logger.debug('_on_update_n2vc_db(table={}, filter={}, path={}, updated_data={}'
+ # .format(table, filter, path, updated_data))
+
+ try:
+
+ nsr_id = filter.get('_id')
+
+ # read ns record from database
+ nsr = self.db.get_one(table='nsrs', q_filter=filter)
+ current_ns_status = nsr.get('nsState')
+
+ # get vca status for NS
+ # status_dict = await self.n2vc.get_status(namespace='.' + nsr_id, yaml_format=False)
+ # TEMPORAL
+ status_dict = str(await self.n2vc.get_status(namespace='.' + nsr_id))
+
+ # vcaStatus
+ db_dict = dict()
+ db_dict['vcaStatus'] = status_dict
+
+ # update configurationStatus for this VCA
+ try:
+ vca_index = int(path[path.rfind(".")+1:])
+
+ vca_list = deep_get(target_dict=nsr, key_list=('_admin', 'deployed', 'VCA'))
+ vca_status = vca_list[vca_index].get('status')
+
+ configuration_status_list = nsr.get('configurationStatus')
+ config_status = configuration_status_list[vca_index].get('status')
+
+ if config_status == 'BROKEN' and vca_status != 'failed':
+ db_dict['configurationStatus'][vca_index] = 'READY'
+ elif config_status != 'BROKEN' and vca_status == 'failed':
+ db_dict['configurationStatus'][vca_index] = 'BROKEN'
+ except Exception as e:
+ # not update configurationStatus
+ self.logger.debug('Error updating vca_index (ignore): {}'.format(e))
+
+ # if nsState = 'READY' check if juju is reporting some error => nsState = 'DEGRADED'
+ # if nsState = 'DEGRADED' check if all is OK
+ is_degraded = False
+ if current_ns_status in ('READY', 'DEGRADED'):
+ error_description = ''
+ # check machines
+ if status_dict.get('machines'):
+ for machine_id in status_dict.get('machines'):
+ machine = status_dict.get('machines').get(machine_id)
+ # check machine agent-status
+ if machine.get('agent-status'):
+ s = machine.get('agent-status').get('status')
+ if s != 'started':
+ is_degraded = True
+ error_description += 'machine {} agent-status={} ; '.format(machine_id, s)
+ # check machine instance status
+ if machine.get('instance-status'):
+ s = machine.get('instance-status').get('status')
+ if s != 'running':
+ is_degraded = True
+ error_description += 'machine {} instance-status={} ; '.format(machine_id, s)
+ # check applications
+ if status_dict.get('applications'):
+ for app_id in status_dict.get('applications'):
+ app = status_dict.get('applications').get(app_id)
+ # check application status
+ if app.get('status'):
+ s = app.get('status').get('status')
+ if s != 'active':
+ is_degraded = True
+ error_description += 'application {} status={} ; '.format(app_id, s)
+
+ if error_description:
+ db_dict['errorDescription'] = error_description
+ if current_ns_status == 'READY' and is_degraded:
+ db_dict['nsState'] = 'DEGRADED'
+ if current_ns_status == 'DEGRADED' and not is_degraded:
+ db_dict['nsState'] = 'READY'
+
+ # write to database
+ self.update_db_2("nsrs", nsr_id, db_dict)
+
+ except Exception as e:
+ self.logger.warn('Error updating NS state for ns={}: {}'.format(nsr_id, e))