X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fcontrollers%2Fnodeb_controller.go;h=5bc2a2cc7bae8c58b6104875d1af9be498a426fb;hb=67b5aa5e2f37db23fb7d1c086e9c540a61f43917;hp=90b9311d8f2da0f52afb2bd8b6c065a9c4012db6;hpb=f1035e286c9cdb58fd786daf4d6c5cc9bea45a37;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/controllers/nodeb_controller.go b/E2Manager/controllers/nodeb_controller.go index 90b9311..5bc2a2c 100644 --- a/E2Manager/controllers/nodeb_controller.go +++ b/E2Manager/controllers/nodeb_controller.go @@ -40,15 +40,16 @@ const ( ParamRanName = "ranName" LimitRequest = 2000 ) +const ApplicationJson = "application/json" +const ContentType = "Content-Type" type INodebController interface { Shutdown(writer http.ResponseWriter, r *http.Request) X2Reset(writer http.ResponseWriter, r *http.Request) - 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 { @@ -90,11 +91,22 @@ func (c *NodebController) UpdateGnb(writer http.ResponseWriter, r *http.Request) return } - request.Gnb = &gnb; + 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.extractJsonBodyDisallowUnknownFields(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) @@ -113,36 +125,27 @@ func (c *NodebController) X2Reset(writer http.ResponseWriter, r *http.Request) { c.handleRequest(writer, &r.Header, httpmsghandlerprovider.ResetRequest, request, false) } -func (c *NodebController) X2Setup(writer http.ResponseWriter, r *http.Request) { - c.logger.Infof("[Client -> E2 Manager] #NodebController.X2Setup - request: %v", c.prettifyRequest(r)) - - request := models.SetupRequest{} - - if !c.extractJsonBody(r, &request, writer) { - return - } - - c.handleRequest(writer, &r.Header, httpmsghandlerprovider.X2SetupRequest, request, true) -} - -func (c *NodebController) EndcSetup(writer http.ResponseWriter, r *http.Request) { - c.logger.Infof("[Client -> E2 Manager] #NodebController.EndcSetup - request: %v", c.prettifyRequest(r)) +func (c *NodebController) extractRequestBodyToProto(r *http.Request, pb proto.Message , writer http.ResponseWriter) bool { + defer r.Body.Close() - request := models.SetupRequest{} + err := jsonpb.Unmarshal(r.Body, pb) - if !c.extractJsonBody(r, &request, writer) { - return + 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 } - c.handleRequest(writer, &r.Header, httpmsghandlerprovider.EndcSetupRequest, request, true) + return true } -func (c *NodebController) extractRequestBodyToProto(r *http.Request, pb proto.Message , writer http.ResponseWriter) bool { +func (c *NodebController) extractJsonBodyDisallowUnknownFields(r *http.Request, request models.Request, writer http.ResponseWriter) bool { defer r.Body.Close() - err := jsonpb.Unmarshal(r.Body, pb) + decoder := json.NewDecoder(r.Body) + decoder.DisallowUnknownFields() - if err != nil { + if err := decoder.Decode(&request); 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 @@ -210,13 +213,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() @@ -281,7 +284,7 @@ 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) }