summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnkitkumar Patel <ankit@research.att.com>2018-03-28 23:39:50 -0400
committerAnkitkumar Patel <ankit@research.att.com>2018-03-28 23:43:05 -0400
commit616d7ba3006001bc53c668e5a34ae943855c2295 (patch)
treea8323f232ebf26960ed3a870dc87989b9b26110a
parentab7a87456538e561d60d209fe534c175ddd0269c (diff)
Added optimization query processing module.
Added optimization query processing module. Issue-ID: OPTFRA-177 Change-Id: I4dd395b77bfe4bc392b90bc7087338f050fa622d Signed-off-by: Ankitkumar Patel <ankit@research.att.com>
-rw-r--r--osdf/optimizers/placementopt/conductor/api_builder.py4
-rw-r--r--osdf/optimizers/placementopt/conductor/translation.py20
-rwxr-xr-xosdf/templates/conductor_interface.json4
-rw-r--r--test/test_get_opt_query_data.py40
4 files changed, 65 insertions, 3 deletions
diff --git a/osdf/optimizers/placementopt/conductor/api_builder.py b/osdf/optimizers/placementopt/conductor/api_builder.py
index b2a5bf7..209aa3b 100644
--- a/osdf/optimizers/placementopt/conductor/api_builder.py
+++ b/osdf/optimizers/placementopt/conductor/api_builder.py
@@ -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
diff --git a/osdf/optimizers/placementopt/conductor/translation.py b/osdf/optimizers/placementopt/conductor/translation.py
index e02ab19..5f44c83 100644
--- a/osdf/optimizers/placementopt/conductor/translation.py
+++ b/osdf/optimizers/placementopt/conductor/translation.py
@@ -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
diff --git a/osdf/templates/conductor_interface.json b/osdf/templates/conductor_interface.json
index ec01cc8..9ab2c82 100755
--- a/osdf/templates/conductor_interface.json
+++ b/osdf/templates/conductor_interface.json
@@ -8,8 +8,8 @@
"parameters": {
"service_name": "{{ service_name }}",
"service_id": "{{ service_id }}",
- "customer_lat": "{{ latitude }}",
- "customer_long": "{{ longitude }}"
+ "customer_lat": {{ latitude }},
+ "customer_long": {{ longitude }}
},
"locations": {
"customer_loc": {
diff --git a/test/test_get_opt_query_data.py b/test/test_get_opt_query_data.py
new file mode 100644
index 0000000..880f93f
--- /dev/null
+++ b/test/test_get_opt_query_data.py
@@ -0,0 +1,40 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2017-2018 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 unittest
+import json
+from osdf.optimizers.placementopt.conductor.translation import get_opt_query_data
+
+
+class TestGetOptQueryData(unittest.TestCase):
+
+ def test_get_opt_query_data(self):
+ main_dir = ""
+ parameter_data_file = main_dir + "test/placement-tests/request.json"
+ policy_data_path = main_dir + "test/policy-local-files/"
+
+ query_policy_data_file = ["QueryPolicy_vCPE.json"]
+ request_json = json.loads(open(parameter_data_file).read())
+ policies = [json.loads(open(policy_data_path + file).read()) for file in query_policy_data_file]
+ req_param_dict = get_opt_query_data(request_json, policies)
+
+ self.assertTrue(req_param_dict is not None)
+
+
+if __name__ == "__main__":
+ unittest.main()
+