summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnkitkumar Patel <ankit@research.att.com>2018-03-27 15:02:46 -0400
committerAnkitkumar Patel <ankit@research.att.com>2018-03-27 15:16:29 -0400
commitca43ea7c87abbcaa71617de50598449ff5ff007c (patch)
tree072f8ed4673d14a042646107e564d0143902caf1
parenta775ec8b904a0ea7ed863726ffe7f7d9b363d47a (diff)
Updated the conductor adaptor
Updated the conductor adaptor code. Issue-ID: OPTFRA-207 Change-Id: I41bd6f2e39bc5ca6d2d27539772175363590416f Signed-off-by: Ankitkumar Patel <ankit@research.att.com>
-rw-r--r--osdf/optimizers/placementopt/conductor/api_builder.py18
-rw-r--r--osdf/optimizers/placementopt/conductor/conductor.py4
-rw-r--r--osdf/optimizers/placementopt/conductor/remote_opt_processor.py4
-rw-r--r--osdf/optimizers/placementopt/conductor/translation.py26
-rwxr-xr-xosdf/templates/conductor_interface.json6
-rwxr-xr-xosdfapp.py2
-rw-r--r--test/policy-local-files/Capacity_vGMuxInfra.json2
-rw-r--r--test/policy-local-files/Capacity_vG_1.json2
-rw-r--r--test/policy-local-files/has_policies_r2/meta-valid-policies.txt14
-rw-r--r--test/policy-local-files/hpa_policy_vGMuxInfra_1.json4
-rw-r--r--test/policy-local-files/hpa_policy_vG_1.json4
-rw-r--r--test/test_process_placement_opt.py2
12 files changed, 50 insertions, 38 deletions
diff --git a/osdf/optimizers/placementopt/conductor/api_builder.py b/osdf/optimizers/placementopt/conductor/api_builder.py
index 55044d0..e359500 100644
--- a/osdf/optimizers/placementopt/conductor/api_builder.py
+++ b/osdf/optimizers/placementopt/conductor/api_builder.py
@@ -52,26 +52,17 @@ def conductor_api_builder(request_json, flat_policies: list, local_config, templ
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['placementOptimization'])
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'])
conductor_policies = [attribute_policy_list, distance_to_location_policy_list, inventory_policy_list,
- resource_instance_policy_list, resource_region_policy_list, zone_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)
- reservation_policies = [x for x in reservation_policy_list if len(x) > 0]
- reservation_groups = list_flatten(reservation_policies)
req_info = request_json['requestInfo']
request_type = req_info.get('requestType', None)
- service_type = request_json['serviceInfo']['serviceName']
- service_info = local_config.get('service_info', {}).get(service_type, {})
- order_info = {}
- if 'orderInfo' in request_json["placementInfo"]:
- order_info = json.loads(request_json["placementInfo"]["orderInfo"])
-
- subs_com_site_id = ""
- if 'subscriberInfo' in request_json['placementInfo']:
- subs_com_site_id = request_json['placementInfo']['subscriberInfo'].get('subscriberCommonSiteId', "")
rendered_req = templ.render(
requestType=request_type,
- chosenComplex=subs_com_site_id,
demand_list=demand_list,
policy_groups=policy_groups,
optimization_policies=optimization_policy_list,
@@ -81,7 +72,6 @@ def conductor_api_builder(request_json, flat_policies: list, local_config, templ
service_type=request_json['serviceInfo']['serviceName'],
service_id=request_json['serviceInfo']['serviceInstanceId'],
provStatus="",
- chosenRegion=order_info.get('requestParameters', {}).get('lcpCloudRegionId'),
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/conductor.py b/osdf/optimizers/placementopt/conductor/conductor.py
index 32a4728..dc67517 100644
--- a/osdf/optimizers/placementopt/conductor/conductor.py
+++ b/osdf/optimizers/placementopt/conductor/conductor.py
@@ -32,7 +32,7 @@ from osdf.utils.interfaces import RestClient
from osdf.operation.exceptions import BusinessException
-def request(req_object, osdf_config, grouped_policies, prov_status):
+def request(req_object, osdf_config, grouped_policies):
"""
Process a placement request from a Client (build Conductor API call, make the call, return result)
:param req_object: Request parameters from the client
@@ -53,7 +53,7 @@ def request(req_object, osdf_config, grouped_policies, prov_status):
ping_wait_time = config.get('conductorPingWaitTime', 60)
rc = RestClient(userid=uid, passwd=passwd, method="GET", log_func=debug_log.debug, headers=headers)
- conductor_req_json_str = conductor_api_builder(req_object, grouped_policies, local_config, prov_status)
+ conductor_req_json_str = conductor_api_builder(req_object, grouped_policies, local_config)
conductor_req_json = json.loads(conductor_req_json_str)
debug_log.debug("Sending first Conductor request for request_id {}".format(req_id))
diff --git a/osdf/optimizers/placementopt/conductor/remote_opt_processor.py b/osdf/optimizers/placementopt/conductor/remote_opt_processor.py
index 957547b..3e89205 100644
--- a/osdf/optimizers/placementopt/conductor/remote_opt_processor.py
+++ b/osdf/optimizers/placementopt/conductor/remote_opt_processor.py
@@ -26,7 +26,7 @@ from osdf.optimizers.licenseopt.simple_license_allocation import license_optim
from osdf.utils.interfaces import get_rest_client
-def process_placement_opt(request_json, policies, osdf_config, prov_status):
+def process_placement_opt(request_json, policies, osdf_config):
"""Perform the work for placement optimization (e.g. call SDC artifact and make conductor request)
NOTE: there is scope to make the requests to policy asynchronous to speed up overall performance
:param request_json: json content from original request
@@ -49,7 +49,7 @@ def process_placement_opt(request_json, policies, osdf_config, prov_status):
# Conductor only handles placement, only call Conductor if placementDemands exist
if request_json.get('licenseInfo', {}).get('licenseDemands'):
metrics_log.info(MH.requesting("placement/conductor", req_id))
- placement_response = conductor.request(request_json, osdf_config, policies, prov_status)
+ placement_response = conductor.request(request_json, osdf_config, policies)
if license_info: # Attach license solution if it exists
placement_response['solutionInfo']['licenseInfo'] = license_info
else: # License selection only scenario
diff --git a/osdf/optimizers/placementopt/conductor/translation.py b/osdf/optimizers/placementopt/conductor/translation.py
index 91706b7..e02ab19 100644
--- a/osdf/optimizers/placementopt/conductor/translation.py
+++ b/osdf/optimizers/placementopt/conductor/translation.py
@@ -50,14 +50,6 @@ def gen_optimization_policy(vnf_list, optimization_policy):
return optimization_policy_list
-def get_matching_vnf(resource, vnf_list):
-
- for vnf in vnf_list:
- if resource in vnf:
- return vnf
- return resource
-
-
def get_matching_vnfs(resources, vnf_list, match_type="intersection"):
"""Get a list of matching VNFs from the list of resources
:param resources:
@@ -157,6 +149,24 @@ def gen_zone_policy(vnf_list, zone_policy):
return cur_policies
+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'] = \
+ {"controller": pmz['controller'], 'request': json.loads(pmz['request'])}
+ return cur_policies
+
+
+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']}
+ return cur_policies
+
+
def get_augmented_policy_attributes(policy_property, demand):
"""Get policy attributes and augment them using policy_config_mapping and demand information"""
attributes = copy.copy(policy_property['attributes'])
diff --git a/osdf/templates/conductor_interface.json b/osdf/templates/conductor_interface.json
index 64f9c4f..ec01cc8 100755
--- a/osdf/templates/conductor_interface.json
+++ b/osdf/templates/conductor_interface.json
@@ -4,14 +4,12 @@
"timeout": {{ timeout }},
"limit": {{ limit }},
"template": {
- "homing_template_version": "2017-10-10",
+ "homing_template_version": "2018-02-01",
"parameters": {
"service_name": "{{ service_name }}",
"service_id": "{{ service_id }}",
"customer_lat": "{{ latitude }}",
- "customer_long": "{{ longitude }}",
- "REQUIRED_MEM": "{{ memory }}",
- "REQUIRED_DISK": "{{ storage }}"
+ "customer_long": "{{ longitude }}"
},
"locations": {
"customer_loc": {
diff --git a/osdfapp.py b/osdfapp.py
index 775bb07..047ef63 100755
--- a/osdfapp.py
+++ b/osdfapp.py
@@ -113,7 +113,7 @@ def do_placement_opt():
PlacementAPI(request_json).validate()
policies = get_policies(request_json, "placement")
audit_log.info(MH.new_worker_thread(req_id, "[for placement]"))
- t = Thread(target=process_placement_opt, args=(request_json, policies, osdf_config, ""))
+ t = Thread(target=process_placement_opt, args=(request_json, policies, osdf_config))
t.start()
audit_log.info(MH.accepted_valid_request(req_id, request))
return osdf.operation.responses.osdf_response_for_request_accept(
diff --git a/test/policy-local-files/Capacity_vGMuxInfra.json b/test/policy-local-files/Capacity_vGMuxInfra.json
index 06896c3..0225d40 100644
--- a/test/policy-local-files/Capacity_vGMuxInfra.json
+++ b/test/policy-local-files/Capacity_vGMuxInfra.json
@@ -14,7 +14,7 @@
"resources": ["vGMuxInfra"],
"capacityProperty": {
"controller": "multicloud",
- "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\", \"unit\": \"GB\"}}}"
+ "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": 16, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": 40, \"unit\": \"GB\"}}"
},
"policyType": "vim_fit",
"applicableResources": "any"
diff --git a/test/policy-local-files/Capacity_vG_1.json b/test/policy-local-files/Capacity_vG_1.json
index 851ea49..f311650 100644
--- a/test/policy-local-files/Capacity_vG_1.json
+++ b/test/policy-local-files/Capacity_vG_1.json
@@ -14,7 +14,7 @@
"resources": ["vG"],
"capacityProperty": {
"controller": "multicloud",
- "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\", \"unit\": \"GB\"}}}"
+ "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": 16, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": 40, \"unit\": \"GB\"}}"
},
"policyType": "vim_fit",
"applicableResources": "any"
diff --git a/test/policy-local-files/has_policies_r2/meta-valid-policies.txt b/test/policy-local-files/has_policies_r2/meta-valid-policies.txt
new file mode 100644
index 0000000..6a22945
--- /dev/null
+++ b/test/policy-local-files/has_policies_r2/meta-valid-policies.txt
@@ -0,0 +1,14 @@
+Affinity_vCPE_1.json
+Capacity_1.json
+Distance_vGMuxInfra_1.json
+Distance_vG_1.json
+Min_Guarantee_vGMuxInfra_1.json
+Placement_Optimization_1.json
+QueryPolicy_vCPE.json
+hpa_policy_vGMuxInfra_1.json
+hpa_policy_vG_1.json
+subscriber_policy.json
+vnfPolicy_vG.json
+vnfPolicy_vGMuxInfra.json
+
+
diff --git a/test/policy-local-files/hpa_policy_vGMuxInfra_1.json b/test/policy-local-files/hpa_policy_vGMuxInfra_1.json
index 7b68578..a3403f0 100644
--- a/test/policy-local-files/hpa_policy_vGMuxInfra_1.json
+++ b/test/policy-local-files/hpa_policy_vGMuxInfra_1.json
@@ -9,10 +9,10 @@
"riskLevel": "2",
"guard": "False",
"content": {
- "resources": "vGMuxInfra",
+ "resources": ["vGMuxInfra"],
"identity": "hpaPolicy_vGMuxInfra",
"policyScope": ["vCPE", "US", "INTERNATIONAL", "ip", "vGMuxInfra", "hpaPolicy"],
- "policyType": "hpaPolicy",
+ "policyType": "hpa",
"flavorFeatures": [
{
"flavorLabel": "flavor_label_vm_01",
diff --git a/test/policy-local-files/hpa_policy_vG_1.json b/test/policy-local-files/hpa_policy_vG_1.json
index 95f9247..9b832f6 100644
--- a/test/policy-local-files/hpa_policy_vG_1.json
+++ b/test/policy-local-files/hpa_policy_vG_1.json
@@ -9,10 +9,10 @@
"riskLevel": "2",
"guard": "False",
"content": {
- "resources": "vG",
+ "resources": ["vG"],
"identity": "hpaPolicy_vG",
"policyScope": ["vCPE", "US", "INTERNATIONAL", "ip", "vG", "hpaPolicy"],
- "policyType": "hpaPolicy",
+ "policyType": "hpa",
"flavorFeatures": [
{
"flavorLabel": "flavor_label_vm_01",
diff --git a/test/test_process_placement_opt.py b/test/test_process_placement_opt.py
index 01be17d..e5dc65e 100644
--- a/test/test_process_placement_opt.py
+++ b/test/test_process_placement_opt.py
@@ -59,7 +59,7 @@ class TestProcessPlacementOpt(unittest.TestCase):
request_json = json_from_file(parameter_data_file)
policies = [json_from_file(policy_data_path + '/' + name) for name in valid_policies_files]
local_config = yaml_from_file(local_config_file)
- templ_string = process_placement_opt(request_json, policies, local_config, [])
+ templ_string = process_placement_opt(request_json, policies, local_config)
if __name__ == "__main__":