1 # ==================================================================================
3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
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 # ==================================================================================
20 from ricxappframe.xapp_frame import RMRXapp, rmr
22 from .handler.SubscriptionHandler import SubscriptionHandler
23 from .manager.MetricManager import MetricManager
24 from .manager.SubscriptionManager import SubscriptionManager
25 from .utils.constants import Constants
26 from .manager import *
28 from .handler import *
29 from mdclogpy import Logger
35 fake_sdl = getenv("USE_FAKE_SDL", False)
36 self._rmr_xapp = RMRXapp(self._default_handler,
37 config_handler=self._handle_config_change,
39 post_init=self._post_init,
40 use_fake_sdl=bool(fake_sdl))
42 def _post_init(self, rmr_xapp):
44 Function that runs when xapp initialization is complete
46 rmr_xapp.logger.info("HWXapp.post_init :: post_init called")
47 # self.sdl_alarm_mgr = SdlAlarmManager()
48 sdl_mgr = SdlManager(rmr_xapp)
49 sdl_mgr.sdlGetGnbList()
50 a1_mgr = A1PolicyManager(rmr_xapp)
52 sub_mgr = SubscriptionManager(rmr_xapp)
53 enb_list = sub_mgr.get_enb_list()
55 sub_mgr.send_subscription_request(enb)
56 gnb_list = sub_mgr.get_gnb_list()
58 sub_mgr.send_subscription_request(gnb)
59 metric_mgr = MetricManager(rmr_xapp)
60 metric_mgr.send_metric()
62 def _handle_config_change(self, rmr_xapp, config):
64 Function that runs at start and on every configuration file change.
66 rmr_xapp.logger.info("HWXapp.handle_config_change:: config: {}".format(config))
67 rmr_xapp.config = config # No mutex required due to GIL
69 def _default_handler(self, rmr_xapp, summary, sbuf):
71 Function that processes messages for which no handler is defined
73 rmr_xapp.logger.info("HWXapp.default_handler called for msg type = " +
74 str(summary[rmr.RMR_MS_MSG_TYPE]))
75 rmr_xapp.rmr_free(sbuf)
77 def createHandlers(self):
79 Function that creates all the handlers for RMR Messages
81 HealthCheckHandler(self._rmr_xapp, Constants.RIC_HEALTH_CHECK_REQ)
82 A1PolicyHandler(self._rmr_xapp, Constants.A1_POLICY_REQ)
83 SubscriptionHandler(self._rmr_xapp,Constants.SUBSCRIPTION_REQ)
85 def start(self, thread=False):
87 This is a convenience function that allows this xapp to run in Docker
88 for "real" (no thread, real SDL), but also easily modified for unit testing
89 (e.g., use_fake_sdl). The defaults for this function are for the Dockerized xapp.
92 self._rmr_xapp.run(thread)
96 can only be called if thread=True when started
97 TODO: could we register a signal handler for Docker SIGTERM that calls this?