Disabling policy retrieval for pci opt 23/67923/4
authorVarma, Vikas <vv8305@att.com>
Wed, 19 Sep 2018 22:38:26 +0000 (18:38 -0400)
committerVarma, Vikas <vv8305@att.com>
Thu, 20 Sep 2018 11:33:49 +0000 (07:33 -0400)
Fixing the pci optimization response.
Disable policy retrieval until the policies are loaded.
Fix merge issues with optfapp.py

Change-Id: I2acb82aac1cd6d154abf37f58755016bc377e475
Signed-off-by: Varma, Vikas <vv8305@att.com>
Issue-ID: OPTFRA-342

config/osdf_config.yaml
osdf/__init__.py
osdf/optimizers/pciopt/pci_opt_processor.py
osdfapp.py
test/pci-optimization-tests/request.json

index 636b6ad..c484fb4 100755 (executable)
@@ -81,3 +81,7 @@ configDbGetNbrListUrl: 'SDNCConfigDBAPI/getNbrList'
 # Credentials for PCIHandler
 pciHMSUsername: ""   # pcihandler username for call back.
 pciHMSPassword: ""   # pcihandler password for call back.
+
+# Credentials for the OOF PCI Opt service
+osdfPCIOptUsername: pci_test
+osdfPCIOptPassword: pci_testpwd
index 5d15a85..c33639e 100755 (executable)
@@ -24,6 +24,7 @@ from jinja2 import Template
 end_point_auth_mapping = {  # map a URL endpoint to auth group
     "cmscheduler": "CMScheduler",
     "placement": "Placement",
+    "pci": "PCIOpt"
 }
 
 userid_suffix, passwd_suffix = "Username", "Password"
index 030128e..989f578 100644 (file)
@@ -20,7 +20,6 @@ import traceback
 from requests import RequestException
 
 from osdf.logging.osdf_logging import metrics_log, MH, error_log
-from osdf.models.api.pciOptimizationResponse import PCIOptimizationResponse, Solution, PCISolution
 from osdf.operation.error_handling import build_json_error_body
 from osdf.utils.interfaces import get_rest_client
 from .configdb import request as config_request
@@ -44,26 +43,9 @@ def process_pci_optimation(request_json, osdf_config, flat_policies):
     try:
         rc = get_rest_client(request_json, service="pcih")
         req_id = request_json["requestInfo"]["requestId"]
-        transaction_id = request_json['requestInfo']['transactionId']
         cell_info_list, network_cell_info = config_request(request_json, osdf_config, flat_policies)
 
-        pci_response = PCIOptimizationResponse()
-        pci_response.transactionId = transaction_id
-        pci_response.requestId = req_id
-        pci_response.requestStatus = 'success'
-        pci_response.solutions = Solution()
-        pci_response.solutions.networkId = request_json['cellInfo']['networkId']
-        pci_response.solutions.pciSolutions = []
-
-        for cell in request_json['cellInfo']['cellIdList']:
-            pci_solution = optimize(cell['cellId'], network_cell_info, cell_info_list)
-            error_log.error(pci_solution)
-            sol = pci_solution[0]['pci']
-            for k, v in sol.items():
-                response = PCISolution()
-                response.cellId = get_cell_id(network_cell_info, k)
-                response.pci = get_pci_value(network_cell_info, v)
-                pci_response.solutions.pciSolutions.append(response)
+        pci_response = get_solutions(cell_info_list, network_cell_info, request_json)
 
         metrics_log.info(MH.inside_worker_thread(req_id))
     except Exception as err:
@@ -82,3 +64,32 @@ def process_pci_optimation(request_json, osdf_config, flat_policies):
         rc.request(json=pci_response, noresponse=True)
     except RequestException:  # can't do much here but log it and move on
         error_log.error("Error sending asynchronous notification for {} {}".format(req_id, traceback.format_exc()))
+
+
+def get_solutions(cell_info_list, network_cell_info, request_json):
+    return {
+        "transactionId": request_json['requestInfo']['transactionId'],
+        "requestId": request_json["requestInfo"]["requestId"],
+        "requestStatus": "completed",
+        "statusMessage": "success",
+        "solutions": [
+            {
+                'networkId': request_json['cellInfo']['networkId'],
+                'pciSolutions': build_solution_list(cell_info_list, network_cell_info, request_json)
+            }
+        ]
+    }
+
+
+def build_solution_list(cell_info_list, network_cell_info, request_json):
+    solution_list = []
+    for cell in request_json['cellInfo']['cellIdList']:
+        opt_solution = optimize(cell, network_cell_info, cell_info_list)
+        sol = opt_solution[0]['pci']
+        for k, v in sol.items():
+            response = {
+                'cellId': get_cell_id(network_cell_info, k),
+                'pci': get_pci_value(network_cell_info, v)
+            }
+            solution_list.append(response)
+    return solution_list
index 1e076f1..b1819ee 100755 (executable)
@@ -180,15 +180,17 @@ def do_pci_optimization():
     g.request_id = req_id
     audit_log.info(MH.received_request(request.url, request.remote_addr, json.dumps(request_json)))
     PCIOptimizationAPI(request_json).validate()
-    policies = get_policies(request_json, "pciopt")
+    #disable policy retrieval
+    # policies = get_policies(request_json, "pciopt")
     audit_log.info(MH.new_worker_thread(req_id, "[for pciopt]"))
-    t = Thread(target=process_pci_optimation, args=(request_json, policies, osdf_config))
+    t = Thread(target=process_pci_optimation, args=(request_json, osdf_config, None))
     t.start()
     audit_log.info(MH.accepted_valid_request(req_id, request))
     return req_accept(request_id=req_id,
                       transaction_id=request_json['requestInfo']['transactionId'],
                       request_status="accepted", status_message="")
 
+
 @app.errorhandler(500)
 def internal_failure(error):
     """Returned when unexpected coding errors occur during initial synchronous processing"""
index 79c98c3..7ec9ab5 100644 (file)
@@ -14,9 +14,7 @@
   "cellInfo": {
     "networkId": "1000",
     "cellIdList": [
-      {
-        "cellId": "cell0"
-      }
+      "cell0"
     ]
   }
 }
\ No newline at end of file