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
21 from .utils.constants import Constants
22 from .manager import *
23 from .handler import *
24 from mdclogpy import Logger
30 fake_sdl = getenv("USE_FAKE_SDL", False)
31 self._rmr_xapp = RMRXapp(self._default_handler,
32 config_handler=self._handle_config_change,
34 post_init=self._post_init,
35 use_fake_sdl=bool(fake_sdl))
37 def _post_init(self, rmr_xapp):
39 Function that runs when xapp initialization is complete
41 rmr_xapp.logger.info("HWXapp.post_init :: post_init called")
42 # self.sdl_alarm_mgr = SdlAlarmManager()
43 sdl_mgr = SdlManager(rmr_xapp)
44 sdl_mgr.sdlGetGnbList()
45 a1_mgr = A1PolicyManager(rmr_xapp)
48 def _handle_config_change(self, rmr_xapp, config):
50 Function that runs at start and on every configuration file change.
52 rmr_xapp.logger.info("HWXapp.handle_config_change:: config: {}".format(config))
53 rmr_xapp.config = config # No mutex required due to GIL
55 def _default_handler(self, rmr_xapp, summary, sbuf):
57 Function that processes messages for which no handler is defined
59 rmr_xapp.logger.info("HWXapp.default_handler called for msg type = " +
60 str(summary[rmr.RMR_MS_MSG_TYPE]))
61 rmr_xapp.rmr_free(sbuf)
63 def createHandlers(self):
65 Function that creates all the handlers for RMR Messages
67 HealthCheckHandler(self._rmr_xapp, Constants.RIC_HEALTH_CHECK_REQ)
68 A1PolicyHandler(self._rmr_xapp, Constants.A1_POLICY_REQ)
70 def start(self, thread=False):
72 This is a convenience function that allows this xapp to run in Docker
73 for "real" (no thread, real SDL), but also easily modified for unit testing
74 (e.g., use_fake_sdl). The defaults for this function are for the Dockerized xapp.
77 self._rmr_xapp.run(thread)
81 can only be called if thread=True when started
82 TODO: could we register a signal handler for Docker SIGTERM that calls this?