diff options
87 files changed, 4533 insertions, 645 deletions
diff --git a/.coveragerc b/.coveragerc index a4ec20c..1fa0d3b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,7 +2,7 @@ [run] branch = True cover_pylib = False -include = osdf/**/*.py, apps/**/*.py +include = osdf/**/*.py, apps/**/*.py, runtime/*.py, runtime/**/*.py [report] # Regexes for lines to exclude from consideration diff --git a/apps/placement/optimizers/conductor/api_builder.py b/apps/placement/optimizers/conductor/api_builder.py index 7b61580..cefde51 100644 --- a/apps/placement/optimizers/conductor/api_builder.py +++ b/apps/placement/optimizers/conductor/api_builder.py @@ -32,7 +32,7 @@ def _build_parameters(group_policies, request_json): :param request_json: parameter data received from a client :return: """ - initial_params = tr.get_opt_query_data(request_json, group_policies['request_param_query']) + 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", "")}) @@ -61,22 +61,34 @@ def conductor_api_builder(request_json, flat_policies: list, local_config, 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['vnfPolicy']) + demand_list = tr.gen_demands(request_json, gp['onap.policies.optimization.VnfPolicy']) + # What's the attribute policy? Need an example attribute_policy_list = tr.gen_attribute_policy(demand_vnf_name_list, gp['attribute']) distance_to_location_policy_list = tr.gen_distance_to_location_policy( - demand_vnf_name_list, gp['distance_to_location']) + demand_vnf_name_list, gp['onap.policies.optimization.DistancePolicy']) + # What's the inventory group policy? A policy to choose the inventory group from existing list? inventory_policy_list = tr.gen_inventory_group_policy(demand_vnf_name_list, gp['inventory_group']) + # What's the instance fit policy, a policy to choose the instance from existing list? resource_instance_policy_list = tr.gen_resource_instance_policy( demand_vnf_name_list, gp['instance_fit']) + # Need an example for the resource_region_policy resource_region_policy_list = tr.gen_resource_region_policy(demand_vnf_name_list, gp['region_fit']) - 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['placement_optimization']) + 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']) + # Need an example for the instance reservation policy 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']) + 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']) + #distance_to_location_policy_list = tr.gen_distance_to_location_policy( + # demand_vnf_name_list, gp['distance_to_location']) + # demand_list = tr.gen_demands(request_json, gp['vnfPolicy']) + #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['placement_optimization']) + #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 = _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, diff --git a/apps/placement/optimizers/conductor/translation.py b/apps/placement/optimizers/conductor/translation.py index 46bee1d..45deb2d 100644 --- a/apps/placement/optimizers/conductor/translation.py +++ b/apps/placement/optimizers/conductor/translation.py @@ -37,7 +37,7 @@ def get_opt_query_data(req_json, policies): if 'requestParameters' in req_json["placementInfo"]: req_params = req_json["placementInfo"]["requestParameters"] for policy in policies: - for queryProp in policy['content']['queryProperties']: + for queryProp in policy[list(policy.keys())[0]]['properties']['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: @@ -53,13 +53,13 @@ def gen_optimization_policy(vnf_list, optimization_policy): """ optimization_policy_list = [] for policy in optimization_policy: - content = policy['content'] + content = policy[list(policy.keys())[0]]['properties'] parameter_list = [] parameters = ["cloud_version", "hpa_score"] for attr in content['objectiveParameter']['parameterAttributes']: parameter = attr['parameter'] if attr['parameter'] in parameters else attr['parameter']+"_between" - vnfs = get_matching_vnfs(attr['resources'], vnf_list) + default, vnfs = get_matching_vnfs(attr['resources'], vnf_list) for vnf in vnfs: value = [vnf] if attr['parameter'] in parameters else [attr['customerLocationInfo'], vnf] parameter_list.append({ @@ -79,14 +79,16 @@ def get_matching_vnfs(resources, vnf_list, match_type="intersection"): :param match_type: "intersection" or "all" or "any" (any => send all_vnfs if there is any intersection) :return: List of matching VNFs """ - resources_lcase = [x.lower() for x in resources] + # Check if it is a default policy + default = True if resources == [] else False + resources_lcase = [x.lower() for x in resources] if not default else [x.lower() for x in vnf_list] if match_type == "all": # don't bother with any comparisons - return resources if set(resources_lcase) <= set(vnf_list) else None - common_vnfs = set(vnf_list) & set(resources_lcase) - common_resources = [x for x in resources if x.lower() in common_vnfs] + return default, resources if set(resources_lcase) <= set(vnf_list) else None + common_vnfs = set(vnf_list) & set(resources_lcase) if not default else set(vnf_list) + common_resources = [x for x in resources if x.lower() in common_vnfs] if not default else list(common_vnfs) if match_type == "intersection": # specifically requested intersection - return list(common_resources) - return resources if common_vnfs else None # "any" match => all resources to be returned + return default, list(common_resources) + return default, resources if common_vnfs else None # "any" match => all resources to be returned def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rtype=None): @@ -102,16 +104,36 @@ def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rt resource_policy_list = [] related_policies = [] for policy in resource_policy: - pc = policy['content'] - demands = get_matching_vnfs(pc['resources'], vnf_list, match_type=match_type) - resource = {pc['identity']: {'type': pc['policyType'], 'demands': demands}} + pc = policy[list(policy.keys())[0]] + default, demands = get_matching_vnfs(pc['properties']['resources'], vnf_list, match_type=match_type) + resource = {pc['properties']['identity']: {'type': pc['type'], 'demands': demands}} if rtype: - resource[pc['identity']]['properties'] = {'controller': pc[rtype]['controller'], - 'request': json.loads(pc[rtype]['request'])} + resource[pc['properties']['identity']]['properties'] = {'controller': pc[rtype]['controller'], + 'request': json.loads(pc[rtype]['request'])} if demands and len(demands) != 0: - resource_policy_list.append(resource) + # The default policy shall not override the specific policy that already appended + if default: + for d in demands: + resource_repeated = True \ + if {pc['properties']['identity']: {'type': pc['type'], 'demands': d}} \ + in resource_policy_list else False + if resource_repeated: + continue + else: + resource_policy_list.append( + {pc['properties']['identity']: {'type': pc['type'], 'demands': d }}) + policy[list(policy.keys())[0]]['properties']['resources'] = d + related_policies.append(policy) + # Need to override the default policies, here delete the outdated policy stored in the db + if resource in resource_policy_list: + for pc in related_policies: + if pc[list(pc.keys()[0])]['properties']['resources'] == resource: + related_policies.remove(pc) + resource_policy_list.remove(resource) related_policies.append(policy) + resource_policy_list.append(resource) + return resource_policy_list, related_policies @@ -143,9 +165,9 @@ def gen_distance_to_location_policy(vnf_list, distance_to_location_policy): """Get policies governing distance-to-location for VNFs in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, distance_to_location_policy, rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - properties = p_main['content']['distanceProperties'] + properties = p_main[list(p_main.keys())[0]]['properties']['distanceProperties'] pcp_d = properties['distance'] - p_new[p_main['content']['identity']]['properties'] = { + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = { 'distance': pcp_d['operator'] + " " + pcp_d['value'].lower() + " " + pcp_d['unit'].lower(), 'location': properties['locationInfo'] } @@ -156,9 +178,9 @@ def gen_attribute_policy(vnf_list, attribute_policy): """Get policies governing attributes of VNFs in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, attribute_policy, rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - properties = p_main['content']['cloudAttributeProperty'] + properties = p_main[list(p_main.keys())[0]]['properties']['cloudAttributeProperty'] attribute_mapping = policy_config_mapping['filtering_attributes'] # wanted attributes and mapping - p_new[p_main['content']['identity']]['properties'] = { + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = { 'evaluate': dict((k, properties.get(attribute_mapping.get(k))) for k in attribute_mapping.keys()) } return cur_policies # cur_policies gets updated in place... @@ -168,8 +190,9 @@ def gen_zone_policy(vnf_list, zone_policy): """Get zone policies in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, zone_policy, match_type="all", rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - pmz = p_main['content']['affinityProperty'] - p_new[p_main['content']['identity']]['properties'] = {'category': pmz['category'], 'qualifier': pmz['qualifier']} + pmz = p_main[list(p_main.keys())[0]]['properties']['affinityProperties'] + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \ + {'category': pmz['category'], 'qualifier': pmz['qualifier']} return cur_policies @@ -177,8 +200,8 @@ 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'] = \ + pmz = p_main[list(p_main.keys())[0]]['properties']['capacityProperty'] + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \ {"controller": pmz['controller'], 'request': json.loads(pmz['request'])} return cur_policies @@ -187,7 +210,8 @@ 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']} + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \ + {'evaluate': p_main[list(p_main.keys())[0]]['properties']['flavorFeatures']} return cur_policies @@ -213,10 +237,12 @@ def get_candidates_demands(demand): def get_policy_properties(demand, policies): """Get policy_properties for cases where there is a match with the demand""" for policy in policies: - policy_demands = set([x.lower() for x in policy['content'].get('resources', [])]) - if demand['resourceModuleName'].lower() not in policy_demands: + policy_demands = set([x.lower() for x in policy[list(policy.keys())[0]]['properties']['resources']]) + if policy_demands and demand['resourceModuleName'].lower() not in policy_demands: continue # no match for this policy - for policy_property in policy['content']['vnfProperties']: + elif policy_demands == set(): # Append resource name for default policy + policy[list(policy.keys())[0]]['properties'].update(resources=list(demand.get('resourceModuleName'))) + for policy_property in policy[list(policy.keys())[0]]['properties']['vnfProperties']: yield policy_property diff --git a/apps/route/optimizers/route_opt.mzn b/apps/route/optimizers/route_opt.mzn new file mode 100644 index 0000000..7aa73cb --- /dev/null +++ b/apps/route/optimizers/route_opt.mzn @@ -0,0 +1,53 @@ + +% Number of nodes +int: N; + % Start node +0..N-1: Start; + % End node +0..N-1: End; + % Number of edges (directed arcs) +int: M; + % The actual edges +set of int: Edges = 1..M; + % Edge lengths +array[Edges] of int: L; + % Edge start node +array[Edges] of 0..N-1: Edge_Start; +array[Edges] of 0..N-1: Edge_End; + + % Variable indicating if edge is used +array[Edges] of var 0..1: x; + +constraint + forall( i in 0..N-1 ) ( + if i = Start then + % outgoing flow + sum(e in Edges where Edge_Start[e] = i)(x[e]) - + % incoming flow + sum(e in Edges where Edge_End[e] = i)(x[e]) + = 1 + elseif i = End then + sum(e in Edges where Edge_Start[e] = i)(x[e]) - + sum(e in Edges where Edge_End[e] = i)(x[e]) + = -1 + else + sum(e in Edges where Edge_Start[e] = i)(x[e]) - + sum(e in Edges where Edge_End[e] = i)(x[e]) + = 0 + endif + ); + + +solve minimize sum(e in Edges)( L[e] * x[e] ); +%solve satisfy; + +output ["Length: ", show(sum(e in Edges)(L[e] * x[e])), "\n"] ++ + ["Start : ", show(Start), "\n"] ++ + ["End : ", show(End), "\n\n"] ++ + ["Edges in shortest path:\n"] ++ + [ if fix(x[e]) = 1 + then show(Edge_Start[e]) ++ " -> " ++ show(Edge_End[e]) ++ "\n" + else "" + endif | e in Edges + ]; + diff --git a/apps/route/optimizers/simple_route_opt.py b/apps/route/optimizers/simple_route_opt.py index b00180d..27c1141 100644 --- a/apps/route/optimizers/simple_route_opt.py +++ b/apps/route/optimizers/simple_route_opt.py @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------- -# Copyright (c) 2018 Huawei Intellectual Property +# Copyright (c) 2020 Huawei Intellectual Property # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,12 @@ import requests from requests.auth import HTTPBasicAuth from osdf.utils.mdc_utils import mdc_from_json +from osdf.logging.osdf_logging import MH, audit_log, error_log, debug_log +import pymzn +from sklearn import preprocessing +import os +BASE_DIR = os.path.dirname(__file__) class RouteOpt: @@ -31,6 +36,8 @@ class RouteOpt: # DNS server and standard port of AAI.. # TODO: read the port from the configuration and add to DNS aai_host = "https://aai.api.simpledemo.onap.org:8443" + audit_log.info("base directory") + audit_log.info(BASE_DIR) aai_headers = { "X-TransactionId": "9999", "X-FromAppId": "OOF", @@ -50,89 +57,184 @@ class RouteOpt: return True return False + def getLinksName(self, routes,initial_start_edge,initial_end_edge, mappingTable): + routes=list(routes) + arr=routes[0]['x'] + listOfLinks=[] + for i in range(0, len(routes[0]['x'])): + if arr[i] == 1 : + # listOfLinks.append(self.fetchLogicalLinks(initial_start_edge[i], initial_end_edge[i], mappingTable)) + listOfLinks.append(mappingTable[initial_start_edge[i] + ":" + initial_end_edge[i]]) + + return listOfLinks + + # def search(self, ip1, ip2, dic): + # if ip1 == "" or ip2 == "": + # return "" + # else: + # string = ip1 + ":" + ip2 + # return dic[string] + # + # def fetchLogicalLinks(self, initial_start_edge, initial_end_edge, mappingTable): + # link_name=self.search(initial_start_edge, initial_end_edge, mappingTable) + # return link_name + + + # def fetchLogicalLinks(self, initial_start_edge, initial_end_edge, mappingTable): + # return mappingTable[initial_start_edge + ":" + initial_end_edge] + + def solve(self, mzn_model, dzn_data): + return pymzn.minizinc(mzn=mzn_model, data=dzn_data) + + def getLinks(self, mzn_model, dzn_data, initial_start_edge,initial_end_edge, mappingTable): + routes = self.solve(mzn_model, dzn_data) + audit_log.info("mocked minizinc solution====>") + audit_log.info(routes) + + converted_links=self.getLinksName(routes, initial_start_edge,initial_end_edge, mappingTable) + audit_log.info("converted links===>") + audit_log.info(converted_links) + return converted_links + + def addition(self, data): + relationship = data["relationship-list"]["relationship"] + res = "" + for index, eachItem in enumerate(relationship): + if index == len(relationship) - 1: + res += eachItem["accessNodeId"] + else: + res += eachItem["accessNodeId"] + ":" + + return data["link-name"], res + + def createMapTable(self, logical_links): + result = map(self.addition, logical_links) + + parseTemplate = {} + + for eachItem in result: + parseTemplate[eachItem[1]] = eachItem[0] + audit_log.info("mapping table") + audit_log.info(parseTemplate) + return parseTemplate + + def build_dzn_data(self, src_access_node_id, dst_access_node_id): + Edge_Start = [] + Edge_End = [] + logical_links = self.get_logical_links() + audit_log.info("mocked response of AAI received (logical links) successful===>") + audit_log.info(logical_links) + # prepare map table + mappingTable = self.createMapTable(logical_links) + # take the logical link where both the p-interface in same onap + if logical_links is not None: + for logical_link in logical_links: + if not self.isCrossONAPLink(logical_link): + # link is in local ONAP + relationship = logical_link["relationship-list"]["relationship"] + + relationshipStartNode = relationship[0] + relationshipStartNodeID = relationshipStartNode["related-link"].split("/")[-1] + start_accessNodeId = relationshipStartNodeID.split("-")[-3] + Edge_Start.append(start_accessNodeId) + + relationshipEndtNode = relationship[1] + relationshipEndNodeID = relationshipEndtNode["related-link"].split("/")[-1] + end_accessNodeId = relationshipEndNodeID.split("-")[-3] + Edge_End.append(end_accessNodeId) + + audit_log.info("edge start and end array of i/p address are===>") + audit_log.info(Edge_Start) + audit_log.info(Edge_End) + # labeling ip to number for mapping + le = preprocessing.LabelEncoder() + le.fit(Edge_Start + Edge_End) + # print(le.classes_) + dzn_start_edge = le.transform(Edge_Start) + + final_dzn_start_arr = [] + for i in range(0, len(dzn_start_edge)): + final_dzn_start_arr.append(dzn_start_edge[i]) + + final_dzn_end_arr = [] + dzn_end_edge = le.transform(Edge_End) + for j in range(0, len(dzn_end_edge)): + final_dzn_end_arr.append(dzn_end_edge[j]) + + audit_log.info("start and end array that passed in dzn_data===>") + audit_log.info(final_dzn_start_arr) + audit_log.info(final_dzn_end_arr) + + link_cost = [] + for k in range(0, len(final_dzn_start_arr)): + link_cost.append(1) + + audit_log.info("src_access_node_id") + audit_log.info(src_access_node_id) + source= le.transform([src_access_node_id]) + audit_log.info("vallue of source===>") + audit_log.info(source) + if source in final_dzn_start_arr : + start = source[0] + audit_log.info("source node") + audit_log.info(start) + + audit_log.info("dst_access_node_id") + audit_log.info(dst_access_node_id) + destination= le.transform([dst_access_node_id]) + if destination in final_dzn_end_arr : + end = destination[0] + audit_log.info("destination node") + audit_log.info(end) + # data to be prepared in the below format: + dzn_data = { + 'N': self.total_node(final_dzn_start_arr + final_dzn_end_arr), + 'M': len(final_dzn_start_arr), + 'Edge_Start': final_dzn_start_arr, + 'Edge_End': final_dzn_end_arr, + 'L': link_cost, + 'Start': start, + 'End': end, + } + # can not do reverse mapping outside of this scope, so doing here + audit_log.info("reverse mapping after prepared dzn_data") + initial_start_edge=le.inverse_transform(final_dzn_start_arr) + initial_end_edge=le.inverse_transform(final_dzn_end_arr) + audit_log.info(initial_start_edge) + audit_log.info(initial_end_edge) + return dzn_data, initial_start_edge,initial_end_edge, mappingTable + + def total_node(self, node): + nodeSet = set() + for i in range(0, len(node)): + nodeSet.add(node[i]) + total_node = len(nodeSet) + return total_node + def getRoute(self, request): """ - This method checks + This method checks :param logical_link: :return: """ - mdc_from_json(request) - - src_access_node_id = request["srcPort"]["src-access-node-id"] - dst_access_node_id = request["dstPort"]["dst-access-node-id"] - - - ingress_p_interface = None - egress_p_interface = None - - # for the case of request_json for same domain, return the same node with destination update - if src_access_node_id == dst_access_node_id: - data = '{'\ - '"vpns":['\ - '{'\ - '"access-topology-id": "' + request["srcPort"]["src-access-topology-id"] + '",'\ - '"access-client-id": "' + request["srcPort"]["src-access-client-id"] + '",'\ - '"access-provider-id": "' + request["srcPort"]["src-access-provider-id"]+ '",'\ - '"access-node-id": "' + request["srcPort"]["src-access-node-id"]+ '",'\ - '"src-access-ltp-id": "' + request["srcPort"]["src-access-ltp-id"]+ '",'\ - '"dst-access-ltp-id": "' + request["dstPort"]["dst-access-ltp-id"] +'"'\ - '}'\ - ']'\ - '}' - return data - else: - logical_links = self.get_logical_links() - - # take the logical link where both the p-interface in same onap - if logical_links != None: - for logical_link in logical_links.get("logical-link"): - if not self.isCrossONAPLink(logical_link): - # link is in local ONAP - for relationship in logical_link["relationship-list"]["relationship"]: - if relationship["related-to"] == "p-interface": - if src_access_node_id in relationship["related-link"]: - i_interface = relationship["related-link"].split("/")[-1] - ingress_p_interface = i_interface.split("-")[-1] - if dst_access_node_id in relationship["related-link"]: - e_interface = relationship["related-link"].split("/")[-1] - egress_p_interface = e_interface.split("-")[-1] - data = '{'\ - '"vpns":['\ - '{'\ - '"access-topology-id": "' + request["srcPort"]["src-access-topology-id"] + '",'\ - '"access-client-id": "' + request["srcPort"]["src-access-client-id"] + '",'\ - '"access-provider-id": "' + request["srcPort"]["src-access-provider-id"]+ '",'\ - '"access-node-id": "' + request["srcPort"]["src-access-node-id"]+ '",'\ - '"src-access-ltp-id": "' + request["srcPort"]["src-access-ltp-id"]+ '",'\ - '"dst-access-ltp-id": "' + ingress_p_interface +'"'\ - '},'\ - '{' \ - '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"] + '",' \ - '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"]+ '",' \ - '"access-provider-id": "' + request["dstPort"]["dst-access-provider-id"]+ '",' \ - '"access-node-id": "' + request["dstPort"]["dst-access-node-id"]+ '",' \ - '"src-access-ltp-id": "' + egress_p_interface + '",' \ - '"dst-access-ltp-id": "' + request["dstPort"]["dst-access-ltp-id"] + '"' \ - '}'\ - ']'\ - '}' - return data - - - def get_pinterface(self, url): - """ - This method returns details for p interface - :return: details of p interface - """ - aai_req_url = self.aai_host + url - response = requests.get(aai_req_url, - headers=self.aai_headers, - auth=HTTPBasicAuth("AAI", "AAI"), - verify=False) + routeInfo = request["routeInfo"]["routeRequests"] + routeRequest = routeInfo[0] + src_access_node_id = routeRequest["srcPort"]["accessNodeId"] + dst_access_node_id = routeRequest["dstPort"]["accessNodeId"] - if response.status_code == 200: - return response.json() + dzn_data, initial_start_edge, initial_end_edge, mappingTable = self.build_dzn_data(src_access_node_id, dst_access_node_id ) + #mzn_model = "/home/root1/Videos/projects/osdf/test/functest/simulators/osdf/optimizers/routeopt/route_opt.mzn" + mzn_model = os.path.join(BASE_DIR, 'route_opt.mzn') + routeSolutions = self.getLinks(mzn_model, dzn_data, initial_start_edge,initial_end_edge, mappingTable) + + return { + "requestId": request["requestInfo"]["requestId"], + "transactionId": request["requestInfo"]["transactionId"], + "statusMessage": " ", + "requestStatus": "accepted", + "solutions": routeSolutions + } def get_logical_links(self): """ @@ -142,12 +244,6 @@ class RouteOpt: """ logical_link_url = "/aai/v13/network/logical-links?operational-status=up" aai_req_url = self.aai_host + logical_link_url - - response = requests.get(aai_req_url, - headers=self.aai_headers, - auth=HTTPBasicAuth("AAI", "AAI"), - verify=False) - - logical_links = None + response = requests.get(aai_req_url,headers=self.aai_headers,auth=HTTPBasicAuth("AAI", "AAI"),verify=False) if response.status_code == 200: return response.json()
\ No newline at end of file diff --git a/config/common_config.yaml b/config/common_config.yaml index 7eced05..f29e8c0 100644 --- a/config/common_config.yaml +++ b/config/common_config.yaml @@ -50,31 +50,35 @@ references: service_name: source: request value: serviceInfo.serviceName + resource: + source: request + value: placementInfo.placementDemands.resourceModuleName subscriber_role: - source: SubscriberPolicy - value: content.properties.subscriberRole + source: onap.policies.optimization.SubscriberPolicy + value: properties.properties.subscriberRole policy_info: prioritization_attributes: policy_type: - - content.policyType + - type resources: - - content.resources - - content.objectiveParameter.parameterAttributes.resources + - properties.resources + - properties.objectiveParameter.parameterAttributes.resources service_name: - - content.serviceName + - properties.services placement: policy_fetch: by_scope policy_scope: - default_scope: OSDF_DUBLIN - vcpe_scope: OSDF_DUBLIN - vfw_scope: OSDF_DUBLIN - td_scope: OSDF_DUBLIN - secondary_scopes: - - - - get_param: service_name + - + scope: + - OSDF_FRANKFURT + geography: - US + service: + - get_param: service_name + resources: + - get_param: resource # - # - get_param: service_name # - get_param: subscriber_role diff --git a/config/opteng_config.yaml b/config/opteng_config.yaml new file mode 100755 index 0000000..d6be7ed --- /dev/null +++ b/config/opteng_config.yaml @@ -0,0 +1,25 @@ +# Policy Platform -- requires Authorization +policyPlatformUrl: https://policy-xacml-pdp:6969/policy/pdpx/decision/v1 # Policy Dev platform URL + +# AAF Authentication config +is_aaf_enabled: False +aaf_cache_expiry_mins: 5 +aaf_url: https://aaftest.simpledemo.onap.org:8095 +aaf_user_roles: + - '/optmodel:org.onap.oof.access|*|read ALL' + - '/optengine:org.onap.oof.access|*|read ALL' + +# Secret Management Service from AAF +aaf_sms_url: http://localhost:10443 +aaf_sms_timeout: 30 +secret_domain: osdf +aaf_ca_certs: ssl_certs/aaf_root_ca.cer + +osdfDatabaseHost: localhost +osdfDatabaseSchema: osdf +osdfDatabaseUsername: osdf +osdfDatabasePassword: osdf +osdfDatabasePort: 3306 + +#key +appkey: os35@rrtky400fdntc#001t5
\ No newline at end of file diff --git a/config/preload_secrets.yaml b/config/preload_secrets.yaml index 0bb2395..b95f1c1 100755 --- a/config/preload_secrets.yaml +++ b/config/preload_secrets.yaml @@ -49,3 +49,7 @@ secrets: values: UserName: pci_test Password: fbf4dcb7f7cda8fdfb742838b0c90ae5bea249801f3f725fdc98941a6e4c347c + - name: osdfOptEngine + values: + UserName: opt_test + Password: 02946408ce6353d45540cd01d912686f19f48c3d8a955d5effdc14c6a43477e5 diff --git a/docker/opteng/Dockerfile b/docker/opteng/Dockerfile new file mode 100644 index 0000000..9dca3e7 --- /dev/null +++ b/docker/opteng/Dockerfile @@ -0,0 +1,74 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +FROM python:3.8-alpine + +ARG MVN_ARTIFACT_VERSION +ARG REPO +ARG HTTP_PROXY=${HTTP_PROXY} +ARG HTTPS_PROXY=${HTTPS_PROXY} + +ENV http_proxy $HTTP_PROXY +ENV https_proxy $HTTPS_PROXY + +ENV OSDF_PORT "8699" +EXPOSE ${OSDF_PORT} + +ENV MZN 2.4.2 +ENV MZN_BASENAME MiniZincIDE-${MZN}-bundle-linux +ENV MZN_GH_BASE https://github.com/MiniZinc/MiniZincIDE +ENV MZN_DL_URL ${MZN_GH_BASE}/releases/download/${MZN}/${MZN_BASENAME}-x86_64.tgz + +RUN apk update && apk upgrade \ + && apk --no-cache --update add --virtual build-deps openssl wget \ + && apk --no-cache --update add less ca-certificates bash libxslt-dev unzip \ + freetype freetype-dev libstdc++ build-base libc6-compat \ + && ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2 + +# Minizinc +RUN wget -q $MZN_DL_URL -O mz.tgz \ + && tar xzf mz.tgz \ + && mv $MZN_BASENAME /mz-dist \ + && rm mz.tgz \ + && echo PATH=/mz-dist/bin:$PATH >> ~/.bashrc + +ENV SHELL /bin/bash +ENV PATH /mz-dist:$PATH + +RUN addgroup -S onap && adduser -S -G onap onap + +# OSDF +WORKDIR /opt/osdf +#RUN wget -O /opt/osdf.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=releases&g=org.onap.optf.osdf&a=optf-osdf&e=zip&v=1.3.4" && \ +# unzip -q -o -B /opt/osdf.zip -d /opt/ && \ +# rm -f /opt/osdf.zip + +COPY onap-osdf-tm/optf-osdf-${MVN_ARTIFACT_VERSION}.zip /tmp/optf-osdf.zip +COPY onap-osdf-tm/runtime /opt/osdf/runtime +COPY onap-osdf-tm/requirements-opteng.txt . +RUN unzip -q -o -B /tmp/optf-osdf.zip -d /opt/ && rm -f /tmp/optf-osdf.zip +RUN mkdir -p /var/log/onap/optf/osdf/ \ + && chown onap:onap /var/log/onap -R \ + && chown onap:onap /opt/osdf -R + +RUN pip install --no-cache-dir -r requirements.txt -r requirements-opteng.txt + +USER onap + +CMD [ "/opt/osdf/osdfapp.sh", "-x", "solverapp.py", "-c", "/opt/osdf/config/opteng_config.yaml" ] diff --git a/docker/opteng/assembly/osdf-files.xml b/docker/opteng/assembly/osdf-files.xml new file mode 100644 index 0000000..60dd6cc --- /dev/null +++ b/docker/opteng/assembly/osdf-files.xml @@ -0,0 +1,55 @@ +<!-- + Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + + 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. + +--> +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"> + <id>osdf-files</id> + + <formats> + <format>tar.gz</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + + + <fileSets> + <fileSet> + <includes> + <include>${project.build.finalName}.zip</include> + </includes> + <directory>${project.build.directory}</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + <fileSet> + <includes> + <include>runtime/**</include> + </includes> + <excludes> + <exclude>**/*.pyc</exclude> + <exclude>**/__pycache__/**</exclude> + </excludes> + <outputDirectory>/</outputDirectory> + </fileSet> + <fileSet> + <includes> + <include>requirements-opteng.txt</include> + </includes> + <outputDirectory>/</outputDirectory> + </fileSet> + + </fileSets> +</assembly> diff --git a/docker/Dockerfile b/docker/osdf/Dockerfile index e339ea7..5860df2 100644 --- a/docker/Dockerfile +++ b/docker/osdf/Dockerfile @@ -59,11 +59,18 @@ WORKDIR /opt/osdf #RUN wget -O /opt/osdf.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=releases&g=org.onap.optf.osdf&a=optf-osdf&e=zip&v=1.3.4" && \ # unzip -q -o -B /opt/osdf.zip -d /opt/ && \ # rm -f /opt/osdf.zip +RUN groupadd onap \ + && useradd -m -g onap onap COPY onap-osdf-tm/optf-osdf-${MVN_ARTIFACT_VERSION}.zip /tmp/optf-osdf.zip COPY onap-osdf-tm/apps /opt/osdf/apps RUN unzip -q -o -B /tmp/optf-osdf.zip -d /opt/ && rm -f /tmp/optf-osdf.zip -RUN mkdir -p /var/log/onap/optf/osdf/ +RUN mkdir -p /var/log/onap/optf/osdf/ \ + && chown -R onap:onap /var/log/onap \ + && chown -R onap:onap /opt/osdf + RUN pip install --no-cache-dir -r requirements.txt -CMD [ "/opt/osdf/osdfapp.sh" ] +USER onap + +CMD [ "/opt/osdf/osdfapp.sh", "-x", "osdfapp.py" ] diff --git a/docker/assembly/osdf-files.xml b/docker/osdf/assembly/osdf-files.xml index fc8a864..fc8a864 100644 --- a/docker/assembly/osdf-files.xml +++ b/docker/osdf/assembly/osdf-files.xml diff --git a/docker/build_image.sh b/docker/osdf/build_image.sh index 3d9d823..3d9d823 100755 --- a/docker/build_image.sh +++ b/docker/osdf/build_image.sh diff --git a/osdf/__init__.py b/osdf/__init__.py index c33639e..8036d89 100755 --- a/osdf/__init__.py +++ b/osdf/__init__.py @@ -20,11 +20,12 @@ from jinja2 import Template - end_point_auth_mapping = { # map a URL endpoint to auth group "cmscheduler": "CMScheduler", "placement": "Placement", - "pci": "PCIOpt" + "pci": "PCIOpt", + "optmodel": "OptEngine", + "optengine": "OptEngine" } userid_suffix, passwd_suffix = "Username", "Password" diff --git a/osdf/adapters/aaf/sms.py b/osdf/adapters/aaf/sms.py index fd3a5d5..0168ba0 100644 --- a/osdf/adapters/aaf/sms.py +++ b/osdf/adapters/aaf/sms.py @@ -100,6 +100,8 @@ def load_secrets(): config['pciHMSPassword'] = decrypt_pass(secret_dict['pciHMS']['Password']) config['osdfPCIOptUsername'] = secret_dict['osdfPCIOpt']['UserName'] config['osdfPCIOptPassword'] = decrypt_pass(secret_dict['osdfPCIOpt']['Password']) + config['osdfOptEngineUsername'] = secret_dict['osdfOptEngine']['UserName'] + config['osdfOptEnginePassword'] = decrypt_pass(secret_dict['osdfOptEngine']['Password']) cfg_base.http_basic_auth_credentials = creds.load_credentials(osdf_config) cfg_base.dmaap_creds = creds.dmaap_creds() diff --git a/osdf/adapters/policy/interface.py b/osdf/adapters/policy/interface.py index 61861de..9ace75e 100644 --- a/osdf/adapters/policy/interface.py +++ b/osdf/adapters/policy/interface.py @@ -58,25 +58,32 @@ def get_by_scope(rest_client, req, config_local, type_service): """ scope_policies = [] references = config_local.get('references', {}) - pscope = config_local.get('policy_info', {}).get(type_service, {}).get('policy_scope', {}) - service_name = dot_notation(req, references.get('service_name', {}).get('value', None)) - primary_scope = pscope['{}_scope'.format(service_name.lower() if pscope.get(service_name + "_scope", None) - else "default")] - for sec_scope in pscope.get('secondary_scopes', []): - policies, scope_fields = [], [] - for field in sec_scope: - scope_fields.extend([get_scope_fields(field, references, req, list_flatten(scope_policies)) - if 'get_param' in field else field]) - scope_fields = set(list_flatten(scope_fields)) - scope_fields = set([x.lower() for x in scope_fields]) - for scope in scope_fields: - policies.extend(policy_api_call(rest_client, primary_scope, scope)) - scope_policies.append([policy for policy in policies - if scope_fields <= set(json.loads(policy['config'])['content']['policyScope'])]) + pscope = config_local.get('policy_info', {}).get(type_service, {}).get('policy_scope', []) + scope_fields = {} + policies = {} + for scopes in pscope: + for key in scopes.keys(): + for field in scopes[key]: + scope_fields[key] = set(list_flatten([get_scope_fields(field, references, req, policies) + if 'get_param' in field else field])) + if scope_fields.get('resources') and len(scope_fields['resources']) > 1: + for s in scope_fields['resources']: + scope_fields['resources'] = [s] + policies.update(policy_api_call(rest_client, scope_fields).get('policies', {})) + else: + policies.update(policy_api_call(rest_client, scope_fields).get('policies', {})) + for policyName in policies.keys(): + keys = scope_fields.keys() & policies[policyName]['properties'].keys() + policy = {} + policy[policyName] = policies[policyName] + scope_policies.append(policy for k in keys + if set(policies.get(policyName, {}).get('properties',{}).get(k)) >= set(scope_fields[k]) + and policy not in scope_policies) + return scope_policies -def get_scope_fields(field, references, req, policy_info): +def get_scope_fields(field, references, req, policies): """ Retrieve the values for scope fields from a request and policies as per the configuration and references defined in a configuration file. If the value of a scope field missing in a request or policies, throw an exception since correct policies cannot be retrieved. @@ -95,9 +102,9 @@ def get_scope_fields(field, references, req, policy_info): raise BusinessException("Field {} is missing a value in a request".format(ref_value.split('.')[-1])) else: scope_fields = [] - for policy in policy_info: - policy_content = json.loads(policy.get('config', "{}")) - if policy_content.get('content', {}).get('policyType', "invalid_policy") == ref_source: + for policyName in policies.keys(): + policy_content = policies.get(policyName) + if policy_content.get('type', "invalid_policy") == ref_source: scope_fields.append(dot_notation(policy_content, ref_value)) scope_values = list_flatten(scope_fields) if len(scope_values) > 0: @@ -105,20 +112,19 @@ def get_scope_fields(field, references, req, policy_info): raise BusinessException("Field {} is missing a value in all policies of type {}".format( ref_value.split('.')[-1], ref_source)) - -def policy_api_call(rest_client, primary_scope, scope_field): - """ Makes a getConfig API call to the policy system to retrieve policies matching a scope. - :param rest_client: rest client object to make a call - :param primary_scope: the primary scope of policies, which is a folder in the policy system - where policies are stored. - :param scope_field: the secondary scope of policies, which is a collection of domain values. - :return: a list of policies matching both primary and secondary scopes. +def policy_api_call(rest_client, scope_fields): """ - api_call_body = {"policyName": "{}.*".format(primary_scope), - "configAttributes": {"policyScope": "{}".format(scope_field)}} + :param rest_client: rest client to make a call + :param scope_fields: a collection of scopes to be used for filtering + :return: a list of policies matching all filters + """ + api_call_body = {"ONAPName": "OOF", + "ONAPComponent": "OOF_Component", + "ONAPInstance": "OOF_Component_Instance", + "action": "optimize", + "resources": "{}".format(scope_fields)} return rest_client.request(json=api_call_body) - def remote_api(req_json, osdf_config, service_type="placement"): """Make a request to policy and return response -- it accounts for multiple requests that be needed :param req_json: policy request object (can have multiple policy names) @@ -140,10 +146,10 @@ def remote_api(req_json, osdf_config, service_type="placement"): formatted_policies = [] for x in itertools.chain(*policies): - if x['config'] is None: - raise BusinessException("Config not found for policy with name %s" % x['policyName']) + if x[list(x.keys())[0]].get('properties') is None: + raise BusinessException("Properties not found for policy with name %s" % x[list(x.keys()[0])]) else: - formatted_policies.append(json.loads(x['config'])) + formatted_policies.append(x) return formatted_policies diff --git a/osdf/adapters/policy/utils.py b/osdf/adapters/policy/utils.py index 2f873af..79047eb 100644 --- a/osdf/adapters/policy/utils.py +++ b/osdf/adapters/policy/utils.py @@ -33,11 +33,11 @@ def group_policies_gen(flat_policies, config): """ filtered_policies = defaultdict(list) policy_name = [] - policies = [x for x in flat_policies if x['content'].get('policyType')] # drop ones without 'policy_type' + policies = [x for x in flat_policies if x[list(x.keys())[0]]["type"]] # drop ones without 'type' priority = config.get('policy_info', {}).get('prioritization_attributes', {}) aggregated_policies = dict() for plc in policies: - attrs = [dot_notation(plc, dot_path) for key in priority.keys() for dot_path in priority[key]] + attrs = [dot_notation(plc[list(plc.keys())[0]], dot_path) for key in priority.keys() for dot_path in priority[key]] attrs_list = [x if isinstance(x, list) else [x] for x in attrs] attributes = [list_flatten(x) if isinstance(x, list) else x for x in attrs_list] for y in itertools.product(*attributes): @@ -45,12 +45,12 @@ def group_policies_gen(flat_policies, config): aggregated_policies[y].append(plc) for key in aggregated_policies.keys(): - aggregated_policies[key].sort(key=lambda x: x['priority'], reverse=True) + #aggregated_policies[key].sort(key=lambda x: x['priority'], reverse=True) prioritized_policy = aggregated_policies[key][0] - if prioritized_policy['policyName'] not in policy_name: + if list(prioritized_policy.keys())[0] not in policy_name: # TODO: Check logic here... should policy appear only once across all groups? - filtered_policies[prioritized_policy['content']['policyType']].append(prioritized_policy) - policy_name.append(prioritized_policy['policyName']) + filtered_policies[prioritized_policy[list(prioritized_policy.keys())[0]]['type']].append(prioritized_policy) + policy_name.append(list(prioritized_policy.keys())[0]) return filtered_policies diff --git a/osdf/apps/baseapp.py b/osdf/apps/baseapp.py index 008ce1d..fd94c11 100644 --- a/osdf/apps/baseapp.py +++ b/osdf/apps/baseapp.py @@ -35,7 +35,7 @@ from osdf.config.base import osdf_config from osdf.logging.osdf_logging import error_log, debug_log from osdf.operation.error_handling import request_exception_to_json_body, internal_error_message from osdf.operation.exceptions import BusinessException -from osdf.utils.mdc_utils import clear_mdc, mdc_from_json, default_mdc +from osdf.utils.mdc_utils import clear_mdc, mdc_from_json, default_mdc, get_request_id from requests import RequestException from schematics.exceptions import DataError @@ -88,11 +88,11 @@ def handle_data_error(e): @app.before_request def log_request(): - g.request_start = time.clock() + g.request_start = time.process_time() if request.data: if request.get_json(): request_json = request.get_json() - g.request_id = request_json['requestInfo']['requestId'] + g.request_id = get_request_id(request_json) mdc_from_json(request_json) else: g.request_id = "N/A" diff --git a/osdf/utils/file_utils.py b/osdf/utils/file_utils.py new file mode 100644 index 0000000..b12c17d --- /dev/null +++ b/osdf/utils/file_utils.py @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +# File related utilities + +import os +from shutil import rmtree + +from osdf.logging.osdf_logging import debug_log + + +def delete_file_folder(p): + if not p: + return + debug_log.debug('Deleting folder/file {}'.format(p)) + if os.path.isfile(p): + os.remove(p) + else: + rmtree(p, ignore_errors=True) diff --git a/osdf/utils/mdc_utils.py b/osdf/utils/mdc_utils.py index bcd0615..14b726d 100644 --- a/osdf/utils/mdc_utils.py +++ b/osdf/utils/mdc_utils.py @@ -53,9 +53,16 @@ def default_mdc(): def mdc_from_json(request_json): default_mdc() - MDC.put('requestID', request_json['requestInfo']['requestId']) + MDC.put('requestID', get_request_id(request_json)) MDC.put('partnerName', request_json['requestInfo']['sourceId']) +def get_request_id(request_json): + request_id = request_json['requestInfo'].get('requestId') + if not request_id: + request_id = request_json['requestInfo'].get('requestID') + return request_id + + def clear_mdc(): MDC.clear() diff --git a/osdf/webapp/appcontroller.py b/osdf/webapp/appcontroller.py index e48e93f..5db879a 100644 --- a/osdf/webapp/appcontroller.py +++ b/osdf/webapp/appcontroller.py @@ -16,14 +16,16 @@ # ------------------------------------------------------------------------- # +import json + +from flask import Response from flask import request from flask_httpauth import HTTPBasicAuth -from flask import Response -import json + import osdf import osdf.config.base as cfg_base -from osdf.config.base import osdf_config from osdf.adapters.aaf import aaf_authentication as aaf_auth +from osdf.config.base import osdf_config auth_basic = HTTPBasicAuth() @@ -38,10 +40,11 @@ unauthorized_message = json.dumps(error_body) @auth_basic.get_password def get_pw(username): - end_point = request.url.split('/')[-1] - auth_group = osdf.end_point_auth_mapping.get(end_point) - return cfg_base.http_basic_auth_credentials[auth_group].get( - username) if auth_group else None + auth_group = '' + for k in osdf.end_point_auth_mapping: + if k in request.url: + auth_group = osdf.end_point_auth_mapping.get(k) + return cfg_base.http_basic_auth_credentials[auth_group].get(username) if auth_group else None @auth_basic.error_handler @@ -21,6 +21,11 @@ OSDF Manager Main Flask Application """ import json +import ssl +import sys +import time +import traceback +from optparse import OptionParser from threading import Thread # for scaling up, may need celery with RabbitMQ or redis from flask import request, g @@ -91,14 +96,15 @@ def placement_rest_api(): version_info=api_version_info, request_status="accepted", status_message="") -@app.route("/api/oof/v1/route", methods=["POST"]) +@app.route("/api/oof/route/v1", methods=["POST"]) def do_route_calc(): """ Perform the basic route calculations and returnn the vpn-bindings """ request_json = request.get_json() audit_log.info("Calculate Route request received!") - return RouteOpt().getRoute(request_json) + response = RouteOpt().getRoute(request_json) + return response @app.route("/api/oof/v1/selection/nst", methods=["POST"]) def do_nst_selection(): @@ -113,7 +119,13 @@ def do_nst_selection(): @auth_basic.login_required def do_pci_optimization(): request_json = request.get_json() + audit_log.info('request json obtained==>') + audit_log.info(request_json) + req_id = request_json['requestInfo']['requestId'] + audit_log.info('requestID obtained==>') + audit_log.info(req_id) + g.request_id = req_id audit_log.info(MH.received_request(request.url, request.remote_addr, json.dumps(request_json))) PCIOptimizationAPI(request_json).validate() @@ -123,6 +135,7 @@ def do_pci_optimization(): t = Thread(target=process_pci_optimation, args=(request_json, osdf_config, None)) t.start() audit_log.info(MH.accepted_valid_request(req_id, request)) + audit_log.info('reached upto return') return req_accept(request_id=req_id, transaction_id=request_json['requestInfo']['transactionId'], request_status="accepted", status_message="") @@ -18,16 +18,46 @@ # ------------------------------------------------------------------------- # +usage() { + echo "Usage:" + echo " $0 -h Display this help message." + echo " $0 -c configfile_path(optional) -x app.py file" + exit 0 +} + cd $(dirname $0) # bash ../etc/make-certs.sh # create the https certificates if they are not present +while getopts ":hc:x:" opt; do + case ${opt} in + h ) + usage + ;; + c ) + # process option configuration + export OSDF_CONFIG_FILE=$OPTARG + ;; + x ) + # process executable file + export EXEC_FILE=$OPTARG + ;; + ? ) + usage + ;; + : ) + echo "Invalid Option: -$OPTARG requires an argument" 1>&2 + exit 1 + ;; + esac +done +shift $(( OPTIND - 1 )) + +set -e + LOGS=logs mkdir -p $LOGS -export OSDF_CONFIG_FILE=${1:-/opt/app/config/osdf_config.yaml} # this file may be passed by invoker -[ ! -e "$OSDF_CONFIG_FILE" ] && unset OSDF_CONFIG_FILE - if [ -e /opt/app/ssl_cert/aaf_root_ca.cer ]; then #assuming that this would be an ubuntu vm. cp /opt/app/ssl_cert/aaf_root_ca.cer /usr/local/share/ca-certificates/aafcacert.crt @@ -41,4 +71,11 @@ else export REQUESTS_CA_BUNDLE=/opt/app/ssl_cert/aaf_root_ca.cer fi -python osdfapp.py 2>$LOGS/err.log 1>$LOGS/out.log < /dev/null # running the app +if [ ! -z "$EXEC_FILE" ] +then + # flask run + echo "Running $EXEC_FILE" + python $EXEC_FILE # running the app +else + usage +fi @@ -14,77 +14,80 @@ License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <packaging>pom</packaging> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd +http://maven.apache.org/POM/4.0.0 "> + <modelVersion>4.0.0</modelVersion> + <packaging>pom</packaging> - <parent> - <groupId>org.onap.oparent</groupId> - <artifactId>oparent-python</artifactId> - <version>3.0.0</version> - </parent> + <parent> + <groupId>org.onap.oparent</groupId> + <artifactId>oparent-python</artifactId> + <version>3.0.0</version> + </parent> - <groupId>org.onap.optf.osdf</groupId> - <artifactId>optf-osdf</artifactId> - <name>optf-osdf</name> - <version>1.3.4-SNAPSHOT</version> - <description>Optimization Service Design Framework</description> + <groupId>org.onap.optf.osdf</groupId> + <artifactId>optf-osdf</artifactId> + <name>optf-osdf</name> + <version>1.3.4-SNAPSHOT</version> + <description>Optimization Service Design Framework</description> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <sonar.sources>.</sonar.sources> - <sonar.junit.reportsPath>xunit-results.xml</sonar.junit.reportsPath> - <sonar.python.coverage.reportPaths>coverage.xml</sonar.python.coverage.reportPaths> - <sonar.language>py</sonar.language> - <sonar.pluginname>python</sonar.pluginname> - <sonar.inclusions>**/**.py,osdfapp.py</sonar.inclusions> - <sonar.exclusions>test/**.py,docs/**.py</sonar.exclusions> - <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> - <osdf.build.timestamp>${maven.build.timestamp}</osdf.build.timestamp> - <osdf.project.version>${project.version}</osdf.project.version> - <osdf.docker.repository>nexus3.onap.org:10003</osdf.docker.repository> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <sonar.sources>.</sonar.sources> + <sonar.junit.reportsPath>xunit-results.xml</sonar.junit.reportsPath> + <sonar.python.coverage.reportPaths>coverage.xml</sonar.python.coverage.reportPaths> + <sonar.language>py</sonar.language> + <sonar.pluginname>python</sonar.pluginname> + <sonar.inclusions>**/**.py,osdfapp.py</sonar.inclusions> + <sonar.exclusions>test/**.py,docs/**.py</sonar.exclusions> + <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> + <osdf.build.timestamp>${maven.build.timestamp}</osdf.build.timestamp> + <osdf.project.version>${project.version}</osdf.project.version> + <osdf.docker.repository>nexus3.onap.org:10003</osdf.docker.repository> <image.namespace>${osdf.docker.repository}/onap/optf-osdf</image.namespace> - </properties> + <opteng.namespace>${osdf.docker.repository}/onap/optf-opteng</opteng.namespace> + </properties> - <build> - <plugins> - <!-- triggers tox test for sonar --> - <plugin> - <artifactId>exec-maven-plugin</artifactId> - <groupId>org.codehaus.mojo</groupId> - </plugin> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <appendAssemblyId>false</appendAssemblyId> - <descriptors> - <descriptor>assembly.xml</descriptor> - </descriptors> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> + <build> + <plugins> + <!-- triggers tox test for sonar --> + <plugin> + <artifactId>exec-maven-plugin</artifactId> + <groupId>org.codehaus.mojo</groupId> + </plugin> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <appendAssemblyId>false</appendAssemblyId> + <descriptors> + <descriptor>assembly.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-release-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-deploy-plugin</artifactId> - <version>2.8</version> - <configuration> - <retryFailedDeploymentCount>2</retryFailedDeploymentCount> - </configuration> - </plugin> - <plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-release-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8</version> + <configuration> + <retryFailedDeploymentCount>2</retryFailedDeploymentCount> + </configuration> + </plugin> + <plugin> <groupId>org.codehaus.groovy.maven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.0</version> @@ -100,7 +103,7 @@ </execution> </executions> </plugin> - <plugin> + <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.26.0</version> @@ -119,14 +122,14 @@ <tag>${project.docker.latesttag.version}</tag> </tags> - <dockerFile>${project.basedir}/docker/Dockerfile</dockerFile> + <dockerFile>${project.basedir}/docker/osdf/Dockerfile</dockerFile> <assembly> - <descriptor>${project.basedir}/docker/assembly/osdf-files.xml</descriptor> + <descriptor>${project.basedir}/docker/osdf/assembly/osdf-files.xml</descriptor> <name>onap-osdf-tm</name> </assembly> <args> - <MVN_ARTIFACT_VERSION>${project.version}</MVN_ARTIFACT_VERSION> - <REPO>${project.repo}</REPO> + <MVN_ARTIFACT_VERSION>${project.version}</MVN_ARTIFACT_VERSION> + <REPO>${project.repo}</REPO> <!-- plugin cannot handle empty (no proxy) arguments <http_proxy_arg>${docker.http_proxy}</http_proxy_arg> @@ -135,6 +138,33 @@ </args> </build> </image> + <image> + <name>${opteng.namespace}</name> + <alias>optf-opteng</alias> + <build> + <cleanup>true</cleanup> + <tags> + <tag>latest</tag> + <tag>${project.docker.latesttagtimestamp.version}</tag> + <tag>${project.docker.latesttag.version}</tag> + </tags> + + <dockerFile>${project.basedir}/docker/opteng/Dockerfile</dockerFile> + <assembly> + <descriptor>${project.basedir}/docker/opteng/assembly/osdf-files.xml</descriptor> + <name>onap-osdf-tm</name> + </assembly> + <args> + <MVN_ARTIFACT_VERSION>${project.version}</MVN_ARTIFACT_VERSION> + <REPO>${project.repo}</REPO> + + <!-- plugin cannot handle empty (no proxy) arguments + <http_proxy_arg>${docker.http_proxy}</http_proxy_arg> + <https_proxy_arg>${docker.https_proxy}</https_proxy_arg> + --> + </args> + </build> + </image> </images> </configuration> <executions> @@ -158,6 +188,6 @@ </execution> </executions> </plugin> - </plugins> - </build> + </plugins> + </build> </project> diff --git a/requirements-opteng.txt b/requirements-opteng.txt new file mode 100644 index 0000000..6d0b524 --- /dev/null +++ b/requirements-opteng.txt @@ -0,0 +1 @@ +mysql-connector-python>=8.0.12
\ No newline at end of file diff --git a/runtime/__init__.py b/runtime/__init__.py new file mode 100644 index 0000000..2aa67d8 --- /dev/null +++ b/runtime/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# diff --git a/runtime/model_api.py b/runtime/model_api.py new file mode 100644 index 0000000..fd87333 --- /dev/null +++ b/runtime/model_api.py @@ -0,0 +1,215 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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 +import traceback + +import mysql.connector +from flask import g, Flask, Response + +from osdf.config.base import osdf_config +from osdf.logging.osdf_logging import debug_log, error_log +from osdf.operation.exceptions import BusinessException + + +def init_db(): + if is_db_enabled(): + get_db() + + +def get_db(): + """Opens a new database connection if there is none yet for the + current application context. + """ + if not hasattr(g, 'pg'): + properties = osdf_config['deployment'] + host, db_port, db = properties["osdfDatabaseHost"], properties["osdfDatabasePort"], \ + properties.get("osdfDatabaseSchema") + user, password = properties["osdfDatabaseUsername"], properties["osdfDatabasePassword"] + g.pg = mysql.connector.connect(host=host, port=db_port, user=user, password=password, database=db) + return g.pg + + +def close_db(): + """Closes the database again at the end of the request.""" + if hasattr(g, 'pg'): + g.pg.close() + + +app = Flask(__name__) + + +def create_model_data(model_api): + with app.app_context(): + try: + model_info = model_api['modelInfo'] + model_id = model_info['modelId'] + debug_log.debug( + "persisting model_api {}".format(model_id)) + connection = get_db() + cursor = connection.cursor(buffered=True) + query = "SELECT model_id FROM optim_model_data WHERE model_id = %s" + values = (model_id,) + cursor.execute(query, values) + if cursor.fetchone() is None: + query = "INSERT INTO optim_model_data (model_id, model_content, description, solver_type) VALUES " \ + "(%s, %s, %s, %s)" + values = (model_id, model_info['modelContent'], model_info.get('description'), model_info['solver']) + cursor.execute(query, values) + g.pg.commit() + + debug_log.debug("A record successfully inserted for request_id: {}".format(model_id)) + return retrieve_model_data(model_id) + close_db() + else: + query = "UPDATE optim_model_data SET model_content = %s, description = %s, solver_type = %s where " \ + "model_id = %s " + values = (model_info['modelContent'], model_info.get('description'), model_info['solver'], model_id) + cursor.execute(query, values) + g.pg.commit() + + return retrieve_model_data(model_id) + close_db() + except Exception as err: + error_log.error("error for request_id: {} - {}".format(model_id, traceback.format_exc())) + close_db() + raise BusinessException(err) + + +def retrieve_model_data(model_id): + status, resp_data = get_model_data(model_id) + + if status == 200: + resp = json.dumps(build_model_dict(resp_data)) + return build_response(resp, status) + else: + resp = json.dumps({ + 'modelId': model_id, + 'statusMessage': "Error retrieving the model data for model {} due to {}".format(model_id, resp_data) + }) + return build_response(resp, status) + + +def build_model_dict(resp_data, content_needed=True): + resp = {'modelId': resp_data[0], 'description': resp_data[2] if resp_data[2] else '', + 'solver': resp_data[3]} + if content_needed: + resp.update({'modelContent': resp_data[1]}) + return resp + + +def build_response(resp, status): + response = Response(resp, content_type='application/json; charset=utf-8') + response.headers.add('content-length', len(resp)) + response.status_code = status + return response + + +def delete_model_data(model_id): + with app.app_context(): + try: + debug_log.debug("deleting model data given model_id = {}".format(model_id)) + d = dict(); + connection = get_db() + cursor = connection.cursor(buffered=True) + query = "delete from optim_model_data WHERE model_id = %s" + values = (model_id,) + cursor.execute(query, values) + g.pg.commit() + close_db() + resp = { + "statusMessage": "model data for modelId {} deleted".format(model_id) + } + return build_response(json.dumps(resp), 200) + except Exception as err: + error_log.error("error deleting model_id: {} - {}".format(model_id, traceback.format_exc())) + close_db() + raise BusinessException(err) + + +def get_model_data(model_id): + with app.app_context(): + try: + debug_log.debug("getting model data given model_id = {}".format(model_id)) + d = dict(); + connection = get_db() + cursor = connection.cursor(buffered=True) + query = "SELECT model_id, model_content, description, solver_type FROM optim_model_data WHERE model_id = %s" + values = (model_id,) + cursor.execute(query, values) + if cursor is None: + return 400, "FAILED" + else: + rows = cursor.fetchone() + if rows is not None: + index = 0 + for row in rows: + d[index] = row + index = index + 1 + return 200, d + else: + close_db() + return 500, "NOT_FOUND" + except Exception: + error_log.error("error for request_id: {} - {}".format(model_id, traceback.format_exc())) + close_db() + return 500, "FAILED" + + +def retrieve_all_models(): + status, resp_data = get_all_models() + model_list = [] + if status == 200: + for r in resp_data: + model_list.append(build_model_dict(r, False)) + resp = json.dumps(model_list) + return build_response(resp, status) + + else: + resp = json.dumps({ + 'statusMessage': "Error retrieving all the model data due to {}".format(resp_data) + }) + return build_response(resp, status) + + +def get_all_models(): + with app.app_context(): + try: + debug_log.debug("getting all model data".format()) + connection = get_db() + cursor = connection.cursor(buffered=True) + query = "SELECT model_id, model_content, description, solver_type FROM optim_model_data" + + cursor.execute(query) + if cursor is None: + return 400, "FAILED" + else: + rows = cursor.fetchall() + if rows is not None: + return 200, rows + else: + close_db() + return 500, "NOT_FOUND" + except Exception: + error_log.error("error for request_id: {}".format(traceback.format_exc())) + close_db() + return 500, "FAILED" + + +def is_db_enabled(): + return osdf_config['deployment'].get('isDatabaseEnabled', False) diff --git a/runtime/models/__init__.py b/runtime/models/__init__.py new file mode 100644 index 0000000..2aa67d8 --- /dev/null +++ b/runtime/models/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# diff --git a/runtime/models/api/__init__.py b/runtime/models/api/__init__.py new file mode 100644 index 0000000..2aa67d8 --- /dev/null +++ b/runtime/models/api/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# diff --git a/runtime/models/api/model_request.py b/runtime/models/api/model_request.py new file mode 100644 index 0000000..710da4b --- /dev/null +++ b/runtime/models/api/model_request.py @@ -0,0 +1,48 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +from schematics.types import StringType +from schematics.types.compound import ModelType + +from osdf.models.api.common import OSDFModel + + +class RequestInfo(OSDFModel): + """Info for northbound request from client such as PCI-mS Handler""" + transactionId = StringType(required=True) + requestID = StringType(required=True) + sourceId = StringType(required=True) + + +class OptimModelInfo(OSDFModel): + """Optimizer request info details.""" + # ModelId from the database + modelId = StringType() + # type of solver (mzn, or-tools, etc.) + solver = StringType(required=True) + # Description of the model + description = StringType() + # a large blob string containing the model (which is not that + # problematic since models are fairly small). + modelContent = StringType() + + +class OptimModelRequestAPI(OSDFModel): + """Request for Optimizer API (specific to optimization and additional metadata""" + requestInfo = ModelType(RequestInfo, required=True) + modelInfo = ModelType(OptimModelInfo, required=True) diff --git a/runtime/models/api/model_response.py b/runtime/models/api/model_response.py new file mode 100644 index 0000000..e4a41a5 --- /dev/null +++ b/runtime/models/api/model_response.py @@ -0,0 +1,31 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +from schematics.types import StringType + +from osdf.models.api.common import OSDFModel + + +class OptimModelResponse(OSDFModel): + modelId = StringType() + # type of solver (mzn, or-tools, etc.) + solver = StringType() + # a large blob string containing the model + modelContent = StringType() + # statusMessage + statusMessage = StringType() diff --git a/runtime/models/api/optim_request.py b/runtime/models/api/optim_request.py new file mode 100644 index 0000000..4a046d2 --- /dev/null +++ b/runtime/models/api/optim_request.py @@ -0,0 +1,60 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +from schematics.types import BaseType, DictType, StringType, IntType +from schematics.types.compound import ModelType + +from osdf.models.api.common import OSDFModel + +""" +""" +class RequestInfo(OSDFModel): + """Info for northbound request from client """ + transactionId = StringType(required=True) + requestID = StringType(required=True) + callbackUrl = StringType() + sourceId = StringType(required=True) + timeout = IntType() + + +class DataInfo(OSDFModel): + """Optimization data info""" + text = StringType() + json = DictType(BaseType) + + +class OptimInfo(OSDFModel): + """Optimizer request info details.""" + # ModelId from the database, if its not populated, + # assume that solverModel will be populated. + modelId = StringType() + # type of solver (mzn, or-tools, etc.) + solver = StringType() + # Arguments for solver + solverArgs = DictType(BaseType) + # NOTE: a large blob string containing the model (which is not that + # problematic since models are fairly small). + modelContent = StringType() + # Data Payload, input data for the solver + optData = ModelType(DataInfo) + + +class OptimizationAPI(OSDFModel): + """Request for Optimizer API (specific to optimization and additional metadata""" + requestInfo = ModelType(RequestInfo, required=True) + optimInfo = ModelType(OptimInfo, required=True) diff --git a/runtime/models/api/optim_response.py b/runtime/models/api/optim_response.py new file mode 100644 index 0000000..6fd0f6b --- /dev/null +++ b/runtime/models/api/optim_response.py @@ -0,0 +1,30 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +from schematics.types import StringType, BaseType +from schematics.types.compound import DictType + +from osdf.models.api.common import OSDFModel + + +class OptimResponse(OSDFModel): + transactionId = StringType(required=True) + requestID = StringType(required=True) + requestStatus = StringType(required=True) + statusMessage = StringType() + solutions = DictType(BaseType) diff --git a/runtime/optim_engine.py b/runtime/optim_engine.py new file mode 100644 index 0000000..4a8788e --- /dev/null +++ b/runtime/optim_engine.py @@ -0,0 +1,79 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +from flask import Response + +from osdf.operation.exceptions import BusinessException +from .model_api import get_model_data +from .models.api.optim_request import OptimizationAPI +from .solvers.mzn.mzn_solver import solve as mzn_solve +from .solvers.py.py_solver import solve as py_solve + + +def is_valid_optim_request(request_json): + # Method to check whether the requestinfo/optimizer value is valid. + opt_info = request_json['optimInfo'] + if not opt_info.get('modelId'): + if not opt_info.get('modelContent') or not opt_info.get('solver'): + raise BusinessException('modelContent and solver needs to be populated if model_id is not set') + if not opt_info.get('optData'): + raise BusinessException('optimInfo.optData needs to be populated to solve for a problem') + + return True + + +def validate_request(request_json): + OptimizationAPI(request_json).validate() + if not is_valid_optim_request(request_json): + raise BusinessException('Invalid optim request ') + return True + + +def process_request(request_json): + response_code, response_message = run_optimizer(request_json) + response = Response(response_message, content_type='application/json; charset=utf-8') + response.headers.add('content-length', len(response_message)) + response.status_code = response_code + return response + + +def run_optimizer(request_json): + validate_request(request_json) + + model_content, solver = get_model_content(request_json) + + if solver == 'mzn': + return mzn_solve(request_json, model_content) + elif solver == 'py': + return py_solve(request_json, model_content) + raise BusinessException('Unsupported optimization solver requested {} '.format(solver)) + + +def get_model_content(request_json): + model_id = request_json['optimInfo'].get('modelId') + if model_id: + status, data = get_model_data(model_id) + if status == 200: + model_content = data[1] + solver = data[3] + else: + raise BusinessException('model_id [{}] not found in the model database'.format(model_id)) + else: + model_content = request_json['optimInfo']['modelContent'] + solver = request_json['optimInfo']['solver'] + return model_content, solver diff --git a/runtime/solvers/__init__.py b/runtime/solvers/__init__.py new file mode 100644 index 0000000..2aa67d8 --- /dev/null +++ b/runtime/solvers/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# diff --git a/runtime/solvers/mzn/__init__.py b/runtime/solvers/mzn/__init__.py new file mode 100644 index 0000000..2aa67d8 --- /dev/null +++ b/runtime/solvers/mzn/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# diff --git a/runtime/solvers/mzn/mzn_solver.py b/runtime/solvers/mzn/mzn_solver.py new file mode 100644 index 0000000..cf002e7 --- /dev/null +++ b/runtime/solvers/mzn/mzn_solver.py @@ -0,0 +1,102 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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 datetime import datetime + +from pymzn import Status, minizinc, cbc, gecode, chuffed, or_tools + +from osdf.utils.file_utils import delete_file_folder + +error_status_map = { + Status.INCOMPLETE: "incomplete", + Status.COMPLETE: "complete", + Status.UNSATISFIABLE: "unsatisfiable", + Status.UNKNOWN: "unknown", + Status.UNBOUNDED: "unbounded", + Status.UNSATorUNBOUNDED: "unsat_or_unbounded", + Status.ERROR: "error" +} + +solver_dict = { + 'cbc': cbc, + 'geocode': gecode, + 'chuffed': chuffed, + 'cp': chuffed, + 'or_tools': or_tools +} + + +def map_status(status): + return error_status_map.get(status, "failed") + + +def solve(request_json, mzn_content): + req_info = request_json['requestInfo'] + opt_info = request_json['optimInfo'] + try: + mzn_solution = mzn_solver(mzn_content, opt_info) + + response = { + 'transactionId': req_info['transactionId'], + 'requestID': req_info['requestID'], + 'requestStatus': 'done', + 'statusMessage': map_status(mzn_solution.status), + 'solutions': mzn_solution[0] if mzn_solution else {} + } + return 200, json.dumps(response) + except Exception as e: + response = { + 'transactionId': req_info['transactionId'], + 'requestID': req_info['requestID'], + 'requestStatus': 'failed', + 'statusMessage': 'Failed due to {}'.format(e) + } + return 400, json.dumps(response) + + +def mzn_solver(mzn_content, opt_info): + args = opt_info['solverArgs'] + solver = get_mzn_solver(args.pop('solver')) + mzn_opts = dict() + + try: + file_name = persist_opt_data(opt_info) + mzn_opts.update(args) + return minizinc(mzn_content, file_name, **mzn_opts, solver=solver) + + finally: + delete_file_folder(file_name) + + +def persist_opt_data(opt_info): + + if opt_info['optData'].get('json'): + data_content = json.dumps(opt_info['optData']['json']) + file_name = '/tmp/optim_engine_{}.json'.format(datetime.timestamp(datetime.now())) + elif opt_info['optData'].get('text'): + data_content = opt_info['optData']['text'] + file_name = '/tmp/optim_engine_{}.dzn'.format(datetime.timestamp(datetime.now())) + + with open(file_name, "wt") as data: + data.write(data_content) + return file_name + + +def get_mzn_solver(solver): + return solver_dict.get(solver) diff --git a/runtime/solvers/py/__init__.py b/runtime/solvers/py/__init__.py new file mode 100644 index 0000000..a8aa582 --- /dev/null +++ b/runtime/solvers/py/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +#
\ No newline at end of file diff --git a/runtime/solvers/py/py_solver.py b/runtime/solvers/py/py_solver.py new file mode 100644 index 0000000..6b200ab --- /dev/null +++ b/runtime/solvers/py/py_solver.py @@ -0,0 +1,92 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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 +import subprocess +import traceback +from datetime import datetime + +from osdf.logging.osdf_logging import error_log, debug_log +from osdf.utils.file_utils import delete_file_folder + + +def py_solver(py_content, opt_info): + py_file = '/tmp/custom_heuristics_{}.py'.format(datetime.timestamp(datetime.now())) + with open(py_file, "wt") as f: + f.write(py_content) + if opt_info['optData'].get('json'): + data_content = json.dumps(opt_info['optData']['json']) + input_file = '/tmp/optim_engine_{}.json'.format(datetime.timestamp(datetime.now())) + elif opt_info['optData'].get('text'): + data_content = opt_info['optData']['text'] + input_file = '/tmp/optim_engine_{}.txt'.format(datetime.timestamp(datetime.now())) + with open(input_file, "wt") as f: + f.write(data_content) + + output_file = '/tmp/opteng_output_{}.json'.format(datetime.timestamp(datetime.now())) + + command = ['python', py_file, input_file, output_file] + + try: + p = subprocess.run(command, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) + + debug_log.debug('Process return code {}'.format(p.returncode)) + if p.returncode > 0: + error_log.error('Process return code {} {}'.format(p.returncode, p.stdout)) + return 'error', {} + with open(output_file) as file: + data = file.read() + return 'success', json.loads(data) + + except Exception as e: + error_log.error("Error running optimizer {}".format(traceback.format_exc())) + return 'error', {} + finally: + cleanup((input_file, output_file, py_file)) + + +def cleanup(file_tup): + for f in file_tup: + try: + delete_file_folder(f) + except Exception as e: + error_log.error("Failed deleting the file {} - {}".format(f, traceback.format_exc())) + + +def solve(request_json, py_content): + req_info = request_json['requestInfo'] + opt_info = request_json['optimInfo'] + try: + status, solution = py_solver(py_content, opt_info) + + response = { + 'transactionId': req_info['transactionId'], + 'requestID': req_info['requestID'], + 'requestStatus': status, + 'statusMessage': "completed", + 'solutions': solution if solution else {} + } + return 200, json.dumps(response) + except Exception as e: + response = { + 'transactionId': req_info['transactionId'], + 'requestID': req_info['requestID'], + 'requestStatus': 'failed', + 'statusMessage': 'Failed due to {}'.format(e) + } + return 400, json.dumps(response) diff --git a/script/TagVersion.groovy b/script/TagVersion.groovy index 6ed6558..01bc840 100644 --- a/script/TagVersion.groovy +++ b/script/TagVersion.groovy @@ -37,7 +37,7 @@ if ( project.properties['osdf.project.version'].endsWith("-SNAPSHOT") ) { project.properties['project.docker.latesttagtimestamp.version']=versionTag + "-SNAPSHOT-"+timestamp; project.properties['project.repo'] = 'snapshots' } else { - project.properties['project.docker.latesttag.version']=baseTag + "-STAGING-latest"; + project.properties['project.docker.latesttag.version']=versionTag + "-STAGING-latest"; project.properties['project.docker.latesttagtimestamp.version']=versionTag + "-STAGING-"+timestamp; project.properties['project.repo'] = 'releases' } diff --git a/solverapp.py b/solverapp.py new file mode 100644 index 0000000..39f2670 --- /dev/null +++ b/solverapp.py @@ -0,0 +1,81 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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. +# +# ------------------------------------------------------------------------- +# + +from flask import request, g + +from osdf.apps.baseapp import app, run_app +from osdf.logging.osdf_logging import audit_log +from osdf.webapp.appcontroller import auth_basic +from runtime.model_api import create_model_data, retrieve_model_data, retrieve_all_models, delete_model_data +from runtime.models.api.model_request import OptimModelRequestAPI +from runtime.optim_engine import process_request + + +@app.route("/api/oof/optengine/v1", methods=["POST"]) +@auth_basic.login_required +def opt_engine_rest_api(): + """Perform OptimEngine optimization after validating the request + """ + request_json = request.get_json() + return process_request(request_json) + + +@app.route("/api/oof/optmodel/v1", methods=["PUT", "POST"]) +@auth_basic.login_required +def opt_model_create_rest_api(): + """Perform OptimEngine optimization after validating the request + """ + request_json = request.get_json() + OptimModelRequestAPI(request_json).validate() + return create_model_data(request_json) + + +@app.route("/api/oof/optmodel/v1/<model_id>", methods=["GET"]) +@auth_basic.login_required +def opt_get_model_rest_api(model_id): + """Retrieve model data + """ + + return retrieve_model_data(model_id) + + +@app.route("/api/oof/optmodel/v1", methods=["GET"]) +@auth_basic.login_required +def opt_get_all_models_rest_api(): + """Retrieve all models data + """ + return retrieve_all_models() + + +@app.route("/api/oof/optmodel/v1/<model_id>", methods=["DELETE"]) +@auth_basic.login_required +def opt_delete_model_rest_api(model_id): + """Perform OptimEngine optimization after validating the request + """ + return delete_model_data(model_id) + + +@app.route("/api/oof/optengine/healthcheck/v1", methods=["GET"]) +def do_health_check(): + """Simple health check""" + audit_log.info("A OptimEngine health check v1 request is processed!") + return "OK" + + +if __name__ == "__main__": + run_app() diff --git a/test/conductor/test_conductor_calls.py b/test/conductor/test_conductor_calls.py index 52e0367..d811e63 100644 --- a/test/conductor/test_conductor_calls.py +++ b/test/conductor/test_conductor_calls.py @@ -40,12 +40,12 @@ class TestConductorCalls(unittest.TestCase): def test_request(self): req_json = json_from_file("./test/placement-tests/request.json") - policies = pol.get_local_policies("test/policy-local-files/", self.lp) + policies = pol.get_local_policies("test/policy-local-files/new_policies/", self.lp) conductor.request(req_json, self.osdf_config, policies) def test_request_vfmod(self): req_json = json_from_file("./test/placement-tests/request_vfmod.json") - policies = pol.get_local_policies("test/policy-local-files/", self.lp) + policies = pol.get_local_policies("test/policy-local-files/new_policies/", self.lp) conductor.request(req_json, self.osdf_config, policies) diff --git a/test/conductor/test_conductor_translation.py b/test/conductor/test_conductor_translation.py index ad70157..cc9dc1c 100644 --- a/test/conductor/test_conductor_translation.py +++ b/test/conductor/test_conductor_translation.py @@ -28,7 +28,7 @@ class TestConductorTranslation(unittest.TestCase): self.main_dir = "" self.conductor_api_template = self.main_dir + "osdf/templates/conductor_interface.json" self.local_config_file = self.main_dir + "config/common_config.yaml" - policy_data_path = self.main_dir + "test/policy-local-files" + policy_data_path = self.main_dir + "test/policy-local-files/new_policies" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' valid_policies_files = local_policies.get_policy_names_from_file(valid_policies_list_file) @@ -44,13 +44,15 @@ class TestConductorTranslation(unittest.TestCase): def test_gen_demands(self): # need to run this only on vnf policies - vnf_policies = [x for x in self.policies if x["content"]["policyType"] == "vnfPolicy"] + vnf_policies = [x for x in self.policies if x[list(x.keys())[0]]["type"] + == "onap.policies.optimization.VnfPolicy"] res = tr.gen_demands(self.request_json, vnf_policies) assert res is not None def test_gen_vfmod_demands(self): # need to run this only on vnf policies - vnf_policies = [x for x in self.policies if x["content"]["policyType"] == "vnfPolicy"] + vnf_policies = [x for x in self.policies if x[list(x.keys())[0]]["type"] + == "onap.policies.optimization.VnfPolicy"] res = tr.gen_demands(self.request_vfmod_json, vnf_policies) assert res is not None diff --git a/test/config/opteng_config.yaml b/test/config/opteng_config.yaml new file mode 100755 index 0000000..4a7e57d --- /dev/null +++ b/test/config/opteng_config.yaml @@ -0,0 +1,25 @@ +# Policy Platform -- requires Authorization +policyPlatformUrl: https://policy-xacml-pdp:6969/policy/pdpx/decision/v1 # Policy Dev platform URL + +# AAF Authentication config +is_aaf_enabled: False +aaf_cache_expiry_mins: 5 +aaf_url: https://aaftest.simpledemo.onap.org:8095 +aaf_user_roles: + - '/optmodel:org.onap.oof.access|*|read ALL' + - '/optengine:org.onap.oof.access|*|read ALL' + +# Secret Management Service from AAF +aaf_sms_url: https://aaf-sms.onap:10443 +aaf_sms_timeout: 30 +secret_domain: osdf +aaf_ca_certs: ssl_certs/aaf_root_ca.cer + +osdfDatabaseHost: localhost +osdfDatabaseSchema: osdf +osdfDatabaseUsername: osdf +osdfDatabasePassword: osdf +osdfDatabasePort: 3306 + +#key +appkey: os35@rrtky400fdntc#001t5
\ No newline at end of file diff --git a/test/functest/simulators/simulated-config/opteng_config.yaml b/test/functest/simulators/simulated-config/opteng_config.yaml new file mode 100755 index 0000000..4a7e57d --- /dev/null +++ b/test/functest/simulators/simulated-config/opteng_config.yaml @@ -0,0 +1,25 @@ +# Policy Platform -- requires Authorization +policyPlatformUrl: https://policy-xacml-pdp:6969/policy/pdpx/decision/v1 # Policy Dev platform URL + +# AAF Authentication config +is_aaf_enabled: False +aaf_cache_expiry_mins: 5 +aaf_url: https://aaftest.simpledemo.onap.org:8095 +aaf_user_roles: + - '/optmodel:org.onap.oof.access|*|read ALL' + - '/optengine:org.onap.oof.access|*|read ALL' + +# Secret Management Service from AAF +aaf_sms_url: https://aaf-sms.onap:10443 +aaf_sms_timeout: 30 +secret_domain: osdf +aaf_ca_certs: ssl_certs/aaf_root_ca.cer + +osdfDatabaseHost: localhost +osdfDatabaseSchema: osdf +osdfDatabaseUsername: osdf +osdfDatabasePassword: osdf +osdfDatabasePort: 3306 + +#key +appkey: os35@rrtky400fdntc#001t5
\ No newline at end of file diff --git a/test/optengine-tests/test_modelapi_invalid.json b/test/optengine-tests/test_modelapi_invalid.json new file mode 100644 index 0000000..a58258e --- /dev/null +++ b/test/optengine-tests/test_modelapi_invalid.json @@ -0,0 +1,13 @@ +{ + "requestInfo": { + "transactinId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt" + }, + "modelInfo": { + "modelId": "model2", + "solver": "mzn", + "description": "graph coloring problem for australia", + "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];" + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_modelapi_valid.json b/test/optengine-tests/test_modelapi_valid.json new file mode 100644 index 0000000..1fbca5b --- /dev/null +++ b/test/optengine-tests/test_modelapi_valid.json @@ -0,0 +1,13 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt" + }, + "modelInfo": { + "modelId": "model2", + "solver": "mzn", + "description": "graph coloring problem for australia", + "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];" + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_invalid.json b/test/optengine-tests/test_optengine_invalid.json new file mode 100644 index 0000000..9a0267a --- /dev/null +++ b/test/optengine-tests/test_optengine_invalid.json @@ -0,0 +1,18 @@ +{ + "requestInfo": { + "transactioId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "solver": "mzn", + "solverArgs": { + "solver": "geocode" + }, + "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];", + "optData": { + "nc": 3 + } + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_invalid2.json b/test/optengine-tests/test_optengine_invalid2.json new file mode 100644 index 0000000..23c5a8e --- /dev/null +++ b/test/optengine-tests/test_optengine_invalid2.json @@ -0,0 +1,15 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + + "solverArgs": { + "solver": "cbc" + }, + "modelContent": "% Baking cakes for the school fete (with data file)\r\n\r\nint: flour; %no. grams of flour available\r\nint: banana; %no. of bananas available\r\nint: sugar; %no. grams of sugar available\r\nint: butter; %no. grams of butter available\r\nint: cocoa; %no. grams of cocoa available\r\n\r\nconstraint assert(flour >= 0,\"Invalid datafile: \" ++\r\n \"Amount of flour should be non-negative\");\r\nconstraint assert(banana >= 0,\"Invalid datafile: \" ++\r\n \"Amount of banana should be non-negative\");\r\nconstraint assert(sugar >= 0,\"Invalid datafile: \" ++\r\n \"Amount of sugar should be non-negative\");\r\nconstraint assert(butter >= 0,\"Invalid datafile: \" ++\r\n \"Amount of butter should be non-negative\");\r\nconstraint assert(cocoa >= 0,\"Invalid datafile: \" ++\r\n \"Amount of cocoa should be non-negative\");\r\n\r\nvar 0..100: b; % no. of banana cakes\r\nvar 0..100: c; % no. of chocolate cakes\r\n\r\n% flour\r\nconstraint 250*b + 200*c <= flour;\r\n% bananas\r\nconstraint 2*b <= banana;\r\n% sugar\r\nconstraint 75*b + 150*c <= sugar;\r\n% butter\r\nconstraint 100*b + 150*c <= butter;\r\n% cocoa\r\nconstraint 75*c <= cocoa;\r\n\r\n% maximize our profit\r\nsolve maximize 400*b + 450*c;\r\n\r\noutput [\"no. of banana cakes = \\(b)\\n\",\r\n \"no. of chocolate cakes = \\(c)\\n\"];" + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_invalid_solver.json b/test/optengine-tests/test_optengine_invalid_solver.json new file mode 100644 index 0000000..a967c16 --- /dev/null +++ b/test/optengine-tests/test_optengine_invalid_solver.json @@ -0,0 +1,15 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "solver": "apy", + "modelContent": "import sys\r\n\r\nif __name__ == \"__main__\":\r\n print(sys.argv[1],sys.argv[2])\r\n\r\n with open(sys.argv[2], \"wt\") as f:\r\n f.write('{\"hello\":\"world\",\"another\":\"string\"}')\r\n\r\n", + "optData": { + "text": "flour = 8000; \r\nbanana = 11; \r\nsugar = 3000; \r\nbutter = 1500; \r\ncocoa = 800; " + } + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_modelId.json b/test/optengine-tests/test_optengine_modelId.json new file mode 100644 index 0000000..b676d91 --- /dev/null +++ b/test/optengine-tests/test_optengine_modelId.json @@ -0,0 +1,19 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "modelId": "test", + "solverArgs": { + "solver": "geocode" + }, + "optData": { + "json": { + "nc": 3 + } + } + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_no_modelid.json b/test/optengine-tests/test_optengine_no_modelid.json new file mode 100644 index 0000000..9a8c3a4 --- /dev/null +++ b/test/optengine-tests/test_optengine_no_modelid.json @@ -0,0 +1,24 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "solver": "mzn", + "solverArgs": { + "solver": "cbc" + }, + "modelContent": "% Baking cakes for the school fete (with data file)\r\n\r\nint: flour; %no. grams of flour available\r\nint: banana; %no. of bananas available\r\nint: sugar; %no. grams of sugar available\r\nint: butter; %no. grams of butter available\r\nint: cocoa; %no. grams of cocoa available\r\n\r\nconstraint assert(flour >= 0,\"Invalid datafile: \" ++\r\n \"Amount of flour should be non-negative\");\r\nconstraint assert(banana >= 0,\"Invalid datafile: \" ++\r\n \"Amount of banana should be non-negative\");\r\nconstraint assert(sugar >= 0,\"Invalid datafile: \" ++\r\n \"Amount of sugar should be non-negative\");\r\nconstraint assert(butter >= 0,\"Invalid datafile: \" ++\r\n \"Amount of butter should be non-negative\");\r\nconstraint assert(cocoa >= 0,\"Invalid datafile: \" ++\r\n \"Amount of cocoa should be non-negative\");\r\n\r\nvar 0..100: b; % no. of banana cakes\r\nvar 0..100: c; % no. of chocolate cakes\r\n\r\n% flour\r\nconstraint 250*b + 200*c <= flour;\r\n% bananas\r\nconstraint 2*b <= banana;\r\n% sugar\r\nconstraint 75*b + 150*c <= sugar;\r\n% butter\r\nconstraint 100*b + 150*c <= butter;\r\n% cocoa\r\nconstraint 75*c <= cocoa;\r\n\r\n% maximize our profit\r\nsolve maximize 400*b + 450*c;\r\n\r\noutput [\"no. of banana cakes = \\(b)\\n\",\r\n \"no. of chocolate cakes = \\(c)\\n\"];", + "optData": { + "json": { + "flour": 4000, + "banana": 6, + "sugar": 2000, + "butter": 500, + "cocoa": 500 + } + } + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_no_optdata.json b/test/optengine-tests/test_optengine_no_optdata.json new file mode 100644 index 0000000..f6645c8 --- /dev/null +++ b/test/optengine-tests/test_optengine_no_optdata.json @@ -0,0 +1,15 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "solver": "mzn", + "solverArgs": { + "solver": "geocode" + }, + "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];" + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_solverid.json b/test/optengine-tests/test_optengine_solverid.json new file mode 100644 index 0000000..bfd446c --- /dev/null +++ b/test/optengine-tests/test_optengine_solverid.json @@ -0,0 +1,15 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "solver": "py", + "modelContent": "import sys\r\n\r\nif __name__ == \"__main__\":\r\n print(sys.argv[1],sys.argv[2])\r\n\r\n with open(sys.argv[2], \"wt\") as f:\r\n f.write('{\"hello\":\"world\",\"another\":\"string\"}')\r\n\r\n", + "optData": { + "text": "flour = 8000; \r\nbanana = 11; \r\nsugar = 3000; \r\nbutter = 1500; \r\ncocoa = 800; " + } + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_optengine_valid.json b/test/optengine-tests/test_optengine_valid.json new file mode 100644 index 0000000..8de2b71 --- /dev/null +++ b/test/optengine-tests/test_optengine_valid.json @@ -0,0 +1,20 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "solver": "mzn", + "solverArgs": { + "solver": "geocode" + }, + "modelContent": "int: nc;\r\nvar 1 .. nc: wa; var 1 .. nc: nt; var 1 .. nc: sa; var 1 .. nc: q;\r\nvar 1 .. nc: nsw; var 1 .. nc: v; var 1 .. nc: t;\r\nconstraint wa != nt;\r\nconstraint wa != sa;\r\nconstraint nt != sa;\r\nconstraint nt != q;\r\nconstraint sa != q;\r\nconstraint sa != nsw;\r\nconstraint sa != v;\r\nconstraint q != nsw;\r\nconstraint nsw != v;\r\nsolve satisfy;\r\noutput [\r\n \"wa=\\(wa)\\t nt=\\(nt)\\t sa=\\(sa)\\n\",\r\n \"q=\\(q)\\t nsw=\\(nsw)\\t v=\\(v)\\n\",\r\n \"t=\", show(t), \"\\n\"\r\n];", + "optData": { + "json": { + "nc": 3 + } + } + } +}
\ No newline at end of file diff --git a/test/optengine-tests/test_py_optengine_valid.json b/test/optengine-tests/test_py_optengine_valid.json new file mode 100644 index 0000000..bfd446c --- /dev/null +++ b/test/optengine-tests/test_py_optengine_valid.json @@ -0,0 +1,15 @@ +{ + "requestInfo": { + "transactionId": "xxx-xxx-xxxx", + "requestID": "yyy-yyy-yyyy", + "sourceId": "cmopt", + "timeout": 600 + }, + "optimInfo": { + "solver": "py", + "modelContent": "import sys\r\n\r\nif __name__ == \"__main__\":\r\n print(sys.argv[1],sys.argv[2])\r\n\r\n with open(sys.argv[2], \"wt\") as f:\r\n f.write('{\"hello\":\"world\",\"another\":\"string\"}')\r\n\r\n", + "optData": { + "text": "flour = 8000; \r\nbanana = 11; \r\nsugar = 3000; \r\nbutter = 1500; \r\ncocoa = 800; " + } + } +}
\ No newline at end of file diff --git a/test/placement-tests/policy_response.json b/test/placement-tests/policy_response.json index 8de8537..a257ecc 100644 --- a/test/placement-tests/policy_response.json +++ b/test/placement-tests/policy_response.json @@ -1,182 +1,694 @@ -[ { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"SubscriberPolicy\",\"policyName\":\"oofBeijing.SubscriberPolicy_v1\",\"description\":\"Subscriber Policy\",\"templateVersion\":\"0.0.1\",\"version\":\"oofBeijing\",\"priority\":\"1\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"identity\":\"subscriber\",\"policyScope\":[\"vcpe\",\"PVT Homing\",\"subscriberpolicy\",\"subscriber_x\",\"subscriber_y\"],\"properties\":{\"subscriberName\":[\"subscriber_x\",\"subscriber_y\"],\"subscriberRole\":[\"PVT Homing\"],\"provStatus\":[\"CAPPED\"]},\"policyType\":\"SubscriberPolicy\"}}", - "policyName": "oofBeijing.Config_MS_SubscriberPolicy_v1.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "SubscriberPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"hpaPolicy\",\"policyName\":\"oofBeijing.hpaPolicy_vGMuxInfra\",\"description\":\"HPA policy for vGMuxInfra\",\"templateVersion\":\"0.0.1\",\"version\":\"1.0\",\"priority\":\"3\",\"riskType\":\"test\",\"riskLevel\":\"2\",\"guard\":\"False\",\"content\":{\"resources\":\"vGMuxInfra\",\"identity\":\"hpaPolicy_vGMuxInfra\",\"policyScope\":[\"vcpe\",\"PVT Homing\",\"us\",\"international\",\"ip\",\"vGMuxInfra\"],\"policyType\":\"hpaPolicy\",\"flavorFeatures\":[{\"flavorLabel\":\"flavor_label_vm_01\",\"flavorProperties\":[{\"hpa-feature\":\"cpuTopology\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numCpusockets\",\"hpa-attribute-value\":\"2\",\"operator\":\">=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpusockets\",\"hpa-attribute-value\":\"4\",\"operator\":\"<=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuCores\",\"hpa-attribute-value\":\"2\",\"operator\":\">=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuCores\",\"hpa-attribute-value\":\"4\",\"operator\":\"<=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuThreads\",\"hpa-attribute-value\":\"4\",\"operator\":\">=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuThreads\",\"hpa-attribute-value\":\"8\",\"operator\":\"<=\",\"unit\":\"\"}]},{\"hpa-feature\":\"basicCapabilities\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numVirtualCpu\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"virtualMemSize\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"GB\"}]},{\"hpa-feature\":\"ovsDpdk\",\"mandatory\":\"False\",\"score\":\"3\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"dataProcessingAccelerationLibrary\",\"hpa-attribute-value\":\"ovsDpdk_version\",\"operator\":\"=\",\"unit\":\"\"}]},{\"hpa-feature\":\"cpuInstructionSetExtensions\",\"mandatory\":\"True\",\"architecture\":\"INTEL-64\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"instructionSetExtensions\",\"hpa-attribute-value\":[\"<CPUINST>\",\"<CPUINST>\"],\"operator\":\"ALL\",\"unit\":\"\"}]}]},{\"flavorLabel\":\"flavor_label_vm_02\",\"flavorProperties\":[{\"hpa-feature\":\"cpuPinningy\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"logicalCpuThreadPinningPolicy\",\"hpa-attribute-value\":\"<CPUTHREADPOLICY>\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"logicalCpuPinningPolicy\",\"hpa-attribute-value\":\"<CPUPOLICY>\",\"operator\":\"=\",\"unit\":\"\"}]},{\"hpa-feature\":\"basicCapabilities\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numVirtualCpu\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"virtualMemSize\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"GB\"}]},{\"hpa-feature\":\"localStorage\",\"mandatory\":\"False\",\"score\":\"5\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"diskSize\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"GB\"},{\"hpa-attribute-key\":\"ephemeralDiskSize\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"GB\"},{\"hpa-attribute-key\":\"swapMemSize\",\"hpa-attribute-value\":\"16\",\"operator\":\"=\",\"unit\":\"MB\"}]},{\"hpa-feature\":\"pcie\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"pciCount\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"pciVendorId\",\"hpa-attribute-value\":\"8086\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"pciDeviceId\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"functionType\",\"hpa-attribute-value\":\"<PCITYPEVALUE>\",\"operator\":\"=\",\"unit\":\"\"}]}]},{\"flavorLabel\":\"flavor_label_vm_03\",\"flavorProperties\":[{\"hpa-feature\":\"numa\",\"mandatory\":\"False\",\"score\":\"5\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numaNodes\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numaCpu-0\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numaMem-0\",\"hpa-attribute-value\":\"2048\",\"operator\":\"=\",\"unit\":\"MB\"},{\"hpa-attribute-key\":\"numaCpu-1\",\"hpa-attribute-value\":\"4\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numaMem-1\",\"value\":\"4096\",\"operator\":\"=\",\"unit\":\"MB\"}]},{\"hpa-feature\":\"basicCapabilities\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numVirtualCpu\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"virtualMemSize\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"GB\"}]},{\"hpa-feature\":\"hugePages\",\"mandatory\":\"False\",\"score\":\"7\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"memoryPageSize\",\"hpa-attribute-value\":\"<MEMORYPAGESIZE>\",\"operator\":\"=\",\"unit\":\"\"}]}]}]}}", - "policyName": "oofBeijing.Config_MS_hpaPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "hpaPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"VnfPolicy\",\"policyName\":\"oofBeijing.vnfPolicy_vG\",\"description\":\"vnfPolicy\",\"templateVersion\":\"1702.03\",\"version\":\"oofBeijing\",\"priority\":\"6\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"identity\":\"vnf_vG\",\"policyScope\":[\"vcpe\",\"PVT Homing\",\"international\",\"ip\",\"vG\"],\"policyType\":\"vnf_policy\",\"resources\":[\"vG\"],\"applicableResources\":\"any\",\"vnfProperties\":[{\"inventoryProvider\":\"aai\",\"serviceType\":\"\",\"inventoryType\":\"cloud\",\"customerId\":\"\"},{\"inventoryProvider\":\"multicloud\",\"serviceType\":\"HNGATEWAY\",\"inventoryType\":\"service\",\"customerId\":\"21014aa2-526b-11e6-beb8-9e71128cae77\"}]}}", - "policyName": "oofBeijing.Config_MS_vnfPolicy_vG.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "VnfPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"VnfPolicy\",\"policyName\":\"oofBeijing.vnfPolicy_vGMuxInfra\",\"description\":\"vnfPolicy\",\"templateVersion\":\"1702.03\",\"version\":\"oofBeijing\",\"priority\":\"6\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"identity\":\"vnf_vGMuxInfra\",\"policyScope\":[\"vcpe\",\"PVT Homing\",\"international\",\"ip\",\"vGMuxInfra\"],\"policyType\":\"vnf_policy\",\"resources\":[\"vGMuxInfra\"],\"applicableResources\":\"any\",\"vnfProperties\":[{\"inventoryProvider\":\"aai\",\"serviceType\":\"\",\"inventoryType\":\"cloud\",\"customerId\":\"\"},{\"inventoryProvider\":\"multicloud\",\"serviceType\":\"HNGATEWAY\",\"inventoryType\":\"service\",\"customerId\":\"21014aa2-526b-11e6-beb8-9e71128cae77\"}]}}", - "policyName": "oofBeijing.Config_MS_vnfPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "VnfPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"distancePolicy\",\"policyName\":\"oofBeijing.distancePolicy_vG\",\"description\":\"Distance Policy for vG\",\"templateVersion\":\"0.0.1\",\"version\":\"oofBeijing\",\"priority\":\"3\",\"riskType\":\"test\",\"riskLevel\":\"2\",\"guard\":\"False\",\"content\":{\"distanceProperties\":{\"locationInfo\":\"customer_location\",\"distance\":{\"value\":\"1500\",\"operator\":\"<\",\"unit\":\"km\"}},\"identity\":\"distance-vG\",\"resources\":[\"vG\"],\"policyScope\":[\"vcpe\",\"PVT Homing\",\"us\",\"international\",\"ip\",\"vG\"],\"policyType\":\"distancePolicy\",\"applicableResources\":\"any\"}}", - "policyName": "oofBeijing.Config_MS_distancePolicy_vG.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "distancePolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\": \"capacityPolicy\", \"policyName\": \"oofBeijing.capacityPolicy_vG\", \"description\": \"Capacity policy for vG\", \"templateVersion\": \"1702.03\", \"version\": \"oofBeijing\", \"priority\": \"5\", \"riskType\": \"test\", \"riskLevel\": \"2\", \"guard\": \"False\", \"content\": {\"identity\": \"capacity_vG\", \"policyScope\": [\"vcpe\", \"PVT Homing\",\"us\", \"international\", \"ip\", \"vG\", \"vim_fit\"], \"resources\": [\"vG\"], \"capacityProperty\": {\"controller\": \"multicloud\", \"request\": \"{\\\"vCPU\\\": 10, \\\"Memory\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_MEM\\\"}, \\\"unit\\\": \\\"GB\\\"}, \\\"Storage\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_DISK\\\", \\\"unit\\\": \\\"GB\\\"}}}\"}, \"policyType\": \"vim_fit\", \"applicableResources\": \"any\"}}", - "policyName": "oofBeijing.Config_MS_capacityPolicy_vG.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "capacityPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\": \"optimizationQueryPolicy\", \"policyName\": \"oofBeijing.queryPolicy_vcpe\", \"description\": \"Optimization query policy for vcpe\", \"templateVersion\": \"0.0.1\", \"version\": \"oofBeijing\", \"priority\": \"3\", \"riskType\": \"test\", \"riskLevel\": \"2\", \"guard\": \"False\", \"content\": {\"queryProperties\": [{\"attribute\": \"locationId\", \"attribute_location\": \"customerLocation\", \"value\": \"\"}, {\"attribute\": \"id\", \"attribute_location\": \"vpnInfo.vpnId\", \"value\": \"\"}, {\"attribute\": \"upstreamBW\", \"attribute_location\": \"vpnInfo.upstreamBW\", \"value\": \"\"}, {\"attribute\": \"customerLatitude\", \"attribute_location\": \"customerLatitude\", \"value\": 32.89748}, {\"attribute\": \"customerLongitude\", \"attribute_location\": \"customerLongitude\", \"value\": -97.040443}], \"policyScope\": [\"vcpe\", \"PVT Homing\",\"us\", \"international\", \"ip\", \"vGMuxInfra\", \"vG\", \"optimizationQueryPolicy\"], \"policyType\": \"optimizationQueryPolicy\"}}", - "policyName": "oofBeijing.Config_MS_queryPolicy_vcpe.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "optimizationQueryPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"PlacementOptimizationPolicy\",\"policyName\":\"oofBeijing.PlacementOptimizationPolicy_vGMuxInfra\",\"description\":\"Placement Optimization Policy for vGMuxInfra\",\"templateVersion\":\"1702.03\",\"version\":\"oofBeijing\",\"priority\":\"5\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"objectiveParameter\":{\"parameterAttributes\":[{\"resource\":[\"vGMuxInfra\"],\"customerLocationInfo\":\"customer_loc\",\"parameter\":\"distance\",\"weight\":\"1\",\"operator\":\"product\"},{\"resource\":[\"vG\"],\"customerLocationInfo\":\"customer_loc\",\"parameter\":\"distance\",\"weight\":\"1\",\"operator\":\"product\"}],\"operator\":\"sum\"},\"identity\":\"optimization\",\"policyScope\":[\"vcpe\",\"PVT Homing\",\"us\",\"international\",\"ip\",\"vGMuxInfra\",\"vG\"],\"policyType\":\"placementOptimization\",\"objective\":\"minimize\"}}", - "policyName": "oofBeijing.Config_MS_PlacementOptimizationPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "PlacementOptimizationPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"distancePolicy\",\"policyName\":\"oofBeijing.distancePolicy_vGMuxInfra\",\"description\":\"Distance Policy for vGMuxInfra\",\"templateVersion\":\"0.0.1\",\"version\":\"oofBeijing\",\"priority\":\"3\",\"riskType\":\"test\",\"riskLevel\":\"2\",\"guard\":\"False\",\"content\":{\"distanceProperties\":{\"locationInfo\":\"customer_location\",\"distance\":{\"value\":\"500\",\"operator\":\"<\",\"unit\":\"km\"}},\"identity\":\"distance-vGMuxInfra\",\"resources\":[\"vGMuxInfra\"],\"policyScope\":[\"vcpe\",\"PVT Homing\",\"us\",\"international\",\"ip\",\"vGMuxInfra\"],\"policyType\":\"distancePolicy\",\"applicableResources\":\"any\"}}", - "policyName": "oofBeijing.Config_MS_distancePolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "distancePolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\": \"capacityPolicy\", \"policyName\": \"oofBeijing.capacityPolicy_vGMuxInfra\", \"description\": \"Capacity policy for vGMuxInfra\", \"templateVersion\": \"1702.03\", \"version\": \"oofBeijing\", \"priority\": \"5\", \"riskType\": \"test\", \"riskLevel\": \"2\", \"guard\": \"False\", \"content\": {\"identity\": \"capacity_vGMuxInfra\", \"policyScope\": [\"vcpe\", \"PVT Homing\",\"us\", \"international\", \"ip\", \"vGMuxInfra\", \"vim_fit\"], \"resources\": [\"vGMuxInfra\"], \"capacityProperty\": {\"controller\": \"multicloud\", \"request\": \"{\\\"vCPU\\\": 10, \\\"Memory\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_MEM\\\"}, \\\"unit\\\": \\\"GB\\\"}, \\\"Storage\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_DISK\\\", \\\"unit\\\": \\\"GB\\\"}}}\"}, \"policyType\": \"vim_fit\", \"applicableResources\": \"any\"}}", - "policyName": "oofBeijing.Config_MS_capacityPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "capacityPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null + "policies": { + "OSDF_FRANKFURT.SubscriberPolicy_v1": { + "type": "onap.policies.optimization.SubscriberPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.SubscriberPolicy_v1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "identity": "subscriber_vCPE", + "properties": { + "subscriberName": [ + "subscriber_x", + "subscriber_y" + ], + "subscriberRole": [ + "PVT Homing" + ], + "provStatus": [ + "CAPPED" + ] + } + } + }, + "OSDF_FRANKFURT.vnfPolicy_vG": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vG", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vnf_vG", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "serviceType": "", + "inventoryType": "cloud", + "customerId": "", + "orchestrationStatus": "", + "equipmentRole": "" + } + ] + } + }, + "OSDF_FRANKFURT.vnfPolicy_vGMuxInfra": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vnf_vGMuxInfra", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "serviceType": "vGMuxInfra-xx", + "inventoryType": "service", + "customerId": "SDN-ETHERNET-INTERNET", + "orchestrationStatus": "", + "equipmentRole": "" + } + ] + } + }, + "OSDF_FRANKFURT.Distance_vG_1": { + "type": "onap.policies.optimization.DistancePolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Distance_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "distance-vG", + "applicableResources": "any", + "distanceProperties": { + "locationInfo": "customer_loc", + "distance": { + "value": "1500", + "operator": "<", + "unit": "km" + } + } + } + }, + "OSDF_FRANKFURT.Distance_vGMuxInfra": { + "type": "onap.policies.optimization.DistancePolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Distance_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "distance-vGMuxInfra", + "applicableResources": "any", + "distanceProperties": { + "locationInfo": "customer_loc", + "distance": { + "value": "500", + "operator": "<", + "unit": "km" + } + } + } + }, + "OSDF_FRANKFURT.Placement_optimization_1": { + "type": "onap.policies.optimization.OptimizationPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Placement_optimization_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG", + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "optimization", + "objective": "minimize", + "objectiveParameter": { + "parameterAttributes": [ + { + "resources": [ + "vGMuxInfra" + ], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "1", + "operator": "product" + }, + { + "resources": [ + "vG" + ], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "1", + "operator": "product" + }, + { + "resources": [ + "vG" + ], + "parameter": "hpa_score", + "weight": "200", + "operator": "product" + }, + { + "resources": [ + "vFW" + ], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "100", + "operator": "product" + }, + { + "resources": [ + "vFW" + ], + "parameter": "hpa_score", + "weight": "200", + "operator": "product" + } + ], + "operator": "sum" + } + } + }, + "OSDF_FRANKFURT.queryPolicy_vCPE": { + "type": "onap.policies.optimization.QueryPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.queryPolicy_vCPE", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra", + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vCPE_Query_Policy", + "queryProperties": [ + { + "attribute": "customerLatitude", + "attribute_location": "customerLatitude" + }, + { + "attribute": "customerLongitude", + "attribute_location": "customerLongitude" + } + ] + } + }, + "OSDF_FRANKFURT.hpa_policy_vG_1": { + "type": "onap.policies.optimization.HpaPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.hpa_policy_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "hpa-vG", + "flavorFeatures": [ + { + "id": "vg_1", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_01", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature": "cpuTopology", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numCpuSockets", + "hpa-attribute-value": "2", + "operator": ">=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuSockets", + "hpa-attribute-value": "4", + "operator": "<=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuCores", + "hpa-attribute-value": "2", + "operator": ">=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuCores", + "hpa-attribute-value": "4", + "operator": "<=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuThreads", + "hpa-attribute-value": "4", + "operator": ">=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuThreads", + "hpa-attribute-value": "8", + "operator": "<=", + "unit": "" + } + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": true, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "ovsDpdk", + "mandatory": false, + "score": 3, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "ovsDpdk_version", + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "cpuInstructionSetExtensions", + "mandatory": true, + "architecture": "INTEL-64", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "instructionSetExtensions", + "hpa-attribute-value": [ + "<CPUINST>", + "<CPUINST>" + ], + "operator": [ + "ALL" + ], + "unit": "" + } + ] + } + ] + }, + { + "id": "vg_2", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_02", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature": "cpuPinningy", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "logicalCpuThreadPinningPolicy", + "hpa-attribute-value": "<CPUTHREADPOLICY>", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "logicalCpuPinningPolicy", + "hpa-attribute-value": "<CPUPOLICY>", + "operator": "=", + "unit": "" + } + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "GB" + } + ] + }, + { + "hpa-feature": "localStorage", + "mandatory": "False", + "score": "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "diskSize", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "GB" + }, + { + "hpa-attribute-key": "ephemeralDiskSize", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "GB" + }, + { + "hpa-attribute-key": "swapMemSize", + "hpa-attribute-value": "16", + "operator": "=", + "unit": "MB" + } + ] + }, + { + "hpa-feature": "pciePassthrough", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "8086", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + } + ] + } + ] + }, + { + "id": "vg_3", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_03", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature": "numa", + "mandatory": "False", + "score": "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numaNodes", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "numaCpu-0", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "numaMem-0", + "hpa-attribute-value": "2048", + "operator": "=", + "unit": "MB" + }, + { + "hpa-attribute-key": "numaCpu-1", + "hpa-attribute-value": "4", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "numaMem-1", + "value": "4096", + "operator": "=", + "unit": "MB" + } + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "GB" + } + ] + }, + { + "hpa-feature": "hugePages", + "mandatory": "False", + "score": "7", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "memoryPageSize", + "hpa-attribute-value": "<MEMORYPAGESIZE>", + "operator": "=", + "unit": "" + } + ] + } + ] + } + ] + } + }, + "OSDF_FRANKFURT.Capacity_vG_1": { + "type": "onap.policies.optimization.Vim_fit", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Capacity_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "capacity_vG", + "applicableResources": "any", + "capacityProperty": { + "controller": "multicloud", + "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}" + } + } + }, + "OSDF_FRANKFURT.Capacity_vGMuxInfra": { + "type": "onap.policies.optimization.Vim_fit", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Capacity_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "capacity_vGMuxInfra", + "applicableResources": "any", + "capacityProperty": { + "controller": "multicloud", + "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}" + } + } + } + } } -]
\ No newline at end of file diff --git a/test/placement-tests/policy_response2.json b/test/placement-tests/policy_response2.json index 2cd6dcb..15ddbe1 100644 --- a/test/placement-tests/policy_response2.json +++ b/test/placement-tests/policy_response2.json @@ -1,182 +1,705 @@ -[ - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"SubscriberPolicy\",\"policyName\":\"oofBeijing.SubscriberPolicy_v1\",\"description\":\"Subscriber Policy\",\"templateVersion\":\"0.0.1\",\"version\":\"oofBeijing\",\"priority\":\"1\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"identity\":\"subscriber\",\"policyScope\":[\"vCPE\",\"PVT Homing\",\"SubscriberPolicy\",\"subscriber_x\",\"subscriber_y\"],\"properties\":{\"subscriberName\":[\"subscriber_x\",\"subscriber_y\"],\"subscriberRole\":[\"PVT Homing\"],\"provStatus\":[\"CAPPED\"]},\"policyType\":\"SubscriberPolicy\"}}", - "policyName": "oofBeijing.Config_MS_SubscriberPolicy_v1.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "SubscriberPolicy", - "uuid": "", - "Location": "" +{ + "policies": { + "OSDF_FRANKFURT.SubscriberPolicy_v1": { + "type": "onap.policies.optimization.SubscriberPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.SubscriberPolicy_v1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "identity": "subscriber_vCPE", + "properties": { + "subscriberName": [ + "subscriber_x", + "subscriber_y" + ], + "subscriberRole": [ + "PVT Homing" + ], + "provStatus": [ + "CAPPED" + ] + } + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"hpaPolicy\",\"policyName\":\"oofBeijing.hpaPolicy_vGMuxInfra\",\"description\":\"HPA policy for vGMuxInfra\",\"templateVersion\":\"0.0.1\",\"version\":\"1.0\",\"priority\":\"3\",\"riskType\":\"test\",\"riskLevel\":\"2\",\"guard\":\"False\",\"content\":{\"resources\":\"vGMuxInfra\",\"identity\":\"hpaPolicy_vGMuxInfra\",\"policyScope\":[\"vCPE\",\"PVT Homing\",\"US\",\"INTERNATIONAL\",\"ip\",\"vGMuxInfra\"],\"policyType\":\"hpaPolicy\",\"flavorFeatures\":[{\"flavorLabel\":\"flavor_label_vm_01\",\"flavorProperties\":[{\"hpa-feature\":\"cpuTopology\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numCpuSockets\",\"hpa-attribute-value\":\"2\",\"operator\":\">=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuSockets\",\"hpa-attribute-value\":\"4\",\"operator\":\"<=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuCores\",\"hpa-attribute-value\":\"2\",\"operator\":\">=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuCores\",\"hpa-attribute-value\":\"4\",\"operator\":\"<=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuThreads\",\"hpa-attribute-value\":\"4\",\"operator\":\">=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numCpuThreads\",\"hpa-attribute-value\":\"8\",\"operator\":\"<=\",\"unit\":\"\"}]},{\"hpa-feature\":\"basicCapabilities\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numVirtualCpu\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"virtualMemSize\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"GB\"}]},{\"hpa-feature\":\"ovsDpdk\",\"mandatory\":\"False\",\"score\":\"3\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"dataProcessingAccelerationLibrary\",\"hpa-attribute-value\":\"ovsDpdk_version\",\"operator\":\"=\",\"unit\":\"\"}]},{\"hpa-feature\":\"cpuInstructionSetExtensions\",\"mandatory\":\"True\",\"architecture\":\"INTEL-64\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"instructionSetExtensions\",\"hpa-attribute-value\":[\"<CPUINST>\",\"<CPUINST>\"],\"operator\":\"ALL\",\"unit\":\"\"}]}]},{\"flavorLabel\":\"flavor_label_vm_02\",\"flavorProperties\":[{\"hpa-feature\":\"cpuPinningy\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"logicalCpuThreadPinningPolicy\",\"hpa-attribute-value\":\"<CPUTHREADPOLICY>\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"logicalCpuPinningPolicy\",\"hpa-attribute-value\":\"<CPUPOLICY>\",\"operator\":\"=\",\"unit\":\"\"}]},{\"hpa-feature\":\"basicCapabilities\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numVirtualCpu\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"virtualMemSize\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"GB\"}]},{\"hpa-feature\":\"localStorage\",\"mandatory\":\"False\",\"score\":\"5\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"diskSize\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"GB\"},{\"hpa-attribute-key\":\"ephemeralDiskSize\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"GB\"},{\"hpa-attribute-key\":\"swapMemSize\",\"hpa-attribute-value\":\"16\",\"operator\":\"=\",\"unit\":\"MB\"}]},{\"hpa-feature\":\"pcie\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"pciCount\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"pciVendorId\",\"hpa-attribute-value\":\"8086\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"pciDeviceId\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"functionType\",\"hpa-attribute-value\":\"<PCITYPEVALUE>\",\"operator\":\"=\",\"unit\":\"\"}]}]},{\"flavorLabel\":\"flavor_label_vm_03\",\"flavorProperties\":[{\"hpa-feature\":\"numa\",\"mandatory\":\"False\",\"score\":\"5\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numaNodes\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numaCpu-0\",\"hpa-attribute-value\":\"2\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numaMem-0\",\"hpa-attribute-value\":\"2048\",\"operator\":\"=\",\"unit\":\"MB\"},{\"hpa-attribute-key\":\"numaCpu-1\",\"hpa-attribute-value\":\"4\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"numaMem-1\",\"value\":\"4096\",\"operator\":\"=\",\"unit\":\"MB\"}]},{\"hpa-feature\":\"basicCapabilities\",\"mandatory\":\"True\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"numVirtualCpu\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"\"},{\"hpa-attribute-key\":\"virtualMemSize\",\"hpa-attribute-value\":\"6\",\"operator\":\"=\",\"unit\":\"GB\"}]},{\"hpa-feature\":\"hugePages\",\"mandatory\":\"False\",\"score\":\"7\",\"architecture\":\"generic\",\"hpa-feature-attributes\":[{\"hpa-attribute-key\":\"memoryPageSize\",\"hpa-attribute-value\":\"<MEMORYPAGESIZE>\",\"operator\":\"=\",\"unit\":\"\"}]}]}]}}", - "policyName": "oofBeijing.Config_MS_hpaPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "hpaPolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.vnfPolicy_vG": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vG", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vnf_vG", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "serviceType": "", + "inventoryType": "cloud", + "customerId": "", + "orchestrationStatus": "", + "equipmentRole": "" + } + ] + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"VnfPolicy\",\"policyName\":\"oofBeijing.vnfPolicy_vG\",\"description\":\"vnfPolicy\",\"templateVersion\":\"1702.03\",\"version\":\"oofBeijing\",\"priority\":\"6\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"identity\":\"vnf_vG\",\"policyScope\":[\"vCPE\",\"INTERNATIONAL\",\"ip\",\"vG\"],\"policyType\":\"vnf_policy\",\"resources\":[\"vG\"],\"applicableResources\":\"any\",\"vnfProperties\":[{\"inventoryProvider\":\"aai\",\"serviceType\":\"\",\"inventoryType\":\"cloud\",\"customerId\":\"\"},{\"inventoryProvider\":\"multicloud\",\"serviceType\":\"HNGATEWAY\",\"inventoryType\":\"service\",\"customerId\":\"21014aa2-526b-11e6-beb8-9e71128cae77\"}]}}", - "policyName": "oofBeijing.Config_MS_vnfPolicy_vG.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "VnfPolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.vnfPolicy_vGMuxInfra": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vnf_vGMuxInfra", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "serviceType": "vGMuxInfra-xx", + "inventoryType": "service", + "customerId": "SDN-ETHERNET-INTERNET", + "orchestrationStatus": "", + "equipmentRole": "" + } + ] + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"VnfPolicy\",\"policyName\":\"oofBeijing.vnfPolicy_vGMuxInfra\",\"description\":\"vnfPolicy\",\"templateVersion\":\"1702.03\",\"version\":\"oofBeijing\",\"priority\":\"6\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"identity\":\"vnf_vGMuxInfra\",\"policyScope\":[\"vCPE\",\"INTERNATIONAL\",\"ip\",\"vGMuxInfra\"],\"policyType\":\"vnf_policy\",\"resources\":[\"vGMuxInfra\"],\"applicableResources\":\"any\",\"vnfProperties\":[{\"inventoryProvider\":\"aai\",\"serviceType\":\"\",\"inventoryType\":\"cloud\",\"customerId\":\"\"},{\"inventoryProvider\":\"multicloud\",\"serviceType\":\"HNGATEWAY\",\"inventoryType\":\"service\",\"customerId\":\"21014aa2-526b-11e6-beb8-9e71128cae77\"}]}}", - "policyName": "oofBeijing.Config_MS_vnfPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "VnfPolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.Distance_vG_1": { + "type": "onap.policies.optimization.DistancePolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Distance_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "distance-vG", + "applicableResources": "any", + "distanceProperties": { + "locationInfo": "customer_loc", + "distance": { + "value": "1500", + "operator": "<", + "unit": "km" + } + } + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"distancePolicy\",\"policyName\":\"oofBeijing.distancePolicy_vG\",\"description\":\"Distance Policy for vG\",\"templateVersion\":\"0.0.1\",\"version\":\"oofBeijing\",\"priority\":\"3\",\"riskType\":\"test\",\"riskLevel\":\"2\",\"guard\":\"False\",\"content\":{\"distanceProperties\":{\"locationInfo\":\"customer_location\",\"distance\":{\"value\":\"1500\",\"operator\":\"<\",\"unit\":\"km\"}},\"identity\":\"distance-vG\",\"resources\":[\"vG\"],\"policyScope\":[\"vCPE\",\"US\",\"INTERNATIONAL\",\"ip\",\"vG\"],\"policyType\":\"distancePolicy\",\"applicableResources\":\"any\"}}", - "policyName": "oofBeijing.Config_MS_distancePolicy_vG.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "distancePolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.Distance_vGMuxInfra": { + "type": "onap.policies.optimization.DistancePolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Distance_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "distance-vGMuxInfra", + "applicableResources": "any", + "distanceProperties": { + "locationInfo": "customer_loc", + "distance": { + "value": "500", + "operator": "<", + "unit": "km" + } + } + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\": \"capacityPolicy\", \"policyName\": \"oofBeijing.capacityPolicy_vG\", \"description\": \"Capacity policy for vG\", \"templateVersion\": \"1702.03\", \"version\": \"oofBeijing\", \"priority\": \"5\", \"riskType\": \"test\", \"riskLevel\": \"2\", \"guard\": \"False\", \"content\": {\"identity\": \"capacity_vG\", \"policyScope\": [\"VCPE\",\"US\", \"INTERNATIONAL\", \"ip\", \"vG\", \"vim_fit\"], \"resources\": [\"vG\"], \"capacityProperty\": {\"controller\": \"multicloud\", \"request\": \"{\\\"vCPU\\\": 10, \\\"Memory\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_MEM\\\"}, \\\"unit\\\": \\\"GB\\\"}, \\\"Storage\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_DISK\\\", \\\"unit\\\": \\\"GB\\\"}}}\"}, \"policyType\": \"vim_fit\", \"applicableResources\": \"any\"}}", - "policyName": "oofBeijing.Config_MS_capacityPolicy_vG.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "capacityPolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.Placement_optimization_1": { + "type": "onap.policies.optimization.OptimizationPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Placement_optimization_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG", + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "optimization", + "objective": "minimize", + "objectiveParameter": { + "parameterAttributes": [ + { + "resources": [ + "vGMuxInfra" + ], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "1", + "operator": "product" + }, + { + "resources": [ + "vG" + ], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "1", + "operator": "product" + }, + { + "resources": [ + "vG" + ], + "parameter": "hpa_score", + "weight": "200", + "operator": "product" + }, + { + "resources": [ + "vFW" + ], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "100", + "operator": "product" + }, + { + "resources": [ + "vFW" + ], + "parameter": "hpa_score", + "weight": "200", + "operator": "product" + } + ], + "operator": "sum" + } + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\": \"optimizationQueryPolicy\", \"policyName\": \"oofBeijing.queryPolicy_vCPE\", \"description\": \"Optimization query policy for vCPE\", \"templateVersion\": \"0.0.1\", \"version\": \"oofBeijing\", \"priority\": \"3\", \"riskType\": \"test\", \"riskLevel\": \"2\", \"guard\": \"False\", \"content\": {\"queryProperties\": [{\"attribute\": \"locationId\", \"attribute_location\": \"customerLocation\", \"value\": \"\"}, {\"attribute\": \"id\", \"attribute_location\": \"vpnInfo.vpnId\", \"value\": \"\"}, {\"attribute\": \"upstreamBW\", \"attribute_location\": \"vpnInfo.upstreamBW\", \"value\": \"\"}, {\"attribute\": \"customerLatitude\", \"attribute_location\": \"customerLatitude\", \"value\": 32.89748}, {\"attribute\": \"customerLongitude\", \"attribute_location\": \"customerLongitude\", \"value\": -97.040443}], \"policyScope\": [\"vCPE\",\"US\", \"INTERNATIONAL\", \"ip\", \"vGMuxInfra\", \"vG\", \"optimizationQueryPolicy\"], \"policyType\": \"optimizationQueryPolicy\"}}", - "policyName": "oofBeijing.Config_MS_queryPolicy_vCPE.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "optimizationQueryPolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.queryPolicy_vCPE": { + "type": "onap.policies.optimization.QueryPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.queryPolicy_vCPE", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra", + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vCPE_Query_Policy", + "queryProperties": [ + { + "attribute": "customerLatitude", + "attribute_location": "customerLatitude" + }, + { + "attribute": "customerLongitude", + "attribute_location": "customerLongitude" + } + ] + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"PlacementOptimizationPolicy\",\"policyName\":\"oofBeijing.PlacementOptimizationPolicy_vGMuxInfra\",\"description\":\"Placement Optimization Policy for vGMuxInfra\",\"templateVersion\":\"1702.03\",\"version\":\"oofBeijing\",\"priority\":\"5\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"objectiveParameter\":{\"parameterAttributes\":[{\"resource\":[\"vGMuxInfra\"],\"customerLocationInfo\":\"customer_loc\",\"parameter\":\"distance\",\"weight\":\"1\",\"operator\":\"product\"},{\"resource\":[\"vG\"],\"customerLocationInfo\":\"customer_loc\",\"parameter\":\"distance\",\"weight\":\"1\",\"operator\":\"product\"}],\"operator\":\"sum\"},\"identity\":\"optimization\",\"policyScope\":[\"vCPE\",\"US\",\"INTERNATIONAL\",\"ip\",\"vGMuxInfra\",\"vG\"],\"policyType\":\"placementOptimization\",\"objective\":\"minimize\"}}", - "policyName": "oofBeijing.Config_MS_PlacementOptimizationPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "PlacementOptimizationPolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.hpa_policy_vG_1": { + "type": "onap.policies.optimization.HpaPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.hpa_policy_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "hpa-vG", + "flavorFeatures": [ + { + "id": "vg_1", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_01", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature": "cpuTopology", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numCpuSockets", + "hpa-attribute-value": "2", + "operator": ">=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuSockets", + "hpa-attribute-value": "4", + "operator": "<=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuCores", + "hpa-attribute-value": "2", + "operator": ">=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuCores", + "hpa-attribute-value": "4", + "operator": "<=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuThreads", + "hpa-attribute-value": "4", + "operator": ">=", + "unit": "" + }, + { + "hpa-attribute-key": "numCpuThreads", + "hpa-attribute-value": "8", + "operator": "<=", + "unit": "" + } + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": true, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "ovsDpdk", + "mandatory": false, + "score": 3, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "ovsDpdk_version", + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "cpuInstructionSetExtensions", + "mandatory": true, + "architecture": "INTEL-64", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "instructionSetExtensions", + "hpa-attribute-value": [ + "<CPUINST>", + "<CPUINST>" + ], + "operator": [ + "ALL" + ], + "unit": "" + } + ] + } + ] + }, + { + "id": "vg_2", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_02", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature": "cpuPinningy", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "logicalCpuThreadPinningPolicy", + "hpa-attribute-value": "<CPUTHREADPOLICY>", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "logicalCpuPinningPolicy", + "hpa-attribute-value": "<CPUPOLICY>", + "operator": "=", + "unit": "" + } + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "GB" + } + ] + }, + { + "hpa-feature": "localStorage", + "mandatory": "False", + "score": "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "diskSize", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "GB" + }, + { + "hpa-attribute-key": "ephemeralDiskSize", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "GB" + }, + { + "hpa-attribute-key": "swapMemSize", + "hpa-attribute-value": "16", + "operator": "=", + "unit": "MB" + } + ] + }, + { + "hpa-feature": "pciePassthrough", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "8086", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + } + ] + } + ] + }, + { + "id": "vg_3", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_03", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature": "numa", + "mandatory": "False", + "score": "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numaNodes", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "numaCpu-0", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "numaMem-0", + "hpa-attribute-value": "2048", + "operator": "=", + "unit": "MB" + }, + { + "hpa-attribute-key": "numaCpu-1", + "hpa-attribute-value": "4", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "numaMem-1", + "value": "4096", + "operator": "=", + "unit": "MB" + } + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "6", + "operator": "=", + "unit": "GB" + } + ] + }, + { + "hpa-feature": "hugePages", + "mandatory": "False", + "score": "7", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "memoryPageSize", + "hpa-attribute-value": "<MEMORYPAGESIZE>", + "operator": "=", + "unit": "" + } + ] + } + ] + } + ] + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"distancePolicy\",\"policyName\":\"oofBeijing.distancePolicy_vGMuxInfra\",\"description\":\"Distance Policy for vGMuxInfra\",\"templateVersion\":\"0.0.1\",\"version\":\"oofBeijing\",\"priority\":\"3\",\"riskType\":\"test\",\"riskLevel\":\"2\",\"guard\":\"False\",\"content\":{\"distanceProperties\":{\"locationInfo\":\"customer_location\",\"distance\":{\"value\":\"500\",\"operator\":\"<\",\"unit\":\"km\"}},\"identity\":\"distance-vGMuxInfra\",\"resources\":[\"vGMuxInfra\"],\"policyScope\":[\"vCPE\",\"US\",\"INTERNATIONAL\",\"ip\",\"vGMuxInfra\"],\"policyType\":\"distancePolicy\",\"applicableResources\":\"any\"}}", - "policyName": "oofBeijing.Config_MS_distancePolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "distancePolicy", - "uuid": "", - "Location": "" + "OSDF_FRANKFURT.Capacity_vG_1": { + "type": "onap.policies.optimization.Vim_fit", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Capacity_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "capacity_vG", + "applicableResources": "any", + "capacityProperty": { + "controller": "multicloud", + "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}" + } + } }, - "responseAttributes": { }, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\": \"capacityPolicy\", \"policyName\": \"oofBeijing.capacityPolicy_vGMuxInfra\", \"description\": \"Capacity policy for vGMuxInfra\", \"templateVersion\": \"1702.03\", \"version\": \"oofBeijing\", \"priority\": \"5\", \"riskType\": \"test\", \"riskLevel\": \"2\", \"guard\": \"False\", \"content\": {\"identity\": \"capacity_vGMuxInfra\", \"policyScope\": [\"VCPE\",\"US\", \"INTERNATIONAL\", \"ip\", \"vGMuxInfra\", \"vim_fit\"], \"resources\": [\"vGMuxInfra\"], \"capacityProperty\": {\"controller\": \"multicloud\", \"request\": \"{\\\"vCPU\\\": 10, \\\"Memory\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_MEM\\\"}, \\\"unit\\\": \\\"GB\\\"}, \\\"Storage\\\": {\\\"quantity\\\": {\\\"get_param\\\": \\\"REQUIRED_DISK\\\", \\\"unit\\\": \\\"GB\\\"}}}\"}, \"policyType\": \"vim_fit\", \"applicableResources\": \"any\"}}", - "policyName": "oofBeijing.Config_MS_capacityPolicy_vGMuxInfra.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ONAPName": "SNIRO-Placement", - "ConfigName": "", - "service": "capacityPolicy", - "uuid": "", - "Location": "" - }, - "responseAttributes": { }, - "property": null + "OSDF_FRANKFURT.Capacity_vGMuxInfra": { + "type": "onap.policies.optimization.Vim_fit", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Capacity_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "PVT Homing" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "capacity_vGMuxInfra", + "applicableResources": "any", + "capacityProperty": { + "controller": "multicloud", + "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}" + } + } + } } -]
\ No newline at end of file +} + diff --git a/test/placement-tests/request_placement_vfmod.json b/test/placement-tests/request_placement_vfmod.json index 4b2b852..5242ee7 100644 --- a/test/placement-tests/request_placement_vfmod.json +++ b/test/placement-tests/request_placement_vfmod.json @@ -93,7 +93,7 @@ }, "constraints": { "affinity_vFW_TD": { - "type": "zone", + "type": "onap.policies.optimization.AffinityPolicy", "demands": [ "vFW-SINK", "vPGN" diff --git a/test/placement-tests/test_by_scope.yaml b/test/placement-tests/test_by_scope.yaml index 2cdd4e4..1968b89 100644 --- a/test/placement-tests/test_by_scope.yaml +++ b/test/placement-tests/test_by_scope.yaml @@ -2,23 +2,32 @@ references: service_name: source: request value: serviceInfo.serviceName + resource: + source: request + value: placementInfo.placementDemands.resourceModuleName subscriber_role: - source: SubscriberPolicy - value: content.properties.subscriberRole + source: onap.policies.optimization.SubscriberPolicy + value: properties.properties.subscriberRole policy_info: placement: policy_fetch: by_scope policy_scope: - default_scope: OSDF_R2 - vcpe_scope: OSDF_R2 - secondary_scopes: - - - - get_param: service_name - - SubscriberPolicy - - + - + scope: + - OSDF_FRANKFURT + - onap.policies.optimization.SubscriberPolicy + service: - get_param: service_name + - + scope: + - OSDF_FRANKFURT - get_param: subscriber_role + service: + - get_param: service_name + # - + # - get_param: service_name + # - get_param: subscriber_role default: # if no explicit service related information is needed policy_fetch: by_name - policy_scope: none + policy_scope: none
\ No newline at end of file diff --git a/test/placement-tests/test_by_scope_org.yaml b/test/placement-tests/test_by_scope_org.yaml new file mode 100644 index 0000000..2cdd4e4 --- /dev/null +++ b/test/placement-tests/test_by_scope_org.yaml @@ -0,0 +1,24 @@ +references: + service_name: + source: request + value: serviceInfo.serviceName + subscriber_role: + source: SubscriberPolicy + value: content.properties.subscriberRole + +policy_info: + placement: + policy_fetch: by_scope + policy_scope: + default_scope: OSDF_R2 + vcpe_scope: OSDF_R2 + secondary_scopes: + - + - get_param: service_name + - SubscriberPolicy + - + - get_param: service_name + - get_param: subscriber_role + default: # if no explicit service related information is needed + policy_fetch: by_name + policy_scope: none diff --git a/test/policy-local-files/meta-valid-policies-org.txt b/test/policy-local-files/meta-valid-policies-org.txt new file mode 100644 index 0000000..99e3e88 --- /dev/null +++ b/test/policy-local-files/meta-valid-policies-org.txt @@ -0,0 +1,16 @@ +Affinity_vCPE_1.json +Capacity_vGMuxInfra.json +Capacity_vG_1.json +Distance_vGMuxInfra_1.json +Distance_vG_1.json +Placement_Optimization_1.json +QueryPolicy_vCPE.json +QueryPolicy_vCPE_2.json +hpa_policy_vGMuxInfra_1.json +hpa_policy_vG_1.json +vnfPolicy_vG.json +vnfPolicy_vGMuxInfra.json +QueryPolicy_vFW_TD.json +vnfPolicy_vFW_TD.json +vnfPolicy_vPGN_TD.json +affinity_vFW_TD.json
\ No newline at end of file diff --git a/test/policy-local-files/meta-valid-policies.txt b/test/policy-local-files/meta-valid-policies.txt index 99e3e88..53f113f 100644 --- a/test/policy-local-files/meta-valid-policies.txt +++ b/test/policy-local-files/meta-valid-policies.txt @@ -11,6 +11,3 @@ hpa_policy_vG_1.json vnfPolicy_vG.json vnfPolicy_vGMuxInfra.json QueryPolicy_vFW_TD.json -vnfPolicy_vFW_TD.json -vnfPolicy_vPGN_TD.json -affinity_vFW_TD.json
\ No newline at end of file diff --git a/test/policy-local-files/new_policies/Affinity_vCPE_1.json b/test/policy-local-files/new_policies/Affinity_vCPE_1.json new file mode 100644 index 0000000..4f111eb --- /dev/null +++ b/test/policy-local-files/new_policies/Affinity_vCPE_1.json @@ -0,0 +1,33 @@ +{ + "OSDF_FRANKFURT.Affinity_vCPE_1": { + "type": "onap.policies.optimization.AffinityPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Affinity_vCPE_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG", + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "affinity_vCPE", + "applicableResources": "any", + "affinityProperties": { + "qualifier": "same", + "category": "complex" + } + } + } +} diff --git a/test/policy-local-files/new_policies/Affinity_vFW_TD.json b/test/policy-local-files/new_policies/Affinity_vFW_TD.json new file mode 100644 index 0000000..53bb31b --- /dev/null +++ b/test/policy-local-files/new_policies/Affinity_vFW_TD.json @@ -0,0 +1,31 @@ +{ + "OSDF_FRANKFURT.Affinity_vFW_TD": { + "type": "onap.policies.optimization.AffinityPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Affinity_vFW_TD", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "TD" + ], + "resources": [ + "vFW-SINK", + "vPGN" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "affinity_vFW_TD", + "applicableResources": "any", + "affinityProperties": { + "qualifier": "same", + "category": "region" + } + } + } +} diff --git a/test/policy-local-files/new_policies/Capacity_vGMuxInfra.json b/test/policy-local-files/new_policies/Capacity_vGMuxInfra.json new file mode 100644 index 0000000..1d6d26d --- /dev/null +++ b/test/policy-local-files/new_policies/Capacity_vGMuxInfra.json @@ -0,0 +1,32 @@ +{ + "OSDF_FRANKFURT.Capacity_vGMuxInfra": { + "type": "onap.policies.optimization.Vim_fit", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Capacity_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "capacity_vGMuxInfra", + "applicableResources": "any", + "capacityProperty": { + "controller": "multicloud", + "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}" + } + } + } +} diff --git a/test/policy-local-files/new_policies/Capacity_vG_1.json b/test/policy-local-files/new_policies/Capacity_vG_1.json new file mode 100644 index 0000000..f07e7bc --- /dev/null +++ b/test/policy-local-files/new_policies/Capacity_vG_1.json @@ -0,0 +1,32 @@ +{ + "OSDF_FRANKFURT.Capacity_vG_1": { + "type": "onap.policies.optimization.Vim_fit", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Capacity_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "capacity_vG", + "applicableResources": "any", + "capacityProperty": { + "controller": "multicloud", + "request": "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}" + } + } + } +} diff --git a/test/policy-local-files/new_policies/Distance_vGMuxInfra_1.json b/test/policy-local-files/new_policies/Distance_vGMuxInfra_1.json new file mode 100644 index 0000000..7de102e --- /dev/null +++ b/test/policy-local-files/new_policies/Distance_vGMuxInfra_1.json @@ -0,0 +1,36 @@ +{ + "OSDF_FRANKFURT.Distance_vGMuxInfra": { + "type": "onap.policies.optimization.DistancePolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Distance_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "distance-vGMuxInfra", + "applicableResources": "any", + "distanceProperties": { + "locationInfo": "customer_loc", + "distance": { + "value": "500", + "operator": "<", + "unit": "km" + } + } + } + } +} diff --git a/test/policy-local-files/new_policies/Distance_vG_1.json b/test/policy-local-files/new_policies/Distance_vG_1.json new file mode 100644 index 0000000..dcb45b2 --- /dev/null +++ b/test/policy-local-files/new_policies/Distance_vG_1.json @@ -0,0 +1,36 @@ +{ + "OSDF_FRANKFURT.Distance_vG_1": { + "type": "onap.policies.optimization.DistancePolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Distance_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "distance-vG", + "applicableResources": "any", + "distanceProperties": { + "locationInfo": "customer_loc", + "distance": { + "value": "1500", + "operator": "<", + "unit": "km" + } + } + } + } +} diff --git a/test/policy-local-files/new_policies/Placement_Optimization_1.json b/test/policy-local-files/new_policies/Placement_Optimization_1.json new file mode 100644 index 0000000..b3efa64 --- /dev/null +++ b/test/policy-local-files/new_policies/Placement_Optimization_1.json @@ -0,0 +1,67 @@ +{ + "OSDF_FRANKFURT.Placement_optimization_1": { + "type": "onap.policies.optimization.OptimizationPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Placement_optimization_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG", + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "optimization", + "objective": "minimize", + "objectiveParameter": { + "parameterAttributes": [ + { + "resources": ["vGMuxInfra"], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "1", + "operator": "product" + }, + { + "resources": ["vG"], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "1", + "operator": "product" + }, + { + "resources": ["vG"], + "parameter": "hpa_score", + "weight": "200", + "operator": "product" + }, + { + "resources": ["vFW"], + "customerLocationInfo": "customer_loc", + "parameter": "distance", + "weight": "100", + "operator": "product" + }, + { + "resources": ["vFW"], + "parameter": "hpa_score", + "weight": "200", + "operator": "product" + } + ], + "operator": "sum" + } + } + } +} diff --git a/test/policy-local-files/new_policies/QueryPolicy_vCPE.json b/test/policy-local-files/new_policies/QueryPolicy_vCPE.json new file mode 100644 index 0000000..1a8d205 --- /dev/null +++ b/test/policy-local-files/new_policies/QueryPolicy_vCPE.json @@ -0,0 +1,38 @@ +{ + "OSDF_FRANKFURT.queryPolicy_vCPE": { + "type": "onap.policies.optimization.QueryPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.queryPolicy_vCPE", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra", + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vCPE_Query_Policy", + "queryProperties": [ + { + "attribute": "customerLatitude", + "attribute_location": "customerLatitude" + }, + { + "attribute": "customerLongitude", + "attribute_location": "customerLongitude" + } + ] + } + } +} diff --git a/test/policy-local-files/new_policies/QueryPolicy_vCPE_2.json b/test/policy-local-files/new_policies/QueryPolicy_vCPE_2.json new file mode 100644 index 0000000..7a4d227 --- /dev/null +++ b/test/policy-local-files/new_policies/QueryPolicy_vCPE_2.json @@ -0,0 +1,55 @@ +{ + "OSDF_FRANKFURT.queryPolicy_vCPE": { + "type": "onap.policies.optimization.QueryPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.queryPolicy_vCPE", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra", + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vCPE_Query_Policy", + "queryProperties": [ + { + "attribute": "locationId", + "attribute_location": "customerLocation", + "value": "" + }, + { + "attribute": "id", + "attribute_location": "vpnInfo.vpnId", + "value": "" + }, + { + "attribute": "upstreamBW", + "attribute_location": "vpnInfo.upstreamBW", + "value": "" + }, + { + "attribute": "customerLatitude", + "attribute_location": "customerLatitude", + "value": 1.1 + }, + { + "attribute": "customerLongitude", + "attribute_location": "customerLongitude", + "value": 2.2 + } + ] + } + } +} diff --git a/test/policy-local-files/new_policies/QueryPolicy_vFW_TD.json b/test/policy-local-files/new_policies/QueryPolicy_vFW_TD.json new file mode 100644 index 0000000..1a6eb21 --- /dev/null +++ b/test/policy-local-files/new_policies/QueryPolicy_vFW_TD.json @@ -0,0 +1,47 @@ +{ + "OSDF_FRANKFURT.queryPolicy_vFW_TD": { + "type": "onap.policies.optimization.QueryPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.queryPolicy_vFW_TD", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vFW_TD" + ], + "resources": [ + "vFW-SINK", + "vPGN" + ], + "geography": [ + "US" + ], + "identity": "vFW_TD_Query_Policy", + "queryProperties": [ + { + "attribute": "chosen_region", + "attribute_location": "chosenRegion" + }, + { + "attribute": "chosen_customer_id", + "attribute_location": "chosenCustomerId" + }, + { + "attribute": "customerLatitude", + "attribute_location": "customerLatitude", + "value": 1.1 + }, + { + "attribute": "customerLongitude", + "attribute_location": "customerLongitude", + "value": 2.2 + } + ] + } + } +} diff --git a/test/policy-local-files/new_policies/hpa_policy_vGMuxInfra_1.json b/test/policy-local-files/new_policies/hpa_policy_vGMuxInfra_1.json new file mode 100644 index 0000000..c233c5f --- /dev/null +++ b/test/policy-local-files/new_policies/hpa_policy_vGMuxInfra_1.json @@ -0,0 +1,231 @@ +{ + "OSDF_FRANKFURT.hpa_policy_vGMuxInfra_1": { + "type": "onap.policies.optimization.HpaPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.hpa_policy_vGMuxInfra_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "hpa-vGMuxInfra", + "flavorFeatures": [ + { + "id": "vgmux_1", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_01", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature" : "cpuTopology", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key":"numCpuSockets", "hpa-attribute-value": "2","operator": ">=", "unit": ""}, + {"hpa-attribute-key":"numCpuSockets", "hpa-attribute-value": "4","operator": "<=", "unit": ""}, + {"hpa-attribute-key":"numCpuCores", "hpa-attribute-value": "2", "operator":">=", "unit": ""}, + {"hpa-attribute-key":"numCpuCores", "hpa-attribute-value": "4", "operator":"<=", "unit": ""}, + {"hpa-attribute-key":"numCpuThreads", "hpa-attribute-value": "4", "operator":">=", "unit": ""}, + {"hpa-attribute-key":"numCpuThreads", "hpa-attribute-value": "8", "operator":"<=", "unit": ""} + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": true, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "ovsDpdk", + "mandatory": false, + "score": 3, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "ovsDpdk_version", + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "cpuInstructionSetExtensions", + "mandatory": true, + "architecture": "INTEL-64", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "instructionSetExtensions", + "hpa-attribute-value": [ + "<CPUINST>", + "<CPUINST>" + ], + "operator": [ + "ALL" + ], + "unit": "" + } + ] + } + ] + }, + { + "id": "vgmux_2", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_02", + "attribute_value": "" + } + ] + } + ], + "flavorProperties":[ + { + "hpa-feature" : "cpuPinningy", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key":"logicalCpuThreadPinningPolicy", "hpa-attribute-value":"<CPUTHREADPOLICY>", "operator": "=", "unit":""}, + {"hpa-attribute-key":"logicalCpuPinningPolicy", "hpa-attribute-value": "<CPUPOLICY>","operator": "=", "unit":""} + ] + }, + { + "hpa-feature" : "basicCapabilities", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "numVirtualCpu", "hpa-attribute-value": "6", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "virtualMemSize", "hpa-attribute-value":"6", "operator": "=", "unit": "GB"} + ] + }, + { + "hpa-feature" : "localStorage", + "mandatory" : "False", + "score" : "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "diskSize", "hpa-attribute-value": "2", "operator": "=", "unit": "GB"}, + {"hpa-attribute-key": "ephemeralDiskSize", "hpa-attribute-value": "2", "operator": "=", "unit": "GB"}, + {"hpa-attribute-key": "swapMemSize", "hpa-attribute-value":"16", "operator": "=", "unit": "MB"} + ] + }, + { + "hpa-feature" : "pciePassthrough", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "pciCount", "hpa-attribute-value": "2", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "pciVendorId", "hpa-attribute-value":"8086", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "pciDeviceId", "hpa-attribute-value": "2", "operator": "=", "unit": ""} + ] + } +] + }, + { + "id": "vgmux_3", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_03", + "attribute_value": "" + } + ] + } + ], + "flavorProperties":[ + { + "hpa-feature" : "numa", + "mandatory" : "False", + "score" : "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "numaNodes", "hpa-attribute-value": "2", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "numaCpu-0", "hpa-attribute-value":"2", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "numaMem-0", "hpa-attribute-value": "2048", "operator": "=", "unit": "MB"}, + {"hpa-attribute-key": "numaCpu-1", "hpa-attribute-value":"4", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "numaMem-1", "value": "4096", "operator": "=", "unit": "MB"} + ] +}, + { + "hpa-feature" : "basicCapabilities", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "numVirtualCpu", "hpa-attribute-value": "6", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "virtualMemSize", "hpa-attribute-value":"6", "operator": "=", "unit": "GB"} + ] + }, + { + "hpa-feature" : "hugePages", + "mandatory" : "False", + "score" : "7", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "memoryPageSize", "hpa-attribute-value": "<MEMORYPAGESIZE>", "operator": "=", "unit": ""} + ] + } + ] + } + ] + } + } +} diff --git a/test/policy-local-files/new_policies/hpa_policy_vG_1.json b/test/policy-local-files/new_policies/hpa_policy_vG_1.json new file mode 100644 index 0000000..4f9a7b4 --- /dev/null +++ b/test/policy-local-files/new_policies/hpa_policy_vG_1.json @@ -0,0 +1,231 @@ +{ + "OSDF_FRANKFURT.hpa_policy_vG_1": { + "type": "onap.policies.optimization.HpaPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.hpa_policy_vG_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "hpa-vG", + "flavorFeatures": [ + { + "id": "vg_1", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_01", + "attribute_value": "" + } + ] + } + ], + "flavorProperties": [ + { + "hpa-feature" : "cpuTopology", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key":"numCpuSockets", "hpa-attribute-value": "2","operator": ">=", "unit": ""}, + {"hpa-attribute-key":"numCpuSockets", "hpa-attribute-value": "4","operator": "<=", "unit": ""}, + {"hpa-attribute-key":"numCpuCores", "hpa-attribute-value": "2", "operator":">=", "unit": ""}, + {"hpa-attribute-key":"numCpuCores", "hpa-attribute-value": "4", "operator":"<=", "unit": ""}, + {"hpa-attribute-key":"numCpuThreads", "hpa-attribute-value": "4", "operator":">=", "unit": ""}, + {"hpa-attribute-key":"numCpuThreads", "hpa-attribute-value": "8", "operator":"<=", "unit": ""} + ] + }, + { + "hpa-feature": "basicCapabilities", + "mandatory": true, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": 6, + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "ovsDpdk", + "mandatory": false, + "score": 3, + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "ovsDpdk_version", + "operator": [ + "=" + ], + "unit": "" + } + ] + }, + { + "hpa-feature": "cpuInstructionSetExtensions", + "mandatory": true, + "architecture": "INTEL-64", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "instructionSetExtensions", + "hpa-attribute-value": [ + "<CPUINST>", + "<CPUINST>" + ], + "operator": [ + "ALL" + ], + "unit": "" + } + ] + } + ] + }, + { + "id": "vg_2", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_02", + "attribute_value": "" + } + ] + } + ], + "flavorProperties":[ + { + "hpa-feature" : "cpuPinningy", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key":"logicalCpuThreadPinningPolicy", "hpa-attribute-value":"<CPUTHREADPOLICY>", "operator": "=", "unit":""}, + {"hpa-attribute-key":"logicalCpuPinningPolicy", "hpa-attribute-value": "<CPUPOLICY>","operator": "=", "unit":""} + ] + }, + { + "hpa-feature" : "basicCapabilities", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "numVirtualCpu", "hpa-attribute-value": "6", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "virtualMemSize", "hpa-attribute-value":"6", "operator": "=", "unit": "GB"} + ] + }, + { + "hpa-feature" : "localStorage", + "mandatory" : "False", + "score" : "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "diskSize", "hpa-attribute-value": "2", "operator": "=", "unit": "GB"}, + {"hpa-attribute-key": "ephemeralDiskSize", "hpa-attribute-value": "2", "operator": "=", "unit": "GB"}, + {"hpa-attribute-key": "swapMemSize", "hpa-attribute-value":"16", "operator": "=", "unit": "MB"} + ] + }, + { + "hpa-feature" : "pciePassthrough", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "pciCount", "hpa-attribute-value": "2", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "pciVendorId", "hpa-attribute-value":"8086", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "pciDeviceId", "hpa-attribute-value": "2", "operator": "=", "unit": ""} + ] + } +] + }, + { + "id": "vg_3", + "type": "vnfc", + "directives": [ + { + "type": "flavor_directives", + "attributes": [ + { + "attribute_name": "flavor_label_vm_03", + "attribute_value": "" + } + ] + } + ], + "flavorProperties":[ + { + "hpa-feature" : "numa", + "mandatory" : "False", + "score" : "5", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "numaNodes", "hpa-attribute-value": "2", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "numaCpu-0", "hpa-attribute-value":"2", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "numaMem-0", "hpa-attribute-value": "2048", "operator": "=", "unit": "MB"}, + {"hpa-attribute-key": "numaCpu-1", "hpa-attribute-value":"4", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "numaMem-1", "value": "4096", "operator": "=", "unit": "MB"} + ] +}, + { + "hpa-feature" : "basicCapabilities", + "mandatory" : "True", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "numVirtualCpu", "hpa-attribute-value": "6", "operator": "=", "unit": ""}, + {"hpa-attribute-key": "virtualMemSize", "hpa-attribute-value":"6", "operator": "=", "unit": "GB"} + ] + }, + { + "hpa-feature" : "hugePages", + "mandatory" : "False", + "score" : "7", + "architecture": "generic", + "directives": [], + "hpa-feature-attributes": [ + {"hpa-attribute-key": "memoryPageSize", "hpa-attribute-value": "<MEMORYPAGESIZE>", "operator": "=", "unit": ""} + ] + } + ] + } + ] + } + } +} diff --git a/test/policy-local-files/new_policies/meta-valid-policies.txt b/test/policy-local-files/new_policies/meta-valid-policies.txt new file mode 100644 index 0000000..7f5a007 --- /dev/null +++ b/test/policy-local-files/new_policies/meta-valid-policies.txt @@ -0,0 +1,16 @@ +Affinity_vCPE_1.json +Capacity_vGMuxInfra.json +Capacity_vG_1.json +Distance_vGMuxInfra_1.json +Distance_vG_1.json +Placement_Optimization_1.json +QueryPolicy_vCPE.json +QueryPolicy_vCPE_2.json +hpa_policy_vGMuxInfra_1.json +hpa_policy_vG_1.json +vnfPolicy_vG.json +vnfPolicy_vGMuxInfra.json +QueryPolicy_vFW_TD.json +vnfPolicy_vFW_TD.json +vnfPolicy_vPGN_TD.json +Affinity_vFW_TD.json diff --git a/test/policy-local-files/new_policies/subscriber_policy_vCPE.json b/test/policy-local-files/new_policies/subscriber_policy_vCPE.json new file mode 100644 index 0000000..305ce58 --- /dev/null +++ b/test/policy-local-files/new_policies/subscriber_policy_vCPE.json @@ -0,0 +1,32 @@ +{ + "OSDF_FRANKFURT.SubscriberPolicy_v1": { + "type": "onap.policies.optimization.SubscriberPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.SubscriberPolicy_v1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "identity": "subscriber_vCPE", + "properties": { + "subscriberName": [ + "subscriber_x", + "subscriber_y" + ], + "subscriberRole": [ + "PVT Homing" + ], + "provStatus": [ + "CAPPED" + ] + } + } + } +} diff --git a/test/policy-local-files/new_policies/vnfPolicy_vFW_TD.json b/test/policy-local-files/new_policies/vnfPolicy_vFW_TD.json new file mode 100644 index 0000000..387ed56 --- /dev/null +++ b/test/policy-local-files/new_policies/vnfPolicy_vFW_TD.json @@ -0,0 +1,47 @@ +{ + "OSDF_FRANKFURT.vnfPolicy_vFW_TD": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vFW_TD", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "TD" + ], + "resources": [ + "vFW-SINK" + ], + "geography": [ + "US" + ], + "identity": "vnf_vFW_TD", + "applicableResources": "any", + "vnfProperties": [{ + "inventoryProvider": "aai", + "serviceType": "", + "inventoryType": "vfmodule", + "customerId": { + "get_param": "chosen_customer_id" + }, + "equipmentRole": "", + "attributes": { + "orchestrationStatus": ["active"], + "provStatus": "ACTIVE", + "cloudRegionId": { + "get_param": "chosen_region" + }, + "service_instance_id": { + "get_param": "service_id" + } + }, + "passthroughAttributes": { + "td-role": "destination" + } + }] + } + } +} diff --git a/test/policy-local-files/new_policies/vnfPolicy_vG.json b/test/policy-local-files/new_policies/vnfPolicy_vG.json new file mode 100644 index 0000000..786ffc2 --- /dev/null +++ b/test/policy-local-files/new_policies/vnfPolicy_vG.json @@ -0,0 +1,38 @@ +{ + "OSDF_FRANKFURT.vnfPolicy_vG": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vG", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vG" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vnf_vG", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "serviceType": "", + "inventoryType": "cloud", + "customerId": "", + "orchestrationStatus": "", + "equipmentRole": "" + } + ] + } + } +} diff --git a/test/policy-local-files/new_policies/vnfPolicy_vGMuxInfra.json b/test/policy-local-files/new_policies/vnfPolicy_vGMuxInfra.json new file mode 100644 index 0000000..deb34fd --- /dev/null +++ b/test/policy-local-files/new_policies/vnfPolicy_vGMuxInfra.json @@ -0,0 +1,38 @@ +{ + "OSDF_FRANKFURT.vnfPolicy_vGMuxInfra": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vGMuxInfra", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT" + ], + "services": [ + "vCPE" + ], + "resources": [ + "vGMuxInfra" + ], + "geography": [ + "US", + "INTERNATIONAL" + ], + "identity": "vnf_vGMuxInfra", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "serviceType": "vGMuxInfra-xx", + "inventoryType": "service", + "customerId": "SDN-ETHERNET-INTERNET", + "orchestrationStatus": "", + "equipmentRole": "" + } + ] + } + } +} diff --git a/test/policy-local-files/new_policies/vnfPolicy_vPGN_TD.json b/test/policy-local-files/new_policies/vnfPolicy_vPGN_TD.json new file mode 100644 index 0000000..c441156 --- /dev/null +++ b/test/policy-local-files/new_policies/vnfPolicy_vPGN_TD.json @@ -0,0 +1,52 @@ +{ + "OSDF_FRANKFURT.vnfPolicy_vPGN_TD": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_vPGN_TD", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "TD" + ], + "resources": [ + "vPGN" + ], + "geography": [ + "US" + ], + "identity": "vnf_vPGN_TD", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "serviceType": "", + "inventoryType": "vfmodule", + "customerId": { + "get_param": "chosen_customer_id" + }, + "equipmentRole": "", + "unique": "False", + "attributes": { + "orchestrationStatus": [ + "active" + ], + "provStatus": "ACTIVE", + "cloudRegionId": { + "get_param": "chosen_region" + }, + "service_instance_id": { + "get_param": "service_id" + } + }, + "passthroughAttributes": { + "td-role": "anchor" + } + } + ] + } + } +} diff --git a/test/test_ConductorApiBuilder.py b/test/test_ConductorApiBuilder.py index 07cb3bb..1be0a4b 100644 --- a/test/test_ConductorApiBuilder.py +++ b/test/test_ConductorApiBuilder.py @@ -30,7 +30,7 @@ class TestConductorApiBuilder(unittest.TestCase): self.main_dir = "" self.conductor_api_template = self.main_dir + "apps/placement/templates/conductor_interface.json" self.local_config_file = self.main_dir + "config/common_config.yaml" - policy_data_path = self.main_dir + "test/policy-local-files" # "test/policy-local-files" + policy_data_path = self.main_dir + "test/policy-local-files/new_policies" # "test/policy-local-files" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' valid_policies_files = local_policies.get_policy_names_from_file(valid_policies_list_file) diff --git a/test/test_PolicyCalls.py b/test/test_PolicyCalls.py index e7e8eab..4358eeb 100644 --- a/test/test_PolicyCalls.py +++ b/test/test_PolicyCalls.py @@ -33,7 +33,7 @@ class TestPolicyCalls(unittest.TestCase): def setUp(self): main_dir = "" parameter_data_file = main_dir + "test/placement-tests/request.json" - policy_data_path = main_dir + "test/policy-local-files/" + policy_data_path = main_dir + "test/policy-local-files/new_policies/" local_config_file = main_dir + "config/common_config.yaml" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' @@ -63,7 +63,7 @@ class TestPolicyCalls(unittest.TestCase): "test/placement-tests/policy_response2.json") with patch('osdf.adapters.policy.interface.policy_api_call', return_value=policy_response): policy_list = interface.remote_api(req_json, osdf_config, service_type="placement") - policy_type = [policy['content']['policyType'] for policy in policy_list] + policy_type = [policy[list(policy.keys())[0]]['type'] for policy in policy_list] #self.assertEqual(set(policy_type), {'hpaPolicy', 'SubscriberPolicy'}) def failure_policy_call(self, req_json_file, resp_json_file): @@ -99,7 +99,8 @@ class TestPolicyCalls(unittest.TestCase): req_json = "./test/placement-tests/request.json" req_json = json.loads(open(req_json).read()) # need to run this only on vnf policies - vnf_policies = [x for x in self.policies if x["content"]["policyType"] == "vnfPolicy"] + vnf_policies = [x for x in self.policies if x[list(x.keys())[0]]["type"] == + "onap.policies.optimization.VnfPolicy"] gen_demands = translation.gen_demands(req_json, vnf_policies) for action in req_json['placementInfo']['placementDemands']: actions_list.append(action['resourceModuleName']) diff --git a/test/test_get_opt_query_data.py b/test/test_get_opt_query_data.py index a7a4d88..06dfbf9 100644 --- a/test/test_get_opt_query_data.py +++ b/test/test_get_opt_query_data.py @@ -25,7 +25,7 @@ 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/" + policy_data_path = main_dir + "test/policy-local-files/new_policies/" query_policy_data_file = ["QueryPolicy_vCPE.json"] request_json = json.loads(open(parameter_data_file).read()) @@ -37,7 +37,7 @@ class TestGetOptQueryData(unittest.TestCase): def test_get_opt_query_data_vfmod(self): main_dir = "" parameter_data_file = main_dir + "test/placement-tests/request_vfmod.json" - policy_data_path = main_dir + "test/policy-local-files/" + policy_data_path = main_dir + "test/policy-local-files/new_policies/" query_policy_data_file = ["QueryPolicy_vFW_TD.json"] request_json = json.loads(open(parameter_data_file).read()) diff --git a/test/test_model_api.py b/test/test_model_api.py new file mode 100644 index 0000000..2a1cecf --- /dev/null +++ b/test/test_model_api.py @@ -0,0 +1,71 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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 +import os + +import pytest +from mock import patch +from schematics.exceptions import DataError + +from runtime.model_api import create_model_data, get_model_data, delete_model_data, retrieve_all_models +from runtime.models.api.model_request import OptimModelRequestAPI +from runtime.optim_engine import validate_request + +BASE_DIR = os.path.dirname(__file__) + +ret_val = {'modelId': 'test', 'description': 'desc', 'solver': 'mzn'} + + +class TestModelApi(): + + def test_valid_mapi_request(self): + req_json = json.loads(open("./test/optengine-tests/test_modelapi_valid.json").read()) + + assert OptimModelRequestAPI(req_json).validate() is None + + def test_invalid_mapi_request(self): + req_json = json.loads(open("./test/optengine-tests/test_modelapi_invalid.json").read()) + with pytest.raises(DataError): + validate_request(req_json) + + @patch('runtime.model_api.build_model_dict') + @patch('mysql.connector.connect') + @patch('runtime.model_api.osdf_config') + def test_create_model(self, config, conn, model_data): + model_data.return_value = ret_val + req_json = json.loads(open("./test/optengine-tests/test_modelapi_valid.json").read()) + + create_model_data(req_json) + + @patch('runtime.model_api.build_model_dict') + @patch('mysql.connector.connect') + @patch('runtime.model_api.osdf_config') + def test_retrieve_model(self, config, conn, model_data): + model_data.return_value = ret_val + get_model_data('test') + + @patch('mysql.connector.connect') + @patch('runtime.model_api.osdf_config') + def test_delete_model(self, config, conn): + delete_model_data('test') + + @patch('mysql.connector.connect') + @patch('runtime.model_api.osdf_config') + def test_retrieve_all_model(self, config, conn): + retrieve_all_models() diff --git a/test/test_optim_engine.py b/test/test_optim_engine.py new file mode 100644 index 0000000..e1756f8 --- /dev/null +++ b/test/test_optim_engine.py @@ -0,0 +1,78 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2020 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 +import os + +import pytest +from mock import patch +from schematics.exceptions import DataError + +from osdf.operation.exceptions import BusinessException +from runtime.optim_engine import validate_request, process_request + +BASE_DIR = os.path.dirname(__file__) + + +class TestOptimEngine(): + + def test_valid_optim_request(self): + req_json = json.loads(open("./test/optengine-tests/test_optengine_valid.json").read()) + + assert validate_request(req_json) == True + + def test_invalid_optim_request(self): + req_json = json.loads(open("./test/optengine-tests/test_optengine_invalid.json").read()) + with pytest.raises(DataError): + validate_request(req_json) + + def test_invalid_optim_request_without_modelid(self): + req_json = json.loads(open("./test/optengine-tests/test_optengine_invalid2.json").read()) + with pytest.raises(BusinessException): + validate_request(req_json) + + def test_invalid_optim_request_no_optdata(self): + req_json = json.loads(open("./test/optengine-tests/test_optengine_no_optdata.json").read()) + with pytest.raises(BusinessException): + validate_request(req_json) + + def test_process_request(self): + req_json = json.loads(open("./test/optengine-tests/test_optengine_valid.json").read()) + + res = process_request(req_json) + assert res.status_code == 400 + + def test_py_process_request(self): + req_json = json.loads(open("./test/optengine-tests/test_py_optengine_valid.json").read()) + + res = process_request(req_json) + assert res.status_code == 200 + + def test_invalid_solver(self): + req_json = json.loads(open("./test/optengine-tests/test_optengine_invalid_solver.json").read()) + + with pytest.raises(BusinessException): + process_request(req_json) + + @patch('runtime.optim_engine.get_model_data') + def test_process_solverid_request(self, mocker): + req_json = json.loads(open("./test/optengine-tests/test_optengine_modelId.json").read()) + + data = 200, ('junk', '', '', 'py') + mocker.return_value = data + process_request(req_json) @@ -17,13 +17,14 @@ commands = # TODO: need to update the above "omit" when we package osdf as pip-installable deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test/test-requirements.txt + -r{toxinidir}/requirements-opteng.txt [run] -source=./apps/,./osdf/,osdfapp.py +source=./apps/,./osdf/,osdfapp.py,./runtime/,solverapp.py [testenv:pylint] whitelist_externals=bash -commands = bash -c "pylint --reports=y osdf apps| tee pylint.out" +commands = bash -c "pylint --reports=y osdf apps runtime| tee pylint.out" [testenv:py3] basepython=python3.6 |