From 1de28b829352c5234b1aba14032d17cdc183ccb2 Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Mon, 4 Nov 2024 09:24:23 +0000
Subject: [PATCH] Pre-merge code fixes and cleanup

---
 src/opticalcontroller/RSA.py                  | 38 +++++--------------
 .../service/ServiceServiceServicerImpl.py     |  2 +-
 2 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py
index 84e1269f2..13f6e0810 100644
--- a/src/opticalcontroller/RSA.py
+++ b/src/opticalcontroller/RSA.py
@@ -266,17 +266,8 @@ class RSA():
             fib[band][str(i)] = 0
         if 'used' in fib:
             fib['used'] = True
-        print(f"fib updated {fib}")    
+        print(f"fib updated {fib}")
         #print(fib)
-        
-    def update_link_2(self, fib, slots, band):
-        #print(fib)
-        for i in slots:
-            fib[band][str(i)] = 0
-        if 'used' in fib:
-            fib['used'] = True
-      
-    
 
     def update_optical_band(self, optical_band_id, slots, band):
         for i in slots:
@@ -292,19 +283,10 @@ class RSA():
         if 'used' in fib:
             fib['used'] = False
         #fib[band].sort()
-        
-    def restore_link_2(self, fib, slots, band):
-       
-        for i in slots:
-            fib[band][str(i)] = 1
-        if 'used' in fib:
-            fib['used'] = False
-       
 
     def restore_optical_band(self, optical_band_id, slots, band):
         for i in slots:
             self.optical_bands[optical_band_id][band][str(i)] = 1
-            
             #self.optical_bands[optical_band_id][band].append(int(i))
         #self.optical_bands[optical_band_id][band].sort()
 
@@ -314,8 +296,8 @@ class RSA():
         print(f"example of self.optical_bands_before { self.optical_bands}")
         for i in slots:
             self.optical_bands[optical_band_id][band][str(i)] = 1
-        print(f"example of self.optical_bands_after { self.optical_bands}")    
-       
+        print(f"example of self.optical_bands_after { self.optical_bands}")
+
         #link_name=    self.optical_bands[optical_band_id]['links'][0] 
         #link = self.get_link_by_name(link_name)    
         #update_optical_band(optical_bands=self.optical_bands,optical_band_id=optical_band_id,band=band,link=link)
@@ -366,7 +348,7 @@ class RSA():
                 # fib = link['fibers'][f]
                 fib = self.get_link_by_name(r_l)["optical_details"]
                 if list_in_list(slots, str_list_to_int(fib[band].keys())):
-                    self.restore_link_2(fib, slots, band, link=l)
+                    self.restore_link(fib, slots, band)
                     if debug:
                         print(fib[band])
             '''
@@ -379,7 +361,7 @@ class RSA():
                 #rfib = rlink['fibers'][rf]
                 rfib = self.get_fiber_details(rl, fiber_b[rl])
                 if not list_in_list(slots, rfib[band]):
-                    self.restore_link_2(rfib, slots, band)
+                    self.restore_link(rfib, slots, band)
                     if debug:
                         print(rfib[band])
             '''
@@ -420,8 +402,8 @@ class RSA():
             print(f"del_flow_fib {fib } and band {band}")
             print(f"del_flow { str_list_to_int(fib[band].keys())}")
           
-            print(f"invoking restore_link_2 fib: {fib} , slots {slots} , band {band} ")
-            self.restore_link_2(fib, slots, band)
+            print(f"invoking restore_link fib: {fib} , slots {slots} , band {band} ")
+            self.restore_link(fib, slots, band)
             self.optical_bands[o_b_id]["is_active"]=False
            
             if debug:
@@ -444,7 +426,7 @@ class RSA():
                 # fib = link['fibers'][f]
                 fib = self.get_link_by_name(r_l)["optical_details"]
                 if list_in_list(slots, str_list_to_int(fib[band].keys())):
-                    self.restore_link_2(fib, slots, band, link=l)
+                    self.restore_link(fib, slots, band)
                     if debug:
                         print(fib[band])
             '''
@@ -509,8 +491,7 @@ class RSA():
                                 continue
                     if list_in_list(slots, str_list_to_int(fib[band].keys())):
                         #fiber_list[l] = fib["ID"]
-                        #self.update_link(fib, slots, band)
-                        self.update_link_2(fib,slots,band)
+                        self.update_link(fib, slots, band)
                         break
         print("INFO: Path forward computation completed")
         return fiber_list
@@ -1232,5 +1213,4 @@ class RSA():
             link = self.get_link_by_name(link_x)
             fib = link["optical_details"]
             self.update_link(fib, new_slots, band_type)
-           
         return new_slots
diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py
index 14b7c8829..5b9eec527 100644
--- a/src/service/service/ServiceServiceServicerImpl.py
+++ b/src/service/service/ServiceServiceServicerImpl.py
@@ -288,7 +288,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
 
             # reply with 2 transponders and 2 roadms
             reply_json = json.loads(reply_txt)
-            LOGGER.warning('reply_json[{:s}]={:s}'.format(str(type(reply_json)), str(reply_json)))
+            LOGGER.debug('[optical] reply_json[{:s}]={:s}'.format(str(type(reply_json)), str(reply_json)))
             optical_band_txt = ""
             if "new_optical_band" in reply_json.keys():
                 if reply_json["new_optical_band"] == 1:
-- 
GitLab