From 06ff34e17cbb761e60da7e2638a6b7a5e9e5e3db Mon Sep 17 00:00:00 2001 From: Irina Date: Tue, 16 Jun 2020 20:42:58 +0300 Subject: [PATCH] RIC-395: E2M new REST API: E2M Set Parameters Change-Id: I629a5493e00c89f6d7c39ba5aec20afcba293adc Signed-off-by: Irina --- .../E2Term_Init_Message_Test.robot | 22 +++++ Automation/Tests/Resource/Keywords.robot | 3 + Automation/Tests/Resource/resource.robot | 2 + Automation/Tests/Resource/scripts_variables.robot | 3 +- .../Tests/SetGeneralConfiguration/__init__.robot | 20 ++++ .../set_general_configuration.robot | 48 ++++++++++ E2Manager/container-tag.yaml | 2 +- E2Manager/controllers/nodeb_controller.go | 14 ++- E2Manager/controllers/nodeb_controller_test.go | 33 +++++++ .../set_general_configuration_handler.go | 68 ++++++++++++++ .../set_general_configuration_handler_test.go | 102 +++++++++++++++++++++ E2Manager/httpserver/http_server.go | 1 + E2Manager/httpserver/http_server_test.go | 14 +++ E2Manager/mocks/nodeb_controller_mock.go | 7 ++ E2Manager/mocks/rnibWriterMock.go | 7 ++ E2Manager/models/general_configuration_request.go | 23 +++++ E2Manager/models/general_configuration_response.go | 41 +++++++++ .../incoming_request_handler_provider.go | 34 +++---- .../incoming_request_handler_provider_test.go | 12 +++ E2Manager/rNibWriter/rNibWriter.go | 34 ++++++- E2Manager/rNibWriter/rNibWriter_test.go | 31 +++++++ E2Manager/services/rnib_data_service.go | 12 +++ E2Manager/tests/dataProvider.go | 2 +- 23 files changed, 513 insertions(+), 22 deletions(-) create mode 100644 Automation/Tests/SetGeneralConfiguration/__init__.robot create mode 100644 Automation/Tests/SetGeneralConfiguration/set_general_configuration.robot create mode 100644 E2Manager/handlers/httpmsghandlers/set_general_configuration_handler.go create mode 100644 E2Manager/handlers/httpmsghandlers/set_general_configuration_handler_test.go create mode 100644 E2Manager/models/general_configuration_request.go create mode 100644 E2Manager/models/general_configuration_response.go diff --git a/Automation/Tests/E2Term_Initialization/E2Term_Init_Message_Test.robot b/Automation/Tests/E2Term_Initialization/E2Term_Init_Message_Test.robot index b575dd8..1351df7 100644 --- a/Automation/Tests/E2Term_Initialization/E2Term_Init_Message_Test.robot +++ b/Automation/Tests/E2Term_Initialization/E2Term_Init_Message_Test.robot @@ -1,3 +1,25 @@ +############################################################################## +# +# Copyright (c) 2019 AT&T Intellectual Property. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################## +# +# This source code is part of the near-RT RIC (RAN Intelligent Controller) +# platform project (RICP). +# + *** Settings *** Suite Setup Prepare Enviorment Resource ../Resource/resource.robot diff --git a/Automation/Tests/Resource/Keywords.robot b/Automation/Tests/Resource/Keywords.robot index 2f45a2d..1f453df 100644 --- a/Automation/Tests/Resource/Keywords.robot +++ b/Automation/Tests/Resource/Keywords.robot @@ -35,6 +35,9 @@ Update Ran request Sleep 1s PUT ${update_gnb_url} ${update_gnb_body} +Set General Configuration request + Sleep 1s + PUT ${set_general_configuration} ${set_general_configuration_body} Update Ran request not valid Sleep 1s diff --git a/Automation/Tests/Resource/resource.robot b/Automation/Tests/Resource/resource.robot index dcfe8d5..dc33988 100644 --- a/Automation/Tests/Resource/resource.robot +++ b/Automation/Tests/Resource/resource.robot @@ -30,6 +30,8 @@ ${docker_number-1} 4 ${url} http://localhost:3800 ${ranName} gnb_208_092_303030 ${getNodeb} /v1/nodeb/${ranName} +${set_general_configuration} /v1/nodeb/parameters +${set_general_configuration_body} {"enableRic":false} ${update_gnb_url} /v1/nodeb/${ranName}/update ${update_gnb_body} {"servedNrCells":[{"servedNrCellInformation":{"cellId":"abcd","choiceNrMode":{"fdd":{}},"nrMode":1,"nrPci":1,"servedPlmns":["whatever"]},"nrNeighbourInfos":[{"nrCgi":"one","choiceNrMode":{"fdd":{}},"nrMode":1,"nrPci":1}]}]} ${update_gnb_body_notvalid} {"servedNrCells":[{"servedNrCellInformation":{"choiceNrMode":{"fdd":{}},"nrMode":1,"nrPci":1,"servedPlmns":["whatever"]},"nrNeighbourInfos":[{"nrCgi":"whatever","choiceNrMode":{"fdd":{}},"nrMode":1,"nrPci":1}]}]} diff --git a/Automation/Tests/Resource/scripts_variables.robot b/Automation/Tests/Resource/scripts_variables.robot index 89dc05a..99c2944 100644 --- a/Automation/Tests/Resource/scripts_variables.robot +++ b/Automation/Tests/Resource/scripts_variables.robot @@ -32,5 +32,4 @@ ${first_retry_to_retrieve_from_db} RnibDataService.retry - retrying 1 GetNo ${third_retry_to_retrieve_from_db} RnibDataService.retry - after 3 attempts of GetNodeb ${RIC_RES_STATUS_REQ_message_type_successfully_sent} Message type: 10090 - Successfully sent RMR message ${E2_TERM_KEEP_ALIVE_REQ_message_type_successfully_sent} Message type: 1101 - Successfully sent RMR message - - +${save_general_configuration} RnibDataService.SaveGeneralConfiguration - configuration: {EnableRic:false} \ No newline at end of file diff --git a/Automation/Tests/SetGeneralConfiguration/__init__.robot b/Automation/Tests/SetGeneralConfiguration/__init__.robot new file mode 100644 index 0000000..4a008d9 --- /dev/null +++ b/Automation/Tests/SetGeneralConfiguration/__init__.robot @@ -0,0 +1,20 @@ +############################################################################## +# +# Copyright (c) 2019 AT&T Intellectual Property. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################## + +*** Settings *** +Documentation Resource status diff --git a/Automation/Tests/SetGeneralConfiguration/set_general_configuration.robot b/Automation/Tests/SetGeneralConfiguration/set_general_configuration.robot new file mode 100644 index 0000000..da7356b --- /dev/null +++ b/Automation/Tests/SetGeneralConfiguration/set_general_configuration.robot @@ -0,0 +1,48 @@ +############################################################################## +# +# Copyright (c) 2019 AT&T Intellectual Property. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################## +# +# This source code is part of the near-RT RIC (RAN Intelligent Controller) +# platform project (RICP). + + + +*** Settings *** +Suite Setup Prepare Enviorment +Resource ../Resource/resource.robot +Resource ../Resource/Keywords.robot +Library OperatingSystem +Library REST ${url} + + + + +*** Test Cases *** + +prepare logs for tests + Remove log files + Save logs + +Set General Configuration + Sleep 2s + Set General Configuration request + Integer response status 200 + String response body enableRic false + +Verify e2mgr logs - Third retry to retrieve from db + ${result} find_error_script.find_error ${EXECDIR} ${e2mgr_log_filename} ${save_general_configuration} + Should Be Equal As Strings ${result} True \ No newline at end of file diff --git a/E2Manager/container-tag.yaml b/E2Manager/container-tag.yaml index 923922c..7733427 100644 --- a/E2Manager/container-tag.yaml +++ b/E2Manager/container-tag.yaml @@ -1,4 +1,4 @@ # The Jenkins job requires a tag to build the Docker image. # Global-JJB script assumes this file is in the repo root. --- -tag: 5.0.2 +tag: 5.0.3 diff --git a/E2Manager/controllers/nodeb_controller.go b/E2Manager/controllers/nodeb_controller.go index d30db6b..49e821d 100644 --- a/E2Manager/controllers/nodeb_controller.go +++ b/E2Manager/controllers/nodeb_controller.go @@ -51,6 +51,7 @@ type INodebController interface { GetNodeb(writer http.ResponseWriter, r *http.Request) UpdateGnb(writer http.ResponseWriter, r *http.Request) GetNodebIdList(writer http.ResponseWriter, r *http.Request) + SetGeneralConfiguration(writer http.ResponseWriter, r *http.Request) } type NodebController struct { @@ -92,11 +93,22 @@ func (c *NodebController) UpdateGnb(writer http.ResponseWriter, r *http.Request) return } - request.Gnb = &gnb; + request.Gnb = &gnb request.RanName = ranName c.handleRequest(writer, &r.Header, httpmsghandlerprovider.UpdateGnbRequest, request, true) } +func (c *NodebController) SetGeneralConfiguration(writer http.ResponseWriter, r *http.Request) { + c.logger.Infof("[Client -> E2 Manager] #NodebController.SetGeneralConfiguration - request: %v", c.prettifyRequest(r)) + + request := models.GeneralConfigurationRequest{} + + if !c.extractJsonBody(r, &request, writer){ + return + } + c.handleRequest(writer, &r.Header, httpmsghandlerprovider.SetGeneralConfigurationRequest, request, false) +} + func (c *NodebController) Shutdown(writer http.ResponseWriter, r *http.Request) { c.logger.Infof("[Client -> E2 Manager] #NodebController.Shutdown - request: %v", c.prettifyRequest(r)) c.handleRequest(writer, &r.Header, httpmsghandlerprovider.ShutdownRequest, nil, false) diff --git a/E2Manager/controllers/nodeb_controller_test.go b/E2Manager/controllers/nodeb_controller_test.go index a9bccdc..1543674 100644 --- a/E2Manager/controllers/nodeb_controller_test.go +++ b/E2Manager/controllers/nodeb_controller_test.go @@ -277,6 +277,39 @@ func TestShutdownHandlerRnibError(t *testing.T) { assert.Equal(t, errorResponse.Code, e2managererrors.NewRnibDbError().Code) } +func TestSetGeneralConfigurationHandlerRnibError(t *testing.T) { + controller, readerMock, _, _, _ := setupControllerTest(t) + + configuration := &entities.GeneralConfiguration{} + readerMock.On("GetGeneralConfiguration").Return(configuration, e2managererrors.NewRnibDbError()) + + writer := httptest.NewRecorder() + + httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{\"enableRic\":false}")) + + controller.SetGeneralConfiguration(writer, httpRequest) + + var errorResponse = parseJsonRequest(t, writer.Body) + + assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) + assert.Equal(t, e2managererrors.NewRnibDbError().Code, errorResponse.Code) +} + +func TestSetGeneralConfigurationInvalidJson(t *testing.T) { + controller, _, _, _, _ := setupControllerTest(t) + + writer := httptest.NewRecorder() + + httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{}{}")) + + controller.SetGeneralConfiguration(writer, httpRequest) + + var errorResponse = parseJsonRequest(t, writer.Body) + + assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) + assert.Equal(t, e2managererrors.NewInvalidJsonError().Code, errorResponse.Code) +} + func controllerGetNodebTestExecuter(t *testing.T, context *controllerGetNodebTestContext) { controller, readerMock, _, _, _ := setupControllerTest(t) writer := httptest.NewRecorder() diff --git a/E2Manager/handlers/httpmsghandlers/set_general_configuration_handler.go b/E2Manager/handlers/httpmsghandlers/set_general_configuration_handler.go new file mode 100644 index 0000000..851dab1 --- /dev/null +++ b/E2Manager/handlers/httpmsghandlers/set_general_configuration_handler.go @@ -0,0 +1,68 @@ +// +// Copyright 2019 AT&T Intellectual Property +// Copyright 2019 Nokia +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This source code is part of the near-RT RIC (RAN Intelligent Controller) +// platform project (RICP). + +package httpmsghandlers + +import "C" +import ( + "e2mgr/e2managererrors" + "e2mgr/logger" + "e2mgr/models" + "e2mgr/services" +) + +type SetGeneralConfigurationHandler struct { + rnibDataService services.RNibDataService + logger *logger.Logger +} + +func NewSetGeneralConfigurationHandler(logger *logger.Logger, rnibDataService services.RNibDataService) *SetGeneralConfigurationHandler { + return &SetGeneralConfigurationHandler{ + logger: logger, + rnibDataService: rnibDataService, + } +} + +func (h *SetGeneralConfigurationHandler) Handle(request models.Request) (models.IResponse, error) { + h.logger.Infof("#SetGeneralConfigurationHandler.Handle - handling set general parameters") + + configuration := request.(models.GeneralConfigurationRequest) + + existingConfig, err := h.rnibDataService.GetGeneralConfiguration() + + if err != nil { + h.logger.Errorf("#SetGeneralConfigurationHandler.Handle - Error fetching general configuration from rNib: %s", err) + return nil, e2managererrors.NewRnibDbError() + } + + if existingConfig.EnableRic != configuration.EnableRic { + + existingConfig.EnableRic = configuration.EnableRic + err := h.rnibDataService.SaveGeneralConfiguration(existingConfig) + + if err != nil { + h.logger.Errorf("#SetGeneralConfigurationHandler.Handle - failed to save general configuration in RNIB. error: %s", err) + return nil, e2managererrors.NewRnibDbError() + } + + } + response := &models.GeneralConfigurationResponse{EnableRic: configuration.EnableRic} + + return response, nil +} diff --git a/E2Manager/handlers/httpmsghandlers/set_general_configuration_handler_test.go b/E2Manager/handlers/httpmsghandlers/set_general_configuration_handler_test.go new file mode 100644 index 0000000..284f922 --- /dev/null +++ b/E2Manager/handlers/httpmsghandlers/set_general_configuration_handler_test.go @@ -0,0 +1,102 @@ +// +// Copyright 2019 AT&T Intellectual Property +// Copyright 2019 Nokia +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This source code is part of the near-RT RIC (RAN Intelligent Controller) +// platform project (RICP). + +package httpmsghandlers + +import ( + "e2mgr/configuration" + "e2mgr/mocks" + "e2mgr/models" + "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" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + "testing" +) + +func setupSetGeneralConfigurationHandlerTest(t *testing.T) (*SetGeneralConfigurationHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock) { + log := initLog(t) + config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3} + readerMock := &mocks.RnibReaderMock{} + writerMock := &mocks.RnibWriterMock{} + rnibDataService := services.NewRnibDataService(log, config, readerMock, writerMock) + handler := NewSetGeneralConfigurationHandler(log, rnibDataService) + return handler, readerMock, writerMock +} + +func TestSetGeneralConfigurationFalse_Success(t *testing.T) { + handler, readerMock, writerMock := setupSetGeneralConfigurationHandlerTest(t) + + configuration := &entities.GeneralConfiguration{EnableRic: true} + readerMock.On("GetGeneralConfiguration").Return(configuration, nil) + + updated := &entities.GeneralConfiguration{EnableRic: false} + writerMock.On("SaveGeneralConfiguration", updated).Return(nil) + + response, err := handler.Handle(models.GeneralConfigurationRequest{EnableRic: false}) + + assert.Nil(t, err) + assert.NotNil(t, response) + assert.IsType(t, &models.GeneralConfigurationResponse{}, response) +} + +func TestSetGeneralConfigurationTrue_Success(t *testing.T) { + handler, readerMock, writerMock := setupSetGeneralConfigurationHandlerTest(t) + + configuration := &entities.GeneralConfiguration{EnableRic: false} + readerMock.On("GetGeneralConfiguration").Return(configuration, nil) + + updated := &entities.GeneralConfiguration{EnableRic: true} + writerMock.On("SaveGeneralConfiguration", updated).Return(nil) + + response, err := handler.Handle(models.GeneralConfigurationRequest{EnableRic: true}) + + assert.Nil(t, err) + assert.NotNil(t, response) + assert.IsType(t, &models.GeneralConfigurationResponse{}, response) +} + +func TestSetGeneralConfigurationIgnore_Success(t *testing.T) { + handler, readerMock, _ := setupSetGeneralConfigurationHandlerTest(t) + + configuration := &entities.GeneralConfiguration{EnableRic: false} + readerMock.On("GetGeneralConfiguration").Return(configuration, nil) + + response, err := handler.Handle(models.GeneralConfigurationRequest{EnableRic: false}) + + assert.Nil(t, err) + assert.NotNil(t, response) + assert.IsType(t, &models.GeneralConfigurationResponse{}, response) +} + +func TestSetGeneralConfigurationHandlerRnibError(t *testing.T) { + handler, readerMock, writerMock := setupSetGeneralConfigurationHandlerTest(t) + + configuration := &entities.GeneralConfiguration{EnableRic: false} + readerMock.On("GetGeneralConfiguration").Return(configuration, nil) + + updated := &entities.GeneralConfiguration{EnableRic: true} + writerMock.On("SaveGeneralConfiguration", updated).Return(common.NewInternalError(errors.New("error"))) + + response, err := handler.Handle(models.GeneralConfigurationRequest{EnableRic: true}) + + assert.NotNil(t, err) + assert.Nil(t, response) +} diff --git a/E2Manager/httpserver/http_server.go b/E2Manager/httpserver/http_server.go index a022ecb..320acd0 100644 --- a/E2Manager/httpserver/http_server.go +++ b/E2Manager/httpserver/http_server.go @@ -49,6 +49,7 @@ func initializeRoutes(router *mux.Router, rootController controllers.IRootContro rr.HandleFunc("/{ranName}", nodebController.GetNodeb).Methods(http.MethodGet) rr.HandleFunc("/{ranName}/update", nodebController.UpdateGnb).Methods(http.MethodPut) rr.HandleFunc("/shutdown", nodebController.Shutdown).Methods(http.MethodPut) + rr.HandleFunc("/parameters", nodebController.SetGeneralConfiguration).Methods(http.MethodPut) rrr := r.PathPrefix("/e2t").Subrouter() rrr.HandleFunc("/list", e2tController.GetE2TInstances).Methods(http.MethodGet) } diff --git a/E2Manager/httpserver/http_server_test.go b/E2Manager/httpserver/http_server_test.go index 3c0620b..cdca134 100644 --- a/E2Manager/httpserver/http_server_test.go +++ b/E2Manager/httpserver/http_server_test.go @@ -39,6 +39,7 @@ func setupRouterAndMocks() (*mux.Router, *mocks.RootControllerMock, *mocks.Nodeb nodebControllerMock.On("Shutdown").Return(nil) nodebControllerMock.On("GetNodeb").Return(nil) nodebControllerMock.On("GetNodebIdList").Return(nil) + nodebControllerMock.On("SetGeneralConfiguration").Return(nil) e2tControllerMock := &mocks.E2TControllerMock{} @@ -103,6 +104,19 @@ func TestRoutePutNodebShutdown(t *testing.T) { nodebControllerMock.AssertNumberOfCalls(t, "Shutdown", 1) } +func TestRoutePutNodebSetGeneralConfiguration(t *testing.T) { + router, _, nodebControllerMock, _ := setupRouterAndMocks() + + req, err := http.NewRequest("PUT", "/v1/nodeb/parameters", nil) + if err != nil { + t.Fatal(err) + } + rr := httptest.NewRecorder() + router.ServeHTTP(rr, req) + + nodebControllerMock.AssertNumberOfCalls(t, "SetGeneralConfiguration", 1) +} + func TestRouteNotFound(t *testing.T) { router, _, _,_ := setupRouterAndMocks() diff --git a/E2Manager/mocks/nodeb_controller_mock.go b/E2Manager/mocks/nodeb_controller_mock.go index a164383..11130b3 100644 --- a/E2Manager/mocks/nodeb_controller_mock.go +++ b/E2Manager/mocks/nodeb_controller_mock.go @@ -81,3 +81,10 @@ func (c *NodebControllerMock) UpdateGnb(writer http.ResponseWriter, r *http.Requ c.Called() } + +func (c *NodebControllerMock) SetGeneralConfiguration(writer http.ResponseWriter, r *http.Request) { + writer.Header().Set("Content-Type", "application/json") + writer.WriteHeader(http.StatusOK) + + c.Called() +} \ No newline at end of file diff --git a/E2Manager/mocks/rnibWriterMock.go b/E2Manager/mocks/rnibWriterMock.go index b076614..3503d10 100644 --- a/E2Manager/mocks/rnibWriterMock.go +++ b/E2Manager/mocks/rnibWriterMock.go @@ -94,5 +94,12 @@ func (rnibWriterMock *RnibWriterMock) RemoveServedNrCells(inventoryName string, func (rnibWriterMock *RnibWriterMock) UpdateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, stateChangeMessageChannel string, event string) error { args := rnibWriterMock.Called(nodebInfo, stateChangeMessageChannel, event) + + return args.Error(0) +} + +func (rnibWriterMock *RnibWriterMock) SaveGeneralConfiguration(config *entities.GeneralConfiguration) error { + args := rnibWriterMock.Called(config) + return args.Error(0) } \ No newline at end of file diff --git a/E2Manager/models/general_configuration_request.go b/E2Manager/models/general_configuration_request.go new file mode 100644 index 0000000..5a642ad --- /dev/null +++ b/E2Manager/models/general_configuration_request.go @@ -0,0 +1,23 @@ +// +// Copyright 2019 AT&T Intellectual Property +// Copyright 2019 Nokia +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package models + + +type GeneralConfigurationRequest struct { + EnableRic bool `json:"enableRic"` +} diff --git a/E2Manager/models/general_configuration_response.go b/E2Manager/models/general_configuration_response.go new file mode 100644 index 0000000..f19761c --- /dev/null +++ b/E2Manager/models/general_configuration_response.go @@ -0,0 +1,41 @@ +// +// Copyright 2019 AT&T Intellectual Property +// Copyright 2019 Nokia +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This source code is part of the near-RT RIC (RAN Intelligent Controller) +// platform project (RICP). + + +package models + +import ( + "e2mgr/e2managererrors" + "encoding/json" +) + +type GeneralConfigurationResponse struct { + EnableRic bool `json:"enableRic"` +} + +func (response *GeneralConfigurationResponse) Marshal() ([]byte, error) { + + data, err := json.Marshal(response) + + if err != nil { + return nil, e2managererrors.NewInternalError() + } + + return data, nil +} \ No newline at end of file diff --git a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go index f5572cd..9e45372 100644 --- a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go +++ b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go @@ -34,14 +34,15 @@ import ( type IncomingRequest string const ( - ShutdownRequest IncomingRequest = "Shutdown" - ResetRequest IncomingRequest = "Reset" - X2SetupRequest IncomingRequest = "X2SetupRequest" - EndcSetupRequest IncomingRequest = "EndcSetupRequest" - GetNodebRequest IncomingRequest = "GetNodebRequest" - GetNodebIdListRequest IncomingRequest = "GetNodebIdListRequest" - GetE2TInstancesRequest IncomingRequest = "GetE2TInstancesRequest" - UpdateGnbRequest IncomingRequest = "UpdateGnbRequest" + SetGeneralConfigurationRequest IncomingRequest = "SetGeneralConfiguration" + ShutdownRequest IncomingRequest = "Shutdown" + ResetRequest IncomingRequest = "Reset" + X2SetupRequest IncomingRequest = "X2SetupRequest" + EndcSetupRequest IncomingRequest = "EndcSetupRequest" + GetNodebRequest IncomingRequest = "GetNodebRequest" + GetNodebIdListRequest IncomingRequest = "GetNodebIdListRequest" + GetE2TInstancesRequest IncomingRequest = "GetE2TInstancesRequest" + UpdateGnbRequest IncomingRequest = "UpdateGnbRequest" ) type IncomingRequestHandlerProvider struct { @@ -60,14 +61,15 @@ func NewIncomingRequestHandlerProvider(logger *logger.Logger, rmrSender *rmrsend func initRequestHandlerMap(logger *logger.Logger, rmrSender *rmrsender.RmrSender, config *configuration.Configuration, rNibDataService services.RNibDataService, ranSetupManager *managers.RanSetupManager, e2tInstancesManager managers.IE2TInstancesManager, e2tAssociationManager *managers.E2TAssociationManager, rmClient clients.IRoutingManagerClient) map[IncomingRequest]httpmsghandlers.RequestHandler { return map[IncomingRequest]httpmsghandlers.RequestHandler{ - ShutdownRequest: httpmsghandlers.NewDeleteAllRequestHandler(logger, rmrSender, config, rNibDataService, e2tInstancesManager, rmClient), - ResetRequest: httpmsghandlers.NewX2ResetRequestHandler(logger, rmrSender, rNibDataService), - X2SetupRequest: httpmsghandlers.NewSetupRequestHandler(logger, rNibDataService, ranSetupManager, entities.E2ApplicationProtocol_X2_SETUP_REQUEST, e2tInstancesManager, e2tAssociationManager), - EndcSetupRequest: httpmsghandlers.NewSetupRequestHandler(logger, rNibDataService, ranSetupManager, entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST, e2tInstancesManager, e2tAssociationManager), - GetNodebRequest: httpmsghandlers.NewGetNodebRequestHandler(logger, rNibDataService), - GetNodebIdListRequest: httpmsghandlers.NewGetNodebIdListRequestHandler(logger, rNibDataService), - GetE2TInstancesRequest: httpmsghandlers.NewGetE2TInstancesRequestHandler(logger, e2tInstancesManager), - UpdateGnbRequest: httpmsghandlers.NewUpdateGnbRequestHandler(logger, rNibDataService), + ShutdownRequest: httpmsghandlers.NewDeleteAllRequestHandler(logger, rmrSender, config, rNibDataService, e2tInstancesManager, rmClient), + ResetRequest: httpmsghandlers.NewX2ResetRequestHandler(logger, rmrSender, rNibDataService), + X2SetupRequest: httpmsghandlers.NewSetupRequestHandler(logger, rNibDataService, ranSetupManager, entities.E2ApplicationProtocol_X2_SETUP_REQUEST, e2tInstancesManager, e2tAssociationManager), + EndcSetupRequest: httpmsghandlers.NewSetupRequestHandler(logger, rNibDataService, ranSetupManager, entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST, e2tInstancesManager, e2tAssociationManager), + GetNodebRequest: httpmsghandlers.NewGetNodebRequestHandler(logger, rNibDataService), + GetNodebIdListRequest: httpmsghandlers.NewGetNodebIdListRequestHandler(logger, rNibDataService), + GetE2TInstancesRequest: httpmsghandlers.NewGetE2TInstancesRequestHandler(logger, e2tInstancesManager), + UpdateGnbRequest: httpmsghandlers.NewUpdateGnbRequestHandler(logger, rNibDataService), + SetGeneralConfigurationRequest: httpmsghandlers.NewSetGeneralConfigurationHandler(logger, rNibDataService), } } diff --git a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go index e06105f..3a04f0b 100644 --- a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go +++ b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go @@ -78,6 +78,18 @@ func TestShutdownRequestHandler(t *testing.T) { assert.True(t, ok) } +func TestSetGeneralConfigurationHandler(t *testing.T) { + provider := setupTest(t) + handler, err := provider.GetHandler(SetGeneralConfigurationRequest) + + assert.NotNil(t, provider) + assert.Nil(t, err) + + _, ok := handler.(*httpmsghandlers.SetGeneralConfigurationHandler) + + assert.True(t, ok) +} + func TestX2SetupRequestHandler(t *testing.T) { provider := setupTest(t) handler, err := provider.GetHandler(X2SetupRequest) diff --git a/E2Manager/rNibWriter/rNibWriter.go b/E2Manager/rNibWriter/rNibWriter.go index df4c7d6..3186d70 100644 --- a/E2Manager/rNibWriter/rNibWriter.go +++ b/E2Manager/rNibWriter/rNibWriter.go @@ -46,6 +46,7 @@ type RNibWriter interface { UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error RemoveServedNrCells(inventoryName string, servedNrCells []*entities.ServedNRCell) error UpdateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, stateChangeMessageChannel string, event string) error + SaveGeneralConfiguration(config *entities.GeneralConfiguration) error } /* @@ -68,6 +69,17 @@ func (w *rNibWriterInstance) RemoveServedNrCells(inventoryName string, servedNrC return nil } +func (w *rNibWriterInstance) SaveGeneralConfiguration(config *entities.GeneralConfiguration) error { + + err := w.SaveWithKeyAndMarshal(common.BuildGeneralConfigurationKey(), config) + + if err != nil { + return common.NewInternalError(err) + } + + return nil +} + /* SaveNodeb saves nodeB entity data in the redis DB according to the specified data model */ @@ -316,6 +328,26 @@ func (w *rNibWriterInstance) RemoveE2TInstance(address string) error { return nil } +func (w *rNibWriterInstance) SaveWithKeyAndMarshal(key string, entity interface{}) error { + + data, err := json.Marshal(entity) + + if err != nil { + return common.NewInternalError(err) + } + + var pairs []interface{} + pairs = append(pairs, key, data) + + err = w.sdl.Set(pairs) + + if err != nil { + return common.NewInternalError(err) + } + + return nil +} + /* UpdateNodebInfoOnConnectionStatusInversion... */ @@ -387,4 +419,4 @@ func appendGnbCells(inventoryName string, cells []*entities.ServedNRCell, pairs func isNotEmpty(nbIdentity *entities.NbIdentity) bool { return nbIdentity.GlobalNbId != nil && nbIdentity.GlobalNbId.PlmnId != "" && nbIdentity.GlobalNbId.NbId != "" -} +} \ No newline at end of file diff --git a/E2Manager/rNibWriter/rNibWriter_test.go b/E2Manager/rNibWriter/rNibWriter_test.go index 07efb66..ec21c3f 100644 --- a/E2Manager/rNibWriter/rNibWriter_test.go +++ b/E2Manager/rNibWriter/rNibWriter_test.go @@ -819,6 +819,37 @@ func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing. assert.Nil(t, rNibErr) } +func TestSaveGeneralConfiguration(t *testing.T) { + w, sdlInstanceMock := initSdlInstanceMock(namespace) + + key := common.BuildGeneralConfigurationKey() + configurationData := "{\"enableRic\":true}" + configuration := &entities.GeneralConfiguration{} + configuration.EnableRic = true + + sdlInstanceMock.On("Set",[]interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil) + rNibErr := w.SaveGeneralConfiguration(configuration) + + assert.Nil(t, rNibErr) + sdlInstanceMock.AssertExpectations(t) +} + +func TestSaveGeneralConfigurationDbError(t *testing.T) { + w, sdlInstanceMock := initSdlInstanceMock(namespace) + + key := common.BuildGeneralConfigurationKey() + configurationData := "{\"enableRic\":true}" + configuration := &entities.GeneralConfiguration{} + configuration.EnableRic = true + + expectedErr := errors.New("expected error") + + sdlInstanceMock.On("Set",[]interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr) + rNibErr := w.SaveGeneralConfiguration(configuration) + + assert.NotNil(t, rNibErr) +} + //Integration tests // //func TestSaveEnbGnbInteg(t *testing.T){ diff --git a/E2Manager/services/rnib_data_service.go b/E2Manager/services/rnib_data_service.go index 03d7baf..dbc9e29 100644 --- a/E2Manager/services/rnib_data_service.go +++ b/E2Manager/services/rnib_data_service.go @@ -51,6 +51,7 @@ type RNibDataService interface { RemoveServedNrCells(inventoryName string, servedNrCells []*entities.ServedNRCell) error GetGeneralConfiguration() (*entities.GeneralConfiguration, error) UpdateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, event string) error + SaveGeneralConfiguration(config *entities.GeneralConfiguration) error } type rNibDataService struct { @@ -288,6 +289,17 @@ func (w *rNibDataService) GetGeneralConfiguration() (*entities.GeneralConfigurat return generalConfiguration, err } +func (w *rNibDataService) SaveGeneralConfiguration(config *entities.GeneralConfiguration) error { + w.logger.Infof("#RnibDataService.SaveGeneralConfiguration - configuration: %+v", *config) + + err := w.retry("SaveGeneralConfiguration", func() (err error) { + err = w.rnibWriter.SaveGeneralConfiguration(config) + return + }) + + return err +} + func (w *rNibDataService) PingRnib() bool { err := w.retry("GetListNodebIds", func() (err error) { _, err = w.rnibReader.GetListNodebIds() diff --git a/E2Manager/tests/dataProvider.go b/E2Manager/tests/dataProvider.go index dfa637e..0adf3f9 100644 --- a/E2Manager/tests/dataProvider.go +++ b/E2Manager/tests/dataProvider.go @@ -55,4 +55,4 @@ func GetHttpRequest() *http.Request { _ = json.NewEncoder(b).Encode(data) req, _ := http.NewRequest("POST", "https://localhost:3800/request", b) return req -} +} \ No newline at end of file -- 2.16.6