Support for NETCONF Get command to get xapp configuration in O1 client 21/8221/1
authorMohammad Arif Belgaumkar <mabelgaumkar@parallelwireless.com>
Tue, 10 May 2022 09:47:49 +0000 (09:47 +0000)
committerMohammad Arif Belgaumkar <mabelgaumkar@parallelwireless.com>
Tue, 10 May 2022 09:48:48 +0000 (09:48 +0000)
ISSUE-ID: RIC-899

Signed-off-by: Mohammad Arif Belgaumkar <mabelgaumkar@parallelwireless.com>
Change-Id: Ib55ab7161bcfd71c665caf61fe3ff80ac1e65a60

agent/pkg/nbi/nbi.go
agent/pkg/sbi/sbi.go
agent/pkg/sbi/types.go
agent/yang/o-ran-sc-ric-xapp-desc-v1.yang

index d86de57..83c3431 100755 (executable)
@@ -135,6 +135,9 @@ func (n *Nbi) SubscribeStatusData() bool {
        if ok := n.SubscribeStatus("o-ran-sc-ric-alarm-v1", "/o-ran-sc-ric-alarm-v1:ric/alarms"); !ok {
                return ok
        }
+       if ok := n.SubscribeStatus("o-ran-sc-ric-xapp-desc-v1", "/o-ran-sc-ric-xapp-desc-v1:ric/configuration"); !ok {
+               return ok
+       }
 
        return true
 }
@@ -275,6 +278,12 @@ func nbiGnbStateCB(session *C.sr_session_ctx_t, module *C.char, xpath *C.char, r
        log.Info("nbiGnbStateCB: module='%s' xpath='%s' rpath='%s' [id=%d]", mod, C.GoString(xpath), C.GoString(rpath), reqid)
 
        if mod == "o-ran-sc-ric-xapp-desc-v1" {
+
+               if C.GoString(xpath) == "/o-ran-sc-ric-xapp-desc-v1:ric/configuration" {
+                       nbGetAllXappsDefCfg(session, parent)
+                       return C.SR_ERR_OK
+               }
+
                xappnamespace := os.Getenv("XAPP_NAMESPACE")
                if xappnamespace == "" {
                        xappnamespace = "ricxapp"
@@ -460,6 +469,26 @@ func (n *Nbi) testGnbStateCB(module string) bool {
        return true
 }
 
+func nbGetAllXappsDefCfg(session *C.sr_session_ctx_t, parent **C.char) {
+       var xappNameList []string
+       var xappCfgList []string
+
+       //Get the default config of all deployed xapps from appgmr using rest api
+       xappNameList, xappCfgList = sbiClient.GetAllDeployedXappsConfig()
+       if xappCfgList == nil || len(xappCfgList) == 0 {
+               log.Error("GetAllDeployedXappsConfig() Failure")
+               return
+       }
+       log.Info("GetAllDeployedXappsConfig Success, recvd xapp config")
+
+       //Loop thru the list of recvd xapps for config
+       for i, xappCfg := range xappCfgList {
+               path := fmt.Sprintf("/o-ran-sc-ric-xapp-desc-v1:ric/configuration/xapps/xapp[name='%s']", xappNameList[i])
+               nbiClient.CreateNewElement(session, parent, path, "name", xappNameList[i])
+               nbiClient.CreateNewElement(session, parent, path, "config", xappCfg)
+       }
+}
+
 type iRnib interface {
        GetListGnbIds() ([]*xapp.RNIBNbIdentity, xapp.RNIBIRNibError)
        GetListEnbIds() ([]*xapp.RNIBNbIdentity, xapp.RNIBIRNibError)
index a201f7f..ad1ddb6 100755 (executable)
@@ -21,6 +21,7 @@ package sbi
 
 import (
        "bytes"
+       "encoding/json"
        "fmt"
        httptransport "github.com/go-openapi/runtime/client"
        "github.com/go-openapi/strfmt"
@@ -199,3 +200,38 @@ func (s *SBIClient) GetAlerts() (*alert.GetAlertsOK, error) {
 
        return resp, nil
 }
+
+func (s *SBIClient) GetAllDeployedXappsConfig() ([]string, []string) {
+
+       //Trigger http rest api to appmgr to get config of all deployed xapps
+       params := apixapp.NewGetAllXappConfigParamsWithTimeout(s.timeout)
+       result, err := s.CreateTransport(s.appmgrAddr).Xapp.GetAllXappConfig(params)
+       if err != nil {
+               log.Error("GetAllDeployedXappsConfig() unsuccessful: %v", err)
+               return nil, nil
+       }
+
+       var xappCfgList []string
+       var xappNameList []string
+       var allXappCfg apimodel.AllXappConfig
+
+       allXappCfg = apimodel.AllXappConfig(result.Payload)
+       for i, xappCfg := range allXappCfg {
+               var xappName string
+               var xappJsonStrCfg string
+               xappName = string(*(xappCfg.Metadata.XappName))
+               xappJsonCfgMap := xappCfg.Config.(map[string]interface{})
+               bs, err := json.Marshal(xappJsonCfgMap)
+               if err != nil {
+                       log.Error("json marshal failure after AllXappConfig: %v", err)
+                       return nil, nil
+               }
+               xappJsonStrCfg = string(bs)
+               log.Info(" %d %s xapp config json data: %v", i, xappName, xappJsonStrCfg)
+               xappCfgList = append(xappCfgList, xappJsonStrCfg)
+               xappNameList = append(xappNameList, xappName)
+       }
+
+       return xappNameList, xappCfgList
+}
+
index f5cd190..c2f751f 100755 (executable)
@@ -44,4 +44,6 @@ type SBIClientInterface interface {
        GetAllPodStatus(namespace string) ([]PodStatus, error)
 
        GetAlerts() (*alert.GetAlertsOK, error)
+
+       GetAllDeployedXappsConfig() ([]string, []string)
 }
index 3a881ee..bac2b50 100755 (executable)
@@ -59,6 +59,11 @@ module o-ran-sc-ric-xapp-desc-v1 {
             description
                 "JSON string of override file for 'helm install' command";
         }
+       leaf config {
+           type string;
+           description
+               "configuration of the xapp";
+       }
         description
             "xApp descriptor";
     }
@@ -125,7 +130,22 @@ module o-ran-sc-ric-xapp-desc-v1 {
             description
                 "State data of the xApps";
         }
+       container configuration {
+           config false;
+           container xapps {
+           list xapp {
+               key "name";
+               uses xapp-descriptor;
+               description
+                   "xApp descriptor";
+           }
+           description
+               "List of xApps for which config to be extracted";
+         }
+         description
+             "config get data of the xApps";
+       }
         description
             "Root object for xApp management and status";
     }
-}
\ No newline at end of file
+}