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)
+ AddEnb(writer http.ResponseWriter, r *http.Request)
}
type NodebController struct {
func (c *NodebController) GetNodebIdList(writer http.ResponseWriter, r *http.Request) {
c.logger.Infof("[Client -> E2 Manager] #NodebController.GetNodebIdList - request: %v", c.prettifyRequest(r))
- c.handleRequest(writer, &r.Header, httpmsghandlerprovider.GetNodebIdListRequest, nil, false)
+ c.handleRequest(writer, &r.Header, httpmsghandlerprovider.GetNodebIdListRequest, nil, false, http.StatusOK)
}
func (c *NodebController) GetNodeb(writer http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
ranName := vars["ranName"]
request := models.GetNodebRequest{RanName: ranName}
- c.handleRequest(writer, &r.Header, httpmsghandlerprovider.GetNodebRequest, request, false)
+ c.handleRequest(writer, &r.Header, httpmsghandlerprovider.GetNodebRequest, request, false, http.StatusOK)
}
func (c *NodebController) UpdateGnb(writer http.ResponseWriter, r *http.Request) {
request.Gnb = &gnb
request.RanName = ranName
- c.handleRequest(writer, &r.Header, httpmsghandlerprovider.UpdateGnbRequest, request, true)
+ c.handleRequest(writer, &r.Header, httpmsghandlerprovider.UpdateGnbRequest, request, true, http.StatusOK)
+}
+
+func (c *NodebController) AddEnb(writer http.ResponseWriter, r *http.Request) {
+ c.logger.Infof("[Client -> E2 Manager] #NodebController.AddEnb - request: %v", c.prettifyRequest(r))
+
+ defer r.Body.Close()
+ body, err := ioutil.ReadAll(io.LimitReader(r.Body, LimitRequest))
+
+ if err != nil {
+ c.logger.Errorf("[Client -> E2 Manager] #NodebController.AddEnb - unable to read request body - error: %s", err)
+ c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer)
+ return
+ }
+
+ addEnbRequest := models.AddEnbRequest{}
+ err = json.Unmarshal(body, &addEnbRequest)
+
+ if err != nil {
+ c.logger.Errorf("[Client -> E2 Manager] #NodebController.AddEnb - unable to unmarshal json - error: %s", err)
+ c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer)
+ return
+ }
+
+ c.handleRequest(writer, &r.Header, httpmsghandlerprovider.AddEnbRequest, &addEnbRequest, true, http.StatusCreated)
}
func (c *NodebController) SetGeneralConfiguration(writer http.ResponseWriter, r *http.Request) {
request := models.GeneralConfigurationRequest{}
- if !c.extractJsonBody(r, &request, writer){
+ if !c.extractJsonBodyDisallowUnknownFields(r, &request, writer) {
return
}
- c.handleRequest(writer, &r.Header, httpmsghandlerprovider.SetGeneralConfigurationRequest, request, false)
+ c.handleRequest(writer, &r.Header, httpmsghandlerprovider.SetGeneralConfigurationRequest, request, false, http.StatusOK)
}
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)
+ c.handleRequest(writer, &r.Header, httpmsghandlerprovider.ShutdownRequest, nil, false, http.StatusNoContent)
}
func (c *NodebController) X2Reset(writer http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
ranName := vars[ParamRanName]
- if r.ContentLength > 0 && !c.extractJsonBody(r, &request, writer) {
+ if err := c.extractJsonBody(r, &request); err != nil {
+ c.handleErrorResponse(err, writer)
return
}
request.RanName = ranName
- c.handleRequest(writer, &r.Header, httpmsghandlerprovider.ResetRequest, request, false)
+ c.handleRequest(writer, &r.Header, httpmsghandlerprovider.ResetRequest, request, false, http.StatusNoContent)
}
-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
return true
}
-func (c *NodebController) extractJsonBody(r *http.Request, request models.Request, writer http.ResponseWriter) bool {
+func (c *NodebController) extractJsonBody(r *http.Request, request models.Request) error {
defer r.Body.Close()
body, err := ioutil.ReadAll(io.LimitReader(r.Body, LimitRequest))
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 e2managererrors.NewInvalidJsonError()
}
err = json.Unmarshal(body, &request)
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 e2managererrors.NewInvalidJsonError()
}
- return true
+ return nil
}
-func (c *NodebController) handleRequest(writer http.ResponseWriter, header *http.Header, requestName httpmsghandlerprovider.IncomingRequest, request models.Request, validateRequestHeaders bool) {
+func (c *NodebController) handleRequest(writer http.ResponseWriter, header *http.Header, requestName httpmsghandlerprovider.IncomingRequest, request models.Request, validateRequestHeaders bool, successStatusCode int) {
if validateRequestHeaders {
return
}
- if response == nil {
- writer.WriteHeader(http.StatusNoContent)
+ if successStatusCode == http.StatusNoContent {
+ writer.WriteHeader(successStatusCode)
c.logger.Infof("[E2 Manager -> Client] #NodebController.handleRequest - status response: %v", http.StatusNoContent)
return
}
c.logger.Infof("[E2 Manager -> Client] #NodebController.handleRequest - response: %s", result)
writer.Header().Set(ContentType, ApplicationJson)
+ writer.WriteHeader(successStatusCode)
writer.Write(result)
}