From b2f2743968c5cda9a708bf5a6f32678caabd6976 Mon Sep 17 00:00:00 2001 From: Irina Date: Tue, 7 Jul 2020 11:17:10 +0000 Subject: [PATCH] [RIC-432] - Support Update eNB REST API. kubernetes removed and nodebValidator added Change-Id: Id5b901d5909aa26e45e49439e1c0570f84430475 Signed-off-by: Irina --- E2Manager/app/main.go | 8 +- E2Manager/container-tag.yaml | 2 +- E2Manager/controllers/e2t_controller_test.go | 3 +- E2Manager/controllers/nodeb_controller_test.go | 6 +- E2Manager/go.mod | 1 - .../httpmsghandlers/add_enb_request_handler.go | 72 +--------- E2Manager/kube_config.yml | 17 --- E2Manager/managers/e2t_shutdown_manager.go | 6 +- E2Manager/managers/e2t_shutdown_manager_test.go | 33 ++--- E2Manager/managers/kubernetes_manager.go | 87 ------------ E2Manager/managers/kubernetes_manager_test.go | 152 --------------------- E2Manager/managers/nodeb_validator.go | 97 +++++++++++++ .../incoming_request_handler_provider.go | 8 +- .../incoming_request_handler_provider_test.go | 5 +- 14 files changed, 131 insertions(+), 366 deletions(-) delete mode 100644 E2Manager/kube_config.yml delete mode 100644 E2Manager/managers/kubernetes_manager.go delete mode 100644 E2Manager/managers/kubernetes_manager_test.go create mode 100644 E2Manager/managers/nodeb_validator.go diff --git a/E2Manager/app/main.go b/E2Manager/app/main.go index cc38556..0ad6412 100644 --- a/E2Manager/app/main.go +++ b/E2Manager/app/main.go @@ -57,22 +57,20 @@ func main() { var msgImpl *rmrCgo.Context rmrMessenger := msgImpl.Init("tcp:"+strconv.Itoa(config.Rmr.Port), config.Rmr.MaxMsgSize, 0, logger) rmrSender := rmrsender.NewRmrSender(logger, rmrMessenger) - kubernetes := managers.NewKubernetesManager(logger, config) - ranSetupManager := managers.NewRanSetupManager(logger, rmrSender, rnibDataService) e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, logger) routingManagerClient := clients.NewRoutingManagerClient(logger, config, clients.NewHttpClient()) ranListManager := managers.NewRanListManager(logger) ranAlarmService := services.NewRanAlarmService(logger, config) ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(logger, rnibDataService, ranListManager, ranAlarmService) e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient, ranConnectStatusChangeManager) - e2tShutdownManager := managers.NewE2TShutdownManager(logger, config, rnibDataService, e2tInstancesManager, e2tAssociationManager, kubernetes, ranConnectStatusChangeManager) + e2tShutdownManager := managers.NewE2TShutdownManager(logger, config, rnibDataService, e2tInstancesManager, e2tAssociationManager, ranConnectStatusChangeManager) e2tKeepAliveWorker := managers.NewE2TKeepAliveWorker(logger, rmrSender, e2tInstancesManager, e2tShutdownManager, config) rmrNotificationHandlerProvider := rmrmsghandlerprovider.NewNotificationHandlerProvider() rmrNotificationHandlerProvider.Init(logger, config, rnibDataService, rmrSender, e2tInstancesManager, routingManagerClient, e2tAssociationManager, ranConnectStatusChangeManager) notificationManager := notificationmanager.NewNotificationManager(logger, rmrNotificationHandlerProvider) rmrReceiver := rmrreceiver.NewRmrReceiver(logger, rmrMessenger, notificationManager) - + nodebValidator := managers.NewNodebValidator() e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances() defer rmrMessenger.Close() @@ -80,7 +78,7 @@ func main() { go rmrReceiver.ListenAndHandle() go e2tKeepAliveWorker.Execute() - httpMsgHandlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(logger, rmrSender, config, rnibDataService, ranSetupManager, e2tInstancesManager, e2tAssociationManager, routingManagerClient, ranConnectStatusChangeManager) + httpMsgHandlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(logger, rmrSender, config, rnibDataService, e2tInstancesManager, routingManagerClient, ranConnectStatusChangeManager, nodebValidator) rootController := controllers.NewRootController(rnibDataService) nodebController := controllers.NewNodebController(logger, httpMsgHandlerProvider) e2tController := controllers.NewE2TController(logger, httpMsgHandlerProvider) diff --git a/E2Manager/container-tag.yaml b/E2Manager/container-tag.yaml index e12ccfc..d452c65 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.2.6 +tag: 5.2.7 diff --git a/E2Manager/controllers/e2t_controller_test.go b/E2Manager/controllers/e2t_controller_test.go index 17abc4e..915e78e 100644 --- a/E2Manager/controllers/e2t_controller_test.go +++ b/E2Manager/controllers/e2t_controller_test.go @@ -58,8 +58,9 @@ func setupE2TControllerTest(t *testing.T) (*E2TController, *mocks.RnibReaderMock ranListManager := managers.NewRanListManager(log) ranAlarmService := services.NewRanAlarmService(log, config) ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService,ranListManager, ranAlarmService) + nodebValidator := managers.NewNodebValidator() - handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, nil, config, rnibDataService, nil, e2tInstancesManager, &managers.E2TAssociationManager{}, nil, ranConnectStatusChangeManager) + handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, nil, config, rnibDataService, e2tInstancesManager, nil, ranConnectStatusChangeManager, nodebValidator) controller := NewE2TController(log, handlerProvider) return controller, readerMock } diff --git a/E2Manager/controllers/nodeb_controller_test.go b/E2Manager/controllers/nodeb_controller_test.go index 78be089..0cbeb50 100644 --- a/E2Manager/controllers/nodeb_controller_test.go +++ b/E2Manager/controllers/nodeb_controller_test.go @@ -211,16 +211,14 @@ func setupControllerTest(t *testing.T) (*NodebController, *mocks.RnibReaderMock, rnibDataService := services.NewRnibDataService(log, config, readerMock, writerMock) rmrSender := getRmrSender(rmrMessengerMock, log) - ranSetupManager := managers.NewRanSetupManager(log, rmrSender, rnibDataService) e2tInstancesManager := &mocks.E2TInstancesManagerMock{} httpClientMock := &mocks.HttpClientMock{} rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock) ranListManager := &mocks.RanListManagerMock{} ranAlarmService := &mocks.RanAlarmServiceMock{} ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService) - - e2tAssociationManager := managers.NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager) - handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, ranSetupManager, e2tInstancesManager, e2tAssociationManager, rmClient, ranConnectStatusChangeManager) + nodebValidator := managers.NewNodebValidator() + handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator) controller := NewNodebController(log, handlerProvider) return controller, readerMock, writerMock, rmrMessengerMock, e2tInstancesManager } diff --git a/E2Manager/go.mod b/E2Manager/go.mod index 2ed9c80..ad730fc 100644 --- a/E2Manager/go.mod +++ b/E2Manager/go.mod @@ -21,7 +21,6 @@ require ( google.golang.org/appengine v1.6.1 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.2.8 - k8s.io/client-go v0.17.0 ) replace gerrit.o-ran-sc.org/r/ric-plt/sdlgo => gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.5.2 diff --git a/E2Manager/handlers/httpmsghandlers/add_enb_request_handler.go b/E2Manager/handlers/httpmsghandlers/add_enb_request_handler.go index c8615a4..8710396 100644 --- a/E2Manager/handlers/httpmsghandlers/add_enb_request_handler.go +++ b/E2Manager/handlers/httpmsghandlers/add_enb_request_handler.go @@ -22,6 +22,7 @@ package httpmsghandlers import ( "e2mgr/e2managererrors" "e2mgr/logger" + "e2mgr/managers" "e2mgr/models" "e2mgr/services" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" @@ -31,12 +32,14 @@ import ( type AddEnbRequestHandler struct { logger *logger.Logger + nodebValidator *managers.NodebValidator rNibDataService services.RNibDataService } -func NewAddEnbRequestHandler(logger *logger.Logger, rNibDataService services.RNibDataService) *AddEnbRequestHandler { +func NewAddEnbRequestHandler(logger *logger.Logger, rNibDataService services.RNibDataService, nodebValidator *managers.NodebValidator) *AddEnbRequestHandler { return &AddEnbRequestHandler{ logger: logger, + nodebValidator: nodebValidator, rNibDataService: rNibDataService, } } @@ -120,7 +123,7 @@ func (h *AddEnbRequestHandler) validateRequestBody(addEnbRequest *models.AddEnbR return errors.New("enb") } - if err := isEnbValid(addEnbRequest.Enb); err != nil { + if err := h.nodebValidator.IsEnbValid(addEnbRequest.Enb); err != nil { return err } @@ -138,68 +141,3 @@ func isGlobalNbIdValid(globalNbId *entities.GlobalNbId) error { return nil } - -func isEnbValid(enb *entities.Enb) error { - if enb.EnbType == entities.EnbType_UNKNOWN_ENB_TYPE { - return errors.New("enb.enbType") - } - - if enb.ServedCells == nil || len(enb.ServedCells) == 0 { - return errors.New("enb.servedCells") - } - - for _, servedCell := range enb.ServedCells { - err := isServedCellValid(servedCell) - - if err != nil { - return err - } - } - - return nil -} - -func isServedCellValid(servedCell *entities.ServedCellInfo) error { - - if servedCell.CellId == "" { - return errors.New("servedCell.cellId") - } - - if servedCell.EutraMode == entities.Eutra_UNKNOWN { - return errors.New("servedCell.eutraMode") - } - - if servedCell.Tac == "" { - return errors.New("servedCell.tac") - } - - if servedCell.BroadcastPlmns == nil || len(servedCell.BroadcastPlmns) == 0 { - return errors.New("servedCell.broadcastPlmns") - } - - if servedCell.ChoiceEutraMode == nil { - return errors.New("servedCell.choiceEutraMode") - } - - return isChoiceEutraModeValid(servedCell.ChoiceEutraMode) -} - -func isChoiceEutraModeValid(choiceEutraMode *entities.ChoiceEUTRAMode) error { - if choiceEutraMode.Fdd != nil { - return isFddInfoValid(choiceEutraMode.Fdd) - } - - if choiceEutraMode.Tdd != nil { - return isTddInfoValid(choiceEutraMode.Tdd) - } - - return errors.New("servedCell.fdd / servedCell.tdd") -} - -func isTddInfoValid(tdd *entities.TddInfo) error { - return nil -} - -func isFddInfoValid(fdd *entities.FddInfo) error { - return nil -} diff --git a/E2Manager/kube_config.yml b/E2Manager/kube_config.yml deleted file mode 100644 index 0163244..0000000 --- a/E2Manager/kube_config.yml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Config -users: -- name: someuser - user: - token: sometoken -clusters: -- cluster: - certificate-authority-data: somedata - server: 10.0.2.15:59009 - name: self-hosted-cluster -contexts: -- context: - cluster: self-hosted-cluster - user: svcs-acct-dply - name: svcs-acct-context -current-context: svcs-acct-context diff --git a/E2Manager/managers/e2t_shutdown_manager.go b/E2Manager/managers/e2t_shutdown_manager.go index 2b82d3a..61761f2 100644 --- a/E2Manager/managers/e2t_shutdown_manager.go +++ b/E2Manager/managers/e2t_shutdown_manager.go @@ -39,18 +39,16 @@ type E2TShutdownManager struct { rnibDataService services.RNibDataService e2TInstancesManager IE2TInstancesManager e2tAssociationManager *E2TAssociationManager - kubernetesManager *KubernetesManager ranConnectStatusChangeManager IRanConnectStatusChangeManager } -func NewE2TShutdownManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, e2TInstancesManager IE2TInstancesManager, e2tAssociationManager *E2TAssociationManager, kubernetes *KubernetesManager, ranConnectStatusChangeManager IRanConnectStatusChangeManager) *E2TShutdownManager { +func NewE2TShutdownManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, e2TInstancesManager IE2TInstancesManager, e2tAssociationManager *E2TAssociationManager, ranConnectStatusChangeManager IRanConnectStatusChangeManager) *E2TShutdownManager { return &E2TShutdownManager{ logger: logger, config: config, rnibDataService: rnibDataService, e2TInstancesManager: e2TInstancesManager, e2tAssociationManager: e2tAssociationManager, - kubernetesManager: kubernetes, ranConnectStatusChangeManager: ranConnectStatusChangeManager, } } @@ -64,8 +62,6 @@ func (m E2TShutdownManager) Shutdown(e2tInstance *entities.E2TInstance) error { return nil } - //go m.kubernetesManager.DeletePod(e2tInstance.PodName) - err := m.markE2tInstanceToBeDeleted(e2tInstance) if err != nil { m.logger.Errorf("#E2TShutdownManager.Shutdown - Failed to mark E2T %s as 'ToBeDeleted'.", e2tInstance.Address) diff --git a/E2Manager/managers/e2t_shutdown_manager_test.go b/E2Manager/managers/e2t_shutdown_manager_test.go index 0a1d00d..a8c4c3b 100644 --- a/E2Manager/managers/e2t_shutdown_manager_test.go +++ b/E2Manager/managers/e2t_shutdown_manager_test.go @@ -44,7 +44,7 @@ import ( const E2TAddress3 = "10.10.2.17:9800" -func initE2TShutdownManagerTest(t *testing.T) (*E2TShutdownManager, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock, *KubernetesManager) { +func initE2TShutdownManagerTest(t *testing.T) (*E2TShutdownManager, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) { log := initLog(t) config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3, E2TInstanceDeletionTimeoutMs: 15000, RnibWriter: configuration.RnibWriterConfig{StateChangeMessageChannel: "RAN_CONNECTION_STATUS_CHANGE"}} @@ -60,18 +60,13 @@ func initE2TShutdownManagerTest(t *testing.T) (*E2TShutdownManager, *mocks.RnibR ranAlarmService := services.NewRanAlarmService(log, config) ranConnectStatusChangeManager := NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService) associationManager := NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager) - //kubernetesManager := initKubernetesManagerTest(t) + shutdownManager := NewE2TShutdownManager(log, config, rnibDataService, e2tInstancesManager, associationManager, ranConnectStatusChangeManager) - /*shutdownManager := NewE2TShutdownManager(log, config, rnibDataService, e2tInstancesManager, associationManager, kubernetesManager) - - return shutdownManager, readerMock, writerMock, httpClientMock, kubernetesManager*/ - shutdownManager := NewE2TShutdownManager(log, config, rnibDataService, e2tInstancesManager, associationManager, nil, ranConnectStatusChangeManager) - - return shutdownManager, readerMock, writerMock, httpClientMock, nil + return shutdownManager, readerMock, writerMock, httpClientMock } func TestShutdownSuccess1OutOf3Instances(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -142,7 +137,7 @@ func TestShutdownSuccess1OutOf3Instances(t *testing.T) { } func TestShutdownSuccess1InstanceWithoutRans(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -168,7 +163,7 @@ func TestShutdownSuccess1InstanceWithoutRans(t *testing.T) { } func TestShutdownSuccess1Instance2Rans(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -219,7 +214,7 @@ func TestShutdownSuccess1Instance2Rans(t *testing.T) { } func TestShutdownE2tInstanceAlreadyBeingDeleted(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.ToBeDeleted @@ -235,7 +230,7 @@ func TestShutdownE2tInstanceAlreadyBeingDeleted(t *testing.T) { } func TestShutdownFailureMarkInstanceAsToBeDeleted(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -251,7 +246,7 @@ func TestShutdownFailureMarkInstanceAsToBeDeleted(t *testing.T) { } func TestShutdownFailureRoutingManagerError(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -322,7 +317,7 @@ func TestShutdownFailureRoutingManagerError(t *testing.T) { } func TestShutdownFailureInClearNodebsAssociation(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -350,7 +345,7 @@ func TestShutdownFailureInClearNodebsAssociation(t *testing.T) { } func TestShutdownFailureInClearNodebsAssociation_UpdateConnectionStatus(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -373,7 +368,7 @@ func TestShutdownFailureInClearNodebsAssociation_UpdateConnectionStatus(t *testi } func TestShutdownResourceNotFoundErrorInGetNodeb(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -403,7 +398,7 @@ func TestShutdownResourceNotFoundErrorInGetNodeb(t *testing.T) { } func TestShutdownResourceGeneralErrorInGetNodeb(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active @@ -444,7 +439,7 @@ func TestShutdownResourceGeneralErrorInGetNodeb(t *testing.T) { } func TestShutdownFailureInRemoveE2TInstance(t *testing.T) { - shutdownManager, readerMock, writerMock, httpClientMock, _ := initE2TShutdownManagerTest(t) + shutdownManager, readerMock, writerMock, httpClientMock := initE2TShutdownManagerTest(t) e2tInstance1 := entities.NewE2TInstance(E2TAddress, PodName) e2tInstance1.State = entities.Active diff --git a/E2Manager/managers/kubernetes_manager.go b/E2Manager/managers/kubernetes_manager.go deleted file mode 100644 index 12037bf..0000000 --- a/E2Manager/managers/kubernetes_manager.go +++ /dev/null @@ -1,87 +0,0 @@ -// -// 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 managers - -import ( - "e2mgr/configuration" - "e2mgr/logger" - "k8s.io/client-go/kubernetes" -) - -type KubernetesManager struct { - Logger *logger.Logger - ClientSet kubernetes.Interface - Config *configuration.Configuration -} - -func NewKubernetesManager(logger *logger.Logger, config *configuration.Configuration) *KubernetesManager { - return &KubernetesManager{ - Logger: logger, - //ClientSet: createClientSet(logger, config), - Config: config, - } -} - -/*func createClientSet(logger *logger.Logger, config *configuration.Configuration) kubernetes.Interface { - - absConfigPath,err := filepath.Abs(config.Kubernetes.ConfigPath) - if err != nil { - logger.Errorf("#KubernetesManager.init - error: %s", err) - return nil - } - - kubernetesConfig, err := clientcmd.BuildConfigFromFlags("", absConfigPath) - if err != nil { - logger.Errorf("#KubernetesManager.init - error: %s", err) - return nil - } - - clientSet, err := kubernetes.NewForConfig(kubernetesConfig) - if err != nil { - logger.Errorf("#KubernetesManager.init - error: %s", err) - return nil - } - return clientSet -}*/ - -/*func (km KubernetesManager) DeletePod(podName string) error { - km.Logger.Infof("#KubernetesManager.DeletePod - POD name: %s ", podName) - - if km.ClientSet == nil { - km.Logger.Errorf("#KubernetesManager.DeletePod - no kubernetesManager connection") - return e2managererrors.NewInternalError() - } - - if len(podName) == 0 { - km.Logger.Warnf("#KubernetesManager.DeletePod - empty pod name") - return e2managererrors.NewInternalError() - } - - err := km.ClientSet.CoreV1().Pods(km.Config.Kubernetes.KubeNamespace).Delete(podName, &metaV1.DeleteOptions{}) - - if err != nil { - km.Logger.Errorf("#KubernetesManager.DeletePod - POD %s can't be deleted, error: %s", podName, err) - return err - } - - km.Logger.Infof("#KubernetesManager.DeletePod - POD %s was deleted", podName) - return nil -}*/ \ No newline at end of file diff --git a/E2Manager/managers/kubernetes_manager_test.go b/E2Manager/managers/kubernetes_manager_test.go deleted file mode 100644 index ef9bcb4..0000000 --- a/E2Manager/managers/kubernetes_manager_test.go +++ /dev/null @@ -1,152 +0,0 @@ -// -// 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 managers -/* - -import ( - "e2mgr/configuration" - "e2mgr/logger" - "github.com/stretchr/testify/assert" - "k8s.io/api/core/v1" - metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/kubernetes/fake" - "testing" -) - -type TestStruct struct { - description string - namespace string - expected []string - objs []runtime.Object -} - -func initKubernetesManagerTest(t *testing.T) *KubernetesManager { - logger, err := logger.InitLogger(logger.DebugLevel) - if err != nil { - t.Errorf("#... - failed to initialize logger, error: %s", err) - } - config := &configuration.Configuration{} - config.Kubernetes.KubeNamespace = "oran" - config.Kubernetes.ConfigPath = "somePath" - - kubernetesManager := NewKubernetesManager(logger, config) - - return kubernetesManager -} - -func TestDelete_NoPodName(t *testing.T) { - test := TestStruct{ - description: "2 namespace, 2 pods in oran", - namespace: "oran", - objs: []runtime.Object{pod("oran", "POD_Test_1"), pod("oran", "POD_Test_2"), pod("some-namespace", "POD_Test_1")}, - } - - kubernetesManager := initKubernetesManagerTest(t) - - t.Run(test.description, func(t *testing.T) { - kubernetesManager.ClientSet = fake.NewSimpleClientset(test.objs...) - - err := kubernetesManager.DeletePod("") - assert.NotNil(t, err) - }) -} - -func TestDelete_NoPods(t *testing.T) { - test := TestStruct{ - description: "no pods", - namespace: "oran", - expected: nil, - objs: nil, - } - - kubernetesManager := initKubernetesManagerTest(t) - - t.Run(test.description, func(t *testing.T) { - kubernetesManager.ClientSet = fake.NewSimpleClientset(test.objs...) - - err := kubernetesManager.DeletePod("POD_Test") - assert.NotNil(t, err) - }) -} - -func TestDelete_PodExists(t *testing.T) { - test := TestStruct{ - description: "2 namespace, 2 pods in oran", - namespace: "oran", - objs: []runtime.Object{pod("oran", "POD_Test_1"), pod("oran", "POD_Test_2"), pod("some-namespace", "POD_Test_1")}, - } - - kubernetesManager := initKubernetesManagerTest(t) - - t.Run(test.description, func(t *testing.T) { - kubernetesManager.ClientSet = fake.NewSimpleClientset(test.objs...) - - err := kubernetesManager.DeletePod("POD_Test_1") - assert.Nil(t, err) - }) -} - -func TestDelete_NoPodInNamespace(t *testing.T) { - test := TestStruct{ - description: "2 namespace, 2 pods in oran", - namespace: "oran", - objs: []runtime.Object{pod("oran", "POD_Test_1"), pod("oran", "POD_Test_2"), pod("some-namespace", "POD_Test")}, - } - - kubernetesManager := initKubernetesManagerTest(t) - - t.Run(test.description, func(t *testing.T) { - kubernetesManager.ClientSet = fake.NewSimpleClientset(test.objs...) - - err := kubernetesManager.DeletePod("POD_Test") - assert.NotNil(t, err) - }) -} - -func TestDelete_NoNamespace(t *testing.T) { - test := TestStruct{ - description: "No oran namespace", - namespace: "oran", - objs: []runtime.Object{pod("some-namespace", "POD_Test_1"), pod("some-namespace", "POD_Test_2"), pod("some-namespace", "POD_Test")}, - } - - kubernetesManager := initKubernetesManagerTest(t) - - t.Run(test.description, func(t *testing.T) { - kubernetesManager.ClientSet = fake.NewSimpleClientset(test.objs...) - - err := kubernetesManager.DeletePod("POD_Test") - assert.NotNil(t, err) - }) -} - -func pod(namespace, image string) *v1.Pod { - - return &v1.Pod{ - ObjectMeta: metaV1.ObjectMeta{ - Name: image, - Namespace: namespace, - Annotations: map[string]string{}, - }, - } -} -*/ \ No newline at end of file diff --git a/E2Manager/managers/nodeb_validator.go b/E2Manager/managers/nodeb_validator.go new file mode 100644 index 0000000..41b854a --- /dev/null +++ b/E2Manager/managers/nodeb_validator.go @@ -0,0 +1,97 @@ +// +// 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 managers + +import ( + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "github.com/pkg/errors" +) + +type NodebValidator struct { +} + +func NewNodebValidator() *NodebValidator { + return &NodebValidator{} +} + +func (h *NodebValidator) IsEnbValid(enb *entities.Enb) error { + if enb.EnbType == entities.EnbType_UNKNOWN_ENB_TYPE { + return errors.New("enb.enbType") + } + + if enb.ServedCells == nil || len(enb.ServedCells) == 0 { + return errors.New("enb.servedCells") + } + + for _, servedCell := range enb.ServedCells { + err := isServedCellValid(servedCell) + + if err != nil { + return err + } + } + + return nil +} + +func isServedCellValid(servedCell *entities.ServedCellInfo) error { + + if servedCell.CellId == "" { + return errors.New("servedCell.cellId") + } + + if servedCell.EutraMode == entities.Eutra_UNKNOWN { + return errors.New("servedCell.eutraMode") + } + + if servedCell.Tac == "" { + return errors.New("servedCell.tac") + } + + if servedCell.BroadcastPlmns == nil || len(servedCell.BroadcastPlmns) == 0 { + return errors.New("servedCell.broadcastPlmns") + } + + if servedCell.ChoiceEutraMode == nil { + return errors.New("servedCell.choiceEutraMode") + } + + return isChoiceEutraModeValid(servedCell.ChoiceEutraMode) +} + +func isChoiceEutraModeValid(choiceEutraMode *entities.ChoiceEUTRAMode) error { + if choiceEutraMode.Fdd != nil { + return isFddInfoValid(choiceEutraMode.Fdd) + } + + if choiceEutraMode.Tdd != nil { + return isTddInfoValid(choiceEutraMode.Tdd) + } + + return errors.New("servedCell.fdd / servedCell.tdd") +} + +func isTddInfoValid(tdd *entities.TddInfo) error { + return nil +} + +func isFddInfoValid(fdd *entities.FddInfo) error { + return nil +} diff --git a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go index 07aa8e4..b56fb69 100644 --- a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go +++ b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go @@ -49,16 +49,16 @@ type IncomingRequestHandlerProvider struct { ranConnectStatusChangeManager managers.IRanConnectStatusChangeManager } -func NewIncomingRequestHandlerProvider(logger *logger.Logger, rmrSender *rmrsender.RmrSender, config *configuration.Configuration, rNibDataService services.RNibDataService, ranSetupManager *managers.RanSetupManager, e2tInstancesManager managers.IE2TInstancesManager, e2tAssociationManager *managers.E2TAssociationManager, rmClient clients.IRoutingManagerClient, ranConnectStatusChangeManager managers.IRanConnectStatusChangeManager) *IncomingRequestHandlerProvider { +func NewIncomingRequestHandlerProvider(logger *logger.Logger, rmrSender *rmrsender.RmrSender, config *configuration.Configuration, rNibDataService services.RNibDataService, e2tInstancesManager managers.IE2TInstancesManager, rmClient clients.IRoutingManagerClient, ranConnectStatusChangeManager managers.IRanConnectStatusChangeManager, nodebValidator *managers.NodebValidator) *IncomingRequestHandlerProvider { return &IncomingRequestHandlerProvider{ - requestMap: initRequestHandlerMap(logger, rmrSender, config, rNibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager), + requestMap: initRequestHandlerMap(logger, rmrSender, config, rNibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator), logger: logger, ranConnectStatusChangeManager: ranConnectStatusChangeManager, } } -func initRequestHandlerMap(logger *logger.Logger, rmrSender *rmrsender.RmrSender, config *configuration.Configuration, rNibDataService services.RNibDataService, e2tInstancesManager managers.IE2TInstancesManager, rmClient clients.IRoutingManagerClient, ranConnectStatusChangeManager managers.IRanConnectStatusChangeManager) map[IncomingRequest]httpmsghandlers.RequestHandler { +func initRequestHandlerMap(logger *logger.Logger, rmrSender *rmrsender.RmrSender, config *configuration.Configuration, rNibDataService services.RNibDataService, e2tInstancesManager managers.IE2TInstancesManager, rmClient clients.IRoutingManagerClient, ranConnectStatusChangeManager managers.IRanConnectStatusChangeManager, nodebValidator *managers.NodebValidator) map[IncomingRequest]httpmsghandlers.RequestHandler { return map[IncomingRequest]httpmsghandlers.RequestHandler{ ShutdownRequest: httpmsghandlers.NewDeleteAllRequestHandler(logger, rmrSender, config, rNibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager), @@ -68,7 +68,7 @@ func initRequestHandlerMap(logger *logger.Logger, rmrSender *rmrsender.RmrSender GetNodebIdListRequest: httpmsghandlers.NewGetNodebIdListRequestHandler(logger, rNibDataService), GetE2TInstancesRequest: httpmsghandlers.NewGetE2TInstancesRequestHandler(logger, e2tInstancesManager), UpdateGnbRequest: httpmsghandlers.NewUpdateGnbRequestHandler(logger, rNibDataService), - AddEnbRequest: httpmsghandlers.NewAddEnbRequestHandler(logger, rNibDataService), + AddEnbRequest: httpmsghandlers.NewAddEnbRequestHandler(logger, rNibDataService, nodebValidator), } } diff --git a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go index d6795a0..f47fae2 100644 --- a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go +++ b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go @@ -52,15 +52,14 @@ func setupTest(t *testing.T) *IncomingRequestHandlerProvider { writerMock := &mocks.RnibWriterMock{} rnibDataService := services.NewRnibDataService(log, config, readerMock, writerMock) rmrSender := getRmrSender(rmrMessengerMock, log) - ranSetupManager := managers.NewRanSetupManager(log, rmrSender, rnibDataService) e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, log) httpClientMock := &mocks.HttpClientMock{} rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock) ranListManager := managers.NewRanListManager(log) ranAlarmService := services.NewRanAlarmService(log, config) ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService,ranListManager, ranAlarmService) - e2tAssociationManager := managers.NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager) - return NewIncomingRequestHandlerProvider(log, rmrSender, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tInstancesManager, e2tAssociationManager, rmClient, ranConnectStatusChangeManager) + nodebValidator := managers.NewNodebValidator() + return NewIncomingRequestHandlerProvider(log, rmrSender, configuration.ParseConfiguration(), rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator) } func TestNewIncomingRequestHandlerProvider(t *testing.T) { -- 2.16.6