Subscription REST interface update
[ric-plt/submgr.git] / pkg / control / restendpoint.go
index b872c47..dc565d4 100644 (file)
@@ -22,6 +22,7 @@ package control
 import (
        "fmt"
        "strconv"
+       "strings"
 
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
@@ -30,6 +31,7 @@ import (
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
+
 func ConstructEndpointAddresses(clientEndpoint models.SubscriptionParamsClientEndpoint) (string, string, error) {
 
        var HTTP_port int64 = *clientEndpoint.HTTPPort
@@ -38,20 +40,29 @@ func ConstructEndpointAddresses(clientEndpoint models.SubscriptionParamsClientEn
        var xAppHTTPEndPoint string
        var xAppRMREndPoint string
 
+       if host == "" {
+               err := fmt.Errorf("ClientEndpoint provided without HOST name")
+               return "", "", err
+       }
+
+       if HTTP_port == 0 && RMR_port == 0 {
+               err := fmt.Errorf("ClientEndpoint provided without PORT numbers")
+               return "INVALID_HTTP_ADDRESS:" + host + (string)(*clientEndpoint.HTTPPort),
+                       "INVALID_RMR_ADDRESS:" + host + (string)(*clientEndpoint.RMRPort),
+                       err
+       }
+
        if *clientEndpoint.HTTPPort > 0 {
                xAppHTTPEndPoint = host + ":" + strconv.FormatInt(*clientEndpoint.HTTPPort, 10)
        }
        if *clientEndpoint.RMRPort > 0 {
+               if i := strings.Index(host, "http"); i != -1 {
+                       host = strings.Replace(host, "http", "rmr", -1)
+               }
                xAppRMREndPoint = host + ":" + strconv.FormatInt(*clientEndpoint.RMRPort, 10)
        }
-       if host == "" || (HTTP_port == 0 && RMR_port == 0) {
-               err := fmt.Errorf("ClientEndpoint aprovided no PORT numbers")
-               return "INVALID_HTTP_ADDRESS:" + host + (string)(*clientEndpoint.HTTPPort),
-                       "INVALID_RMR_ADDRESS:" + host + (string)(*clientEndpoint.RMRPort),
-                       err
-       }
 
-       xapp.Logger.Info("xAppHttpEndPoint=%v, xAppRrmEndPoint=%v", xAppHTTPEndPoint, xAppRMREndPoint)
+       xapp.Logger.Debug("xAppHttpEndPoint=%v, xAppRrmEndPoint=%v", xAppHTTPEndPoint, xAppRMREndPoint)
 
        return xAppHTTPEndPoint, xAppRMREndPoint, nil
 }