Implement function to subscribe to RAN NSSMF for NSSI LCM, PM notifications 11/15211/2
authorsunil.n <sunil.n@samsung.com>
Mon, 10 Nov 2025 11:59:26 +0000 (17:29 +0530)
committerSunil N <sunil.n@samsung.com>
Wed, 12 Nov 2025 11:32:52 +0000 (11:32 +0000)
Change-Id: I244226f4d84f4f814dbb80894cb48a311b8a154e
Signed-off-by: sunil.n <sunil.n@samsung.com>
sample-rapp-generator/rapp-slice-prb-prediction/src/ran_nssmf_client.py

index 9feccc0..39bee6f 100644 (file)
@@ -1,6 +1,8 @@
 import json
 import logging
 
+import requests
+
 from sme_client import SMEClient
 
 
@@ -37,4 +39,56 @@ class RAN_NSSMF_CLIENT(object):
             logger.debug(f"InfluxDB Address: {self.address}")
         else:
             logger.error("Failed to discover RAN NSSMF URL from SME.")
+
+    def subscribe_to_file_ready_notifications(self, callback_uri: str):
+        """
+        Subscribes to file-ready notifications from the RAN NSSMF.
+
+        Args:
+            callback_uri (str): The URI where the RAN NSSMF should send notifications.
+
+        Returns:
+            requests.Response: The response object from the POST request.
+        """
+        base_url = self.ran_nssmf_address
+        
+        if not base_url:
+            logger.error("RAN NSSMF address is not configured. Cannot subscribe.")
+            return None
+
+        # Ensure base_url does not have a trailing slash
+        base_url = base_url.rstrip('/')
+        subscription_url = f"{base_url}/3GPPManagement/FileDataReportingMnS/v17.0.0/subscriptions"
+        
+        payload = {
+            "consumerReference": callback_uri
+        }
+        
+        headers = {
+            "Content-Type": "application/json"
+        }
+        
+        logger.info(f"Subscribing to file-ready notifications at: {subscription_url}")
+        logger.debug(f"Payload: {payload}")
+        
+        try:
+            response = requests.post(subscription_url, json=payload, headers=headers, timeout=10)
+            response.raise_for_status()  # Raise an exception for HTTP errors (4xx or 5xx)
+            
+            logger.info(f"Successfully subscribed to notifications. Status: {response.status_code}")
+            if response.headers.get("Location"):
+                logger.info(f"Subscription Location: {response.headers.get('Location')}")
+            
+            return response
+            
+        except requests.exceptions.HTTPError as http_err:
+            logger.error(f"HTTP error occurred while subscribing: {http_err} - Response: {http_err.response.text}")
+        except requests.exceptions.ConnectionError as conn_err:
+            logger.error(f"Connection error occurred while subscribing: {conn_err}")
+        except requests.exceptions.Timeout as timeout_err:
+            logger.error(f"Timeout error occurred while subscribing: {timeout_err}")
+        except requests.exceptions.RequestException as req_err:
+            logger.error(f"An unexpected error occurred while subscribing: {req_err}")
+            
+        return None
             
\ No newline at end of file