diff options
author | Chayal, Avteet (ac229e) <ac229e@att.com> | 2020-03-19 03:13:27 -0400 |
---|---|---|
committer | Chayal, Avteet (ac229e) <ac229e@att.com> | 2020-03-19 19:38:06 -0400 |
commit | fdeaf8b56c8d342ef8145aae15c87525fe105f2a (patch) | |
tree | d954fda2eec3faa1ebd47d3222c27ad39ae5005f | |
parent | d39860b859417c1a7773f39ad8db311848ec0676 (diff) |
OSDF migration to new Policy API
Map policy type with constraints type for HAS payload
Added new attribute policies for Network Sliciing reference
Fixed the logic to proccess Attribute policy translation
Issue-ID: OPTFRA-721
Change-Id: I6b01815963b48b3df97c1a3109cc39b2a8bc2c3c
Signed-off-by: Chayal, Avteet (ac229e) <ac229e@att.com>
-rw-r--r-- | apps/placement/optimizers/conductor/api_builder.py | 42 | ||||
-rw-r--r-- | apps/placement/optimizers/conductor/translation.py | 43 | ||||
-rw-r--r-- | config/common_config.yaml | 7 | ||||
-rw-r--r-- | config/has_config.yaml | 4 | ||||
-rw-r--r-- | test/placement-tests/request_placement_vfmod.json | 2 | ||||
-rw-r--r-- | test/policy-local-files/Attribute_vNS_1.json | 49 | ||||
-rw-r--r-- | test/policy-local-files/new_policies/Attribute_vNS_1.json | 51 | ||||
-rw-r--r-- | test/policy-local-files/new_policies/meta-valid-policies.txt | 1 |
8 files changed, 167 insertions, 32 deletions
diff --git a/apps/placement/optimizers/conductor/api_builder.py b/apps/placement/optimizers/conductor/api_builder.py index cefde51..398db8d 100644 --- a/apps/placement/optimizers/conductor/api_builder.py +++ b/apps/placement/optimizers/conductor/api_builder.py @@ -63,32 +63,28 @@ def conductor_api_builder(request_json, flat_policies: list, local_config, demand_vnf_name_list = [] for placementDemand in request_json['placementInfo']['placementDemands']: demand_vnf_name_list.append(placementDemand['resourceModuleName'].lower()) - demand_list = tr.gen_demands(request_json, gp['onap.policies.optimization.VnfPolicy']) - # What's the attribute policy? Need an example - attribute_policy_list = tr.gen_attribute_policy(demand_vnf_name_list, gp['attribute']) + demand_list = tr.gen_demands( + request_json, gp['onap.policies.optimization.VnfPolicy']) + attribute_policy_list = tr.gen_attribute_policy( + demand_vnf_name_list, gp['onap.policies.optimization.AttributePolicy']) distance_to_location_policy_list = tr.gen_distance_to_location_policy( demand_vnf_name_list, gp['onap.policies.optimization.DistancePolicy']) - # What's the inventory group policy? A policy to choose the inventory group from existing list? - inventory_policy_list = tr.gen_inventory_group_policy(demand_vnf_name_list, gp['inventory_group']) - # What's the instance fit policy, a policy to choose the instance from existing list? + inventory_policy_list = tr.gen_inventory_group_policy( + demand_vnf_name_list, gp['onap.policies.optimization.InventoryGroupPolicy']) resource_instance_policy_list = tr.gen_resource_instance_policy( - demand_vnf_name_list, gp['instance_fit']) - # Need an example for the resource_region_policy - resource_region_policy_list = tr.gen_resource_region_policy(demand_vnf_name_list, gp['region_fit']) - zone_policy_list = tr.gen_zone_policy(demand_vnf_name_list, gp['onap.policies.optimization.AffinityPolicy']) - optimization_policy_list = tr.gen_optimization_policy(demand_vnf_name_list, - gp['onap.policies.optimization.OptimizationPolicy']) - # Need an example for the instance reservation policy - reservation_policy_list = tr.gen_reservation_policy(demand_vnf_name_list, gp['instance_reservation']) - capacity_policy_list = tr.gen_capacity_policy(demand_vnf_name_list, gp['onap.policies.optimization.Vim_fit']) - hpa_policy_list = tr.gen_hpa_policy(demand_vnf_name_list, gp['onap.policies.optimization.HpaPolicy']) - #distance_to_location_policy_list = tr.gen_distance_to_location_policy( - # demand_vnf_name_list, gp['distance_to_location']) - # demand_list = tr.gen_demands(request_json, gp['vnfPolicy']) - #zone_policy_list = tr.gen_zone_policy(demand_vnf_name_list, gp['zone']) - #optimization_policy_list = tr.gen_optimization_policy(demand_vnf_name_list, gp['placement_optimization']) - #capacity_policy_list = tr.gen_capacity_policy(demand_vnf_name_list, gp['vim_fit']) - #hpa_policy_list = tr.gen_hpa_policy(demand_vnf_name_list, gp['hpa']) + demand_vnf_name_list, gp['onap.policies.optimization.ResourceInstancePolicy']) + resource_region_policy_list = tr.gen_resource_region_policy( + demand_vnf_name_list, gp['onap.policies.optimization.ResourceRegionPolicy']) + zone_policy_list = tr.gen_zone_policy( + demand_vnf_name_list, gp['onap.policies.optimization.AffinityPolicy']) + optimization_policy_list = tr.gen_optimization_policy( + demand_vnf_name_list, gp['onap.policies.optimization.OptimizationPolicy']) + reservation_policy_list = tr.gen_reservation_policy( + demand_vnf_name_list, gp['onap.policies.optimization.InstanceReservationPolicy']) + capacity_policy_list = tr.gen_capacity_policy( + demand_vnf_name_list, gp['onap.policies.optimization.Vim_fit']) + hpa_policy_list = tr.gen_hpa_policy( + demand_vnf_name_list, gp['onap.policies.optimization.HpaPolicy']) req_params_dict = _build_parameters(gp, request_json) conductor_policies = [attribute_policy_list, distance_to_location_policy_list, inventory_policy_list, resource_instance_policy_list, resource_region_policy_list, zone_policy_list, diff --git a/apps/placement/optimizers/conductor/translation.py b/apps/placement/optimizers/conductor/translation.py index 45deb2d..d637152 100644 --- a/apps/placement/optimizers/conductor/translation.py +++ b/apps/placement/optimizers/conductor/translation.py @@ -106,7 +106,7 @@ def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rt for policy in resource_policy: pc = policy[list(policy.keys())[0]] default, demands = get_matching_vnfs(pc['properties']['resources'], vnf_list, match_type=match_type) - resource = {pc['properties']['identity']: {'type': pc['type'], 'demands': demands}} + resource = {pc['properties']['identity']: {'type': map_constraint_type(pc['type']), 'demands': demands}} if rtype: resource[pc['properties']['identity']]['properties'] = {'controller': pc[rtype]['controller'], @@ -116,13 +116,13 @@ def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rt if default: for d in demands: resource_repeated = True \ - if {pc['properties']['identity']: {'type': pc['type'], 'demands': d}} \ + if {pc['properties']['identity']: {'type': map_constraint_type(pc['type']), 'demands': d}} \ in resource_policy_list else False if resource_repeated: continue else: resource_policy_list.append( - {pc['properties']['identity']: {'type': pc['type'], 'demands': d }}) + {pc['properties']['identity']: {'type': map_constraint_type(pc['type']), 'demands': d }}) policy[list(policy.keys())[0]]['properties']['resources'] = d related_policies.append(policy) # Need to override the default policies, here delete the outdated policy stored in the db @@ -178,10 +178,12 @@ def gen_attribute_policy(vnf_list, attribute_policy): """Get policies governing attributes of VNFs in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, attribute_policy, rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - properties = p_main[list(p_main.keys())[0]]['properties']['cloudAttributeProperty'] + properties = p_main[list(p_main.keys())[0]]['properties']['attributeProperties'] attribute_mapping = policy_config_mapping['filtering_attributes'] # wanted attributes and mapping p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = { - 'evaluate': dict((k, properties.get(attribute_mapping.get(k))) for k in attribute_mapping.keys()) + 'evaluate': dict((attribute_mapping[k], properties.get(k) + if k != "cloudRegion" else gen_cloud_region(properties)) + for k in attribute_mapping.keys()) } return cur_policies # cur_policies gets updated in place... @@ -312,3 +314,34 @@ def gen_demands(req_json, vnf_policies): if len(prop) > 0: demand_dictionary.update({demand['resourceModuleName']: prop}) return demand_dictionary + + +def map_constraint_type(policy_type): + if "onap.policies.optimization.AttributePolicy" == policy_type: + return "attribute" + if "onap.policies.optimization.DistancePolicy" == policy_type: + return "distance_to_location" + if "onap.policies.optimization.InventoryGroupPolicy" == policy_type: + return "inventory_group" + if "onap.policies.optimization.ResourceInstancePolicy" == policy_type: + return "instance_fit" + if "onap.policies.optimization.ResourceRegionPolicy" == policy_type: + return "region_fit" + if "onap.policies.optimization.AffinityPolicy" == policy_type: + return "zone" + if "onap.policies.optimization.InstanceReservationPolicy" == policy_type: + return "instance_reservation" + if "onap.policies.optimization.Vim_fit" == policy_type: + return "vim_fit" + if "onap.policies.optimization.HpaPolicy" == policy_type: + return "hpa" + + return policy_type + + +def gen_cloud_region(property): + prop = {"cloud_region_attributes": dict()} + if 'cloudRegion' in property: + for k,v in property['cloudRegion'].items(): + update_converted_attribute(k, v, prop, 'cloud_region_attributes') + return prop["cloud_region_attributes"] diff --git a/config/common_config.yaml b/config/common_config.yaml index f29e8c0..cf75e2a 100644 --- a/config/common_config.yaml +++ b/config/common_config.yaml @@ -11,9 +11,10 @@ osdf_temp: # special configuration required for "workarounds" or testing local_policies: global_disabled: True local_placement_policies_enabled: True - placement_policy_dir_vcpe: "./test/policy-local-files/" + placement_policy_dir_vcpe: "./test/policy-local-files/new_policies/" placement_policy_files_vcpe: # workaroud for policy platform glitches (or "work-arounds" for other components) - Affinity_vCPE_1.json + - Attribute_vNS_1.json #- Capacity_vGMuxInfra.json #- Capacity_vG_1.json - Distance_vG_1.json @@ -24,7 +25,7 @@ osdf_temp: # special configuration required for "workarounds" or testing - QueryPolicy_vCPE.json - vnfPolicy_vG.json - vnfPolicy_vGMuxInfra.json - placement_policy_dir_vfw: "./test/policy-local-files/" + placement_policy_dir_vfw: "./test/policy-local-files/new_policies/" placement_policy_files_vfw: # workaroud for policy platform glitches (or "work-arounds" for other components) #- Capacity_vFW_1.json - Distance_vFW_1.json @@ -32,7 +33,7 @@ osdf_temp: # special configuration required for "workarounds" or testing - Placement_Optimization_1.json - QueryPolicy_vFW.json - vnfPolicy_vFW.json - placement_policy_dir_vfw_td: "./test/policy-local-files/" + placement_policy_dir_vfw_td: "./test/policy-local-files/new_policies/" placement_policy_files_vfw_td: - vnfPolicy_vFW_TD.json - vnfPolicy_vPGN_TD.json diff --git a/config/has_config.yaml b/config/has_config.yaml index 2371508..0b94391 100644 --- a/config/has_config.yaml +++ b/config/has_config.yaml @@ -19,6 +19,10 @@ policy_config_mapping: cloudRegionId: cloud-region-id orchestrationStatus: orchestration-status provStatus: prov-status + cloudRegion: cloud-region + cloud_region_attributes: + serviceRequests: service-requests + cloudRequests: cloud-requests passthrough_attributes: {} candidates: # for (k1, v1), if k1 is in demand, set prop[k2] = _get_candidates(demand[k1]) diff --git a/test/placement-tests/request_placement_vfmod.json b/test/placement-tests/request_placement_vfmod.json index 5242ee7..4b2b852 100644 --- a/test/placement-tests/request_placement_vfmod.json +++ b/test/placement-tests/request_placement_vfmod.json @@ -93,7 +93,7 @@ }, "constraints": { "affinity_vFW_TD": { - "type": "onap.policies.optimization.AffinityPolicy", + "type": "zone", "demands": [ "vFW-SINK", "vPGN" diff --git a/test/policy-local-files/Attribute_vNS_1.json b/test/policy-local-files/Attribute_vNS_1.json new file mode 100644 index 0000000..e4766db --- /dev/null +++ b/test/policy-local-files/Attribute_vNS_1.json @@ -0,0 +1,49 @@ +{ + "service": "attributePolicy", + "policyName": "OSDF_FRANKFURT.AttributePolicy_vNS_1", + "description": "Attribute Policy for Network Slicing (NS)", + "templateVersion": "OpenSource.version.1", + "version": "OpenSource.version.1", + "priority": "1", + "riskType": "test", + "riskLevel": "3", + "guard": "False", + "content": { + "identity": "attribute-vNS", + "policyScope": [ + "vNS", + "us", + "international", + "ip" + ], + "policyType": "attribute", + "resources": [ + "vNS", + "" + ], + "attributeProperties": { + "cloudRegion": { + "serviceRequests": [ + "", + "" + ], + "cloudRequests": [ + "", + "" + ] + }, + "networkRoles": { + "all": [ + "", + "" + ] + }, + "complex": { + "any": [ + "", + "" + ] + } + } + } +}
\ No newline at end of file diff --git a/test/policy-local-files/new_policies/Attribute_vNS_1.json b/test/policy-local-files/new_policies/Attribute_vNS_1.json new file mode 100644 index 0000000..35b3c74 --- /dev/null +++ b/test/policy-local-files/new_policies/Attribute_vNS_1.json @@ -0,0 +1,51 @@ +{ + "OSDF_FRANKFURT.Attribute_vNS_1": { + "type": "onap.policies.optimization.AttributePolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Attribute_vNS_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vNS" + ], + "resources": [ + "vNS" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "attribute-vNS", + "attributeProperties": { + "cloudRegion": { + "serviceRequests": [ + "", + "" + ], + "cloudRequests": [ + "", + "" + ] + }, + "networkRoles": { + "all": [ + "", + "" + ] + }, + "complex": { + "any": [ + "", + "" + ] + } + } + } + } +}
\ No newline at end of file diff --git a/test/policy-local-files/new_policies/meta-valid-policies.txt b/test/policy-local-files/new_policies/meta-valid-policies.txt index 7f5a007..5f969bf 100644 --- a/test/policy-local-files/new_policies/meta-valid-policies.txt +++ b/test/policy-local-files/new_policies/meta-valid-policies.txt @@ -14,3 +14,4 @@ QueryPolicy_vFW_TD.json vnfPolicy_vFW_TD.json vnfPolicy_vPGN_TD.json Affinity_vFW_TD.json +Attribute_vNS_1.json
\ No newline at end of file |