osdf pci-opt response will have only the updates 00/73700/2
authorvrvarma <vv8305@att.com>
Tue, 27 Nov 2018 16:18:48 +0000 (11:18 -0500)
committervrvarma <vv8305@att.com>
Tue, 27 Nov 2018 18:46:02 +0000 (13:46 -0500)
Change the pci-optimization responses to only have the updates
Return Error message in case of failures or no solutions

Change-Id: Ia2efc7dc1e5cbcdc2c9425a3f58b840130d759ed
Signed-off-by: vrvarma <vv8305@att.com>
Issue-ID: OPTFRA-404

osdf/optimizers/pciopt/pci_opt_processor.py
osdf/optimizers/pciopt/solver/optimizer.py
osdf/optimizers/pciopt/solver/pci_utils.py

index f774b65..da87b83 100644 (file)
@@ -17,6 +17,7 @@
 #
 
 import traceback
+
 from requests import RequestException
 
 from osdf.logging.osdf_logging import metrics_log, MH, error_log
@@ -66,15 +67,16 @@ def process_pci_optimation(request_json, osdf_config, flat_policies):
 
 
 def get_solutions(cell_info_list, network_cell_info, request_json):
+    status, solutions = build_solution_list(cell_info_list, network_cell_info, request_json)
     return {
         "transactionId": request_json['requestInfo']['transactionId'],
         "requestId": request_json["requestInfo"]["requestId"],
         "requestStatus": "completed",
-        "statusMessage": "success",
+        "statusMessage": status,
         "solutions": [
             {
                 'networkId': request_json['cellInfo']['networkId'],
-                'pciSolutions': build_solution_list(cell_info_list, network_cell_info, request_json)
+                'pciSolutions': solutions
             }
         ]
     }
@@ -82,13 +84,20 @@ def get_solutions(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(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
+    status = "success"
+    req_id = request_json["requestInfo"]["requestId"]
+    try:
+        opt_solution = optimize(network_cell_info, cell_info_list)
+        sol = opt_solution[0]['pci']
+        for k, v in sol.items():
+            old_pci = get_pci_value(network_cell_info, k)
+            if old_pci != v:
+                response = {
+                    'cellId': get_cell_id(network_cell_info, k),
+                    'pci': v
+                }
+                solution_list.append(response)
+    except RuntimeError:
+        error_log.error("Failed finding solution for {} {}".format(req_id, traceback.format_exc()))
+        status = "failed"
+    return status, solution_list
index 91e693c..5a1a5c2 100644 (file)
@@ -64,7 +64,7 @@ def add_to_neighbor_list(network_cell_info, cell, neighbor_list):
     for nbr in cell.get('nbr_list', []):
         host_id = cell['id']
         nbr_id = get_id(network_cell_info, nbr['cellId'])
-        if host_id != nbr_id:
+        if nbr_id and host_id != nbr_id:
             entry = sorted([host_id, nbr_id])
             neighbor_list.add((entry[0], entry[1]))
 
@@ -74,8 +74,9 @@ def get_second_level_neighbor(network_cell_info):
     for cell in network_cell_info['cell_list']:
         comb_list = build_second_level_list(network_cell_info, cell)
         for comb in comb_list:
-            s = sorted(comb)
-            second_neighbor_list.add((s[0], s[1]))
+            if comb[0] and comb[1]:
+                s = sorted(comb)
+                second_neighbor_list.add((s[0], s[1]))
     return sorted(second_neighbor_list)
 
 
index 71b5dd2..df46d1b 100644 (file)
@@ -30,6 +30,7 @@ def get_cell_id(network_cell_info, id):
             return i['cell_id']
     return None
 
+
 def get_pci_value(network_cell_info, id):
     cell_id = get_cell_id(network_cell_info, id)
     for i in network_cell_info['cell_list']: