Updates:
[ric-plt/a1.git] / a1 / controller.py
index f2fdfea..2de69b8 100644 (file)
@@ -17,7 +17,6 @@ Main a1 controller
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 # ==================================================================================
-from flask import Response
 from jsonschema import validate
 from jsonschema.exceptions import ValidationError
 import connexion
@@ -48,10 +47,8 @@ def _try_func_return(func):
         """
         # mdc_logger.exception(exc)  # waiting for https://jira.o-ran-sc.org/browse/RIC-39
         return "", 503
-    except BaseException:
-        # catch all, should never happen...
-        # mdc_logger.exception(exc)  # waiting for https://jira.o-ran-sc.org/browse/RIC-39
-        return Response(status=500)
+
+    # let other types of unexpected exceptions blow up and log
 
 
 # Healthcheck
@@ -63,11 +60,15 @@ def get_healthcheck():
     Currently, this checks:
     1. whether the a1 webserver is up (if it isn't, this won't even be called, so even entering this function confirms it is)
     2. checks whether the rmr thread is running and has completed a loop recently
-    TODO: make "seconds" to pass in a configurable parameter?
+    3. checks that our SDL connection is healthy
     """
-    if a1rmr.healthcheck_rmr_thread():
-        return "", 200
-    return "rmr thread is unhealthy", 500
+    if not a1rmr.healthcheck_rmr_thread():
+        mdc_logger.debug("A1 is not healthy due to the rmr thread")
+        return "rmr thread is unhealthy", 500
+    if not data.SDL.healthcheck():
+        mdc_logger.debug("A1 is not healthy because it does not have a connection to SDL")
+        return "sdl connection is unhealthy", 500
+    return "", 200
 
 
 # Policy types
@@ -87,6 +88,7 @@ def create_policy_type(policy_type_id):
 
     def put_type_handler():
         data.store_policy_type(policy_type_id, body)
+        mdc_logger.debug("Policy type {} created.".format(policy_type_id))
         return "", 201
 
     body = connexion.request.json
@@ -107,6 +109,7 @@ def delete_policy_type(policy_type_id):
 
     def delete_policy_type_handler():
         data.delete_policy_type(policy_type_id)
+        mdc_logger.debug("Policy type {} deleted.".format(policy_type_id))
         return "", 204
 
     return _try_func_return(delete_policy_type_handler)
@@ -175,10 +178,6 @@ def delete_policy_instance(policy_type_id, policy_instance_id):
     """
 
     def delete_instance_handler():
-        """
-        here we send out the DELETEs but we don't delete the instance until a GET is called where we check the statuses
-        We also set the status as deleted which would be reflected in a GET to ../status (before the DELETE completes)
-        """
         data.delete_policy_instance(policy_type_id, policy_instance_id)
 
         # queue rmr send (best effort)