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
23 from .utils.constants import Constants
24 from .manager import *
26 from .handler import *
27 from mdclogpy import Logger
33 fake_sdl = getenv("USE_FAKE_SDL", False)
34 self._rmr_xapp = RMRXapp(self._default_handler,
35 config_handler=self._handle_config_change,
37 post_init=self._post_init,
38 use_fake_sdl=bool(fake_sdl))
40 def _post_init(self, rmr_xapp):
42 Function that runs when xapp initialization is complete
44 rmr_xapp.logger.info("HWXapp.post_init :: post_init called")
45 # self.sdl_alarm_mgr = SdlAlarmManager()
46 sdl_mgr = SdlManager(rmr_xapp)
47 sdl_mgr.sdlGetGnbList()
48 a1_mgr = A1PolicyManager(rmr_xapp)
50 sub_mgr = SubscriptionManager(rmr_xapp)
51 enb_list = sub_mgr.get_enb_list()
53 sub_mgr.send_subscription_request(enb)
54 gnb_list = sub_mgr.get_gnb_list()
56 sub_mgr.send_subscription_request(gnb)
57 metric_mgr = MetricManager(rmr_xapp)
58 metric_mgr.send_metric()
60 def _handle_config_change(self, rmr_xapp, config):
62 Function that runs at start and on every configuration file change.
64 rmr_xapp.logger.info("HWXapp.handle_config_change:: config: {}".format(config))
65 rmr_xapp.config = config # No mutex required due to GIL
67 def _default_handler(self, rmr_xapp, summary, sbuf):
69 Function that processes messages for which no handler is defined
71 rmr_xapp.logger.info("HWXapp.default_handler called for msg type = " +
72 str(summary[rmr.RMR_MS_MSG_TYPE]))
73 rmr_xapp.rmr_free(sbuf)
75 def createHandlers(self):
77 Function that creates all the handlers for RMR Messages
79 HealthCheckHandler(self._rmr_xapp, Constants.RIC_HEALTH_CHECK_REQ)
80 A1PolicyHandler(self._rmr_xapp, Constants.A1_POLICY_REQ)
81 SubscriptionHandler(self._rmr_xapp,Constants.SUBSCRIPTION_REQ)
83 def start(self, thread=False):
85 This is a convenience function that allows this xapp to run in Docker
86 for "real" (no thread, real SDL), but also easily modified for unit testing
87 (e.g., use_fake_sdl). The defaults for this function are for the Dockerized xapp.
90 self._rmr_xapp.run(thread)
94 can only be called if thread=True when started
95 TODO: could we register a signal handler for Docker SIGTERM that calls this?