summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/placement/optimizers/conductor/api_builder.py28
-rw-r--r--apps/placement/optimizers/conductor/translation.py80
2 files changed, 73 insertions, 35 deletions
diff --git a/apps/placement/optimizers/conductor/api_builder.py b/apps/placement/optimizers/conductor/api_builder.py
index 7b61580..cefde51 100644
--- a/apps/placement/optimizers/conductor/api_builder.py
+++ b/apps/placement/optimizers/conductor/api_builder.py
@@ -32,7 +32,7 @@ def _build_parameters(group_policies, request_json):
:param request_json: parameter data received from a client
:return:
"""
- initial_params = tr.get_opt_query_data(request_json, group_policies['request_param_query'])
+ initial_params = tr.get_opt_query_data(request_json, group_policies['onap.policies.optimization.QueryPolicy'])
params = dict()
params.update({"REQUIRED_MEM": initial_params.pop("requiredMemory", "")})
params.update({"REQUIRED_DISK": initial_params.pop("requiredDisk", "")})
@@ -61,22 +61,34 @@ def conductor_api_builder(request_json, flat_policies: list, local_config,
templ = Template(open(template).read())
gp = group_policies_gen(flat_policies, 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['vnfPolicy'])
+ 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'])
distance_to_location_policy_list = tr.gen_distance_to_location_policy(
- demand_vnf_name_list, gp['distance_to_location'])
+ 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?
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['zone'])
- optimization_policy_list = tr.gen_optimization_policy(demand_vnf_name_list, gp['placement_optimization'])
+ 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['vim_fit'])
- hpa_policy_list = tr.gen_hpa_policy(demand_vnf_name_list, gp['hpa'])
+ 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'])
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 46bee1d..45deb2d 100644
--- a/apps/placement/optimizers/conductor/translation.py
+++ b/apps/placement/optimizers/conductor/translation.py
@@ -37,7 +37,7 @@ def get_opt_query_data(req_json, policies):
if 'requestParameters' in req_json["placementInfo"]:
req_params = req_json["placementInfo"]["requestParameters"]
for policy in policies:
- for queryProp in policy['content']['queryProperties']:
+ for queryProp in policy[list(policy.keys())[0]]['properties']['queryProperties']:
attr_val = queryProp['value'] if 'value' in queryProp and queryProp['value'] != "" \
else dot_notation(req_params, queryProp['attribute_location'])
if attr_val is not None:
@@ -53,13 +53,13 @@ def gen_optimization_policy(vnf_list, optimization_policy):
"""
optimization_policy_list = []
for policy in optimization_policy:
- content = policy['content']
+ content = policy[list(policy.keys())[0]]['properties']
parameter_list = []
parameters = ["cloud_version", "hpa_score"]
for attr in content['objectiveParameter']['parameterAttributes']:
parameter = attr['parameter'] if attr['parameter'] in parameters else attr['parameter']+"_between"
- vnfs = get_matching_vnfs(attr['resources'], vnf_list)
+ default, vnfs = get_matching_vnfs(attr['resources'], vnf_list)
for vnf in vnfs:
value = [vnf] if attr['parameter'] in parameters else [attr['customerLocationInfo'], vnf]
parameter_list.append({
@@ -79,14 +79,16 @@ def get_matching_vnfs(resources, vnf_list, match_type="intersection"):
:param match_type: "intersection" or "all" or "any" (any => send all_vnfs if there is any intersection)
:return: List of matching VNFs
"""
- resources_lcase = [x.lower() for x in resources]
+ # Check if it is a default policy
+ default = True if resources == [] else False
+ resources_lcase = [x.lower() for x in resources] if not default else [x.lower() for x in vnf_list]
if match_type == "all": # don't bother with any comparisons
- return resources if set(resources_lcase) <= set(vnf_list) else None
- common_vnfs = set(vnf_list) & set(resources_lcase)
- common_resources = [x for x in resources if x.lower() in common_vnfs]
+ return default, resources if set(resources_lcase) <= set(vnf_list) else None
+ common_vnfs = set(vnf_list) & set(resources_lcase) if not default else set(vnf_list)
+ common_resources = [x for x in resources if x.lower() in common_vnfs] if not default else list(common_vnfs)
if match_type == "intersection": # specifically requested intersection
- return list(common_resources)
- return resources if common_vnfs else None # "any" match => all resources to be returned
+ return default, list(common_resources)
+ return default, resources if common_vnfs else None # "any" match => all resources to be returned
def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rtype=None):
@@ -102,16 +104,36 @@ def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rt
resource_policy_list = []
related_policies = []
for policy in resource_policy:
- pc = policy['content']
- demands = get_matching_vnfs(pc['resources'], vnf_list, match_type=match_type)
- resource = {pc['identity']: {'type': pc['policyType'], 'demands': demands}}
+ 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}}
if rtype:
- resource[pc['identity']]['properties'] = {'controller': pc[rtype]['controller'],
- 'request': json.loads(pc[rtype]['request'])}
+ resource[pc['properties']['identity']]['properties'] = {'controller': pc[rtype]['controller'],
+ 'request': json.loads(pc[rtype]['request'])}
if demands and len(demands) != 0:
- resource_policy_list.append(resource)
+ # The default policy shall not override the specific policy that already appended
+ if default:
+ for d in demands:
+ resource_repeated = True \
+ if {pc['properties']['identity']: {'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 }})
+ 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
+ if resource in resource_policy_list:
+ for pc in related_policies:
+ if pc[list(pc.keys()[0])]['properties']['resources'] == resource:
+ related_policies.remove(pc)
+ resource_policy_list.remove(resource)
related_policies.append(policy)
+ resource_policy_list.append(resource)
+
return resource_policy_list, related_policies
@@ -143,9 +165,9 @@ def gen_distance_to_location_policy(vnf_list, distance_to_location_policy):
"""Get policies governing distance-to-location for VNFs in order to populate the Conductor API call"""
cur_policies, related_policies = gen_policy_instance(vnf_list, distance_to_location_policy, rtype=None)
for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy
- properties = p_main['content']['distanceProperties']
+ properties = p_main[list(p_main.keys())[0]]['properties']['distanceProperties']
pcp_d = properties['distance']
- p_new[p_main['content']['identity']]['properties'] = {
+ p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = {
'distance': pcp_d['operator'] + " " + pcp_d['value'].lower() + " " + pcp_d['unit'].lower(),
'location': properties['locationInfo']
}
@@ -156,9 +178,9 @@ 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['content']['cloudAttributeProperty']
+ properties = p_main[list(p_main.keys())[0]]['properties']['cloudAttributeProperty']
attribute_mapping = policy_config_mapping['filtering_attributes'] # wanted attributes and mapping
- p_new[p_main['content']['identity']]['properties'] = {
+ 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())
}
return cur_policies # cur_policies gets updated in place...
@@ -168,8 +190,9 @@ def gen_zone_policy(vnf_list, zone_policy):
"""Get zone policies in order to populate the Conductor API call"""
cur_policies, related_policies = gen_policy_instance(vnf_list, zone_policy, match_type="all", rtype=None)
for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy
- pmz = p_main['content']['affinityProperty']
- p_new[p_main['content']['identity']]['properties'] = {'category': pmz['category'], 'qualifier': pmz['qualifier']}
+ pmz = p_main[list(p_main.keys())[0]]['properties']['affinityProperties']
+ p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \
+ {'category': pmz['category'], 'qualifier': pmz['qualifier']}
return cur_policies
@@ -177,8 +200,8 @@ def gen_capacity_policy(vnf_list, capacity_policy):
"""Get zone policies in order to populate the Conductor API call"""
cur_policies, related_policies = gen_policy_instance(vnf_list, capacity_policy, rtype=None)
for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy
- pmz = p_main['content']['capacityProperty']
- p_new[p_main['content']['identity']]['properties'] = \
+ pmz = p_main[list(p_main.keys())[0]]['properties']['capacityProperty']
+ p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \
{"controller": pmz['controller'], 'request': json.loads(pmz['request'])}
return cur_policies
@@ -187,7 +210,8 @@ def gen_hpa_policy(vnf_list, hpa_policy):
"""Get zone policies in order to populate the Conductor API call"""
cur_policies, related_policies = gen_policy_instance(vnf_list, hpa_policy, rtype=None)
for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy
- p_new[p_main['content']['identity']]['properties'] = {'evaluate': p_main['content']['flavorFeatures']}
+ p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \
+ {'evaluate': p_main[list(p_main.keys())[0]]['properties']['flavorFeatures']}
return cur_policies
@@ -213,10 +237,12 @@ def get_candidates_demands(demand):
def get_policy_properties(demand, policies):
"""Get policy_properties for cases where there is a match with the demand"""
for policy in policies:
- policy_demands = set([x.lower() for x in policy['content'].get('resources', [])])
- if demand['resourceModuleName'].lower() not in policy_demands:
+ policy_demands = set([x.lower() for x in policy[list(policy.keys())[0]]['properties']['resources']])
+ if policy_demands and demand['resourceModuleName'].lower() not in policy_demands:
continue # no match for this policy
- for policy_property in policy['content']['vnfProperties']:
+ elif policy_demands == set(): # Append resource name for default policy
+ policy[list(policy.keys())[0]]['properties'].update(resources=list(demand.get('resourceModuleName')))
+ for policy_property in policy[list(policy.keys())[0]]['properties']['vnfProperties']:
yield policy_property