From: rangajal Date: Thu, 13 Feb 2020 11:06:11 +0000 (+0000) Subject: Restart/Start of RM, fetch E2T data from E2manager - implementation in RM for v1... X-Git-Tag: 0.4.15~6 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=cb93dbf2fac19dd49332847327b364be27d8bb71;p=ric-plt%2Frtmgr.git Restart/Start of RM, fetch E2T data from E2manager - implementation in RM for v1/e2t/list API handling Change-Id: Iba7a81b2fd94dfedf21cae937401d8ce71898316 Signed-off-by: rangajal --- diff --git a/RELNOTES b/RELNOTES index 372c7d8..8bcf0f8 100644 --- 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 diff --git a/cmd/rtmgr.go b/cmd/rtmgr.go index bd17d4f..2bb7f8d 100644 --- a/cmd/rtmgr.go +++ b/cmd/rtmgr.go @@ -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()) diff --git a/container-tag.yaml b/container-tag.yaml index e06d180..6b9814a 100644 --- a/container-tag.yaml +++ b/container-tag.yaml @@ -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 diff --git a/pkg/nbi/httpgetter.go b/pkg/nbi/httpgetter.go index 5d7b818..be2577c 100644 --- a/pkg/nbi/httpgetter.go +++ b/pkg/nbi/httpgetter.go @@ -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 } diff --git a/pkg/nbi/httpgetter_test.go b/pkg/nbi/httpgetter_test.go index 088917e..0080a84 100644 --- a/pkg/nbi/httpgetter_test.go +++ b/pkg/nbi/httpgetter_test.go @@ -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) { diff --git a/pkg/nbi/httprestful.go b/pkg/nbi/httprestful.go index c43631e..b07a8db 100644 --- a/pkg/nbi/httprestful.go +++ b/pkg/nbi/httprestful.go @@ -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 diff --git a/pkg/nbi/httprestful_test.go b/pkg/nbi/httprestful_test.go index e73f303..3419dcd 100644 --- a/pkg/nbi/httprestful_test.go +++ b/pkg/nbi/httprestful_test.go @@ -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()) } diff --git a/pkg/nbi/types.go b/pkg/nbi/types.go index 80e7fd2..f538ac4 100644 --- a/pkg/nbi/types.go +++ b/pkg/nbi/types.go @@ -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 } diff --git a/pkg/rtmgr/types.go b/pkg/rtmgr/types.go index b9c4cd6..958ad6d 100644 --- a/pkg/rtmgr/types.go +++ b/pkg/rtmgr/types.go @@ -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"` }