aboutsummaryrefslogtreecommitdiffstats
path: root/apps/placement/optimizers/conductor/api_builder.py
diff options
context:
space:
mode:
authorkrishnaa96 <krishna.moorthy6@wipro.com>2020-03-10 10:55:13 +0530
committerkrishnaa96 <krishna.moorthy6@wipro.com>2020-03-20 20:39:59 +0530
commitf30da9513ae0501f453ee93729b381270fad0a2b (patch)
treea3ab005e2f16bfe8709bdcfbab6d28b5c6760a19 /apps/placement/optimizers/conductor/api_builder.py
parent420f4b3a4ca25d5de5c9318b2ca89e1ef126b278 (diff)
Add generic conductor interface
Issue-ID: OPTFRA-715 Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com> Change-Id: I84218ab65e645a90d2ff1c365bdde1e06ab27d2e
Diffstat (limited to 'apps/placement/optimizers/conductor/api_builder.py')
-rw-r--r--apps/placement/optimizers/conductor/api_builder.py107
1 files changed, 0 insertions, 107 deletions
diff --git a/apps/placement/optimizers/conductor/api_builder.py b/apps/placement/optimizers/conductor/api_builder.py
deleted file mode 100644
index 398db8d..0000000
--- a/apps/placement/optimizers/conductor/api_builder.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# -------------------------------------------------------------------------
-# Copyright (c) 2015-2017 AT&T Intellectual Property
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# -------------------------------------------------------------------------
-#
-
-import json
-
-from jinja2 import Template
-
-import apps.placement.optimizers.conductor.translation as tr
-from osdf.adapters.policy.utils import group_policies_gen
-from osdf.utils.programming_utils import list_flatten
-
-
-def _build_parameters(group_policies, request_json):
- """
- Function prepares parameters section for has request
- :param group_policies: filtered policies
- :param request_json: parameter data received from a client
- :return:
- """
- 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", "")})
- params.update({"customer_lat": initial_params.pop("customerLatitude", 0.0)})
- params.update({"customer_long": initial_params.pop("customerLongitude", 0.0)})
- params.update({"service_name": request_json['serviceInfo']['serviceName']})
- params.update({"service_id": request_json['serviceInfo']['serviceInstanceId']})
-
- for key, val in initial_params.items():
- if val and val != "":
- params.update({key: val})
-
- return params
-
-
-def conductor_api_builder(request_json, flat_policies: list, local_config,
- template="apps/placement/templates/conductor_interface.json"):
- """Build an OSDF southbound API call for HAS-Conductor/Placement optimization
- :param request_json: parameter data received from a client
- :param flat_policies: policy data received from the policy platform (flat policies)
- :param template: template to generate southbound API call to conductor
- :param local_config: local configuration file with pointers for the service specific information
- :param prov_status: provStatus retrieved from Subscriber policy
- :return: json to be sent to Conductor/placement optimization
- """
- 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['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'])
- 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['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,
- reservation_policy_list, capacity_policy_list, hpa_policy_list]
- filtered_policies = [x for x in conductor_policies if len(x) > 0]
- policy_groups = list_flatten(filtered_policies)
- req_info = request_json['requestInfo']
- request_type = req_info.get('requestType', None)
- rendered_req = templ.render(
- requestType=request_type,
- demand_list=demand_list,
- policy_groups=policy_groups,
- optimization_policies=optimization_policy_list,
- name=req_info['requestId'],
- timeout=req_info['timeout'],
- limit=req_info['numSolutions'],
- request_params=req_params_dict,
- json=json)
- json_payload = json.dumps(json.loads(rendered_req)) # need this because template's JSON is ugly!
- return json_payload