aboutsummaryrefslogtreecommitdiffstats
path: root/apps/nxi_termination
diff options
context:
space:
mode:
authorkrishnaa96 <krishna.moorthy6@wipro.com>2021-09-09 16:23:17 +0530
committerkrishnaa96 <krishna.moorthy6@wipro.com>2021-10-04 21:13:51 +0530
commite35d4a1b94bbcd844300282d1c3c8722ef58062d (patch)
tree1e3db2313ba02a09feb48842852c8118547072f9 /apps/nxi_termination
parent92373ddd2e28cc2000a2634d273836fea5d87a6e (diff)
Support second level NSSI in terminate app
Issue-ID: OPTFRA-990 Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com> Change-Id: If47b19d18e5eb1cbef24418c7697e0770818959f
Diffstat (limited to 'apps/nxi_termination')
-rw-r--r--apps/nxi_termination/optimizers/remote_opt_processor.py59
1 files changed, 40 insertions, 19 deletions
diff --git a/apps/nxi_termination/optimizers/remote_opt_processor.py b/apps/nxi_termination/optimizers/remote_opt_processor.py
index 7878f5d..fc3bc17 100644
--- a/apps/nxi_termination/optimizers/remote_opt_processor.py
+++ b/apps/nxi_termination/optimizers/remote_opt_processor.py
@@ -21,6 +21,7 @@ from jinja2 import Template
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 execute_dsl_query
+from osdf.adapters.aai.fetch_aai_data import get_aai_data
from osdf.logging.osdf_logging import debug_log
@@ -42,25 +43,38 @@ def process_nxi_termination_opt(request_json, osdf_config):
}
try:
+ if request_type == "NSSI":
+ templates = query_templates["nssi"]
+ for template in templates:
+ resource_count = get_resource_count(template, inputs, osdf_config)
+ if resource_count == -1:
+ continue
+ elif resource_count > 1 or (resource_count == 1 and not addtnl_args.get("serviceInstanceId")):
+ terminate_response = False
+ elif resource_count == 0:
+ terminate_response = True
+ elif resource_count == 1 and addtnl_args.get("serviceInstanceId"):
+ new_template = template + "('service-instance-id','{}')".format(addtnl_args["serviceInstanceId"])
+ terminate_response = get_resource_count(new_template, inputs, osdf_config) == 1
+ return set_response("success", "", request_info, terminate_response)
+
if request_type == "NSI":
- query_type = "nsi"
- if addtnl_args and "serviceProfileId" in addtnl_args:
- inputs["profile_id"] = addtnl_args["serviceProfileId"]
- query_type = "nsi_with_profile"
- else:
- query_type = "nssi"
- if addtnl_args and "serviceInstanceId" in addtnl_args:
- inputs["nsi_id"] = addtnl_args["serviceInstanceId"]
- query_type = "nssi_with_nsi"
-
- debug_log.debug("query type: {}".format(query_type))
-
- resource_count = get_resource_count(query_templates[query_type], inputs, osdf_config)
- if query_type not in ["nsi", "nssi"]:
- # if additional args is provided, it must have exactly one resource in its relationships
- resource_count = resource_count - 1
-
- return set_response("success", "", request_info, resource_count <= 0)
+ allotted_resources = get_allotted_resources(request_json, osdf_config)
+ resource_count = len(allotted_resources)
+ if resource_count == 1 and addtnl_args.get("serviceInstanceId"):
+ debug_log.debug("resource count {}".format(resource_count))
+ terminate_response = False
+ properties = allotted_resources[0]["relationship-data"]
+ for property in properties:
+ if property["relationship-key"] == "service-instance.service-instance-id" \
+ and property["relationship-value"] == addtnl_args.get("serviceInstanceId"):
+ terminate_response = True
+ elif resource_count > 1 or (resource_count == 1 and not addtnl_args.get("serviceInstanceId")):
+ terminate_response = False
+ elif resource_count == 0:
+ terminate_response = True
+
+ return set_response("success", "", request_info, terminate_response)
except AAIException as e:
reason = str(e)
return set_response("failure", reason, request_info)
@@ -83,4 +97,11 @@ def get_resource_count(query_template, inputs, osdf_config):
dsl_response = execute_dsl_query(query, "count", osdf_config)
debug_log.debug("dsl_response {}".format(dsl_response))
# the dsl query with format "count" includes the original service-instance, hence reducing one from the result
- return dsl_response["results"][0]["service-instance"] - 1
+ count = dsl_response["results"][0]
+ return count.get("service-instance", 0) - 1
+
+
+def get_allotted_resources(request_json, osdf_config):
+ response = get_aai_data(request_json, osdf_config)
+ rel_list = response["relationship-list"]["relationship"]
+ return [rel for rel in rel_list if rel["related-to"] == "allotted-resource"]