X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fnbi%2Fhttpgetter.go;h=7de6b966a17b0d6e47fb0ba5e123accf8fbfa003;hb=930db799fe886da7b2c80f89ed3f67c0433c4ed7;hp=678040346066a067275110301de3a80fccc634ab;hpb=871fa393844ce1b61b8d5218d27687d9fc05803a;p=ric-plt%2Frtmgr.git diff --git a/pkg/nbi/httpgetter.go b/pkg/nbi/httpgetter.go index 6780403..7de6b96 100644 --- a/pkg/nbi/httpgetter.go +++ b/pkg/nbi/httpgetter.go @@ -14,12 +14,17 @@ 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. + + + This source code is part of the near-RT RIC (RAN Intelligent Controller) + platform project (RICP). + ================================================================================== */ /* Mnemonic: httpgetter.go Abstract: HTTPgetter NBI implementation - Simple HTTP getter solution. Only for testing purpose. + Simple HTTP getter solution. Date: 15 March 2019 */ @@ -27,24 +32,56 @@ package nbi import ( "encoding/json" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "net/http" - "rtmgr" + "routing-manager/pkg/rpe" + "routing-manager/pkg/rtmgr" + "routing-manager/pkg/sdl" + "sync" "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 +} + +var myClient = &http.Client{Timeout: 15 * time.Second} -func fetchXappList(url string) (*[]rtmgr.XApp, error) { - rtmgr.Logger.Debug("Invoked httpgetter.fetchXappList") - r, err := myClient.Get(url) +func fetchAllXApps(xmurl string) (*[]rtmgr.XApp, error) { + xapp.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 { + xapp.Logger.Debug("http client raw response: %v", r) + var xApps []rtmgr.XApp + err = json.NewDecoder(r.Body).Decode(&xApps) + if err != nil { + xapp.Logger.Warn("Json decode failed: " + err.Error()) + } + xapp.Logger.Info("HTTP GET: OK") + xapp.Logger.Debug("httpGetter.fetchXappList returns: %v", xApps) + return &xApps, err + } + xapp.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, e2murl string, + sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) error { + return nil +} + +func (g *HttpGetter) Terminate() error { + return nil }