From 006fbce1d1ea814cb37f5bfcff6f53e27f018a9e Mon Sep 17 00:00:00 2001 From: irina Date: Thu, 5 Sep 2019 16:11:02 +0300 Subject: [PATCH] merge of Natalia - change rnib errors Change-Id: Ia6bd709535fb0b19111fc0cd046087e6c8ae883b Signed-off-by: irina --- E2Manager/controllers/controller_test.go | 4 +- E2Manager/controllers/nodeb_controller.go | 10 ++--- E2Manager/controllers/nodeb_controller_test.go | 8 ++-- E2Manager/go.mod | 10 ++--- E2Manager/go.sum | 11 ++++++ .../handlers/delete_all_request_handler_test.go | 10 ++--- .../handlers/e2_term_init_notification_handler.go | 4 +- .../e2_term_init_notification_handler_test.go | 14 +++---- ...b_load_information_notification_handler_test.go | 4 +- E2Manager/handlers/x2_reset_request_handler.go | 3 +- .../handlers/x2_reset_request_handler_test.go | 2 +- .../x2_reset_request_notification_handler_test.go | 8 ++-- .../handlers/x2_reset_response_handler_test.go | 7 ++-- E2Manager/managers/ran_reconnection_manager.go | 5 +-- .../managers/ran_reconnection_manager_test.go | 12 +++--- E2Manager/managers/ran_setup_manager_test.go | 10 ++--- E2Manager/mocks/rnibReaderMock.go | 45 +++++++++++----------- E2Manager/mocks/rnibWriterMock.go | 13 +++---- E2Manager/rNibWriter/rNibWriter.go | 31 +++++++-------- E2Manager/rNibWriter/rNibWriter_test.go | 35 ++++++++--------- E2Manager/services/rnib_reader_service.go | 5 +-- 21 files changed, 126 insertions(+), 125 deletions(-) diff --git a/E2Manager/controllers/controller_test.go b/E2Manager/controllers/controller_test.go index 448ac9d..69dbfda 100644 --- a/E2Manager/controllers/controller_test.go +++ b/E2Manager/controllers/controller_test.go @@ -58,7 +58,7 @@ func TestShutdownHandlerRnibError(t *testing.T) { return writerMock } - rnibErr := &common.RNibError{} + rnibErr := &common.ResourceNotFoundError{} var nbIdentityList []*entities.NbIdentity readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibErr) @@ -116,7 +116,7 @@ func TestShutdownStatusNoContent(t *testing.T) { } config := configuration.ParseConfiguration() - var rnibError common.IRNibError + var rnibError error nbIdentityList := []*entities.NbIdentity{} readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibError) diff --git a/E2Manager/controllers/nodeb_controller.go b/E2Manager/controllers/nodeb_controller.go index c0f8541..5a82f10 100644 --- a/E2Manager/controllers/nodeb_controller.go +++ b/E2Manager/controllers/nodeb_controller.go @@ -250,13 +250,13 @@ func printHandlingRequestElapsedTimeInMs(logger *logger.Logger, startTime time.T float64(time.Since(startTime))/float64(time.Millisecond)) } -func rnibErrorToHttpError(rnibError common.IRNibError) (int, int, string) { - switch rnibError.GetCode() { - case common.RESOURCE_NOT_FOUND: +func rnibErrorToHttpError(rnibError error) (int, int, string) { + switch rnibError.(type) { + case *common.ResourceNotFoundError: return http.StatusNotFound, notFoundErrorCode, notFoundErrorMessage - case common.INTERNAL_ERROR: + case *common.InternalError: return http.StatusInternalServerError, internalErrorCode, internalErrorMessage - case common.VALIDATION_ERROR: + case *common.ValidationError: return http.StatusBadRequest, validationErrorCode, validationFailedMessage default: return http.StatusInternalServerError, internalErrorCode, internalErrorMessage diff --git a/E2Manager/controllers/nodeb_controller_test.go b/E2Manager/controllers/nodeb_controller_test.go index 2b906b4..26f92c5 100644 --- a/E2Manager/controllers/nodeb_controller_test.go +++ b/E2Manager/controllers/nodeb_controller_test.go @@ -166,7 +166,7 @@ func TestNodebController_GetNodeb_Success(t *testing.T) { rnibReaderMock := mocks.RnibReaderMock{} - var rnibError common.IRNibError + var rnibError error rnibReaderMock.On("GetNodeb", "testNode").Return(&entities.NodebInfo{}, rnibError) rnibReaderProvider := func() reader.RNibReader { @@ -188,7 +188,7 @@ func TestNodebController_GetNodeb_NotFound(t *testing.T) { writer := httptest.NewRecorder() rnibReaderMock := mocks.RnibReaderMock{} - rnibError := common.NewResourceNotFoundError(errors.Errorf("#reader.GetNodeb - responding node %s not found", "testNode")) + rnibError := common.NewResourceNotFoundErrorf("#reader.GetNodeb - responding node %s not found", "testNode") var nodebInfo *entities.NodebInfo rnibReaderMock.On("GetNodeb", "testNode").Return(nodebInfo, rnibError) @@ -238,7 +238,7 @@ func TestNodebController_GetNodebIdList_Success(t *testing.T) { writer := httptest.NewRecorder() rnibReaderMock := mocks.RnibReaderMock{} - var rnibError common.IRNibError + var rnibError error nbList := []*entities.NbIdentity{ {InventoryName:"test1", GlobalNbId: &entities.GlobalNbId{PlmnId:"plmnId1",NbId: "nbId1"}}, @@ -268,7 +268,7 @@ func TestNodebController_GetNodebIdList_EmptyList(t *testing.T) { rnibReaderMock := mocks.RnibReaderMock{} - var rnibError common.IRNibError + var rnibError error nbList := []*entities.NbIdentity{} rnibReaderMock.On("GetListNodebIds").Return(nbList, rnibError) diff --git a/E2Manager/go.mod b/E2Manager/go.mod index 1a279a7..2832a8d 100644 --- a/E2Manager/go.mod +++ b/E2Manager/go.mod @@ -1,10 +1,10 @@ module e2mgr require ( - gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.19 - gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.19 - gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader v1.0.19 - gerrit.o-ran-sc.org/r/ric-plt/sdlgo v0.2.0 + gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.21 + gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.21 + gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader v1.0.21 + gerrit.o-ran-sc.org/r/ric-plt/sdlgo v0.3.0 github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect github.com/go-ozzo/ozzo-validation v3.5.0+incompatible github.com/golang/protobuf v1.3.1 @@ -17,4 +17,4 @@ require ( gopkg.in/yaml.v2 v2.2.2 ) -replace gerrit.o-ran-sc.org/r/ric-plt/sdlgo => gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.2.0 +replace gerrit.o-ran-sc.org/r/ric-plt/sdlgo => gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.3.0 diff --git a/E2Manager/go.sum b/E2Manager/go.sum index 780bb9b..6f12574 100644 --- a/E2Manager/go.sum +++ b/E2Manager/go.sum @@ -1,12 +1,20 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.19 h1:b6ggNQ4PdWxCkQupfus80nsCs0YD84u+cGc+nQ2W560= gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.19/go.mod h1:QJ1uPPZosGbhxUWpUpeM5fLqFHdnWTrVnvW2DgyOCes= +gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.21 h1:eK9nUZOTMJ/EnMpH9bkWtMgOvCn3u4+PNCb9gu10s6w= +gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.21/go.mod h1:QJ1uPPZosGbhxUWpUpeM5fLqFHdnWTrVnvW2DgyOCes= gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.19 h1:5VGHtsiGnR/VfcsqhbKVScUTLBgoePp1KhSVylwlFKM= gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.19/go.mod h1:GXiXLz4ORBeIr0FLIbzENRykgh3Po5uPkX2jICxnRF0= +gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.21 h1:PQ/Mu2ol+8Oh/0BqCWWhPlVVoRCg5dQDEGm4+Opp5w4= +gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.21/go.mod h1:GXiXLz4ORBeIr0FLIbzENRykgh3Po5uPkX2jICxnRF0= gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader v1.0.19 h1:WwUWG3mp2uU9ouqAzj4d6dUGZUA+2HmutQBiH4s4UIw= gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader v1.0.19/go.mod h1:7fQ7/R9hBsCi5g6444ySaavYLB+/aCsCyDEiqWK+L34= +gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader v1.0.21 h1:N3UbqJ9WqC8JEz/TwHHwZwCFAW6VTlZLpD5lnbdD+Y8= +gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader v1.0.21/go.mod h1:SQBZLy1HP94i1vQ3y730wGFsrHqZtgPaEkzPgtqBNw0= gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.2.0 h1:7edCLIQtk9xCwxTtLRUlXr8wQ6nmr/Mo4ZoqjF3m0NE= gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.2.0/go.mod h1:2Y8gw2jqj9urI8VFqFQn7BX0J3A852+YrXVV9V8gOt4= +gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.3.0 h1:Gg3PH9XVAuSjyAr8Z8Ebmcmt6PTKeU/+FG6J7qQl+ew= +gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.3.0/go.mod h1:y2WhrCvdLkAKdH+ySdHSOSehACJkTMyZghCGVcqoZzc= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -39,6 +47,8 @@ github.com/go-ozzo/ozzo-validation v3.5.0+incompatible h1:sUy/in/P6askYr16XJgTKq github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU= github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4= github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= +github.com/go-redis/redis v6.15.3+incompatible h1:NZ0O90AhLSvSrvLZ/S9h7D4kl1mW2PrKyxL7MyBKO2g= +github.com/go-redis/redis v6.15.3+incompatible/go.mod h1:W2YCLaZryXHirdd9QqwkiVUxCQsrx8SbLq9Uqk7JS7A= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -153,6 +163,7 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= diff --git a/E2Manager/handlers/delete_all_request_handler_test.go b/E2Manager/handlers/delete_all_request_handler_test.go index 8dfa188..e4e57b8 100644 --- a/E2Manager/handlers/delete_all_request_handler_test.go +++ b/E2Manager/handlers/delete_all_request_handler_test.go @@ -55,7 +55,7 @@ func TestHandleBeforeTimerGetListNodebIdsFailedFlow(t *testing.T){ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider) - rnibErr := &common.RNibError{} + rnibErr := &common.ResourceNotFoundError{} var nbIdentityList []*entities.NbIdentity readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibErr) @@ -83,7 +83,7 @@ func TestHandleAfterTimerGetListNodebIdsFailedFlow(t *testing.T){ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider) - rnibErr := &common.RNibError{} + rnibErr := &common.ResourceNotFoundError{} //Before timer: Disconnected->ShutDown, ShuttingDown->Ignore, Connected->ShuttingDown nbIdentityList := createIdentityList() @@ -265,7 +265,7 @@ func TestHandleGetNodebFailedFlow(t *testing.T){ nbIdentityList := createIdentityList() readerMock.On("GetListNodebIds").Return(nbIdentityList, nil) - errRnib := &common.RNibError{} + errRnib := &common.ResourceNotFoundError{} 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,} @@ -328,7 +328,7 @@ func TestHandleSaveFailedFlow(t *testing.T){ readerMock.On("GetNodeb", "RanName_2").Return(nb2, nil) readerMock.On("GetNodeb", "RanName_3").Return(nb3, nil) - errRnib := &common.RNibError{} + errRnib := &common.ResourceNotFoundError{} 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) @@ -431,7 +431,7 @@ func TestHandleGetListEnbIdsEmptyFlow(t *testing.T){ handler := NewDeleteAllRequestHandler(getRmrService(rmrMessengerMock, log), config, writerProvider, readerProvider) - var rnibError common.IRNibError + var rnibError error nbIdentityList := []*entities.NbIdentity{} readerMock.On("GetListNodebIds").Return(nbIdentityList, rnibError) diff --git a/E2Manager/handlers/e2_term_init_notification_handler.go b/E2Manager/handlers/e2_term_init_notification_handler.go index cec0bfc..6cc88ae 100644 --- a/E2Manager/handlers/e2_term_init_notification_handler.go +++ b/E2Manager/handlers/e2_term_init_notification_handler.go @@ -58,8 +58,8 @@ func (handler E2TermInitNotificationHandler) Handle(logger *logger.Logger, e2Ses if err := handler.ranReconnectionManager.ReconnectRan(nbIdentity.InventoryName); err != nil { logger.Errorf("#E2TermInitNotificationHandler.Handle - Ran name: %s - connection attempt failure, error: %s", (*nbIdentity).GetInventoryName(), err.Error()) - rNibError, ok := err.(common.IRNibError) - if !ok || rNibError.GetCode() != common.RESOURCE_NOT_FOUND { + _, ok := err.(*common.ResourceNotFoundError) + if !ok { break } } diff --git a/E2Manager/handlers/e2_term_init_notification_handler_test.go b/E2Manager/handlers/e2_term_init_notification_handler_test.go index 88ac026..2086c46 100644 --- a/E2Manager/handlers/e2_term_init_notification_handler_test.go +++ b/E2Manager/handlers/e2_term_init_notification_handler_test.go @@ -38,7 +38,7 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RnibReaderM func TestE2TerminInitHandlerSuccessOneRan(t *testing.T) { log, readerMock, writerMock, rmrMessengerMock, ranReconnectMgr := initRanLostConnectionTest(t) - var rnibErr common.IRNibError + var rnibErr error readerProvider := func() reader.RNibReader { return readerMock @@ -68,7 +68,7 @@ func TestE2TerminInitHandlerSuccessOneRan(t *testing.T) { func TestE2TerminInitHandlerSuccessTwoRans(t *testing.T) { log, readerMock, writerMock, rmrMessengerMock, ranReconnectMgr := initRanLostConnectionTest(t) - var rnibErr common.IRNibError + var rnibErr error readerProvider := func() reader.RNibReader { return readerMock @@ -101,7 +101,7 @@ func TestE2TerminInitHandlerSuccessTwoRans(t *testing.T) { func TestE2TerminInitHandlerSuccessThreeRansFirstRmrFailure(t *testing.T) { log, readerMock, writerMock, rmrMessengerMock, ranReconnectMgr := initRanLostConnectionTest(t) - var rnibErr common.IRNibError + var rnibErr error readerProvider := func() reader.RNibReader { return readerMock @@ -145,7 +145,7 @@ func TestE2TerminInitHandlerSuccessThreeRansFirstRmrFailure(t *testing.T) { func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) { log, readerMock, writerMock, rmrMessengerMock, ranReconnectMgr := initRanLostConnectionTest(t) - var rnibErr common.IRNibError + var rnibErr error readerProvider := func() reader.RNibReader { return readerMock @@ -158,7 +158,7 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) var initialNodeb1 = &entities.NodebInfo{RanName: ids[1].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} var initialNodeb2 = &entities.NodebInfo{RanName: ids[2].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} readerMock.On("GetNodeb", ids[0].InventoryName).Return(initialNodeb0, rnibErr) - readerMock.On("GetNodeb", ids[1].InventoryName).Return(initialNodeb1, common.NewResourceNotFoundError(fmt.Errorf("not found"))) + readerMock.On("GetNodeb", ids[1].InventoryName).Return(initialNodeb1, common.NewResourceNotFoundError("not found")) readerMock.On("GetNodeb", ids[2].InventoryName).Return(initialNodeb2, rnibErr) var argNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} @@ -196,7 +196,7 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *testing.T) { log, readerMock, writerMock, rmrMessengerMock, ranReconnectMgr := initRanLostConnectionTest(t) - var rnibErr common.IRNibError + var rnibErr error readerProvider := func() reader.RNibReader { return readerMock @@ -246,7 +246,7 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *te func TestE2TerminInitHandlerSuccessZeroRans(t *testing.T) { log, readerMock, writerMock, rmrMessengerMock, ranReconnectMgr := initRanLostConnectionTest(t) - var rnibErr common.IRNibError + var rnibErr error readerProvider := func() reader.RNibReader { return readerMock diff --git a/E2Manager/handlers/enb_load_information_notification_handler_test.go b/E2Manager/handlers/enb_load_information_notification_handler_test.go index c3e31f0..89ec80a 100644 --- a/E2Manager/handlers/enb_load_information_notification_handler_test.go +++ b/E2Manager/handlers/enb_load_information_notification_handler_test.go @@ -69,7 +69,7 @@ func createNotificationRequestAndHandle(log *logger.Logger, ranName string, tran // return writerMock // } // -// var rnibErr common.IRNibError +// var rnibErr error // writerMock.On("SaveRanLoadInformation",inventoryName, mock.Anything).Return(rnibErr) // // loadInformationHandler := NewEnbLoadInformationNotificationHandler(rnibWriterProvider) @@ -95,7 +95,7 @@ func createNotificationRequestAndHandle(log *logger.Logger, ranName string, tran // return writerMock // } // -// var rnibErr common.IRNibError +// var rnibErr error // writerMock.On("SaveRanLoadInformation",inventoryName, mock.Anything).Return(rnibErr) // // loadInformationHandler := NewEnbLoadInformationNotificationHandler(rnibWriterProvider) diff --git a/E2Manager/handlers/x2_reset_request_handler.go b/E2Manager/handlers/x2_reset_request_handler.go index 5964c67..f61e60c 100644 --- a/E2Manager/handlers/x2_reset_request_handler.go +++ b/E2Manager/handlers/x2_reset_request_handler.go @@ -67,7 +67,8 @@ func (handler *X2ResetRequestHandler) Handle(logger *logger.Logger, request mode nodeb, err := handler.readerProvider().GetNodeb(resetRequest.RanName) if err != nil { logger.Errorf("#reset_request_handler.Handle - failed to get status of RAN: %s from RNIB. Error: %s", resetRequest.RanName, err.Error()) - if err.GetCode() == common.RESOURCE_NOT_FOUND { + _, ok := err.(*common.ResourceNotFoundError) + if ok { return e2managererrors.NewResourceNotFoundError() } return e2managererrors.NewRnibDbError() diff --git a/E2Manager/handlers/x2_reset_request_handler_test.go b/E2Manager/handlers/x2_reset_request_handler_test.go index 79dc93e..991b582 100644 --- a/E2Manager/handlers/x2_reset_request_handler_test.go +++ b/E2Manager/handlers/x2_reset_request_handler_test.go @@ -168,7 +168,7 @@ func TestHandleFailureRanNotFound(t *testing.T){ rmrService:=getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) - readerMock.On("GetNodeb",ranName).Return(&entities.NodebInfo{}, common.NewResourceNotFoundError(fmt.Errorf("nodeb not found"))) + readerMock.On("GetNodeb",ranName).Return(&entities.NodebInfo{}, common.NewResourceNotFoundError("nodeb not found")) actual := handler.Handle(log, models.ResetRequest{RanName: ranName }) diff --git a/E2Manager/handlers/x2_reset_request_notification_handler_test.go b/E2Manager/handlers/x2_reset_request_notification_handler_test.go index 7ce83e0..60264b4 100644 --- a/E2Manager/handlers/x2_reset_request_notification_handler_test.go +++ b/E2Manager/handlers/x2_reset_request_notification_handler_test.go @@ -46,7 +46,7 @@ func TestX2ResetRequestNotifSuccess(t *testing.T) { StartTime: time.Now(), TransactionId: string(xaction)} nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED,} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) messageChannel := make(chan *models.NotificationResponse) @@ -74,7 +74,7 @@ func TestHandleX2ResetRequestNotifShuttingDownStatus(t *testing.T) { StartTime: time.Now(), TransactionId: string(xaction)} nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) @@ -97,7 +97,7 @@ func TestHandleX2ResetRequestNotifDisconnectStatus(t *testing.T) { StartTime: time.Now(), TransactionId: string(xaction)} nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_DISCONNECTED,} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) @@ -120,7 +120,7 @@ func TestHandleX2ResetRequestNotifGetNodebFailed(t *testing.T){ StartTime: time.Now(), TransactionId: string(xaction)} var nb *entities.NodebInfo - rnibErr := &common.RNibError{} + rnibErr := &common.ResourceNotFoundError{} readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) h.Handle(log,nil, ¬ificationRequest, nil) diff --git a/E2Manager/handlers/x2_reset_response_handler_test.go b/E2Manager/handlers/x2_reset_response_handler_test.go index 8846501..95485dc 100644 --- a/E2Manager/handlers/x2_reset_response_handler_test.go +++ b/E2Manager/handlers/x2_reset_response_handler_test.go @@ -27,7 +27,6 @@ import ( "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" - "github.com/pkg/errors" "testing" "time" ) @@ -57,7 +56,7 @@ func TestX2ResetResponseSuccess(t *testing.T) { var messageChannel chan<- *models.NotificationResponse nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED_SETUP_FAILED,} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) h.Handle(log,e2Sessions, ¬ificationRequest, messageChannel) @@ -87,7 +86,7 @@ func TestX2ResetResponseReaderFailure(t *testing.T) { var messageChannel chan<- *models.NotificationResponse var nb *entities.NodebInfo - rnibErr := common.NewResourceNotFoundError(errors.New("nodeb not found")) + rnibErr := common.NewResourceNotFoundError("nodeb not found") readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) h.Handle(log,e2Sessions, ¬ificationRequest, messageChannel) @@ -117,7 +116,7 @@ func TestX2ResetResponseUnpackFailure(t *testing.T) { var messageChannel chan<- *models.NotificationResponse nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED_SETUP_FAILED,} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) h.Handle(log,e2Sessions, ¬ificationRequest, messageChannel) diff --git a/E2Manager/managers/ran_reconnection_manager.go b/E2Manager/managers/ran_reconnection_manager.go index 87a656e..70acee0 100644 --- a/E2Manager/managers/ran_reconnection_manager.go +++ b/E2Manager/managers/ran_reconnection_manager.go @@ -22,7 +22,6 @@ import ( "e2mgr/logger" "e2mgr/rNibWriter" "e2mgr/services" - "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" ) @@ -80,7 +79,7 @@ func (m *RanReconnectionManager) canReconnectRan(nodebInfo *entities.NodebInfo) int(nodebInfo.GetConnectionAttempts()) < m.config.MaxConnectionAttempts } -func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) common.IRNibError { +func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) error { if nodebInfo.ConnectionStatus == connectionStatus { return nil } @@ -97,7 +96,7 @@ func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.Nodeb return nil } -func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) common.IRNibError { +func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) error { connectionStatus := nodebInfo.GetConnectionStatus() if connectionStatus == entities.ConnectionStatus_SHUT_DOWN { diff --git a/E2Manager/managers/ran_reconnection_manager_test.go b/E2Manager/managers/ran_reconnection_manager_test.go index 8eaf385..cd3dc58 100644 --- a/E2Manager/managers/ran_reconnection_manager_test.go +++ b/E2Manager/managers/ran_reconnection_manager_test.go @@ -73,7 +73,7 @@ func TestShutdownRanReconnection(t *testing.T) { _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) err := ranReconnectionManager.ReconnectRan(ranName) assert.Nil(t, err) @@ -85,7 +85,7 @@ func TestShuttingdownRanReconnection(t *testing.T) { _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN @@ -100,7 +100,7 @@ func TestConnectingRanWithMaxAttemptsReconnection(t *testing.T) { _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED @@ -115,7 +115,7 @@ func TestUnconnectableRanUpdateNodebInfoFailure(t *testing.T) { _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN @@ -130,7 +130,7 @@ func TestConnectedRanExecuteSetupSuccess(t *testing.T) { _,rmrMessengerMock, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol:entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING @@ -148,7 +148,7 @@ func TestConnectedRanExecuteSetupFailure(t *testing.T) { _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED} - var rnibErr common.IRNibError + var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo := *origNodebInfo updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING diff --git a/E2Manager/managers/ran_setup_manager_test.go b/E2Manager/managers/ran_setup_manager_test.go index 7c866c8..f10e929 100644 --- a/E2Manager/managers/ran_setup_manager_test.go +++ b/E2Manager/managers/ran_setup_manager_test.go @@ -44,7 +44,7 @@ func TestExecuteSetupConnectingX2Setup(t *testing.T) { var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} - var rnibErr common.IRNibError + var rnibErr error writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr) payload := e2pdus.PackedX2setupRequest @@ -75,7 +75,7 @@ func TestExecuteSetupConnectingEndcX2Setup(t *testing.T) { var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST} var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST, ConnectionAttempts: 1} - var rnibErr common.IRNibError + var rnibErr error writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr) payload := e2pdus.PackedEndcX2setupRequest @@ -107,7 +107,7 @@ func TestExecuteSetupDisconnected(t *testing.T) { var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} var argNodebDisconnected = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 0} - var rnibErr common.IRNibError + var rnibErr error writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr) writerMock.On("UpdateNodebInfo", argNodebDisconnected).Return(rnibErr) @@ -175,7 +175,7 @@ func TestExecuteSetupDisconnectedRnibError(t *testing.T) { var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} var argNodebDisconnected = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 0} - var rnibErr common.IRNibError + var rnibErr error writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr) writerMock.On("UpdateNodebInfo", argNodebDisconnected).Return(common.NewInternalError(fmt.Errorf("DB error"))) @@ -209,7 +209,7 @@ func TestExecuteSetupUnsupportedProtocol(t *testing.T) { var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_UNKNOWN_E2_APPLICATION_PROTOCOL} var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_UNKNOWN_E2_APPLICATION_PROTOCOL, ConnectionAttempts: 1} - var rnibErr common.IRNibError + var rnibErr error writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr) payload := e2pdus.PackedX2setupRequest diff --git a/E2Manager/mocks/rnibReaderMock.go b/E2Manager/mocks/rnibReaderMock.go index 43f9d90..5ac4b20 100644 --- a/E2Manager/mocks/rnibReaderMock.go +++ b/E2Manager/mocks/rnibReaderMock.go @@ -17,7 +17,6 @@ package mocks import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "github.com/stretchr/testify/mock" ) @@ -26,123 +25,123 @@ type RnibReaderMock struct { mock.Mock } -func (m *RnibReaderMock) GetNodeb(inventoryName string) (*entities.NodebInfo, common.IRNibError) { +func (m *RnibReaderMock) GetNodeb(inventoryName string) (*entities.NodebInfo, error) { args := m.Called(inventoryName) errArg := args.Get(1); if errArg != nil { - return args.Get(0).(*entities.NodebInfo), errArg.(common.IRNibError); + return args.Get(0).(*entities.NodebInfo), errArg.(error); } return args.Get(0).(*entities.NodebInfo), nil } -func (m *RnibReaderMock) GetNodebByGlobalNbId(nodeType entities.Node_Type, globalNbId *entities.GlobalNbId) (*entities.NodebInfo, common.IRNibError) { +func (m *RnibReaderMock) GetNodebByGlobalNbId(nodeType entities.Node_Type, globalNbId *entities.GlobalNbId) (*entities.NodebInfo, error) { args := m.Called(nodeType, globalNbId) errArg := args.Get(1); if errArg != nil { - return args.Get(0).(*entities.NodebInfo), errArg.(common.IRNibError); + return args.Get(0).(*entities.NodebInfo), errArg.(error); } return args.Get(0).(*entities.NodebInfo), nil } -func (m *RnibReaderMock) GetCellList(inventoryName string) (*entities.Cells, common.IRNibError) { +func (m *RnibReaderMock) GetCellList(inventoryName string) (*entities.Cells, error) { args := m.Called(inventoryName) errArg := args.Get(1); if errArg != nil { - return args.Get(0).(*entities.Cells), errArg.(common.IRNibError); + return args.Get(0).(*entities.Cells), errArg.(error); } return args.Get(0).(*entities.Cells), nil } -func (m *RnibReaderMock) GetListGnbIds() (*[]*entities.NbIdentity, common.IRNibError) { +func (m *RnibReaderMock) GetListGnbIds() ([]*entities.NbIdentity, error) { args := m.Called() errArg := args.Get(1); if errArg != nil { - return args.Get(0).(*[]*entities.NbIdentity), errArg.(common.IRNibError); + return args.Get(0).([]*entities.NbIdentity), errArg.(error); } - return args.Get(0).(*[]*entities.NbIdentity), nil + return args.Get(0).([]*entities.NbIdentity), nil } -func (m *RnibReaderMock) GetListEnbIds() (*[]*entities.NbIdentity, common.IRNibError) { +func (m *RnibReaderMock) GetListEnbIds() ([]*entities.NbIdentity, error) { args := m.Called() errArg := args.Get(1); if errArg != nil { - return args.Get(0).(*[]*entities.NbIdentity), errArg.(common.IRNibError); + return args.Get(0).([]*entities.NbIdentity), errArg.(error); } - return args.Get(0).(*[]*entities.NbIdentity), nil + return args.Get(0).([]*entities.NbIdentity), nil } -func (m *RnibReaderMock) GetCountGnbList() (int, common.IRNibError) { +func (m *RnibReaderMock) GetCountGnbList() (int, error) { args := m.Called() errArg := args.Get(1); if errArg != nil { - return args.Int(0), errArg.(common.IRNibError); + return args.Int(0), errArg.(error); } return args.Int(0), nil } -func (m *RnibReaderMock) GetCell(inventoryName string, pci uint32) (*entities.Cell, common.IRNibError) { +func (m *RnibReaderMock) GetCell(inventoryName string, pci uint32) (*entities.Cell, error) { args := m.Called(inventoryName, pci) errArg := args.Get(1); if errArg != nil { - return args.Get(0).(*entities.Cell), errArg.(common.IRNibError); + return args.Get(0).(*entities.Cell), errArg.(error); } return args.Get(0).(*entities.Cell), nil } -func (m *RnibReaderMock) GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, common.IRNibError) { +func (m *RnibReaderMock) GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, error) { args := m.Called(cellType, cellId) errArg := args.Get(1); if errArg != nil { - return args.Get(0).(*entities.Cell), errArg.(common.IRNibError); + return args.Get(0).(*entities.Cell), errArg.(error); } return args.Get(0).(*entities.Cell), nil } -func (m *RnibReaderMock) GetListNodebIds() ([]*entities.NbIdentity, common.IRNibError) { +func (m *RnibReaderMock) GetListNodebIds() ([]*entities.NbIdentity, error) { args := m.Called() errArg := args.Get(1) if errArg != nil { - return args.Get(0).([]*entities.NbIdentity), errArg.(common.IRNibError) + return args.Get(0).([]*entities.NbIdentity), errArg.(error) } return args.Get(0).([]*entities.NbIdentity), nil } -func (m *RnibReaderMock) GetRanLoadInformation(inventoryName string) (*entities.RanLoadInformation, common.IRNibError) { +func (m *RnibReaderMock) GetRanLoadInformation(inventoryName string) (*entities.RanLoadInformation, error) { args := m.Called() errArg := args.Get(1) if errArg != nil { - return args.Get(0).(*entities.RanLoadInformation), errArg.(common.IRNibError) + return args.Get(0).(*entities.RanLoadInformation), errArg.(error) } return args.Get(0).(*entities.RanLoadInformation), nil diff --git a/E2Manager/mocks/rnibWriterMock.go b/E2Manager/mocks/rnibWriterMock.go index cb17fe1..d6b1ef9 100644 --- a/E2Manager/mocks/rnibWriterMock.go +++ b/E2Manager/mocks/rnibWriterMock.go @@ -18,7 +18,6 @@ package mocks import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "github.com/stretchr/testify/mock" ) @@ -27,37 +26,37 @@ type RnibWriterMock struct { mock.Mock } -func (rnibWriterMock *RnibWriterMock) SaveNodeb(nbIdentity *entities.NbIdentity, nb *entities.NodebInfo) common.IRNibError { +func (rnibWriterMock *RnibWriterMock) SaveNodeb(nbIdentity *entities.NbIdentity, nb *entities.NodebInfo) error { args := rnibWriterMock.Called(nbIdentity, nb) errArg := args.Get(0) if errArg != nil { - return errArg.(common.IRNibError) + return errArg.(error) } return nil } -func (rnibWriterMock *RnibWriterMock) UpdateNodebInfo(nodebInfo *entities.NodebInfo) common.IRNibError { +func (rnibWriterMock *RnibWriterMock) UpdateNodebInfo(nodebInfo *entities.NodebInfo) error { args := rnibWriterMock.Called(nodebInfo) errArg := args.Get(0) if errArg != nil { - return errArg.(common.IRNibError) + return errArg.(error) } return nil } -func (rnibWriterMock *RnibWriterMock) SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) common.IRNibError { +func (rnibWriterMock *RnibWriterMock) SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error { args := rnibWriterMock.Called(inventoryName, ranLoadInformation) errArg := args.Get(0) if errArg != nil { - return errArg.(common.IRNibError) + return errArg.(error) } return nil diff --git a/E2Manager/rNibWriter/rNibWriter.go b/E2Manager/rNibWriter/rNibWriter.go index 72f9eb8..702c7a0 100644 --- a/E2Manager/rNibWriter/rNibWriter.go +++ b/E2Manager/rNibWriter/rNibWriter.go @@ -18,7 +18,6 @@ package rNibWriter import ( - "errors" "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" @@ -37,9 +36,9 @@ type rNibWriterInstance struct { RNibWriter interface allows saving data to the redis DB */ type RNibWriter interface { - SaveNodeb(nbIdentity *entities.NbIdentity, nb *entities.NodebInfo) common.IRNibError - UpdateNodebInfo(nodebInfo *entities.NodebInfo) common.IRNibError - SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) common.IRNibError + SaveNodeb(nbIdentity *entities.NbIdentity, nb *entities.NodebInfo) error + UpdateNodebInfo(nodebInfo *entities.NodebInfo) error + SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error } /* @@ -62,23 +61,21 @@ InitPool initializes the writer's instances pool func initPool(poolSize int, newObj func() interface{}, destroyObj func(interface{})) { writerPool = common.NewPool(poolSize, newObj, destroyObj) } - /* -GetRNibWriter returns RNibWriter instance from the pool +GetRNibWriter returns reference to RNibWriter */ func GetRNibWriter() RNibWriter { - return writerPool.Get().(RNibWriter) + return &rNibWriterInstance{} } - /* SaveNodeb saves nodeB entity data in the redis DB according to the specified data model */ -func (w *rNibWriterInstance) SaveNodeb(nbIdentity *entities.NbIdentity, entity *entities.NodebInfo) common.IRNibError { - +func (*rNibWriterInstance) SaveNodeb(nbIdentity *entities.NbIdentity, entity *entities.NodebInfo) error { + w := writerPool.Get().(*rNibWriterInstance) isNotEmptyIdentity := isNotEmpty(nbIdentity) if isNotEmptyIdentity && entity.GetNodeType() == entities.Node_UNKNOWN { - return common.NewValidationError(errors.New(fmt.Sprintf("#rNibWriter.saveNodeB - Unknown responding node type, entity: %v", entity))) + return common.NewValidationError(fmt.Sprintf("#rNibWriter.saveNodeB - Unknown responding node type, entity: %v", entity)) } defer writerPool.Put(w) data, err := proto.Marshal(entity) @@ -146,8 +143,8 @@ func (w *rNibWriterInstance) SaveNodeb(nbIdentity *entities.NbIdentity, entity * /* UpdateNodebInfo... */ -func (w *rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) common.IRNibError { - +func (*rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) error { + w := writerPool.Get().(*rNibWriterInstance) defer writerPool.Put(w) nodebNameKey, rNibErr := common.ValidateAndBuildNodeBNameKey(nodebInfo.GetRanName()) @@ -183,8 +180,8 @@ func (w *rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) comm /* SaveRanLoadInformation stores ran load information for the provided ran */ -func (w *rNibWriterInstance) SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) common.IRNibError { - +func (*rNibWriterInstance) SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error { + w := writerPool.Get().(*rNibWriterInstance) defer writerPool.Put(w) key, rnibErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName) @@ -218,7 +215,7 @@ func Close() { writerPool.Close() } -func appendEnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedCellInfo, pairs []interface{}) ([]interface{}, common.IRNibError) { +func appendEnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedCellInfo, pairs []interface{}) ([]interface{}, error) { for _, cell := range cells { cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}} cellData, err := proto.Marshal(&cellEntity) @@ -239,7 +236,7 @@ func appendEnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedCel return pairs, nil } -func appendGnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedNRCell, pairs []interface{}) ([]interface{}, common.IRNibError) { +func appendGnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedNRCell, pairs []interface{}) ([]interface{}, error) { for _, cell := range cells { cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}} cellData, err := proto.Marshal(&cellEntity) diff --git a/E2Manager/rNibWriter/rNibWriter_test.go b/E2Manager/rNibWriter/rNibWriter_test.go index 63a5d18..c887da6 100644 --- a/E2Manager/rNibWriter/rNibWriter_test.go +++ b/E2Manager/rNibWriter/rNibWriter_test.go @@ -128,7 +128,7 @@ func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) { rNibErr := w.UpdateNodebInfo(nodebInfo) assert.NotNil(t, rNibErr) - assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode()) + assert.IsType(t, &common.ValidationError{}, rNibErr) } func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) { @@ -223,8 +223,8 @@ func TestSaveEnbCellIdValidationFailure(t *testing.T) { nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} rNibErr := w.SaveNodeb(nbIdentity, &nb) assert.NotNil(t, rNibErr) - assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode()) - assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error()) + assert.IsType(t, &common.ValidationError{}, rNibErr) + assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error()) } func TestSaveEnbInventoryNameValidationFailure(t *testing.T) { @@ -244,8 +244,8 @@ func TestSaveEnbInventoryNameValidationFailure(t *testing.T) { nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} rNibErr := w.SaveNodeb(nbIdentity, &nb) assert.NotNil(t, rNibErr) - assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode()) - assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error()) + assert.IsType(t, &common.ValidationError{}, rNibErr) + assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error()) } func TestSaveEnbOnClosedPool(t *testing.T) { @@ -291,8 +291,8 @@ func TestSaveGnbCellIdValidationFailure(t *testing.T) { nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} rNibErr := w.SaveNodeb(nbIdentity, &nb) assert.NotNil(t, rNibErr) - assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode()) - assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error()) + assert.IsType(t, &common.ValidationError{}, rNibErr) + assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error()) } func TestSaveGnb(t *testing.T) { @@ -393,7 +393,7 @@ func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) { err := w.SaveRanLoadInformation(inventoryName, nil) assert.NotNil(t, err) - assert.Equal(t, common.VALIDATION_ERROR, err.GetCode()) + assert.IsType(t, &common.ValidationError{}, err) } func TestSaveRanLoadInformationSdlFailure(t *testing.T) { @@ -423,8 +423,7 @@ func TestSaveRanLoadInformationSdlFailure(t *testing.T) { rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation) assert.NotNil(t, rNibErr) - assert.Equal(t, common.INTERNAL_ERROR, rNibErr.GetCode()) - assert.Equal(t, expectedErr, rNibErr.GetError()) + assert.IsType(t, &common.InternalError{}, rNibErr) } func generateCellLoadInformation() *entities.CellLoadInformation { @@ -514,7 +513,7 @@ func TestSaveUnknownTypeEntityFailure(t *testing.T) { writerPool = nil initSdlInstanceMock(namespace, 1) w := GetRNibWriter() - expectedErr := common.NewValidationError(errors.New("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")) + expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ") nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} nb := &entities.NodebInfo{} nb.Port = 5656 @@ -548,17 +547,17 @@ func TestSaveEntityFailure(t *testing.T) { func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) { writerPool = nil - assert.Panics(t, func() { GetRNibWriter() }) + assert.Panics(t, func() { GetRNibWriter().SaveNodeb(nil,nil) }) } func TestGetRNibWriter(t *testing.T) { writerPool = nil initSdlInstanceMock(namespace, 1) received := GetRNibWriter() - assert.NotEmpty(t, received) + assert.Empty(t, received) available, created := writerPool.Stats() assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") - assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1") + assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") writerPool.Close() } @@ -571,13 +570,12 @@ func TestClose(t *testing.T) { writerPool.Put(w2) available, created := writerPool.Stats() assert.Equal(t, 2, available, "number of available objects in the writerPool should be 2") - assert.Equal(t, 2, created, "number of created objects in the writerPool should be 2") + assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") var e error instanceMock.On("Close").Return(e) Close() available, created = writerPool.Stats() assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") - assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") } func TestCloseOnClosedPoolFailure(t *testing.T) { @@ -587,7 +585,7 @@ func TestCloseOnClosedPoolFailure(t *testing.T) { writerPool.Put(w1) available, created := writerPool.Stats() assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1") - assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1") + assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") var e error instanceMock.On("Close").Return(e) Close() @@ -601,13 +599,12 @@ func TestCloseFailure(t *testing.T) { writerPool.Put(w1) available, created := writerPool.Stats() assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1") - assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1") + assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") e := errors.New("expected error") instanceMock.On("Close").Return(e) Close() available, created = writerPool.Stats() assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0") - assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0") } func TestInit(t *testing.T) { diff --git a/E2Manager/services/rnib_reader_service.go b/E2Manager/services/rnib_reader_service.go index 5d81220..4b014d7 100644 --- a/E2Manager/services/rnib_reader_service.go +++ b/E2Manager/services/rnib_reader_service.go @@ -18,7 +18,6 @@ package services import ( - "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" ) @@ -31,11 +30,11 @@ func NewRnibReaderService(rnibReaderProvider func() reader.RNibReader) *RnibRead return &RnibReaderService{rnibReaderProvider} } -func (s RnibReaderService) GetNodeb(ranName string) (*entities.NodebInfo, common.IRNibError) { +func (s RnibReaderService) GetNodeb(ranName string) (*entities.NodebInfo, error) { return s.rnibReaderProvider().GetNodeb(ranName) } -func (s RnibReaderService) GetNodebIdList()([]*entities.NbIdentity, common.IRNibError) { +func (s RnibReaderService) GetNodebIdList()([]*entities.NbIdentity, error) { return s.rnibReaderProvider().GetListNodebIds() } -- 2.16.6