diff options
author | Vikas Varma <vikas.varma@att.com> | 2020-03-16 12:13:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-16 12:13:51 +0000 |
commit | bb6a43aeadc50bc5e0780c894fc756e7ee95ecf3 (patch) | |
tree | a085952b8b3ff77346fe26fad9018bedaebcb560 | |
parent | bfb0a45de2eaade4064c40d294fd56e89672d199 (diff) | |
parent | 5c8e0e4e54f8cfa3c1ec034ccb5b6f5c14eb0b50 (diff) |
Merge "take-1 for the NST selection function"
-rw-r--r-- | apps/nst/__init__.py | 0 | ||||
-rw-r--r-- | apps/nst/models/api/nstSelectionRequest.py | 48 | ||||
-rw-r--r-- | apps/nst/optimizers/__init__.py | 0 | ||||
-rw-r--r-- | apps/nst/optimizers/conf/configIinputs.json | 21 | ||||
-rw-r--r-- | apps/nst/optimizers/nst_select_processor.py | 79 | ||||
-rwxr-xr-x | osdfapp.py | 9 |
6 files changed, 157 insertions, 0 deletions
diff --git a/apps/nst/__init__.py b/apps/nst/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/apps/nst/__init__.py diff --git a/apps/nst/models/api/nstSelectionRequest.py b/apps/nst/models/api/nstSelectionRequest.py new file mode 100644 index 0000000..dcc385e --- /dev/null +++ b/apps/nst/models/api/nstSelectionRequest.py @@ -0,0 +1,48 @@ +# ------------------------------------------------------------------------- +# 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. +# 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, StringType, URLType, IntType +from schematics.types.compound import ModelType, ListType, DictType + +from osdf.models.api.common import OSDFModel +from osdf.logging.osdf_logging import MH, audit_log + +class RequestInfo(OSDFModel): + """Info for northbound request from client such as SO""" + transactionId = StringType(required=True) + requestId = StringType(required=True) + callbackUrl = URLType(required=True) + callbackHeader = DictType(BaseType) + sourceId = StringType(required=True) + timeout = IntType() + + +class ServiceProfile(OSDFModel): + """Information specific to ServiceProfile """ + # resourceName = StringType(required=True) + # resourceId = StringType(required=True) + serviceProfileParameters = DictType(BaseType) + + + + +class NSTSelectionAPI(OSDFModel): + """Request for NST selection """ + requestInfo = ModelType(RequestInfo, required=True) + serviceProfile = ModelType(ServiceProfile, required=True) + diff --git a/apps/nst/optimizers/__init__.py b/apps/nst/optimizers/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/apps/nst/optimizers/__init__.py diff --git a/apps/nst/optimizers/conf/configIinputs.json b/apps/nst/optimizers/conf/configIinputs.json new file mode 100644 index 0000000..59fd5ed --- /dev/null +++ b/apps/nst/optimizers/conf/configIinputs.json @@ -0,0 +1,21 @@ +{ + "NST": [{ + "NST1 ": { + "name": "NST_1", + "id": "NST_1_id", + "latency": 5, + "uplink": 5, + "downlink": 8 + } + }, + { + "NST2 ": { + "name": "NST_2", + "id": "NST_2_id", + "latency": 3, + "uplink": 7, + "downlink": 1 + } + } + ] +}
\ No newline at end of file diff --git a/apps/nst/optimizers/nst_select_processor.py b/apps/nst/optimizers/nst_select_processor.py new file mode 100644 index 0000000..c340a90 --- /dev/null +++ b/apps/nst/optimizers/nst_select_processor.py @@ -0,0 +1,79 @@ +# ------------------------------------------------------------------------- +# 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. +# 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 osdf.logging.osdf_logging import MH, audit_log +""" +This application generates NST SELECTION API calls using the information received from SO +""" + +def buildSolution(request_json): + return { + "NSTsolution" : getNSTSolution(request_json) + } + +def getNSTSolution(request_json): +# the file is in the same folder for now will move it to the conf folder o fthe has once its integrated there... + with open('./conf/configIinputs.json', 'r') as openfile: + serviceProfile = request_json["serviceProfile"] + resourceName = "NST" + serviceProfileParameters = serviceProfile["serviceProfileParameters"] + nst_object = json.load(openfile) + foundNst = False + for nst in nst_object[resourceName]: + [(nstName, nstList)] = nst.items() + matchall = False + for constraint_name in serviceProfileParameters: + value = serviceProfileParameters[constraint_name] + constraint_value= nstList[constraint_name] + if constraint_value != value: + matchall = False + break + else: + matchall = True + if matchall: + foundNst = True + NSTName = nstList["name"] + matchlevel = 1 + if not(foundNst): + NSTName = None + matchlevel = 0 + return { + "invariantUUID" : "INvariant UUID", + "UUID" : "uuid", + "NSTName" : NSTName, + "matchLevel" : matchlevel + } + + +def process_nst_selection( request_json, osdf_config): + """ + Process a PCI request from a Client (build config-db, policy and API call, make the call, return result) + :param req_object: Request parameters from the client + :param osdf_config: Configuration specific to OSDF application (core + deployment) + :return: response from NST Opt + """ + solution = buildSolution(request_json) + + return { + "requestId" : request_json['requestInfo']['requestId'], + "transactionId" : request_json['requestInfo']['transactionId'], + "statusMessage" : " ", + "requestStatus" : "accepted", + "solutions" : solution + }
\ No newline at end of file @@ -31,7 +31,9 @@ from threading import Thread # for scaling up, may need celery with RabbitMQ or from flask import request, g from osdf.apps.baseapp import app, run_app +from apps.nst.models.api.nstSelectionRequest import NSTSelectionAPI from apps.pci.models.api.pciOptimizationRequest import PCIOptimizationAPI +from apps.nst.optimizers.nst_select_processor import process_nst_selection from apps.pci.optimizers.pci_opt_processor import process_pci_optimation from apps.placement.models.api.placementRequest import PlacementAPI from apps.placement.optimizers.conductor.remote_opt_processor import process_placement_opt @@ -104,6 +106,13 @@ def do_route_calc(): response = RouteOpt().getRoute(request_json) return response +@app.route("/api/oof/v1/selection/nst", methods=["POST"]) +def do_nst_selection(): + request_json = request.get_json() + req_id = request_json['requestInfo']['requestId'] + NSTSelectionAPI(request_json).validate() + response = process_nst_selection(request_json, osdf_config) + return response @app.route("/api/oof/v1/pci", methods=["POST"]) @app.route("/api/oof/pci/v1", methods=["POST"]) |