summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorhariharan97 <rh20085046@wipro.com>2020-08-26 09:42:29 +0530
committerhariharan97 <rh20085046@wipro.com>2020-09-02 17:38:41 +0530
commit7b7cfac3d2ae636f63c0e94df1a7129f2d10cb54 (patch)
treeaefbb5da4319a5fe3bc7b4a2c8d6b2156201038b /apps
parent053c09a2ed1a8fc8aeef3f8185902634feec8000 (diff)
Add Nxi-Termination feature
Issue-ID: OPTFRA-825 Signed-off-by: hariharan97 <rh20085046@wipro.com> Change-Id: I0d768e36708e9f26e5bcdf661b2bcb5772ed48c2
Diffstat (limited to 'apps')
-rw-r--r--apps/nxi_termination/__init__.py0
-rw-r--r--apps/nxi_termination/models/api/_init_.py0
-rw-r--r--apps/nxi_termination/models/api/nxi_termination_request.py45
-rw-r--r--apps/nxi_termination/optimizers/__init__.py0
-rw-r--r--apps/nxi_termination/optimizers/remote_opt_processor.py123
-rw-r--r--apps/nxi_termination/optimizers/response_processor.py45
6 files changed, 213 insertions, 0 deletions
diff --git a/apps/nxi_termination/__init__.py b/apps/nxi_termination/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/nxi_termination/__init__.py
diff --git a/apps/nxi_termination/models/api/_init_.py b/apps/nxi_termination/models/api/_init_.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/nxi_termination/models/api/_init_.py
diff --git a/apps/nxi_termination/models/api/nxi_termination_request.py b/apps/nxi_termination/models/api/nxi_termination_request.py
new file mode 100644
index 0000000..45456cf
--- /dev/null
+++ b/apps/nxi_termination/models/api/nxi_termination_request.py
@@ -0,0 +1,45 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2020 Wipro Limited.
+#
+# 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 osdf.models.api.common import OSDFModel
+from schematics.types import BaseType
+from schematics.types.compound import DictType
+from schematics.types.compound import ModelType
+from schematics.types import IntType
+from schematics.types import StringType
+from schematics.types import URLType
+
+
+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()
+ addtnlArgs = DictType(BaseType)
+
+
+class NxiTerminationApi(OSDFModel):
+ """Request for nxi termination (specific to optimization and additional metadata"""
+ requestInfo = ModelType(RequestInfo, required=True)
+ type = StringType(required=True, choices=['NSI', 'NSSI'])
+ NxIId = StringType(required=True)
+ UUID = StringType()
+ invariantUUID = StringType()
diff --git a/apps/nxi_termination/optimizers/__init__.py b/apps/nxi_termination/optimizers/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/nxi_termination/optimizers/__init__.py
diff --git a/apps/nxi_termination/optimizers/remote_opt_processor.py b/apps/nxi_termination/optimizers/remote_opt_processor.py
new file mode 100644
index 0000000..8867c97
--- /dev/null
+++ b/apps/nxi_termination/optimizers/remote_opt_processor.py
@@ -0,0 +1,123 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2020 Wipro Limited.
+#
+# 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 apps.nxi_termination.optimizers.response_processor import get_nxi_termination_failure_response
+from apps.nxi_termination.optimizers.response_processor import get_nxi_termination_response
+from osdf.adapters.aai.fetch_aai_data import AAIException
+from osdf.adapters.aai.fetch_aai_data import get_aai_data
+
+
+def process_nxi_termination_opt(request_json, osdf_config):
+
+ """Process the nxi Termination request from API layer
+
+ :param request_json: api request
+ :param osdf_config: configuration specific to OSDF app
+ :return: response as a success,failure
+ """
+
+ type = request_json["type"]
+ request_info = request_json.get("requestInfo", {})
+ addtnl_args = request_info.get("addtnlArgs", {})
+ if type == "NSI":
+ arg_val = addtnl_args.get("serviceProfileId", "")
+ return check_nxi_termination(request_json, osdf_config, addtnl_args, arg_val,
+ get_service_profiles, get_service_profile_id)
+
+ else:
+ arg_val = addtnl_args.get("serviceInstanceId", "")
+ return check_nxi_termination(request_json, osdf_config, addtnl_args, arg_val, get_relationshiplist, get_nsi_id)
+
+
+def check_nxi_termination(request_json, osdf_config, addtnl_args, arg_val, get_response_object, get_response_id):
+ request_info = request_json.get("requestInfo", {})
+
+ try:
+ response_object = get_response_object(request_json, osdf_config)
+ if addtnl_args and arg_val and len(response_object) == 1:
+ response_id = get_response_id(response_object)
+ if arg_val == response_id:
+ reason = ''
+ return set_success_response(reason, request_info, terminate_response=True)
+
+ else:
+ reason = "{} is not available in AAI".format(arg_val)
+ return set_success_response(reason, request_info, terminate_response=False)
+
+ elif len(response_object) == 0:
+ reason = ''
+ return set_success_response(reason, request_info, terminate_response=True)
+
+ else:
+ reason = "Associated to more than one"
+ return set_success_response(reason, request_info, terminate_response=False)
+
+ except AAIException as e:
+ reason = str(e)
+ return set_failure_response(reason, request_info)
+
+ except Exception as e:
+ reason = "{} Exception Occurred while processing".format(str(e))
+ return set_failure_response(reason, request_info)
+
+
+def get_service_profiles(request_json, osdf_config):
+ try:
+ json_response = get_aai_data(request_json, osdf_config)
+ service_profiles = json_response.get("service-profiles", {})
+ service_profile = service_profiles.get("service-profile", [])
+ return service_profile
+ except AAIException as e:
+ raise AAIException(e)
+
+
+def get_relationshiplist(request_json, osdf_config):
+ try:
+ json_response = get_aai_data(request_json, osdf_config)
+ rel_list = json_response.get("relationship-list", {})
+ relationship = rel_list.get("relationship", [])
+ return relationship
+ except AAIException as e:
+ raise AAIException(e)
+
+
+def get_service_profile_id(service_profile):
+ profile_obj = service_profile[0]
+ return profile_obj.get("profile-id", "")
+
+
+def get_nsi_id(relationship):
+ rel_obj = relationship[0]
+ rel_data = rel_obj.get("relationship-data", [])
+ for data in rel_data:
+ if data["relationship-key"] == "service-instance.service-instance-id":
+ return data["relationship-value"]
+
+
+def set_success_response(reason, request_info, terminate_response):
+ res = dict()
+ res["requestStatus"] = "success"
+ res["terminateResponse"] = terminate_response
+ res["reason"] = reason
+ return get_nxi_termination_response(request_info, res)
+
+
+def set_failure_response(reason, request_info,):
+ res = dict()
+ res["requestStatus"] = "failure"
+ res["reason"] = reason
+ return get_nxi_termination_failure_response(request_info, res)
diff --git a/apps/nxi_termination/optimizers/response_processor.py b/apps/nxi_termination/optimizers/response_processor.py
new file mode 100644
index 0000000..e7f1041
--- /dev/null
+++ b/apps/nxi_termination/optimizers/response_processor.py
@@ -0,0 +1,45 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2020 Wipro Limited.
+#
+# 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.
+#
+# -------------------------------------------------------------------------
+#
+
+def get_nxi_termination_response(request_info, response):
+
+ """Get NXI termination response from final solution
+
+ :param request_info: request info
+ :param response: response to be send
+ :return: NxI Termination response to send back as dictionary
+ """
+ return {'requestId': request_info['requestId'],
+ 'transactionId': request_info['transactionId'],
+ 'requestStatus': response["requestStatus"],
+ 'terminateResponse': response["terminateResponse"],
+ 'reason': response['reason']}
+
+
+def get_nxi_termination_failure_response(request_info, response):
+
+ """Get NXI termination response from final solution
+
+ :param request_info: request info
+ :param response: response to be send
+ :return: NxI Termination response to send back as dictionary
+ """
+ return {'requestId': request_info['requestId'],
+ 'transactionId': request_info['transactionId'],
+ 'requestStatus': response["requestStatus"],
+ 'reason': response['reason']}