Xapp-frame, v0.8.1 Rest Subscription Creation /Query /Deletion
[ric-plt/submgr.git] / pkg / control / restendpoint.go
diff --git a/pkg/control/restendpoint.go b/pkg/control/restendpoint.go
new file mode 100644 (file)
index 0000000..b872c47
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+==================================================================================
+  Copyright (c) 2019 AT&T Intellectual Property.
+  Copyright (c) 2019 Nokia
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================================
+*/
+
+package control
+
+import (
+       "fmt"
+       "strconv"
+
+       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
+       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+)
+
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+func ConstructEndpointAddresses(clientEndpoint models.SubscriptionParamsClientEndpoint) (string, string, error) {
+
+       var HTTP_port int64 = *clientEndpoint.HTTPPort
+       var RMR_port int64 = *clientEndpoint.RMRPort
+       var host string = clientEndpoint.Host
+       var xAppHTTPEndPoint string
+       var xAppRMREndPoint string
+
+       if *clientEndpoint.HTTPPort > 0 {
+               xAppHTTPEndPoint = host + ":" + strconv.FormatInt(*clientEndpoint.HTTPPort, 10)
+       }
+       if *clientEndpoint.RMRPort > 0 {
+               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)
+
+       return xAppHTTPEndPoint, xAppRMREndPoint, nil
+}