Merge "[RICPLT-1423] Big Red button API - Implementation - Disconnect status"
diff --git a/E2Manager/controllers/controller.go b/E2Manager/controllers/controller.go
index c02e671..0e13d0d 100644
--- a/E2Manager/controllers/controller.go
+++ b/E2Manager/controllers/controller.go
@@ -39,17 +39,15 @@
type Controller struct {
logger *logger.Logger
handlerProvider *providers.IncomingRequestHandlerProvider
- rmrResponseChannel chan<- *models.NotificationResponse
}
func NewController(logger *logger.Logger, rmrService *services.RmrService, rNibReaderProvider func() reader.RNibReader, rNibWriterProvider func() rNibWriter.RNibWriter,
- config *configuration.Configuration, rmrResponseChannel chan<- *models.NotificationResponse) *Controller {
+ config *configuration.Configuration) *Controller {
provider := providers.NewIncomingRequestHandlerProvider(logger, rmrService, config, rNibWriterProvider, rNibReaderProvider)
return &Controller{
logger: logger,
handlerProvider: provider,
- rmrResponseChannel: rmrResponseChannel,
}
}
@@ -102,7 +100,7 @@
return
}
- err = handler.Handle(c.logger, request, c.rmrResponseChannel)
+ err = handler.Handle(c.logger, request)
if err != nil {
c.handleErrorResponse(err, writer)
diff --git a/E2Manager/controllers/controller_test.go b/E2Manager/controllers/controller_test.go
index 6b9e7ae..6bc1613 100644
--- a/E2Manager/controllers/controller_test.go
+++ b/E2Manager/controllers/controller_test.go
@@ -51,14 +51,13 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
- var messageChannel chan<- *models.NotificationResponse
rnibErr := &common.RNibError{}
var nbIdentityList []*entities.NbIdentity
readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibErr)
writer := httptest.NewRecorder()
- controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config)
controller.ShutdownHandler(writer, tests.GetHttpRequest(), nil)
var errorResponse = parseJsonRequest(t, writer.Body)
@@ -80,11 +79,10 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
- var messageChannel chan<- *models.NotificationResponse
writer := httptest.NewRecorder()
- controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config)
header := &http.Header{}
@@ -111,14 +109,13 @@
return writerMock
}
config := configuration.ParseConfiguration()
- var messageChannel chan<- *models.NotificationResponse
var rnibError common.IRNibError
nbIdentityList := []*entities.NbIdentity{}
readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibError)
writer := httptest.NewRecorder()
- controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config)
controller.ShutdownHandler(writer, tests.GetHttpRequest(), nil)
assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode)
@@ -137,10 +134,9 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
- var messageChannel chan<- *models.NotificationResponse
writer := httptest.NewRecorder()
- controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config)
err := e2managererrors.NewInternalError()
controller.handleErrorResponse(err, writer)
@@ -164,9 +160,8 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
- var messageChannel chan<- *models.NotificationResponse
writer := httptest.NewRecorder()
- controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config)
err := e2managererrors.NewCommandAlreadyInProgressError()
controller.handleErrorResponse(err, writer)
@@ -190,9 +185,8 @@
return writerMock
}
config := configuration.ParseConfiguration()
- var messageChannel chan<- *models.NotificationResponse
- controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config, messageChannel)
+ controller := NewController(log, getRmrService(rmrMessengerMock, log), readerProvider, writerProvider, config)
header := http.Header{}
header.Set("Content-Type", "application/json")
diff --git a/E2Manager/handlers/delete_all_request_handler.go b/E2Manager/handlers/delete_all_request_handler.go
index 95f83a2..c5240e2 100644
--- a/E2Manager/handlers/delete_all_request_handler.go
+++ b/E2Manager/handlers/delete_all_request_handler.go
@@ -17,36 +17,39 @@
package handlers
+import "C"
import (
"e2mgr/configuration"
"e2mgr/e2managererrors"
"e2mgr/logger"
+ "e2mgr/models"
"e2mgr/rNibWriter"
"e2mgr/rmrCgo"
+ "e2mgr/services"
"e2mgr/stateMachine"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
"time"
-
- "e2mgr/models"
)
type DeleteAllRequestHandler struct {
readerProvider func() reader.RNibReader
writerProvider func() rNibWriter.RNibWriter
+ rmrService *services.RmrService
config *configuration.Configuration
}
-func NewDeleteAllRequestHandler(config *configuration.Configuration, writerProvider func() rNibWriter.RNibWriter,
+func NewDeleteAllRequestHandler(rmrService *services.RmrService, config *configuration.Configuration, writerProvider func() rNibWriter.RNibWriter,
readerProvider func() reader.RNibReader) *DeleteAllRequestHandler {
return &DeleteAllRequestHandler {
readerProvider: readerProvider,
writerProvider: writerProvider,
+ rmrService: rmrService,
config: config,
}
}
-func (handler *DeleteAllRequestHandler) Handle(logger *logger.Logger, request models.Request, rmrResponseChannel chan<- *models.NotificationResponse) error {
+func (handler *DeleteAllRequestHandler) Handle(logger *logger.Logger, request models.Request) error {
err, continueFlow := handler.updateNodebStates(logger, false)
if err != nil {
@@ -59,7 +62,10 @@
//TODO change to rmr_request
response := models.NotificationResponse{MgsType: rmrCgo.RIC_SCTP_CLEAR_ALL}
- rmrResponseChannel <- &response
+ if err:= handler.rmrService.SendRmrMessage(&response); err != nil {
+ logger.Errorf("#delete_all_request_handler.Handle - failed to send sctp clear all message to RMR: %s", err)
+ return e2managererrors.NewRmrError()
+ }
time.Sleep(time.Duration(handler.config.BigRedButtonTimeoutSec) * time.Second)
logger.Infof("#delete_all_request_handler.Handle - timer expired")
@@ -84,6 +90,7 @@
return nil, false
}
+ numOfRanToShutDown := 0
for _,nbIdentity := range nbIdentityList{
node, err := handler.readerProvider().GetNodeb((*nbIdentity).GetInventoryName())
@@ -96,21 +103,35 @@
if timeoutExpired{
- handler.saveNodebShutDownState(logger, nbIdentity, node)
+ if handler.saveNodebShutDownState(logger, nbIdentity, node){
+ numOfRanToShutDown++
+ }
continue
}
- handler.saveNodebNextState(logger, nbIdentity, node)
+ if handler.saveNodebNextState(logger, nbIdentity, node){
+ numOfRanToShutDown++
+ }
}
- logger.Infof("#delete_all_request_handler.updateNodebStates - update nodeb states in RNIB completed")
+ if numOfRanToShutDown > 0{
+ logger.Infof("#delete_all_request_handler.updateNodebStates - update nodebs states in RNIB completed")
+ }else {
+ logger.Infof("#delete_all_request_handler.updateNodebStates - nodebs states are not updated ")
+ return nil, false
+ }
+
return nil, true
}
-func (handler *DeleteAllRequestHandler) saveNodebNextState(logger *logger.Logger, nbIdentity *entities.NbIdentity, node *entities.NodebInfo) {
+func (handler *DeleteAllRequestHandler) saveNodebNextState(logger *logger.Logger, nbIdentity *entities.NbIdentity, node *entities.NodebInfo) bool{
+
+ if node.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN{
+ return true
+ }
nextStatus, res := stateMachine.NodeNextStateDeleteAll(node.ConnectionStatus)
if res == false {
- return
+ return false
}
node.ConnectionStatus = nextStatus
@@ -120,24 +141,25 @@
if err != nil {
logger.Errorf("#delete_all_request_handler.saveNodebNextState - failed to save nodeB entity for inventory name: %v to RNIB. Error: %s",
(*nbIdentity).GetInventoryName(), err.Error())
- return
+ return false
}
if logger.DebugEnabled() {
logger.Debugf("#delete_all_request_handler.saveNodebNextState - connection status of inventory name: %v changed to %v",
(*nbIdentity).GetInventoryName(), nextStatus.String())
}
+ return true
}
-func (handler *DeleteAllRequestHandler) saveNodebShutDownState(logger *logger.Logger, nbIdentity *entities.NbIdentity, node *entities.NodebInfo) {
+func (handler *DeleteAllRequestHandler) saveNodebShutDownState(logger *logger.Logger, nbIdentity *entities.NbIdentity, node *entities.NodebInfo) bool{
if node.ConnectionStatus == entities.ConnectionStatus_SHUT_DOWN{
- return
+ return false
}
if node.ConnectionStatus != entities.ConnectionStatus_SHUTTING_DOWN {
logger.Errorf("#delete_all_request_handler.saveNodebShutDownState - ignore, status is not Shutting Down, inventory name: %v ", (*nbIdentity).GetInventoryName())
- return
+ return false
}
node.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
@@ -147,8 +169,9 @@
if err != nil {
logger.Errorf("#delete_all_request_handler.saveNodebShutDownState - failed to save nodeB entity for inventory name: %v to RNIB. Error: %s",
(*nbIdentity).GetInventoryName(), err.Error())
- return
+ return false
}
logger.Errorf("#delete_all_request_handler.saveNodebShutDownState - Shut Down , inventory name: %v ", (*nbIdentity).GetInventoryName())
+ return true
}
diff --git a/E2Manager/handlers/delete_all_request_handler_test.go b/E2Manager/handlers/delete_all_request_handler_test.go
index 3204b71..62214a8 100644
--- a/E2Manager/handlers/delete_all_request_handler_test.go
+++ b/E2Manager/handlers/delete_all_request_handler_test.go
@@ -25,6 +25,10 @@
"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"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
@@ -45,18 +49,18 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
+
config := configuration.ParseConfiguration()
- handler := NewDeleteAllRequestHandler(config, writerProvider, readerProvider)
-
- var messageChannel chan<- *models.NotificationResponse
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
rnibErr := &common.RNibError{}
var nbIdentityList []*entities.NbIdentity
readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibErr)
expected := &e2managererrors.RnibDbError{}
- actual := handler.Handle(log, nil, messageChannel)
+ actual := handler.Handle(log, nil)
if reflect.TypeOf(actual) != reflect.TypeOf(expected){
t.Errorf("Error actual = %v, and Expected = %v.", actual, expected)
}
@@ -73,12 +77,11 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
config := configuration.ParseConfiguration()
config.BigRedButtonTimeoutSec = 1
- handler := NewDeleteAllRequestHandler(config, writerProvider, readerProvider)
-
- messageChannel := make(chan*models.NotificationResponse)
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
rnibErr := &common.RNibError{}
//Before timer: Disconnected->ShutDown, ShuttingDown->Ignore, Connected->ShuttingDown
@@ -98,13 +101,9 @@
writerMock.On("SaveNodeb", mock.Anything, updatedNb1).Return(nil)
writerMock.On("SaveNodeb", mock.Anything, updatedNb3).Return(nil)
- go func(){
- response := <-messageChannel
- assert.Equal(t, response.MgsType, rmrCgo.RIC_SCTP_CLEAR_ALL)
- }()
-
expected := &e2managererrors.RnibDbError{}
- actual := handler.Handle(log, nil, messageChannel)
+ actual := handler.Handle(log, nil)
+
if reflect.TypeOf(actual) != reflect.TypeOf(expected){
t.Errorf("Error actual = %v, and Expected = %v.", actual, expected)
}
@@ -121,11 +120,10 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
config := configuration.ParseConfiguration()
config.BigRedButtonTimeoutSec = 1
- handler := NewDeleteAllRequestHandler(config, writerProvider, readerProvider)
-
- messageChannel := make(chan*models.NotificationResponse)
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
//Before timer: Disconnected->ShutDown, ShuttingDown->Ignore, Connected->ShuttingDown
nbIdentityList := createIdentityList()
@@ -158,12 +156,10 @@
writerMock.On("SaveNodeb", mock.Anything, updatedNb2AfterTimer).Return(nil)
writerMock.On("SaveNodeb", mock.Anything, updatedNb3AfterTimer).Return(nil)
- go func(){
- response := <-messageChannel
- assert.Equal(t, response.MgsType, rmrCgo.RIC_SCTP_CLEAR_ALL)
- }()
+ mbuf := rmrCgo.NewMBuf(tests.MessageType, tests.MaxMsgSize,"RanName" , &tests.DummyPayload, &tests.DummyXAction)
+ rmrMessengerMock.On("SendMsg", mock.AnythingOfType(fmt.Sprintf("%T", mbuf)), tests.MaxMsgSize).Return(mbuf, nil)
- actual := handler.Handle(log, nil, messageChannel)
+ actual := handler.Handle(log, nil)
assert.Nil(t, actual)
}
@@ -179,11 +175,10 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
config := configuration.ParseConfiguration()
config.BigRedButtonTimeoutSec = 1
- handler := NewDeleteAllRequestHandler(config, writerProvider, readerProvider)
-
- messageChannel := make(chan*models.NotificationResponse)
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
nbIdentityList := []*entities.NbIdentity{{InventoryName: "RanName_1"}}
readerMock.On("GetListNodebIds").Return(nbIdentityList, nil)
@@ -203,13 +198,49 @@
updatedNb1AfterTimer := &entities.NodebInfo{RanName:"RanName_1", ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
writerMock.On("SaveNodeb", mock.Anything, updatedNb1AfterTimer).Return(nil)
+ mbuf := rmrCgo.NewMBuf(tests.MessageType, tests.MaxMsgSize,"RanName" , &tests.DummyPayload, &tests.DummyXAction)
+ rmrMessengerMock.On("SendMsg", mock.AnythingOfType(fmt.Sprintf("%T", mbuf)), tests.MaxMsgSize).Return(mbuf, nil)
- go func(){
- response := <-messageChannel
- assert.Equal(t, response.MgsType, rmrCgo.RIC_SCTP_CLEAR_ALL)
- }()
+ actual := handler.Handle(log, nil)
- actual := handler.Handle(log, nil, messageChannel)
+ assert.Nil(t, actual)
+}
+
+func TestHandleShuttingDownStatusFlow(t *testing.T){
+ log := initLog(t)
+
+ readerMock := &mocks.RnibReaderMock{}
+ readerProvider := func() reader.RNibReader {
+ return readerMock
+ }
+ writerMock := &mocks.RnibWriterMock{}
+ writerProvider := func() rNibWriter.RNibWriter {
+ return writerMock
+ }
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
+ config := configuration.ParseConfiguration()
+ config.BigRedButtonTimeoutSec = 1
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
+
+ nbIdentityList := []*entities.NbIdentity{{InventoryName: "RanName_1"}}
+ readerMock.On("GetListNodebIds").Return(nbIdentityList, nil)
+
+ nb1 := &entities.NodebInfo{RanName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN,}
+ readerMock.On("GetNodeb", "RanName_1").Return(nb1, nil)
+
+ //after timer: ShutDown->Ignore, ShuttingDown->ShutDown
+ readerMock.On("GetListNodebIds").Return(nbIdentityList, nil)
+
+ nb1AfterTimer := &entities.NodebInfo{RanName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN,}
+ readerMock.On("GetNodeb", "RanName_1").Return(nb1AfterTimer, nil)
+
+ updatedNb1AfterTimer := &entities.NodebInfo{RanName:"RanName_1", ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
+ writerMock.On("SaveNodeb", mock.Anything, updatedNb1AfterTimer).Return(nil)
+
+ mbuf := rmrCgo.NewMBuf(tests.MessageType, tests.MaxMsgSize,"RanName" , &tests.DummyPayload, &tests.DummyXAction)
+ rmrMessengerMock.On("SendMsg", mock.AnythingOfType(fmt.Sprintf("%T", mbuf)), tests.MaxMsgSize).Return(mbuf, nil)
+
+ actual := handler.Handle(log, nil)
assert.Nil(t, actual)
}
@@ -225,11 +256,10 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
config := configuration.ParseConfiguration()
config.BigRedButtonTimeoutSec = 1
- handler := NewDeleteAllRequestHandler(config, writerProvider, readerProvider)
-
- messageChannel := make(chan*models.NotificationResponse)
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
//Before timer: Disconnected->ShutDown(will fail), ShuttingDown->Ignore, Connected->ShuttingDown
nbIdentityList := createIdentityList()
@@ -263,12 +293,10 @@
writerMock.On("SaveNodeb", mock.Anything, updatedNb2AfterTimer).Return(nil)
writerMock.On("SaveNodeb", mock.Anything, updatedNb3AfterTimer).Return(nil)
- go func(){
- response := <-messageChannel
- assert.Equal(t, response.MgsType, rmrCgo.RIC_SCTP_CLEAR_ALL)
- }()
+ mbuf := rmrCgo.NewMBuf(tests.MessageType, tests.MaxMsgSize,"RanName" , &tests.DummyPayload, &tests.DummyXAction)
+ rmrMessengerMock.On("SendMsg", mock.AnythingOfType(fmt.Sprintf("%T", mbuf)), tests.MaxMsgSize).Return(mbuf, nil)
- actual := handler.Handle(log, nil, messageChannel)
+ actual := handler.Handle(log, nil)
assert.Nil(t, actual)
}
@@ -284,11 +312,10 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
config := configuration.ParseConfiguration()
config.BigRedButtonTimeoutSec = 1
- handler := NewDeleteAllRequestHandler(config, writerProvider, readerProvider)
-
- messageChannel := make(chan*models.NotificationResponse)
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
//Before timer: Disconnected->ShutDown, ShuttingDown->Ignore, Connected->ShuttingDown(will fail)
nbIdentityList := createIdentityList()
@@ -322,16 +349,72 @@
writerMock.On("SaveNodeb", mock.Anything, updatedNb2AfterTimer).Return(nil)
writerMock.On("SaveNodeb", mock.Anything, updatedNb3AfterTimer).Return(errRnib)
- go func(){
- response := <-messageChannel
- assert.Equal(t, response.MgsType, rmrCgo.RIC_SCTP_CLEAR_ALL)
- }()
+ mbuf := rmrCgo.NewMBuf(tests.MessageType, tests.MaxMsgSize,"RanName" , &tests.DummyPayload, &tests.DummyXAction)
+ rmrMessengerMock.On("SendMsg", mock.AnythingOfType(fmt.Sprintf("%T", mbuf)), tests.MaxMsgSize).Return(mbuf, nil)
- actual := handler.Handle(log, nil, messageChannel)
+ actual := handler.Handle(log, nil)
assert.Nil(t, actual)
}
+func TestHandleSendRmrFailedFlow(t *testing.T){
+ log := initLog(t)
+
+ readerMock := &mocks.RnibReaderMock{}
+ readerProvider := func() reader.RNibReader {
+ return readerMock
+ }
+ writerMock := &mocks.RnibWriterMock{}
+ writerProvider := func() rNibWriter.RNibWriter {
+ return writerMock
+ }
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
+ config := configuration.ParseConfiguration()
+ config.BigRedButtonTimeoutSec = 1
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
+
+ //Before timer: Disconnected->ShutDown, ShuttingDown->Ignore, Connected->ShuttingDown(will fail)
+ nbIdentityList := createIdentityList()
+ readerMock.On("GetListNodebIds").Return(nbIdentityList, nil)
+
+ nb1 := &entities.NodebInfo{RanName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,}
+ nb2 := &entities.NodebInfo{RanName: "RanName_2", ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,}
+ nb3 := &entities.NodebInfo{RanName: "RanName_3", ConnectionStatus:entities.ConnectionStatus_CONNECTED,}
+ readerMock.On("GetNodeb", "RanName_1").Return(nb1, nil)
+ readerMock.On("GetNodeb", "RanName_2").Return(nb2, nil)
+ readerMock.On("GetNodeb", "RanName_3").Return(nb3, nil)
+
+ updatedNb1 := &entities.NodebInfo{RanName:"RanName_1", ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
+ updatedNb3 := &entities.NodebInfo{RanName:"RanName_3", ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,}
+ writerMock.On("SaveNodeb", mock.Anything, updatedNb1).Return(nil)
+ writerMock.On("SaveNodeb", mock.Anything, updatedNb3).Return(nil)
+
+ //after timer: ShutDown->Ignore, ShuttingDown->ShutDown(will fail)
+ readerMock.On("GetListNodebIds").Return(nbIdentityList, nil)
+
+ nb1AfterTimer := &entities.NodebInfo{RanName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN,}
+ nb2AfterTimer := &entities.NodebInfo{RanName: "RanName_2", ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,}
+ nb3AfterTimer := &entities.NodebInfo{RanName: "RanName_3", ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,}
+ readerMock.On("GetNodeb", "RanName_1").Return(nb1AfterTimer, nil)
+ readerMock.On("GetNodeb", "RanName_2").Return(nb2AfterTimer, nil)
+ readerMock.On("GetNodeb", "RanName_3").Return(nb3AfterTimer, nil)
+
+ updatedNb2AfterTimer := &entities.NodebInfo{RanName:"RanName_2", ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
+ updatedNb3AfterTimer := &entities.NodebInfo{RanName:"RanName_3", ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
+ writerMock.On("SaveNodeb", mock.Anything, updatedNb2AfterTimer).Return(nil)
+ writerMock.On("SaveNodeb", mock.Anything, updatedNb3AfterTimer).Return(nil)
+
+ expected := e2managererrors.NewRmrError()
+ mbuf := rmrCgo.NewMBuf(tests.MessageType, tests.MaxMsgSize,"RanName" , &tests.DummyPayload, &tests.DummyXAction)
+ rmrMessengerMock.On("SendMsg", mock.AnythingOfType(fmt.Sprintf("%T", mbuf)), tests.MaxMsgSize).Return(mbuf, expected)
+
+ actual := handler.Handle(log, nil)
+
+ if reflect.TypeOf(actual) != reflect.TypeOf(expected){
+ t.Errorf("Error actual = %v, and Expected = %v.", actual, expected)
+ }
+}
+
func TestHandleGetListEnbIdsEmptyFlow(t *testing.T){
log := initLog(t)
@@ -343,18 +426,17 @@
writerProvider := func() rNibWriter.RNibWriter {
return writerMock
}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
config := configuration.ParseConfiguration()
- handler := NewDeleteAllRequestHandler(config, writerProvider, readerProvider)
-
- var messageChannel chan<- *models.NotificationResponse
+ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider)
var rnibError common.IRNibError
nbIdentityList := []*entities.NbIdentity{}
readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibError)
- actual := handler.Handle(log, nil, messageChannel)
+ actual := handler.Handle(log, nil)
readerMock.AssertNumberOfCalls(t, "GetNodeb", 0)
assert.Nil(t, actual)
}
@@ -378,4 +460,12 @@
t.Errorf("#delete_all_request_handler_test.TestHandleSuccessFlow - failed to initialize logger, error: %s", err)
}
return log
+}
+
+
+func getRmrService(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *services.RmrService {
+ rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock)
+ messageChannel := make(chan *models.NotificationResponse)
+ 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)
}
\ No newline at end of file
diff --git a/E2Manager/handlers/ranLostConnectionHandler.go b/E2Manager/handlers/ranLostConnectionHandler.go
index 0404e74..33c4948 100644
--- a/E2Manager/handlers/ranLostConnectionHandler.go
+++ b/E2Manager/handlers/ranLostConnectionHandler.go
@@ -55,9 +55,7 @@
if rNibErr = src.rnibWriterProvider().SaveNodeb(nbIdentity, nb); rNibErr != nil {
logger.Errorf("#ranLostConnectionHandler.Handle - transactionId %s: rNibWriter failed to save nb entity %s. Error: %s", request.TransactionId, nb.RanName, rNibErr.Error())
} else {
- logger.Infof("#ranLostConnectionHandler.Handle - transactionId %s: saved to rNib", request.TransactionId)
- logger.Debugf("#ranLostConnectionHandler.Handle - transactionId %s: saved to rNib. RanName %s, ConnectionStatus %v", request.TransactionId, nb.RanName, nb.ConnectionStatus)
-
+ logger.Infof("#ranLostConnectionHandler.Handle - transactionId %s: saved to rNib. RanName %s, ConnectionStatus %v", request.TransactionId, nb.RanName, nb.ConnectionStatus)
}
}
e2session, ok := e2Sessions[request.TransactionId]
diff --git a/E2Manager/handlers/request_handler.go b/E2Manager/handlers/request_handler.go
index 5e343fe..a8745f9 100644
--- a/E2Manager/handlers/request_handler.go
+++ b/E2Manager/handlers/request_handler.go
@@ -23,5 +23,5 @@
)
type RequestHandler interface {
- Handle(logger *logger.Logger, request models.Request, rmrResponseChannel chan<- *models.NotificationResponse) error
+ Handle(logger *logger.Logger, request models.Request) error
}
diff --git a/E2Manager/handlers/x2_reset_request_handler.go b/E2Manager/handlers/x2_reset_request_handler.go
index c5605c6..63484bb 100644
--- a/E2Manager/handlers/x2_reset_request_handler.go
+++ b/E2Manager/handlers/x2_reset_request_handler.go
@@ -134,7 +134,7 @@
}
}
-func (handler *X2ResetRequestHandler) Handle(logger *logger.Logger, request models.Request, rmrResponseChannel chan<- *models.NotificationResponse) error {
+func (handler *X2ResetRequestHandler) Handle(logger *logger.Logger, request models.Request) error {
resetRequest := request.(models.ResetRequest)
if len(resetRequest.Cause) == 0 {
diff --git a/E2Manager/main/http_server.go b/E2Manager/main/http_server.go
index e7ee10a..4a7b969 100644
--- a/E2Manager/main/http_server.go
+++ b/E2Manager/main/http_server.go
@@ -59,14 +59,14 @@
defer rmrService.CloseContext()
go rmrServiceReceiver.ListenAndHandle()
go rmrService.SendResponse()
- runServer(rmrService, logger, config, rmrResponseChannel)
+ runServer(rmrService, logger, config)
}
-func runServer(rmrService *services.RmrService, logger *logger.Logger, config *configuration.Configuration, rmrResponseChannel chan *models.NotificationResponse) {
+func runServer(rmrService *services.RmrService, logger *logger.Logger, config *configuration.Configuration) {
router := httprouter.New()
controller := controllers.NewNodebController(logger, rmrService, reader.GetRNibReader, rNibWriter.GetRNibWriter)
- newController := controllers.NewController(logger, rmrService, reader.GetRNibReader, rNibWriter.GetRNibWriter, config, rmrResponseChannel)
+ newController := controllers.NewController(logger, rmrService, reader.GetRNibReader, rNibWriter.GetRNibWriter, config)
router.POST("/v1/nodeb/:messageType", controller.HandleRequest)
router.GET("/v1/nodeb-ids", controller.GetNodebIdList)
diff --git a/E2Manager/providers/incoming_request_handler_provider.go b/E2Manager/providers/incoming_request_handler_provider.go
index e8a124a..dc42966 100644
--- a/E2Manager/providers/incoming_request_handler_provider.go
+++ b/E2Manager/providers/incoming_request_handler_provider.go
@@ -52,7 +52,7 @@
rNibReaderProvider func() reader.RNibReader) map[IncomingRequest]handlers.RequestHandler {
return map[IncomingRequest]handlers.RequestHandler{
- ShutdownRequest: handlers.NewDeleteAllRequestHandler(config, rNibWriterProvider, rNibReaderProvider), //TODO change to pointer
+ ShutdownRequest: handlers.NewDeleteAllRequestHandler(rmrService, config, rNibWriterProvider, rNibReaderProvider), //TODO change to pointer
ResetRequest: handlers.NewX2ResetRequestHandler(rmrService, config, rNibWriterProvider, rNibReaderProvider), //TODO change to pointer
}
}