[RIC-247] RAN Health Check Request API - Validation
[ric-plt/e2mgr.git] / E2Manager / controllers / nodeb_controller.go
index a1f5b78..f2efd65 100644 (file)
@@ -48,9 +48,12 @@ type INodebController interface {
        X2Reset(writer http.ResponseWriter, r *http.Request)
        GetNodeb(writer http.ResponseWriter, r *http.Request)
        UpdateGnb(writer http.ResponseWriter, r *http.Request)
+       UpdateEnb(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)
+       DeleteEnb(writer http.ResponseWriter, r *http.Request)
+       HealthCheckRequest(writer http.ResponseWriter, r *http.Request)
 }
 
 type NodebController struct {
@@ -94,14 +97,43 @@ 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, http.StatusOK)
+       c.handleRequest(writer, &r.Header, httpmsghandlerprovider.UpdateGnbRequest, &request, true, http.StatusOK)
+}
+
+func (c *NodebController) UpdateEnb(writer http.ResponseWriter, r *http.Request) {
+       c.logger.Infof("[Client -> E2 Manager] #NodebController.UpdateEnb - request: %v", c.prettifyRequest(r))
+
+       defer r.Body.Close()
+       body, err := ioutil.ReadAll(r.Body)
+
+       if err != nil {
+               c.logger.Errorf("[Client -> E2 Manager] #NodebController.UpdateEnb - unable to read request body - error: %s", err)
+               c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer)
+               return
+       }
+
+       updateEnbRequest := models.UpdateEnbRequest{}
+       err = json.Unmarshal(body, &updateEnbRequest)
+
+       if err != nil {
+               c.logger.Errorf("[Client -> E2 Manager] #NodebController.UpdateEnb - unable to unmarshal json - error: %s", err)
+               c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer)
+               return
+       }
+
+       vars := mux.Vars(r)
+       ranName := vars[ParamRanName]
+
+       updateEnbRequest.RanName = ranName
+
+       c.handleRequest(writer, &r.Header, httpmsghandlerprovider.UpdateEnbRequest, &updateEnbRequest, 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))
+       body, err := ioutil.ReadAll(r.Body)
 
        if err != nil {
                c.logger.Errorf("[Client -> E2 Manager] #NodebController.AddEnb - unable to read request body - error: %s", err)
@@ -121,6 +153,14 @@ func (c *NodebController) AddEnb(writer http.ResponseWriter, r *http.Request) {
        c.handleRequest(writer, &r.Header, httpmsghandlerprovider.AddEnbRequest, &addEnbRequest, true, http.StatusCreated)
 }
 
+func (c *NodebController) DeleteEnb(writer http.ResponseWriter, r *http.Request) {
+       c.logger.Infof("[Client -> E2 Manager] #NodebController.DeleteEnb - request: %v", c.prettifyRequest(r))
+       vars := mux.Vars(r)
+       ranName := vars["ranName"]
+       request := &models.DeleteEnbRequest{RanName: ranName}
+       c.handleRequest(writer, &r.Header, httpmsghandlerprovider.DeleteEnbRequest, request, true, http.StatusNoContent)
+}
+
 func (c *NodebController) SetGeneralConfiguration(writer http.ResponseWriter, r *http.Request) {
        c.logger.Infof("[Client -> E2 Manager] #NodebController.SetGeneralConfiguration - request: %v", c.prettifyRequest(r))
 
@@ -151,6 +191,19 @@ func (c *NodebController) X2Reset(writer http.ResponseWriter, r *http.Request) {
        c.handleRequest(writer, &r.Header, httpmsghandlerprovider.ResetRequest, request, false, http.StatusNoContent)
 }
 
+func (c *NodebController) HealthCheckRequest(writer http.ResponseWriter, r *http.Request) {
+       c.logger.Infof("[Client -> E2 Manager] #NodebController.HealthCheckRequest - request: %v", c.prettifyRequest(r))
+
+       request := models.HealthCheckRequest{}
+
+       if err := c.extractJsonBody(r, &request); err != nil {
+               c.handleErrorResponse(err, writer)
+               return
+       }
+
+       c.handleRequest(writer, &r.Header, httpmsghandlerprovider.HealthCheckRequest, request, true, http.StatusNoContent)
+}
+
 func (c *NodebController) extractRequestBodyToProto(r *http.Request, pb proto.Message, writer http.ResponseWriter) bool {
        defer r.Body.Close()
 
@@ -299,6 +352,14 @@ func (c *NodebController) handleErrorResponse(err error, writer http.ResponseWri
                        e2Error, _ := err.(*e2managererrors.RoutingManagerError)
                        errorResponseDetails = models.ErrorResponse{Code: e2Error.Code, Message: e2Error.Message}
                        httpError = http.StatusServiceUnavailable
+               case *e2managererrors.NodebExistsError:
+                       e2Error, _ := err.(*e2managererrors.NodebExistsError)
+                       errorResponseDetails = models.ErrorResponse{Code: e2Error.Code, Message: e2Error.Message}
+                       httpError = http.StatusBadRequest
+               case *e2managererrors.NoConnectedRanError:
+                       e2Error, _ := err.(*e2managererrors.NoConnectedRanError)
+                       errorResponseDetails = models.ErrorResponse{Code: e2Error.Code, Message: e2Error.Message}
+                       httpError = http.StatusNotFound
                default:
                        e2Error := e2managererrors.NewInternalError()
                        errorResponseDetails = models.ErrorResponse{Code: e2Error.Code, Message: e2Error.Message}