Added optimization query processing module. 71/39971/1
authorAnkitkumar Patel <ankit@research.att.com>
Thu, 29 Mar 2018 03:39:50 +0000 (23:39 -0400)
committerAnkitkumar Patel <ankit@research.att.com>
Thu, 29 Mar 2018 03:43:05 +0000 (23:43 -0400)
Added optimization query processing module.

Issue-ID: OPTFRA-177
Change-Id: I4dd395b77bfe4bc392b90bc7087338f050fa622d
Signed-off-by: Ankitkumar Patel <ankit@research.att.com>
osdf/optimizers/placementopt/conductor/api_builder.py
osdf/optimizers/placementopt/conductor/translation.py
osdf/templates/conductor_interface.json
test/test_get_opt_query_data.py [new file with mode: 0644]

index b2a5bf7..209aa3b 100644 (file)
@@ -55,6 +55,7 @@ def conductor_api_builder(request_json, flat_policies: list, local_config,
     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]
@@ -72,7 +73,8 @@ def conductor_api_builder(request_json, flat_policies: list, local_config,
         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
index e02ab19..5f44c83 100644 (file)
@@ -20,10 +20,30 @@ import json
 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
index ec01cc8..9ab2c82 100755 (executable)
@@ -8,8 +8,8 @@
     "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
diff --git a/test/test_get_opt_query_data.py b/test/test_get_opt_query_data.py
new file mode 100644 (file)
index 0000000..880f93f
--- /dev/null
@@ -0,0 +1,40 @@
+# -------------------------------------------------------------------------\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