[RICPLT-1703] - Reset Request + rmr_service refactoring (disabled)
Signed-off-by: rh362j <ronen.hasid@intl.att.com>
Change-Id: I939041928c0fa18d2682262ce920710b99cf0539
diff --git a/E2Manager/controllers/controller.go b/E2Manager/controllers/controller.go
index 07b3ec2..a0c7a15 100644
--- a/E2Manager/controllers/controller.go
+++ b/E2Manager/controllers/controller.go
@@ -24,22 +24,28 @@
"e2mgr/models"
"e2mgr/providers"
"e2mgr/rNibWriter"
+ "e2mgr/services"
"encoding/json"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
"github.com/julienschmidt/httprouter"
+ "io"
"net/http"
+ "time"
)
+const (
+ ParamRanName = "ranName"
+)
type Controller struct {
logger *logger.Logger
handlerProvider *providers.IncomingRequestHandlerProvider
rmrResponseChannel chan<- *models.NotificationResponse
}
-func NewController(logger *logger.Logger, rNibReaderProvider func() reader.RNibReader, rNibWriterProvider func() rNibWriter.RNibWriter,
+func NewController(logger *logger.Logger, rmrService *services.RmrService, rNibReaderProvider func() reader.RNibReader, rNibWriterProvider func() rNibWriter.RNibWriter,
config *configuration.Configuration, rmrResponseChannel chan<- *models.NotificationResponse) *Controller {
- provider := providers.NewIncomingRequestHandlerProvider(logger, config, rNibWriterProvider, rNibReaderProvider)
+ provider := providers.NewIncomingRequestHandlerProvider(logger, rmrService, config, rNibWriterProvider, rNibReaderProvider)
return &Controller{
logger: logger,
handlerProvider: provider,
@@ -52,9 +58,32 @@
c.handleRequest(writer, &r.Header, providers.ShutdownRequest,nil, false, http.StatusNoContent)
}
-//TODO create struct to input parameters
+func (c *Controller) X2ResetHandler(writer http.ResponseWriter, r *http.Request, params httprouter.Params){
+ startTime := time.Now()
+ request:= models.ResetRequest{}
+ ranName:= params.ByName(ParamRanName)
+ if !c.extractJsonBody(r.Body, &request, writer){
+ return
+ }
+ request.RanName = ranName
+ request.StartTime = startTime
+ c.handleRequest(writer, &r.Header, providers.ResetRequest, request, false, http.StatusNoContent)
+}
+
+func (c *Controller) extractJsonBody(body io.Reader, request models.Request, writer http.ResponseWriter) bool{
+ decoder := json.NewDecoder(body)
+ if err:= decoder.Decode(request); err != nil {
+ if err != nil {
+ c.logger.Errorf("[Client -> E2 Manager] #controller.extractJsonBody - unable to extract json body - error: %s", err)
+ c.handleErrorResponse(e2managererrors.NewRequestValidationError(), writer)
+ return false
+ }
+ }
+ return true
+}
+
func (c *Controller) handleRequest(writer http.ResponseWriter, header *http.Header, requestName providers.IncomingRequest,
- request *models.Request, validateHeader bool, httpStatusResponse int) {
+ request models.Request, validateHeader bool, httpStatusResponse int) {
c.logger.Infof("[Client -> E2 Manager] #controller.handleRequest - request: %v", requestName) //TODO print request if exist
@@ -113,6 +142,19 @@
e2Error, _ := err.(*e2managererrors.HeaderValidationError)
errorResponseDetails = models.ErrorResponse{Code: e2Error.Err.Code, Message: e2Error.Err.Message}
httpError = http.StatusUnsupportedMediaType
+ case *e2managererrors.WrongStateError:
+ e2Error, _ := err.(*e2managererrors.WrongStateError)
+ errorResponseDetails = models.ErrorResponse{Code: e2Error.Err.Code, Message: e2Error.Err.Message}
+ httpError = http.StatusBadRequest
+ case *e2managererrors.RequestValidationError:
+ e2Error, _ := err.(*e2managererrors.RequestValidationError)
+ errorResponseDetails = models.ErrorResponse{Code: e2Error.Err.Code, Message: e2Error.Err.Message}
+ httpError = http.StatusBadRequest
+ case *e2managererrors.RmrError:
+ e2Error, _ := err.(*e2managererrors.RmrError)
+ errorResponseDetails = models.ErrorResponse{Code: e2Error.Err.Code, Message: e2Error.Err.Message}
+ httpError = http.StatusInternalServerError
+
default:
e2Error, _ := err.(*e2managererrors.InternalError)
errorResponseDetails = models.ErrorResponse{Code: e2Error.Err.Code, Message: e2Error.Err.Message}
diff --git a/E2Manager/controllers/controller_test.go b/E2Manager/controllers/controller_test.go
index e753bcf..6b9e7ae 100644
--- a/E2Manager/controllers/controller_test.go
+++ b/E2Manager/controllers/controller_test.go
@@ -42,6 +42,7 @@
log := initLog(t)
config := configuration.ParseConfiguration()
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
readerMock := &mocks.RnibReaderMock{}
readerProvider := func() reader.RNibReader {
return readerMock
@@ -57,7 +58,7 @@
readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibErr)
writer := httptest.NewRecorder()
- controller := NewController(log, readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
controller.ShutdownHandler(writer, tests.GetHttpRequest(), nil)
var errorResponse = parseJsonRequest(t, writer.Body)
@@ -70,6 +71,7 @@
log := initLog(t)
config := configuration.ParseConfiguration()
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
readerMock := &mocks.RnibReaderMock{}
readerProvider := func() reader.RNibReader {
return readerMock
@@ -82,7 +84,7 @@
writer := httptest.NewRecorder()
- controller := NewController(log, readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
header := &http.Header{}
@@ -99,6 +101,7 @@
func TestShutdownStatusNoContent(t *testing.T){
log := initLog(t)
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
readerMock := &mocks.RnibReaderMock{}
readerProvider := func() reader.RNibReader {
return readerMock
@@ -115,7 +118,7 @@
readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibError)
writer := httptest.NewRecorder()
- controller := NewController(log, readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
controller.ShutdownHandler(writer, tests.GetHttpRequest(), nil)
assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode)
@@ -125,6 +128,7 @@
log := initLog(t)
config := configuration.ParseConfiguration()
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
readerMock := &mocks.RnibReaderMock{}
readerProvider := func() reader.RNibReader {
return readerMock
@@ -136,7 +140,7 @@
var messageChannel chan<- *models.NotificationResponse
writer := httptest.NewRecorder()
- controller := NewController(log, readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
err := e2managererrors.NewInternalError()
controller.handleErrorResponse(err, writer)
@@ -151,6 +155,7 @@
log := initLog(t)
config := configuration.ParseConfiguration()
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
readerMock := &mocks.RnibReaderMock{}
readerProvider := func() reader.RNibReader {
return readerMock
@@ -161,7 +166,7 @@
}
var messageChannel chan<- *models.NotificationResponse
writer := httptest.NewRecorder()
- controller := NewController(log, readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
err := e2managererrors.NewCommandAlreadyInProgressError()
controller.handleErrorResponse(err, writer)
@@ -175,6 +180,7 @@
func TestValidateHeaders(t *testing.T){
log := initLog(t)
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
readerMock := &mocks.RnibReaderMock{}
readerProvider := func() reader.RNibReader {
return readerMock
@@ -186,7 +192,7 @@
config := configuration.ParseConfiguration()
var messageChannel chan<- *models.NotificationResponse
- controller := NewController(log, readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
header := http.Header{}
header.Set("Content-Type", "application/json")
diff --git a/E2Manager/controllers/nodeb_controller_test.go b/E2Manager/controllers/nodeb_controller_test.go
index 9497ff8..f6a9e54 100644
--- a/E2Manager/controllers/nodeb_controller_test.go
+++ b/E2Manager/controllers/nodeb_controller_test.go
@@ -19,12 +19,12 @@
import (
"e2mgr/logger"
- "e2mgr/managers"
"e2mgr/mocks"
"e2mgr/models"
"e2mgr/rNibWriter"
"e2mgr/rmrCgo"
"e2mgr/services"
+ "e2mgr/sessions"
"e2mgr/tests"
"fmt"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
@@ -143,19 +143,12 @@
func getRmrService(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *services.RmrService {
rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock)
- rnibReaderProvider := func() reader.RNibReader {
- return &mocks.RnibReaderMock{}
- }
-
- rnibWriterProvider := func() rNibWriter.RNibWriter {
- return &mocks.RnibWriterMock{}
- }
- nManager := managers.NewNotificationManager(rnibReaderProvider, rnibWriterProvider)
- rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger)
messageChannel := make(chan *models.NotificationResponse)
- return services.NewRmrService(services.NewRmrConfig(tests.Port, tests.MaxMsgSize, tests.Flags, log), rmrMessenger, E2Sessions, nManager, messageChannel)
+ rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger)
+ return services.NewRmrService(services.NewRmrConfig(tests.Port, tests.MaxMsgSize, tests.Flags, log), rmrMessenger, make(sessions.E2Sessions), messageChannel)
}
+
func executeGetNodeb(logger *logger.Logger, writer *httptest.ResponseRecorder, rnibReaderProvider func() reader.RNibReader) {
req, _ := http.NewRequest("GET", "/nodeb", nil)