From 219c5386a3ad46c4646bd5a4f45389a42db065c0 Mon Sep 17 00:00:00 2001 From: is005q Date: Wed, 18 Dec 2019 14:21:39 +0200 Subject: [PATCH] [RICPLT-2727] Add RoutingManagerClient and more...... Change-Id: I85990f05a1e2ef127bcbc8af6f0c51f0804f65b3 Signed-off-by: is005q --- E2Manager/app/main.go | 2 + E2Manager/clients/http_client.go | 30 +++++++ E2Manager/clients/routing_manager_client.go | 91 ++++++++++++++++++++++ E2Manager/clients/routing_manager_client_test.go | 84 ++++++++++++++++++++ E2Manager/configuration/configuration.go | 2 + E2Manager/e2managererrors/routing_manager_error.go | 37 +++++++++ E2Manager/managers/e2t_instances_manager.go | 35 ++++++++- E2Manager/managers/e2t_instances_manager_test.go | 87 +++++++++++++++++---- E2Manager/mocks/http_client_mock.go | 41 ++++++++++ E2Manager/models/routing_manager_e2t_data.go | 41 ++++++++++ E2Manager/resources/configuration.yaml | 1 + 11 files changed, 433 insertions(+), 18 deletions(-) create mode 100644 E2Manager/clients/http_client.go create mode 100644 E2Manager/clients/routing_manager_client.go create mode 100644 E2Manager/clients/routing_manager_client_test.go create mode 100644 E2Manager/e2managererrors/routing_manager_error.go create mode 100644 E2Manager/mocks/http_client_mock.go create mode 100644 E2Manager/models/routing_manager_e2t_data.go diff --git a/E2Manager/app/main.go b/E2Manager/app/main.go index f7674f3..1ca5291 100644 --- a/E2Manager/app/main.go +++ b/E2Manager/app/main.go @@ -63,6 +63,8 @@ func main() { notificationManager := notificationmanager.NewNotificationManager(logger, rmrNotificationHandlerProvider) rmrReceiver := rmrreceiver.NewRmrReceiver(logger, rmrMessenger, notificationManager) + e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances() + defer rmrMessenger.Close() go rmrReceiver.ListenAndHandle() diff --git a/E2Manager/clients/http_client.go b/E2Manager/clients/http_client.go new file mode 100644 index 0000000..e3692f5 --- /dev/null +++ b/E2Manager/clients/http_client.go @@ -0,0 +1,30 @@ +// +// 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 clients + +import ( + "io" + "net/http" +) + +type HttpClient interface { + Post(url, contentType string, body io.Reader) (resp *http.Response, err error) +} \ No newline at end of file diff --git a/E2Manager/clients/routing_manager_client.go b/E2Manager/clients/routing_manager_client.go new file mode 100644 index 0000000..af31cdf --- /dev/null +++ b/E2Manager/clients/routing_manager_client.go @@ -0,0 +1,91 @@ +// +// 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 clients + +import ( + "bytes" + "e2mgr/configuration" + "e2mgr/e2managererrors" + "e2mgr/logger" + "e2mgr/models" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" +) + +const ( + AddE2TInstanceApiSuffix = "e2t" +) + +type RoutingManagerClient struct { + logger *logger.Logger + config *configuration.Configuration + httpClient HttpClient +} + +type IRoutingManagerClient interface { + AddE2TInstance(e2tAddress string) error +} + +func NewRoutingManagerClient(logger *logger.Logger, config *configuration.Configuration, httpClient HttpClient) *RoutingManagerClient { + return &RoutingManagerClient{ + logger: logger, + config: config, + httpClient: httpClient, + } +} + +func (c *RoutingManagerClient) AddE2TInstance(e2tAddress string) error { + data := models.NewRoutingManagerE2TData(e2tAddress) + + marshaled, err := json.Marshal(data) + + if err != nil { + return e2managererrors.NewRoutingManagerError(err) + } + + body := bytes.NewBuffer(marshaled) + c.logger.Infof("[E2M -> Routing Manager] #RoutingManagerClient.AddE2TInstance - request body: %+v", body) + + url := c.config.RoutingManagerBaseUrl + AddE2TInstanceApiSuffix + resp, err := c.httpClient.Post(url, "application/json", body) + + if err != nil { + return e2managererrors.NewRoutingManagerError(err) + } + + defer resp.Body.Close() + + respBody, err := ioutil.ReadAll(resp.Body) + + if err != nil { + return e2managererrors.NewRoutingManagerError(err) + } + + if resp.StatusCode != http.StatusOK { // TODO: shall we check for != 201? + c.logger.Errorf("[Routing Manager -> E2M] #RoutingManagerClient.AddE2TInstance - failure. http status code: %d, response body: %s", resp.StatusCode, string(respBody)) + return e2managererrors.NewRoutingManagerError(fmt.Errorf("Invalid data")) // TODO: which error shall we return? + } + + c.logger.Infof("[Routing Manager -> E2M] #RoutingManagerClient.AddE2TInstance - success. http status code: %d, response body: %s", resp.StatusCode, string(respBody)) + return nil +} diff --git a/E2Manager/clients/routing_manager_client_test.go b/E2Manager/clients/routing_manager_client_test.go new file mode 100644 index 0000000..5efc753 --- /dev/null +++ b/E2Manager/clients/routing_manager_client_test.go @@ -0,0 +1,84 @@ +// +// 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 clients + +import ( + "e2mgr/configuration" + "e2mgr/logger" + "e2mgr/mocks" + "testing" +) + +const E2TAddress = "10.0.2.15:38000" + +// TODO: add response Body and dont check for nil in prod code. itll always be populated + +func initRoutingManagerClientTest(t *testing.T) (*RoutingManagerClient, *mocks.HttpClientMock, *configuration.Configuration) { + logger := initLog(t) + config := &configuration.Configuration{ + RoutingManagerBaseUrl: "http://iltlv740.intl.att.com:8080/ric/v1/handles/v1/", + } + httpClientMock := &mocks.HttpClientMock{} + rmClient := NewRoutingManagerClient(logger, config, httpClientMock) + return rmClient, httpClientMock, config +} + +//func TestAddE2TInstanceSuccess(t *testing.T) { +// rmClient, httpClientMock, config := initRoutingManagerClientTest(t) +// +// data := models.NewRoutingManagerE2TData(E2TAddress) +// marshaled, _ := json.Marshal(data) +// body := bytes.NewBuffer(marshaled) +// url := config.RoutingManagerBaseUrl + "e2t" +// httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: 200}, nil) +// err := rmClient.AddE2TInstance(E2TAddress) +// assert.Nil(t, err) +//} +// +//func TestAddE2TInstanceFailure(t *testing.T) { +// rmClient, httpClientMock, config := initRoutingManagerClientTest(t) +// +// data := models.NewRoutingManagerE2TData(E2TAddress) +// marshaled, _ := json.Marshal(data) +// body := bytes.NewBuffer(marshaled) +// url := config.RoutingManagerBaseUrl + "e2t" +// httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: 400}, nil) +// err := rmClient.AddE2TInstance(E2TAddress) +// assert.NotNil(t, err) +//} + +// TODO: extract to test_utils +func initLog(t *testing.T) *logger.Logger { + log, err := logger.InitLogger(logger.InfoLevel) + if err != nil { + t.Errorf("#delete_all_request_handler_test.TestHandleSuccessFlow - failed to initialize logger, error: %s", err) + } + return log +} + +//func TestAddE2TInstanceInteg(t *testing.T) { +// logger := initLog(t) +// config := configuration.ParseConfiguration() +// httpClient := &http.Client{} +// rmClient := NewRoutingManagerClient(logger, config, httpClient) +// err := rmClient.AddE2TInstance(E2TAddress) +// assert.Nil(t, err) +//} diff --git a/E2Manager/configuration/configuration.go b/E2Manager/configuration/configuration.go index 2c93c09..3cc24a9 100644 --- a/E2Manager/configuration/configuration.go +++ b/E2Manager/configuration/configuration.go @@ -40,6 +40,7 @@ type Configuration struct { RnibRetryIntervalMs int KeepAliveResponseTimeoutMs int KeepAliveDelayMs int + RoutingManagerBaseUrl string } func ParseConfiguration() *Configuration { @@ -66,6 +67,7 @@ func ParseConfiguration() *Configuration { config.RnibRetryIntervalMs = viper.GetInt("rnibRetryIntervalMs") config.KeepAliveResponseTimeoutMs = viper.GetInt("keepAliveResponseTimeoutMs") config.KeepAliveDelayMs = viper.GetInt("KeepAliveDelayMs") + config.RoutingManagerBaseUrl = viper.GetString("routingManagerBaseUrl") return &config } diff --git a/E2Manager/e2managererrors/routing_manager_error.go b/E2Manager/e2managererrors/routing_manager_error.go new file mode 100644 index 0000000..d6e291a --- /dev/null +++ b/E2Manager/e2managererrors/routing_manager_error.go @@ -0,0 +1,37 @@ +// +// 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 e2managererrors + +import "fmt" + +type RoutingManagerError struct { + *BaseError +} + +func NewRoutingManagerError(err error) *RoutingManagerError { + return &RoutingManagerError{ + &BaseError{ + Code: 511, + Message: fmt.Sprintf("Routing manager error: %s", err), + }, + } +} + +func (e *RoutingManagerError) Error() string { + return e.Message +} diff --git a/E2Manager/managers/e2t_instances_manager.go b/E2Manager/managers/e2t_instances_manager.go index fb59f2f..2e36d61 100644 --- a/E2Manager/managers/e2t_instances_manager.go +++ b/E2Manager/managers/e2t_instances_manager.go @@ -128,6 +128,38 @@ func (m *E2TInstancesManager) GetE2TInstances() ([]*entities.E2TInstance, error) return e2tInstances, nil } +func (m *E2TInstancesManager) ResetKeepAliveTimestampsForAllE2TInstances() { + + e2tInstances, err := m.GetE2TInstances() + + if err != nil { + m.logger.Errorf("E2TInstancesManager.ResetKeepAliveTimestampForAllE2TInstances - Couldn't reset timestamps due to a DB error") + return + } + + if len(e2tInstances) == 0 { + m.logger.Infof("E2TInstancesManager.ResetKeepAliveTimestampForAllE2TInstances - No instances, ignoring reset") + return + } + + for _, v := range e2tInstances { + + if v.State != entities.Active { + continue + } + + v.KeepAliveTimestamp = time.Now().UnixNano() + + err := m.rnibDataService.SaveE2TInstance(v) + + if err != nil { + m.logger.Errorf("E2TInstancesManager.ResetKeepAliveTimestampForAllE2TInstances - E2T address: %s - failed resetting e2t instance keep alive timestamp. error: %s", v.Address, err) + } + } + + m.logger.Infof("E2TInstancesManager.ResetKeepAliveTimestampForAllE2TInstances - Done with reset") +} + func findActiveE2TInstanceWithMinimumAssociatedRans(e2tInstances []*entities.E2TInstance) *entities.E2TInstance { var minInstance *entities.E2TInstance minAssociatedRanCount := math.MaxInt32 @@ -155,7 +187,6 @@ func (m *E2TInstancesManager) AddE2TInstance(e2tAddress string) error { return err } - e2tAddresses, err := m.rnibDataService.GetE2TAddresses() if err != nil { @@ -294,4 +325,4 @@ func (m *E2TInstancesManager) ResetKeepAliveTimestamp(e2tAddress string) error { } return nil -} \ No newline at end of file +} diff --git a/E2Manager/managers/e2t_instances_manager_test.go b/E2Manager/managers/e2t_instances_manager_test.go index 006c5a2..f836bda 100644 --- a/E2Manager/managers/e2t_instances_manager_test.go +++ b/E2Manager/managers/e2t_instances_manager_test.go @@ -143,7 +143,7 @@ func TestAssociateRanGetInstanceFailure(t *testing.T) { func TestAssociateRanSaveInstanceFailure(t *testing.T) { rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) - e2tInstance1 := entities.NewE2TInstance(E2TAddress) + e2tInstance1 := entities.NewE2TInstance(E2TAddress) rnibReaderMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance1, nil) rnibWriterMock.On("SaveE2TInstance", mock.Anything).Return(common.NewInternalError(fmt.Errorf("for test"))) @@ -155,7 +155,7 @@ func TestAssociateRanSaveInstanceFailure(t *testing.T) { func TestAssociateRanSuccess(t *testing.T) { rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) - e2tInstance := entities.NewE2TInstance(E2TAddress) + e2tInstance := entities.NewE2TInstance(E2TAddress) rnibReaderMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, nil) updateE2TInstance := *e2tInstance @@ -182,7 +182,7 @@ func TestDissociateRanGetInstanceFailure(t *testing.T) { func TestDissociateRanSaveInstanceFailure(t *testing.T) { rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) - e2tInstance1 := entities.NewE2TInstance(E2TAddress) + e2tInstance1 := entities.NewE2TInstance(E2TAddress) rnibReaderMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance1, nil) rnibWriterMock.On("SaveE2TInstance", mock.Anything).Return(common.NewInternalError(fmt.Errorf("for test"))) @@ -196,7 +196,7 @@ func TestDissociateRanSuccess(t *testing.T) { rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) e2tInstance := entities.NewE2TInstance(E2TAddress) - e2tInstance.AssociatedRanList = []string{"test0","test1"} + e2tInstance.AssociatedRanList = []string{"test0", "test1"} updatedE2TInstance := *e2tInstance updatedE2TInstance.AssociatedRanList = []string{"test0"} rnibReaderMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, nil) @@ -235,7 +235,7 @@ func TestSelectE2TInstancesGetE2TInstancesFailure(t *testing.T) { addresses := []string{E2TAddress} rnibReaderMock.On("GetE2TAddresses").Return(addresses, nil) - rnibReaderMock.On("GetE2TInstances",addresses ).Return([]*entities.E2TInstance{}, common.NewInternalError(fmt.Errorf("for test"))) + rnibReaderMock.On("GetE2TInstances", addresses).Return([]*entities.E2TInstance{}, common.NewInternalError(fmt.Errorf("for test"))) address, err := e2tInstancesManager.SelectE2TInstance() assert.NotNil(t, err) assert.Empty(t, address) @@ -248,7 +248,7 @@ func TestSelectE2TInstancesEmptyE2TInstancesList(t *testing.T) { addresses := []string{E2TAddress} rnibReaderMock.On("GetE2TAddresses").Return(addresses, nil) - rnibReaderMock.On("GetE2TInstances",addresses ).Return([]*entities.E2TInstance{}, nil) + rnibReaderMock.On("GetE2TInstances", addresses).Return([]*entities.E2TInstance{}, nil) address, err := e2tInstancesManager.SelectE2TInstance() assert.NotNil(t, err) assert.Empty(t, address) @@ -258,16 +258,16 @@ func TestSelectE2TInstancesEmptyE2TInstancesList(t *testing.T) { func TestSelectE2TInstancesNoActiveE2TInstance(t *testing.T) { rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) - addresses := []string{E2TAddress,E2TAddress2} + addresses := []string{E2TAddress, E2TAddress2} e2tInstance1 := entities.NewE2TInstance(E2TAddress) e2tInstance1.State = entities.ToBeDeleted - e2tInstance1.AssociatedRanList = []string{"test1","test2","test3"} + e2tInstance1.AssociatedRanList = []string{"test1", "test2", "test3"} e2tInstance2 := entities.NewE2TInstance(E2TAddress2) e2tInstance2.State = entities.ToBeDeleted - e2tInstance2.AssociatedRanList = []string{"test4","test5","test6", "test7"} + e2tInstance2.AssociatedRanList = []string{"test4", "test5", "test6", "test7"} rnibReaderMock.On("GetE2TAddresses").Return(addresses, nil) - rnibReaderMock.On("GetE2TInstances",addresses).Return([]*entities.E2TInstance{e2tInstance1, e2tInstance2}, nil) + rnibReaderMock.On("GetE2TInstances", addresses).Return([]*entities.E2TInstance{e2tInstance1, e2tInstance2}, nil) address, err := e2tInstancesManager.SelectE2TInstance() assert.NotNil(t, err) assert.Equal(t, "", address) @@ -277,14 +277,14 @@ func TestSelectE2TInstancesNoActiveE2TInstance(t *testing.T) { func TestSelectE2TInstancesSuccess(t *testing.T) { rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) - addresses := []string{E2TAddress,E2TAddress2} + addresses := []string{E2TAddress, E2TAddress2} e2tInstance1 := entities.NewE2TInstance(E2TAddress) - e2tInstance1.AssociatedRanList = []string{"test1","test2","test3"} + e2tInstance1.AssociatedRanList = []string{"test1", "test2", "test3"} e2tInstance2 := entities.NewE2TInstance(E2TAddress2) - e2tInstance2.AssociatedRanList = []string{"test4","test5","test6", "test7"} + e2tInstance2.AssociatedRanList = []string{"test4", "test5", "test6", "test7"} rnibReaderMock.On("GetE2TAddresses").Return(addresses, nil) - rnibReaderMock.On("GetE2TInstances",addresses).Return([]*entities.E2TInstance{e2tInstance1, e2tInstance2}, nil) + rnibReaderMock.On("GetE2TInstances", addresses).Return([]*entities.E2TInstance{e2tInstance1, e2tInstance2}, nil) address, err := e2tInstancesManager.SelectE2TInstance() assert.Nil(t, err) assert.Equal(t, E2TAddress, address) @@ -361,7 +361,62 @@ func TestResetKeepAliveTimestampRoutingManagerFailure(t *testing.T) { func TestRemoveE2TInstance(t *testing.T) { _, _, e2tInstancesManager := initE2TInstancesManagerTest(t) - e2tInstance1 := entities.NewE2TInstance(E2TAddress) + e2tInstance1 := entities.NewE2TInstance(E2TAddress) err := e2tInstancesManager.RemoveE2TInstance(e2tInstance1) assert.Nil(t, err) -} \ No newline at end of file +} + +func TestResetKeepAliveTimestampsForAllE2TInstancesGetE2TInstancesFailure(t *testing.T) { + rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) + rnibReaderMock.On("GetE2TAddresses").Return([]string{}, common.NewInternalError(errors.New("Error"))) + e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances() + rnibWriterMock.AssertNotCalled(t, "SaveE2TInstance") +} + +func TestResetKeepAliveTimestampsForAllE2TInstancesNoInstances(t *testing.T) { + rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) + rnibReaderMock.On("GetE2TAddresses").Return([]string{}, nil) + e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances() + rnibWriterMock.AssertNotCalled(t, "SaveE2TInstance") +} + +func TestResetKeepAliveTimestampsForAllE2TInstancesNoActiveInstances(t *testing.T) { + rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) + e2tAddresses := []string{E2TAddress, E2TAddress2} + rnibReaderMock.On("GetE2TAddresses").Return(e2tAddresses, nil) + e2tInstance1 := entities.NewE2TInstance(E2TAddress) + e2tInstance1.State = entities.ToBeDeleted + e2tInstance2 := entities.NewE2TInstance(E2TAddress2) + e2tInstance2.State = entities.RoutingManagerFailure + rnibReaderMock.On("GetE2TInstances", e2tAddresses).Return([]*entities.E2TInstance{e2tInstance1, e2tInstance2}, nil) + e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances() + rnibWriterMock.AssertNotCalled(t, "SaveE2TInstance") +} + +func TestResetKeepAliveTimestampsForAllE2TInstancesOneActiveInstance(t *testing.T) { + rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) + e2tAddresses := []string{E2TAddress, E2TAddress2} + rnibReaderMock.On("GetE2TAddresses").Return(e2tAddresses, nil) + e2tInstance1 := entities.NewE2TInstance(E2TAddress) + e2tInstance1.State = entities.Active + e2tInstance2 := entities.NewE2TInstance(E2TAddress2) + e2tInstance2.State = entities.ToBeDeleted + rnibReaderMock.On("GetE2TInstances", e2tAddresses).Return([]*entities.E2TInstance{e2tInstance1, e2tInstance2}, nil) + rnibWriterMock.On("SaveE2TInstance", mock.Anything).Return(nil) + e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances() + rnibWriterMock.AssertNumberOfCalls(t, "SaveE2TInstance",1) +} + +func TestResetKeepAliveTimestampsForAllE2TInstancesSaveE2TInstanceFailure(t *testing.T) { + rnibReaderMock, rnibWriterMock, e2tInstancesManager := initE2TInstancesManagerTest(t) + e2tAddresses := []string{E2TAddress, E2TAddress2} + rnibReaderMock.On("GetE2TAddresses").Return(e2tAddresses, nil) + e2tInstance1 := entities.NewE2TInstance(E2TAddress) + e2tInstance1.State = entities.Active + e2tInstance2 := entities.NewE2TInstance(E2TAddress2) + e2tInstance2.State = entities.ToBeDeleted + rnibReaderMock.On("GetE2TInstances", e2tAddresses).Return([]*entities.E2TInstance{e2tInstance1, e2tInstance2}, nil) + rnibWriterMock.On("SaveE2TInstance", mock.Anything).Return(common.NewInternalError(errors.New("Error"))) + e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances() + rnibWriterMock.AssertNumberOfCalls(t, "SaveE2TInstance",1) +} diff --git a/E2Manager/mocks/http_client_mock.go b/E2Manager/mocks/http_client_mock.go new file mode 100644 index 0000000..1294c48 --- /dev/null +++ b/E2Manager/mocks/http_client_mock.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 mocks + +import ( + "github.com/stretchr/testify/mock" + "io" + "net/http" +) + +type HttpClientMock struct { + mock.Mock +} + +func (c *HttpClientMock) Post(url, contentType string, body io.Reader) (resp *http.Response, err error) { + args := c.Called(url, contentType, body) + return args.Get(0).(*http.Response), args.Error(1) +} + +//func (c *HttpClientMock) Do(req *http.Request) (*http.Response, error) { +// args := c.Called(req) +// return args.Get(0).(*http.Response), args.Error(1) +//} diff --git a/E2Manager/models/routing_manager_e2t_data.go b/E2Manager/models/routing_manager_e2t_data.go new file mode 100644 index 0000000..9e8e313 --- /dev/null +++ b/E2Manager/models/routing_manager_e2t_data.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 + +type RoutingManagerE2TData struct { + E2TAddress string `json:"E2TAddress"` + RanNamelist []string `json:"ranNamelist,omitempty"` +} + +func NewRoutingManagerE2TData (e2tAddress string, ranNameList ...string) *RoutingManagerE2TData { + data := &RoutingManagerE2TData{ + E2TAddress: e2tAddress, + } + + if len(ranNameList) == 0 { + return data + } + + for _, ranName := range ranNameList { + data.RanNamelist = append(data.RanNamelist, ranName) + } + + return data +} diff --git a/E2Manager/resources/configuration.yaml b/E2Manager/resources/configuration.yaml index 27f55d1..356b172 100644 --- a/E2Manager/resources/configuration.yaml +++ b/E2Manager/resources/configuration.yaml @@ -12,3 +12,4 @@ maxRnibConnectionAttempts: 3 rnibRetryIntervalMs: 10 keepAliveResponseTimeoutMs: 1500 keepAliveDelayMs: 500 +routingManagerBaseUrl: http://iltlv740.intl.att.com:8080/ric/v1/handles/v1/ -- 2.16.6