Restart/Start of RM, fetch E2T data from E2manager - implementation in RM for v1... 03/2503/1
authorrangajal <ranjit.angajala@nokia.com>
Thu, 13 Feb 2020 11:06:11 +0000 (11:06 +0000)
committerrangajal <ranjit.angajala@nokia.com>
Thu, 13 Feb 2020 11:06:18 +0000 (11:06 +0000)
Change-Id: Iba7a81b2fd94dfedf21cae937401d8ce71898316
Signed-off-by: rangajal <ranjit.angajala@nokia.com>
RELNOTES
cmd/rtmgr.go
container-tag.yaml
pkg/nbi/httpgetter.go
pkg/nbi/httpgetter_test.go
pkg/nbi/httprestful.go
pkg/nbi/httprestful_test.go
pkg/nbi/types.go
pkg/rtmgr/types.go

index 372c7d8..8bcf0f8 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -1,3 +1,6 @@
+### v0.4.14
+* Restart/Start of RM, fetch E2T data from E2manager - implementation in RM for v1/e2t/list API handling 
+
 ### v0.4.13
 * Corrected route table syntax in case of broadcast message 
 
index bd17d4f..2bb7f8d 100644 (file)
@@ -88,7 +88,7 @@ func serve(nbiEngine nbi.Engine, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpe
 
        triggerSBI := make(chan bool)
 
-       nbiErr := nbiEngine.Initialize(xapp.Config.GetString("xmurl"), xapp.Config.GetString("nbiurl"), xapp.Config.GetString("rtfile"), xapp.Config.GetString("cfgfile"),
+       nbiErr := nbiEngine.Initialize(xapp.Config.GetString("xmurl"), xapp.Config.GetString("nbiurl"), xapp.Config.GetString("rtfile"), xapp.Config.GetString("cfgfile"), xapp.Config.GetString("e2murl"), 
                sdlEngine, rpeEngine, triggerSBI, m)
        if nbiErr != nil {
                xapp.Logger.Error("Failed to initialize nbi due to: " + nbiErr.Error())
index e06d180..6b9814a 100644 (file)
@@ -2,4 +2,4 @@
 # By default this file is in the docker build directory,
 # but the location can configured in the JJB template.
 ---
-tag: 0.4.13
+tag: 0.4.14
index 5d7b818..be2577c 100644 (file)
@@ -77,7 +77,7 @@ func fetchAllXApps(xmurl string) (*[]rtmgr.XApp, error) {
        return nil, nil
 }
 
-func (g *HttpGetter) Initialize(xmurl string, nbiif string, fileName string, configfile string,
+func (g *HttpGetter) Initialize(xmurl string, nbiif string, fileName string, configfile string, e2murl string,
        sdlEngine sdl.Engine, rpeEngine rpe.Engine, triggerSBI chan<- bool, m *sync.Mutex) error {
        return nil
 }
index 088917e..0080a84 100644 (file)
@@ -38,6 +38,7 @@ import (
 
 var (
        XMURL = "http://127.0.0.1:3000/ric/v1/xapps"
+       E2MURL = "http://127.0.0.1:8080/ric/v1/e2t/list"
 )
 
 func TestFetchXappListInvalidData(t *testing.T) {
index c43631e..b07a8db 100644 (file)
@@ -527,43 +527,128 @@ func httpGetXApps(xmurl string) (*[]rtmgr.XApp, error) {
        return nil, nil
 }
 
-func retrieveStartupData(xmurl string, nbiif string, fileName string, configfile string, sdlEngine sdl.Engine) error {
-       var readErr error
-       var maxRetries = 10
-       for i := 1; i <= maxRetries; i++ {
-               time.Sleep(2 * time.Second)
-               xappData, err := httpGetXApps(xmurl)
-               if xappData != nil && err == nil {
-                       pcData, confErr := rtmgr.GetPlatformComponents(configfile)
-                       if confErr != nil {
-                               xapp.Logger.Error(confErr.Error())
-                               return confErr
-                       }
-                       xapp.Logger.Info("Recieved intial xapp data and platform data, writing into SDL.")
-                       // Combine the xapps data and platform data before writing to the SDL
-                       ricData := &rtmgr.RicComponents{XApps: *xappData, Pcs: *pcData, E2Ts: make(map[string]rtmgr.E2TInstance)}
-                       writeErr := sdlEngine.WriteAll(fileName, ricData)
-                       if writeErr != nil {
-                               xapp.Logger.Error(writeErr.Error())
-                       }
-                       // post subscription req to appmgr
-                       readErr = PostSubReq(xmurl, nbiif)
-                       if readErr == nil {
-                               return nil
+func httpGetE2TList(e2murl string) (*[]rtmgr.E2tIdentity, error) {
+       xapp.Logger.Info("Invoked httprestful.httpGetE2TList: " + e2murl)
+       r, err := myClient.Get(e2murl)
+       if err != nil {
+               return nil, err
+       }
+       defer r.Body.Close()
+
+       if r.StatusCode == 200 {
+               xapp.Logger.Debug("http client raw response: %v", r)
+               var E2Tlist []rtmgr.E2tIdentity
+               err = json.NewDecoder(r.Body).Decode(&E2Tlist)
+               if err != nil {
+                       xapp.Logger.Warn("Json decode failed: " + err.Error())
+               }
+               xapp.Logger.Info("HTTP GET: OK")
+               xapp.Logger.Debug("httprestful.httpGetXApps returns: %v", E2Tlist)
+               return &E2Tlist, err
+       }
+       xapp.Logger.Warn("httprestful got an unexpected http status code: %v", r.StatusCode)
+       return nil, nil
+}
+
+func PopulateE2TMap(e2tDataList *[]rtmgr.E2tIdentity, e2ts map[string]rtmgr.E2TInstance, meids []string) {
+       xapp.Logger.Info("Invoked httprestful.PopulateE2TMap ")
+
+       for _, e2tData := range *e2tDataList {
+               var str string
+
+               e2tinst := rtmgr.E2TInstance{
+                       Ranlist: make([]string, len(e2tData.Rannames)),
+               }
+
+               e2tinst.Fqdn = e2tData.E2taddress
+               e2tinst.Name = "E2TERMINST"
+               copy(e2tinst.Ranlist, e2tData.Rannames)
+
+               if len(e2tData.Rannames) > 0 {
+                       var meidar string
+                       for _, meid := range e2tData.Rannames {
+                               meidar += meid + " "
                        }
+                       str += "mme_ar|" + e2tData.E2taddress + "|" + strings.TrimSuffix(meidar, " ")
+               }
+
+               e2ts[e2tinst.Fqdn] = e2tinst
+               meids = append(meids,str)
+       }
+}
+
+func retrieveStartupData(xmurl string, nbiif string, fileName string, configfile string, e2murl string, sdlEngine sdl.Engine) error {
+       xapp.Logger.Info("Invoked retrieveStartupData ")
+        var readErr error
+        var maxRetries = 10
+       var xappData *[]rtmgr.XApp
+       xappData = new([]rtmgr.XApp)
+       xapp.Logger.Info("Trying to fetch XApps data from XAPP manager")
+        for i := 1; i <= maxRetries; i++ {
+                time.Sleep(2 * time.Second)
+
+               readErr = nil
+                xappData, err := httpGetXApps(xmurl)
+                if xappData != nil && err == nil {
+                       break
+                } else if err == nil {
+                        readErr = errors.New("unexpected HTTP status code")
+                } else {
+                        xapp.Logger.Warn("cannot get xapp data due to: " + err.Error())
+                        readErr = err
+                }
+        }
+
+       if ( readErr != nil) {
+               return readErr
+       }
+
+       var meids []string
+       e2ts := make(map[string]rtmgr.E2TInstance)
+       xapp.Logger.Info("Trying to fetch E2T data from E2manager")
+        for i := 1; i <= maxRetries; i++ {
+                time.Sleep(2 * time.Second)
+
+               readErr = nil
+               e2tDataList, err := httpGetE2TList(e2murl)
+               if e2tDataList != nil && err == nil {
+                       PopulateE2TMap(e2tDataList, e2ts, meids[:])
+                       break
                } else if err == nil {
                        readErr = errors.New("unexpected HTTP status code")
                } else {
-                       xapp.Logger.Warn("cannot get xapp data due to: " + err.Error())
+                       xapp.Logger.Warn("cannot get E2T data from E2M due to: " + err.Error())
                        readErr = err
                }
        }
+
+       if ( readErr != nil) {
+               return readErr
+       }
+
+       pcData, confErr := rtmgr.GetPlatformComponents(configfile)
+        if confErr != nil {
+                xapp.Logger.Error(confErr.Error())
+                return confErr
+        }
+        xapp.Logger.Info("Recieved intial xapp data, E2T data and platform data, writing into SDL.")
+        // Combine the xapps data and platform data before writing to the SDL
+       ricData := &rtmgr.RicComponents{XApps: *xappData, Pcs: *pcData, E2Ts: e2ts, MeidMap: meids}
+        writeErr := sdlEngine.WriteAll(fileName, ricData)
+        if writeErr != nil {
+                xapp.Logger.Error(writeErr.Error())
+        }
+        // post subscription req to appmgr
+        readErr = PostSubReq(xmurl, nbiif)
+        if readErr == nil {
+                return nil
+        }
        return readErr
 }
 
-func (r *HttpRestful) Initialize(xmurl string, nbiif string, fileName string, configfile string,
+func (r *HttpRestful) Initialize(xmurl string, nbiif string, fileName string, configfile string, e2murl string,
        sdlEngine sdl.Engine, rpeEngine rpe.Engine, triggerSBI chan<- bool, m *sync.Mutex) error {
-       err := r.RetrieveStartupData(xmurl, nbiif, fileName, configfile, sdlEngine)
+       err := r.RetrieveStartupData(xmurl, nbiif, fileName, configfile, e2murl, sdlEngine)
        if err != nil {
                xapp.Logger.Error("Exiting as nbi failed to get the initial startup data from the xapp manager: " + err.Error())
                return err
index e73f303..3419dcd 100644 (file)
@@ -66,6 +66,8 @@ var BasicXAppLists = []byte(`[
 
 var SubscriptionResp = []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`)
 
+var E2TListResp = []byte(`[{"e2tAddress":"127.0.0.1:0","ranNames":["RanM0","RanN0"]},{"e2tAddress":"127.0.0.1:1","ranNames":["RanM1","RanN1"]},{"e2tAddress":"127.0.0.1:2","ranNames":["RanM2","RanN2"]},{"e2tAddress":"127.0.0.1:3","ranNames":["RanM3","RanN3"]}]`)
+
 var InvalidSubResp = []byte(`{"Version":0, "EventType":all}`)
 
 func TestValidateXappCallbackData_1(t *testing.T) {
@@ -468,7 +470,7 @@ func TestHttpInstance(t *testing.T) {
        //ts.Start()
        //defer ts.Close()
        var m sync.Mutex
-       err = httpinstance.Initialize(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine, rpeEngine, triggerSBI, &m)
+       err = httpinstance.Initialize(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine, rpeEngine, triggerSBI, &m)
 }
 
 func TestXappCallbackDataChannelwithdata(t *testing.T) {
@@ -519,7 +521,7 @@ func TestProvideXappSubscriptionHandleImpl(t *testing.T) {
        //subdel test
 }
 
-func createMockAppmgrWithData(url string, g []byte, p []byte) *httptest.Server {
+func createMockAppmgrWithData(url string, g []byte, p []byte, t []byte) *httptest.Server {
        l, err := net.Listen("tcp", url)
        if err != nil {
                fmt.Println("Failed to create listener: " + err.Error())
@@ -535,6 +537,11 @@ func createMockAppmgrWithData(url string, g []byte, p []byte) *httptest.Server {
                        w.WriteHeader(http.StatusCreated)
                        w.Write(p)
                }
+               if r.Method == "GET" && r.URL.String() == "/ric/v1/e2t/list" {
+                       w.Header().Add("Content-Type", "application/json")
+                       w.WriteHeader(http.StatusOK)
+                       w.Write(t)
+               }
 
        }))
        ts.Listener.Close()
@@ -640,7 +647,7 @@ func TestHttpGetXAppsInvalidData(t *testing.T) {
 
 func TestHttpGetXAppsWithValidData(t *testing.T) {
        var expected = 1
-       ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, nil)
+       ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, nil, nil)
 
        ts.Start()
        defer ts.Close()
@@ -658,7 +665,7 @@ func TestHttpGetXAppsWithValidData(t *testing.T) {
 func TestRetrieveStartupDataTimeout(t *testing.T) {
        sdlEngine, _ := sdl.GetSdl("file")
        createMockPlatformComponents()
-       err := retrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine)
+       err := retrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine)
        if err == nil {
                t.Error("Cannot retrieve startup data: " + err.Error())
        }
@@ -667,13 +674,18 @@ func TestRetrieveStartupDataTimeout(t *testing.T) {
 }
 
 func TestRetrieveStartupData(t *testing.T) {
-       ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, SubscriptionResp)
+       ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, SubscriptionResp, nil)
        ts.Start()
        defer ts.Close()
+
+       ts1 := createMockAppmgrWithData("127.0.0.1:8080", nil, nil, E2TListResp)
+       ts1.Start()
+       defer ts1.Close()
+
        sdlEngine, _ := sdl.GetSdl("file")
        var httpRestful, _ = GetNbi("httpRESTful")
        createMockPlatformComponents()
-       err := httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine)
+       err := httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine)
        //err := retrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine)
        if err != nil {
                t.Error("Cannot retrieve startup data: " + err.Error())
@@ -683,13 +695,13 @@ func TestRetrieveStartupData(t *testing.T) {
 }
 
 func TestRetrieveStartupDataWithInvalidSubResp(t *testing.T) {
-       ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, InvalidSubResp)
+       ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, InvalidSubResp, nil)
        ts.Start()
        defer ts.Close()
        sdlEngine, _ := sdl.GetSdl("file")
        var httpRestful, _ = GetNbi("httpRESTful")
        createMockPlatformComponents()
-       err := httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine)
+       err := httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine)
        if err == nil {
                t.Error("Cannot retrieve startup data: " + err.Error())
        }
index 80e7fd2..f538ac4 100644 (file)
@@ -42,7 +42,7 @@ type RecvXappCallbackDataHandler func(<-chan *models.XappCallbackData) (*[]rtmgr
 type RecvNewE2TdataHandler func(<-chan *models.E2tData) (*rtmgr.E2TInstance, string, error)
 type LaunchRestHandler func(*string, chan<- *models.XappCallbackData, chan<- *models.XappSubscriptionData, chan<- *rtmgr.XappList, chan<- *models.XappSubscriptionData, chan<- *models.E2tData, chan<- models.RanE2tMap, chan<- models.RanE2tMap, chan<- *models.E2tDeleteData)
 type ProvideXappHandleHandlerImpl func(chan<- *models.XappCallbackData, *models.XappCallbackData) error
-type RetrieveStartupDataHandler func(string, string, string, string, sdl.Engine) error
+type RetrieveStartupDataHandler func(string, string, string, string, string, sdl.Engine) error
 
 type EngineConfig struct {
        Name        string
@@ -53,6 +53,6 @@ type EngineConfig struct {
 }
 
 type Engine interface {
-       Initialize(string, string, string, string, sdl.Engine, rpe.Engine, chan<- bool, *sync.Mutex) error
+       Initialize(string, string, string, string, string, sdl.Engine, rpe.Engine, chan<- bool, *sync.Mutex) error
        Terminate() error
 }
index b9c4cd6..958ad6d 100644 (file)
@@ -92,6 +92,11 @@ type E2TInstance struct {
         Ranlist []string `json:"ranlist"`
 }
 
+type E2tIdentity struct {
+        E2taddress string `json:"e2tAddress"`
+        Rannames []string `json:"ranNames"`
+}
+
 type ConfigRtmgr struct {
        Pcs PlatformComponents `json:"PlatformComponents"`
 }