[RICPLT-2165] Add rnibDataService to support retries
[ric-plt/e2mgr.git] / E2Manager / providers / rmrmsghandlerprovider / notification_handler_provider.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 package rmrmsghandlerprovider
19
20 import (
21         "e2mgr/handlers/rmrmsghandlers"
22         "e2mgr/managers"
23         "e2mgr/rmrCgo"
24         "e2mgr/services"
25         "fmt"
26 )
27
28 type NotificationHandlerProvider struct {
29         notificationHandlers map[int]rmrmsghandlers.NotificationHandler
30 }
31
32 func NewNotificationHandlerProvider(rnibDataService services.RNibDataService, ranReconnectionManager *managers.RanReconnectionManager) *NotificationHandlerProvider {
33         return &NotificationHandlerProvider{
34                 notificationHandlers: initNotificationHandlersMap(rnibDataService, ranReconnectionManager),
35         }
36 }
37
38 //TODO change handlers.NotificationHandler to *handlers.NotificationHandler
39 func initNotificationHandlersMap(rnibDataService services.RNibDataService, ranReconnectionManager *managers.RanReconnectionManager) map[int]rmrmsghandlers.NotificationHandler {
40         return map[int]rmrmsghandlers.NotificationHandler{
41                 rmrCgo.RIC_X2_SETUP_RESP:           rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewX2SetupResponseManager(), "X2 Setup Response"),
42                 rmrCgo.RIC_X2_SETUP_FAILURE:        rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewX2SetupFailureResponseManager(), "X2 Setup Failure Response"),
43                 rmrCgo.RIC_ENDC_X2_SETUP_RESP:      rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewEndcSetupResponseManager(), "ENDC Setup Response"),
44                 rmrCgo.RIC_ENDC_X2_SETUP_FAILURE:   rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewEndcSetupFailureResponseManager(), "ENDC Setup Failure Response"),
45                 rmrCgo.RIC_SCTP_CONNECTION_FAILURE: rmrmsghandlers.NewRanLostConnectionHandler(ranReconnectionManager),
46                 rmrCgo.RIC_ENB_LOAD_INFORMATION:    rmrmsghandlers.NewEnbLoadInformationNotificationHandler(rnibDataService),
47                 rmrCgo.RIC_ENB_CONF_UPDATE:         rmrmsghandlers.NewX2EnbConfigurationUpdateHandler(),
48                 rmrCgo.RIC_ENDC_CONF_UPDATE:        rmrmsghandlers.NewEndcConfigurationUpdateHandler(),
49                 rmrCgo.RIC_X2_RESET_RESP:           rmrmsghandlers.NewX2ResetResponseHandler(rnibDataService),
50                 rmrCgo.RIC_X2_RESET:                rmrmsghandlers.NewX2ResetRequestNotificationHandler(rnibDataService),
51                 rmrCgo.RIC_E2_TERM_INIT:            rmrmsghandlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibDataService),
52         }
53 }
54
55 func (provider NotificationHandlerProvider) GetNotificationHandler(messageType int) (rmrmsghandlers.NotificationHandler, error) {
56         handler, ok := provider.notificationHandlers[messageType]
57
58         if !ok {
59                 return nil, fmt.Errorf("notification handler not found for message %d", messageType)
60         }
61
62         return handler, nil
63
64 }