diff options
Diffstat (limited to 'conductor')
9 files changed, 76 insertions, 59 deletions
diff --git a/conductor/conductor/common/music/api.py b/conductor/conductor/common/music/api.py index 77b6a5a..dba852a 100644 --- a/conductor/conductor/common/music/api.py +++ b/conductor/conductor/common/music/api.py @@ -118,6 +118,8 @@ class MusicAPI(object): LOG.info(_LI("Initializing Music API")) server_url = CONF.music_api.server_url.rstrip('/') + if server_url and server_url.startswith('https'): + CONF.music_api.enable_https_mode = True if not server_url: # host/port/path are deprecated and should not be used anymore. # Defaults removed from oslo_config to give more incentive. @@ -142,8 +144,6 @@ class MusicAPI(object): # Set one parameter for connection mode # Currently depend on music version if CONF.music_api.enable_https_mode: - self.rest.server_url = 'https://{}:{}/{}'.format( - host, port, version, path.rstrip('/').lstrip('/')) self.rest.session.verify = CONF.music_api.certificate_authority_bundle_file if CONF.music_api.music_new_version: diff --git a/conductor/conductor/controller/translator.py b/conductor/conductor/controller/translator.py index 1c28889..c0d7e29 100644 --- a/conductor/conductor/controller/translator.py +++ b/conductor/conductor/controller/translator.py @@ -70,8 +70,7 @@ CONSTRAINTS = { }, 'threshold': { 'split': True, - 'required': ['attribute', 'threshold', 'operator'], - 'optional': ['unit'] + 'required': ['evaluate'], }, 'distance_between_demands': { 'required': ['distance'], diff --git a/conductor/conductor/data/plugins/inventory_provider/aai.py b/conductor/conductor/data/plugins/inventory_provider/aai.py index ddb857b..302bb89 100644 --- a/conductor/conductor/data/plugins/inventory_provider/aai.py +++ b/conductor/conductor/data/plugins/inventory_provider/aai.py @@ -1880,9 +1880,9 @@ class AAI(base.InventoryProviderBase): elif inventory_type == 'nssi': if filtering_attributes and model_invariant_id: - resolved_demands[name] = self.get_nssi_candidates(filtering_attributes, - model_invariant_id, model_version_id, - service_role, candidate_uniqueness) + resolved_demands[name].extend(self.get_nssi_candidates(filtering_attributes, + model_invariant_id, model_version_id, + service_role, candidate_uniqueness)) else: LOG.error("Unknown inventory_type " @@ -1977,7 +1977,6 @@ class AAI(base.InventoryProviderBase): nssi_instances = response_body.get("service-instance", []) for nssi_instance in nssi_instances: - inventory_attributes = dict() inventory_attributes["orchestration-status"] = nssi_instance.get('orchestration-status') inventory_attributes["service-role"] = nssi_instance.get('service-role') @@ -1985,17 +1984,9 @@ class AAI(base.InventoryProviderBase): if self.match_inventory_attributes(filtering_attributes, inventory_attributes, nssi_instance.get('service-instance-id')): - properties = list() - relationships = nssi_instance['relationship-list']['relationship'] - for relationship in relationships: - if relationship['related-to'] == 'service-instance': - properties = relationship['related-to-property'] + nsi_link = self._get_aai_rel_link(nssi_instance, 'service-instance') - nsi_name = None - if properties: - for prop in properties: - if prop['property-key'] == 'service-instance.service-instance-name': - nsi_name = prop['property-value'] + nsi_info = self.get_nsi_info(nsi_link) slice_profiles = nssi_instance.get('slice-profiles').get('slice-profile') slice_profile = min(slice_profiles, key=lambda x: x['latency']) @@ -2029,8 +2020,26 @@ class AAI(base.InventoryProviderBase): candidate['service_area_dimension'] = slice_profile.get('service-area-dimension') candidate['cs_availability'] = slice_profile.get('cs-availability') candidate['uniqueness'] = candidate_uniqueness - if nsi_name: - candidate['nsi_name'] = nsi_name + if nsi_info: + candidate['nsi_name'] = nsi_info.get('instance_name') + candidate['nsi_id'] = nsi_info.get('instance_id') + candidate['nsi_model_version_id'] = nsi_info.get('model_version_id') + candidate['nsi_model_invariant_id'] = nsi_info.get('model_invariant_id') candidates.append(candidate) return candidates + + def get_nsi_info(self, nsi_link): + nsi_info = dict() + if nsi_link: + nsi_link_path = self._get_aai_path_from_link(nsi_link) + path = self._aai_versioned_path(nsi_link_path) + nsi_response = self._request('get', path, data=None) + if nsi_response and nsi_response.status_code == 200: + nsi_response_body = nsi_response.json() + nsi_info['instance_id'] = nsi_response_body.get('service-instance-id') + nsi_info['instance_name'] = nsi_response_body.get('service-instance-name') + nsi_info['model_version_id'] = nsi_response_body.get('model-version-id') + nsi_info['model_invariant_id'] = nsi_response_body.get('model-invariant-id') + + return nsi_info diff --git a/conductor/conductor/solver/optimizer/constraints/threshold.py b/conductor/conductor/solver/optimizer/constraints/threshold.py index a94c608..48ea2c7 100644 --- a/conductor/conductor/solver/optimizer/constraints/threshold.py +++ b/conductor/conductor/solver/optimizer/constraints/threshold.py @@ -19,6 +19,7 @@ from conductor.i18n import _LI from conductor.solver.optimizer.constraints import constraint +from conductor.solver.utils.utils import OPERATIONS from oslo_log import log LOG = log.getLogger(__name__) @@ -26,37 +27,31 @@ LOG = log.getLogger(__name__) class Threshold(constraint.Constraint): - OPERATIONS = {'gte': lambda x, y: x >= y, - 'lte': lambda x, y: x <= y, - 'gt': lambda x, y: x > y, - 'lt': lambda x, y: x < y, - 'eq': lambda x, y: x == y - } - def __init__(self, _name, _type, _demand_list, _priority=0, _properties=None): constraint.Constraint.__init__( self, _name, _type, _demand_list, _priority) - self.attribute = _properties.get('attribute') - self.operation = self.OPERATIONS.get(_properties.get('operator')) - self.threshold = _properties.get('threshold') + self.properties_list = _properties.get('evaluate') def solve(self, _decision_path, _candidate_list, _request): - filtered_candidates = list() + conflict_list = list() demand_name = _decision_path.current_demand.name - LOG.info(_LI("Solving constraint type '{}' for demand - [{}]").format( - self.constraint_type, demand_name)) + LOG.info(_LI("Solving constraint {} of type '{}' for demand - [{}]").format( + self.name, self.constraint_type, demand_name)) for candidate in _candidate_list: - attribute_value = candidate.get(self.attribute) - if self.operation(attribute_value, self.threshold): - filtered_candidates.append(candidate) - - return filtered_candidates - - + for prop in self.properties_list: + attribute = prop.get('attribute') + threshold = prop.get('threshold') + operation = OPERATIONS.get(prop.get('operator')) + attribute_value = candidate.get(attribute) + if not operation(attribute_value, threshold): + conflict_list.append(candidate) + continue + filtered_candidates = [c for c in _candidate_list if c not in conflict_list] + return filtered_candidates diff --git a/conductor/conductor/solver/utils/utils.py b/conductor/conductor/solver/utils/utils.py index 06de301..c995eec 100755 --- a/conductor/conductor/solver/utils/utils.py +++ b/conductor/conductor/solver/utils/utils.py @@ -24,6 +24,14 @@ from oslo_log import log LOG = log.getLogger(__name__) +OPERATIONS = {'gte': lambda x, y: x >= y, + 'lte': lambda x, y: x <= y, + 'gt': lambda x, y: x > y, + 'lt': lambda x, y: x < y, + 'eq': lambda x, y: x == y + } + + def compute_air_distance(_src, _dst): """Compute Air Distance diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/nssi_candidate.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/nssi_candidate.json index a26f322..2be5561 100644 --- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/nssi_candidate.json +++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/nssi_candidate.json @@ -27,7 +27,10 @@ "reliability":null, "cost":1.0, "nsi_name": "nsi_test_0211", + "nsi_id": "4115d3c8-dd59-45d6-b09d-e756dee9b518", + "nsi_model_version_id": "8b664b11-6646-4776-9f59-5c3de46da2d6", + "nsi_model_invariant_id": "39b10fe6-efcc-40bc-8184-c38414b80771", "instance_name": "nssi_test_0211", "uniqueness": "true" } -]
\ No newline at end of file +] diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py index cf18087..295057f 100644 --- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py +++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py @@ -738,6 +738,15 @@ tenant/3c6c471ada7747fe8ff7f28e100b61e8/vservers/vserver/00bddefc-126e-4e4f-a18d nssi_candidates_file = './conductor/tests/unit/data/plugins/inventory_provider/nssi_candidate.json' nssi_candidates = json.loads(open(nssi_candidates_file).read()) + nsi_info = {'instance_name': 'nsi_test_0211', + 'instance_id': '4115d3c8-dd59-45d6-b09d-e756dee9b518', + 'model_version_id': '8b664b11-6646-4776-9f59-5c3de46da2d6', + 'model_invariant_id': '39b10fe6-efcc-40bc-8184-c38414b80771'} + + self.nsi_patcher = mock.patch('conductor.data.plugins.inventory_provider.aai.AAI.get_nsi_info', + return_value=nsi_info) + self.nsi_patcher.start() + service_role = 'nssi' model_invariant_id = '21d57d4b-52ad-4d3c-a798-248b5bb9124a' model_version_id = 'bfba363e-e39c-4bd9-a9d5-1371c28f4d22' diff --git a/conductor/conductor/tests/unit/solver/optimizer/constraints/test_threshold.py b/conductor/conductor/tests/unit/solver/optimizer/constraints/test_threshold.py index 34b8193..276701c 100644 --- a/conductor/conductor/tests/unit/solver/optimizer/constraints/test_threshold.py +++ b/conductor/conductor/tests/unit/solver/optimizer/constraints/test_threshold.py @@ -31,30 +31,24 @@ class TestThreshold(unittest.TestCase): candidates_file = './conductor/tests/unit/data/plugins/inventory_provider/nssi_candidate.json' candidates = json.loads(open(candidates_file).read()) - properties = {'attribute': 'latency', 'threshold': 30, 'operator': 'lte'} + properties = {'evaluate': + [{'attribute': 'latency', 'threshold': 30, 'operator': 'lte'}, + {'attribute': 'exp_data_rate_ul', 'threshold': 70, 'operator': 'gte'}]} - threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0, _properties=properties) + threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0, + _properties=properties) decision_path = DecisionPath() decision_path.current_demand = Demand('URLLC') self.assertEqual(candidates, threshold_obj.solve(decision_path, candidates, None)) - properties = {'attribute': 'latency', 'threshold': 10, 'operator': 'lte'} + properties = {'evaluate': + [{'attribute': 'latency', 'threshold': 10, 'operator': 'lte'}, + {'attribute': 'exp_data_rate_ul', 'threshold': 120, 'operator': 'gte'}]} - threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0, _properties=properties) - - self.assertEqual([], threshold_obj.solve(decision_path, candidates, None)) - - properties = {'attribute': 'exp_data_rate_ul', 'threshold': 70, 'operator': 'gte'} - - threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0, _properties=properties) - - self.assertEqual(candidates, threshold_obj.solve(decision_path, candidates, None)) - - properties = {'attribute': 'exp_data_rate_ul', 'threshold': 120, 'operator': 'gte'} - - threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0, _properties=properties) + threshold_obj = Threshold('urllc_threshold', 'threshold', ['URLLC'], _priority=0, + _properties=properties) self.assertEqual([], threshold_obj.solve(decision_path, candidates, None)) diff --git a/conductor/pom.xml b/conductor/pom.xml index ad93782..d99f0ca 100644 --- a/conductor/pom.xml +++ b/conductor/pom.xml @@ -22,13 +22,13 @@ <parent> <groupId>org.onap.optf.has</groupId> - <version>2.0.2-SNAPSHOT</version> + <version>2.0.3-SNAPSHOT</version> <artifactId>optf-has</artifactId> </parent> <groupId>org.onap.optf.has</groupId> <artifactId>optf-has-conductor</artifactId> - <version>2.0.2-SNAPSHOT</version> + <version>2.0.3-SNAPSHOT</version> <name>optf-has-conductor</name> <description>Homing Allocation Service/Conductor</description> |