Added optimization query processing module.
Issue-ID: OPTFRA-177
Change-Id: I4dd395b77bfe4bc392b90bc7087338f050fa622d
Signed-off-by: Ankitkumar Patel <ankit@research.att.com>
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'])
+ req_params_dict = tr.get_opt_query_data(request_json, gp['optimizationQueryPolicy'])
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]
limit=req_info['numSolutions'],
service_type=request_json['serviceInfo']['serviceName'],
service_id=request_json['serviceInfo']['serviceInstanceId'],
- provStatus="",
+ latitude=req_params_dict.get("customerLatitude", 0.0),
+ longitude=req_params_dict.get("customerLongitude", 0.0),
json=json)
json_payload = json.dumps(json.loads(rendered_req)) # need this because template's JSON is ugly!
return json_payload
import yaml
from osdf.utils.data_conversion import text_to_symbol
+from osdf.utils.programming_utils import dot_notation
policy_config_mapping = yaml.load(open('config/has_config.yaml')).get('policy_config_mapping')
+def get_opt_query_data(req_json, policies):
+ """
+ Fetch service and order specific details from the requestParameters field of a request.
+ :param req_json: a request file
+ :param policies: A set of policies
+ :return: A dictionary with service and order-specific attributes.
+ """
+ req_param_dict = {}
+ if 'requestParameters' in req_json["placementInfo"]:
+ req_params = req_json["placementInfo"]["requestParameters"]
+ for policy in policies:
+ for queryProp in policy['content']['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:
+ req_param_dict.update({queryProp['attribute']: attr_val})
+ return req_param_dict
+
+
def gen_optimization_policy(vnf_list, optimization_policy):
"""Generate optimization policy details to pass to Conductor
:param vnf_list: List of vnf's to used in placement request
"parameters": {\r
"service_name": "{{ service_name }}",\r
"service_id": "{{ service_id }}",\r
- "customer_lat": "{{ latitude }}",\r
- "customer_long": "{{ longitude }}"\r
+ "customer_lat": {{ latitude }},\r
+ "customer_long": {{ longitude }}\r
},\r
"locations": {\r
"customer_loc": {\r
--- /dev/null
+# -------------------------------------------------------------------------\r
+# Copyright (c) 2017-2018 AT&T Intellectual Property\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+#\r
+# -------------------------------------------------------------------------\r
+#\r
+import unittest\r
+import json\r
+from osdf.optimizers.placementopt.conductor.translation import get_opt_query_data\r
+\r
+\r
+class TestGetOptQueryData(unittest.TestCase):\r
+\r
+ def test_get_opt_query_data(self):\r
+ main_dir = ""\r
+ parameter_data_file = main_dir + "test/placement-tests/request.json"\r
+ policy_data_path = main_dir + "test/policy-local-files/"\r
+ \r
+ query_policy_data_file = ["QueryPolicy_vCPE.json"]\r
+ request_json = json.loads(open(parameter_data_file).read())\r
+ policies = [json.loads(open(policy_data_path + file).read()) for file in query_policy_data_file]\r
+ req_param_dict = get_opt_query_data(request_json, policies)\r
+ \r
+ self.assertTrue(req_param_dict is not None)\r
+\r
+\r
+if __name__ == "__main__":\r
+ unittest.main()\r
+\r