aboutsummaryrefslogtreecommitdiffstats
path: root/apps/placement/optimizers
diff options
context:
space:
mode:
authorChayal, Avteet (ac229e) <ac229e@att.com>2020-03-19 03:13:27 -0400
committerChayal, Avteet (ac229e) <ac229e@att.com>2020-03-19 19:38:06 -0400
commitfdeaf8b56c8d342ef8145aae15c87525fe105f2a (patch)
treed954fda2eec3faa1ebd47d3222c27ad39ae5005f /apps/placement/optimizers
parentd39860b859417c1a7773f39ad8db311848ec0676 (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>
Diffstat (limited to 'apps/placement/optimizers')
-rw-r--r--apps/placement/optimizers/conductor/api_builder.py42
-rw-r--r--apps/placement/optimizers/conductor/translation.py43
2 files changed, 57 insertions, 28 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"]