notificationManager := notificationmanager.NewNotificationManager(logger, rmrNotificationHandlerProvider)
rmrReceiver := rmrreceiver.NewRmrReceiver(logger, rmrMessenger, notificationManager)
+ e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances()
+
defer rmrMessenger.Close()
go rmrReceiver.ListenAndHandle()
--- /dev/null
+//
+// 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
--- /dev/null
+//
+// 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
+}
--- /dev/null
+//
+// 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)
+//}
RnibRetryIntervalMs int
KeepAliveResponseTimeoutMs int
KeepAliveDelayMs int
+ RoutingManagerBaseUrl string
}
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
}
--- /dev/null
+//
+// 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
+}
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
return err
}
-
e2tAddresses, err := m.rnibDataService.GetE2TAddresses()
if err != nil {
}
return nil
-}
\ No newline at end of file
+}
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")))
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
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")))
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)
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)
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)
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)
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)
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)
+}
--- /dev/null
+//
+// 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)
+//}
--- /dev/null
+//
+// 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
+}
rnibRetryIntervalMs: 10
keepAliveResponseTimeoutMs: 1500
keepAliveDelayMs: 500
+routingManagerBaseUrl: http://iltlv740.intl.att.com:8080/ric/v1/handles/v1/