X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fnbi%2Fhttpgetter.go;h=bdcc435291908b3bf2ab08891a5e11e4817bea6a;hb=refs%2Fchanges%2F55%2F1055%2F1;hp=678040346066a067275110301de3a80fccc634ab;hpb=871fa393844ce1b61b8d5218d27687d9fc05803a;p=ric-plt%2Frtmgr.git diff --git a/pkg/nbi/httpgetter.go b/pkg/nbi/httpgetter.go index 6780403..bdcc435 100644 --- a/pkg/nbi/httpgetter.go +++ b/pkg/nbi/httpgetter.go @@ -19,7 +19,7 @@ /* Mnemonic: httpgetter.go Abstract: HTTPgetter NBI implementation - Simple HTTP getter solution. Only for testing purpose. + Simple HTTP getter solution. Date: 15 March 2019 */ @@ -28,23 +28,53 @@ package nbi import ( "encoding/json" "net/http" - "rtmgr" + "routing-manager/pkg/rpe" + "routing-manager/pkg/rtmgr" + "routing-manager/pkg/sdl" "time" ) -var myClient = &http.Client{Timeout: 1 * time.Second} +type HttpGetter struct { + Engine + FetchAllXApps FetchAllXAppsHandler +} + +func NewHttpGetter() *HttpGetter { + instance := new(HttpGetter) + instance.FetchAllXApps = fetchAllXApps + return instance +} -func fetchXappList(url string) (*[]rtmgr.XApp, error) { - rtmgr.Logger.Debug("Invoked httpgetter.fetchXappList") - r, err := myClient.Get(url) +var myClient = &http.Client{Timeout: 5 * time.Second} + +func fetchAllXApps(xmurl string) (*[]rtmgr.XApp, error) { + rtmgr.Logger.Info("Invoked httpGetter.fetchXappList: " + xmurl) + r, err := myClient.Get(xmurl) if err != nil { return nil, err } defer r.Body.Close() - rtmgr.Logger.Debug("http client raw response: %v", r) - var xapps []rtmgr.XApp - json.NewDecoder(r.Body).Decode(&xapps) - rtmgr.Logger.Info("HTTP GET: OK") - rtmgr.Logger.Debug("httpgetter.fetchXappList returns: %v", xapps) - return &xapps, err + + if r.StatusCode == 200 { + rtmgr.Logger.Debug("http client raw response: %v", r) + var xApps []rtmgr.XApp + err = json.NewDecoder(r.Body).Decode(&xApps) + if err != nil { + rtmgr.Logger.Warn("Json decode failed: " + err.Error()) + } + rtmgr.Logger.Info("HTTP GET: OK") + rtmgr.Logger.Debug("httpGetter.fetchXappList returns: %v", xApps) + return &xApps, err + } + rtmgr.Logger.Warn("httpGetter got an unexpected http status code: %v", r.StatusCode) + return nil, nil +} + +func (g *HttpGetter) Initialize(xmurl string, nbiif string, fileName string, configfile string, + sdlEngine sdl.Engine, rpeEngine rpe.Engine, triggerSBI chan<- bool) error { + return nil +} + +func (g *HttpGetter) Terminate() error { + return nil }