X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fcontrollers%2Fnodeb_controller.go;h=49e821d85ac1b6f5b843c821f6dd8af4c46f3cbd;hb=refs%2Fheads%2FPI5;hp=8b8c743f7aa178b06d4bbddbb68eb95a69571ca6;hpb=e597612ca39c11bb5b562b9e492e5340a618dba9;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/controllers/nodeb_controller.go b/E2Manager/controllers/nodeb_controller.go index 8b8c743..49e821d 100644 --- a/E2Manager/controllers/nodeb_controller.go +++ b/E2Manager/controllers/nodeb_controller.go @@ -17,7 +17,6 @@ // This source code is part of the near-RT RIC (RAN Intelligent Controller) // platform project (RICP). - package controllers import ( @@ -26,6 +25,9 @@ import ( "e2mgr/models" "e2mgr/providers/httpmsghandlerprovider" "encoding/json" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" "github.com/gorilla/mux" "io" "io/ioutil" @@ -38,6 +40,8 @@ const ( ParamRanName = "ranName" LimitRequest = 2000 ) +const ApplicationJson = "application/json" +const ContentType = "Content-Type" type INodebController interface { Shutdown(writer http.ResponseWriter, r *http.Request) @@ -45,7 +49,9 @@ type INodebController interface { X2Setup(writer http.ResponseWriter, r *http.Request) EndcSetup(writer http.ResponseWriter, r *http.Request) GetNodeb(writer http.ResponseWriter, r *http.Request) + UpdateGnb(writer http.ResponseWriter, r *http.Request) GetNodebIdList(writer http.ResponseWriter, r *http.Request) + SetGeneralConfiguration(writer http.ResponseWriter, r *http.Request) } type NodebController struct { @@ -74,6 +80,35 @@ func (c *NodebController) GetNodeb(writer http.ResponseWriter, r *http.Request) c.handleRequest(writer, &r.Header, httpmsghandlerprovider.GetNodebRequest, request, false) } +func (c *NodebController) UpdateGnb(writer http.ResponseWriter, r *http.Request) { + c.logger.Infof("[Client -> E2 Manager] #NodebController.UpdateGnb - request: %v", c.prettifyRequest(r)) + vars := mux.Vars(r) + ranName := vars[ParamRanName] + + request := models.UpdateGnbRequest{} + + gnb := entities.Gnb{} + + if !c.extractRequestBodyToProto(r, &gnb, writer) { + return + } + + request.Gnb = &gnb + request.RanName = ranName + c.handleRequest(writer, &r.Header, httpmsghandlerprovider.UpdateGnbRequest, request, true) +} + +func (c *NodebController) SetGeneralConfiguration(writer http.ResponseWriter, r *http.Request) { + c.logger.Infof("[Client -> E2 Manager] #NodebController.SetGeneralConfiguration - request: %v", c.prettifyRequest(r)) + + request := models.GeneralConfigurationRequest{} + + if !c.extractJsonBody(r, &request, writer){ + return + } + c.handleRequest(writer, &r.Header, httpmsghandlerprovider.SetGeneralConfigurationRequest, request, false) +} + func (c *NodebController) Shutdown(writer http.ResponseWriter, r *http.Request) { c.logger.Infof("[Client -> E2 Manager] #NodebController.Shutdown - request: %v", c.prettifyRequest(r)) c.handleRequest(writer, &r.Header, httpmsghandlerprovider.ShutdownRequest, nil, false) @@ -116,6 +151,20 @@ func (c *NodebController) EndcSetup(writer http.ResponseWriter, r *http.Request) c.handleRequest(writer, &r.Header, httpmsghandlerprovider.EndcSetupRequest, request, true) } +func (c *NodebController) extractRequestBodyToProto(r *http.Request, pb proto.Message , writer http.ResponseWriter) bool { + defer r.Body.Close() + + err := jsonpb.Unmarshal(r.Body, pb) + + if err != nil { + c.logger.Errorf("[Client -> E2 Manager] #NodebController.extractJsonBody - unable to extract json body - error: %s", err) + c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer) + return false + } + + return true +} + func (c *NodebController) extractJsonBody(r *http.Request, request models.Request, writer http.ResponseWriter) bool { defer r.Body.Close() body, err := ioutil.ReadAll(io.LimitReader(r.Body, LimitRequest)) @@ -136,9 +185,9 @@ func (c *NodebController) extractJsonBody(r *http.Request, request models.Reques return true } -func (c *NodebController) handleRequest(writer http.ResponseWriter, header *http.Header, requestName httpmsghandlerprovider.IncomingRequest, request models.Request, validateHeader bool) { +func (c *NodebController) handleRequest(writer http.ResponseWriter, header *http.Header, requestName httpmsghandlerprovider.IncomingRequest, request models.Request, validateRequestHeaders bool) { - if validateHeader { + if validateRequestHeaders { err := c.validateRequestHeader(header) if err != nil { @@ -175,13 +224,13 @@ func (c *NodebController) handleRequest(writer http.ResponseWriter, header *http } c.logger.Infof("[E2 Manager -> Client] #NodebController.handleRequest - response: %s", result) - writer.Header().Set("Content-Type", "application/json") + writer.Header().Set(ContentType, ApplicationJson) writer.Write(result) } func (c *NodebController) validateRequestHeader(header *http.Header) error { - if header.Get("Content-Type") != "application/json" { + if header.Get(ContentType) != ApplicationJson { c.logger.Errorf("#NodebController.validateRequestHeader - validation failure, incorrect content type") return e2managererrors.NewHeaderValidationError() @@ -246,13 +295,9 @@ func (c *NodebController) handleErrorResponse(err error, writer http.ResponseWri c.logger.Errorf("[E2 Manager -> Client] #NodebController.handleErrorResponse - http status: %d, error response: %+v", httpError, errorResponseDetails) - writer.Header().Set("Content-Type", "application/json") + writer.Header().Set(ContentType, ApplicationJson) writer.WriteHeader(httpError) _, err = writer.Write(errorResponse) - - if err != nil { - c.logger.Errorf("#NodebController.handleErrorResponse - Cannot send response. writer:%v", writer) - } } func (c *NodebController) prettifyRequest(request *http.Request) string {