2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
29 "e2mgr/managers/notificationmanager"
30 "e2mgr/providers/httpmsghandlerprovider"
31 "e2mgr/providers/rmrmsghandlerprovider"
35 "e2mgr/services/rmrreceiver"
36 "e2mgr/services/rmrsender"
39 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
40 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
41 "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
42 "github.com/spf13/viper"
43 "github.com/fsnotify/fsnotify"
48 const GeneralKeyDefaultValue = "{\"enableRic\":true}"
49 const DEFAULT_CONFIG_FILE = "../resources/configuration.yaml"
50 const DEFAULT_PORT = "8080"
51 var Log *logger.Logger
53 func initKeys(logger *logger.Logger, sdl *sdlgo.SyncStorage) error {
54 ok, err := sdl.SetIfNotExists(common.GetRNibNamespace(), common.BuildGeneralConfigurationKey(), GeneralKeyDefaultValue)
57 logger.Errorf("#app.main - Failed setting GENERAL key")
62 logger.Infof("#app.main - Successfully set GENERAL key")
64 logger.Infof("#app.main - GENERAL key exists, no need to set")
70 /**Dynamic log-level changes **/
73 viper.SetConfigFile(parseCmd())
74 if err := viper.ReadInConfig(); err != nil {
75 Log.Errorf("Error reading config file, %s", err)
77 Log.Infof("Using config file: %s\n", viper.ConfigFileUsed())
78 // Watch for config file changes and re-read data ...
81 func parseCmd() string {
83 fileName = flag.String("f", DEFAULT_CONFIG_FILE, "Specify the configuration file.")
84 flag.String("port", DEFAULT_PORT, "Specify the port file.")
92 viper.OnConfigChange(func(e fsnotify.Event) {
93 Log.Infof("config file changed %s", e.Name)
98 /*********MDC LOG CHNAGES ********/
101 if err := viper.UnmarshalKey("loglevel", &loglevel); err != nil {
102 Log.Errorf("Unmarshalling failed while reading %d", loglevel)
107 Log.Infof("LOGLEVEL is set to ERROR\n")
109 Log.Infof("LOGLEVEL is set to WARNING\n")
111 Log.Infof("LOGLEVEL is set to INFO\n")
113 Log.Infof("LOGLEVEL is set to DEBUG\n")
115 Log.SetLevel(loglevel)
120 config := configuration.ParseConfiguration()
122 Log, _ = logger.InitLogger(level)
124 Log.SetMdc("e2mgr", "0.2.2")
126 fmt.Printf("#app.main - failed to initialize logger, error: %s", err)
129 Log.Infof("#app.main - Configuration %s", config)
133 sdl := sdlgo.NewSyncStorage()
134 err := initKeys(Log, sdl)
141 rnibDataService := services.NewRnibDataService(Log, config, reader.GetNewRNibReader(sdl), rNibWriter.GetRNibWriter(sdl, config.RnibWriter))
143 ranListManager := managers.NewRanListManager(Log, rnibDataService)
145 err = ranListManager.InitNbIdentityMap()
148 Log.Errorf("#app.main - quit")
152 var msgImpl *rmrCgo.Context
153 rmrMessenger := msgImpl.Init("tcp:"+strconv.Itoa(config.Rmr.Port), config.Rmr.MaxMsgSize, 0, Log)
154 rmrSender := rmrsender.NewRmrSender(Log, rmrMessenger)
155 e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, Log)
156 routingManagerClient := clients.NewRoutingManagerClient(Log, config, clients.NewHttpClient())
157 ranAlarmService := services.NewRanAlarmService(Log, config)
158 ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(Log, rnibDataService, ranListManager, ranAlarmService)
159 e2tAssociationManager := managers.NewE2TAssociationManager(Log, rnibDataService, e2tInstancesManager, routingManagerClient, ranConnectStatusChangeManager)
160 e2tShutdownManager := managers.NewE2TShutdownManager(Log, config, rnibDataService, e2tInstancesManager, e2tAssociationManager, ranConnectStatusChangeManager)
161 e2tKeepAliveWorker := managers.NewE2TKeepAliveWorker(Log, rmrSender, e2tInstancesManager, e2tShutdownManager, config)
162 rmrNotificationHandlerProvider := rmrmsghandlerprovider.NewNotificationHandlerProvider()
163 rmrNotificationHandlerProvider.Init(Log, config, rnibDataService, rmrSender, e2tInstancesManager, routingManagerClient, e2tAssociationManager, ranConnectStatusChangeManager, ranListManager)
165 notificationManager := notificationmanager.NewNotificationManager(Log, rmrNotificationHandlerProvider)
166 rmrReceiver := rmrreceiver.NewRmrReceiver(Log, rmrMessenger, notificationManager)
167 nodebValidator := managers.NewNodebValidator()
168 updateEnbManager := managers.NewUpdateEnbManager(Log, rnibDataService, nodebValidator)
169 updateGnbManager := managers.NewUpdateGnbManager(Log, rnibDataService, nodebValidator)
171 e2tInstancesManager.ResetKeepAliveTimestampsForAllE2TInstances()
173 defer rmrMessenger.Close()
175 go rmrReceiver.ListenAndHandle()
176 go e2tKeepAliveWorker.Execute()
178 httpMsgHandlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(Log, rmrSender, config, rnibDataService, e2tInstancesManager, routingManagerClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, updateGnbManager, ranListManager)
179 rootController := controllers.NewRootController(rnibDataService)
180 nodebController := controllers.NewNodebController(Log, httpMsgHandlerProvider)
181 e2tController := controllers.NewE2TController(Log, httpMsgHandlerProvider)
182 symptomController := controllers.NewSymptomdataController(Log, httpMsgHandlerProvider, rnibDataService, ranListManager)
183 //fmt.Println("loadconfig called at last")
185 _ = httpserver.Run(Log, config.Http.Port, rootController, nodebController, e2tController, symptomController)
186 //fmt.Println("loadconfig called at last")