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 ._BaseHandler import _BaseHandler
25 class A1PolicyHandler(_BaseHandler):
27 def __init__(self, rmr_xapp: RMRXapp, msgtype):
28 super().__init__(rmr_xapp, msgtype)
30 def request_handler(self, rmr_xapp, summary, sbuf):
31 self._rmr_xapp.rmr_free(sbuf)
33 req = json.loads(summary[rmr.RMR_MS_PAYLOAD]) # input should be a json encoded as bytes
34 self.logger.debug("A1PolicyHandler.resp_handler:: Handler processing request")
35 except (json.decoder.JSONDecodeError, KeyError):
36 self.logger.error("A1PolicyManager.resp_handler:: Handler failed to parse request")
39 if self.verifyPolicy(req):
40 self.logger.info("A1PolicyHandler.resp_handler:: Handler processed request: {}".format(req))
42 self.logger.error("A1PolicyHandler.resp_handler:: Request verification failed: {}".format(req))
44 self.logger.debug("A1PolicyHandler.resp_handler:: Request verification success: {}".format(req))
46 resp = self.buildPolicyResp(req)
47 self._rmr_xapp.rmr_send(json.dumps(resp).encode(), Constants.A1_POLICY_RESP)
48 self.logger.info("A1PolicyHandler.resp_handler:: Response sent: {}".format(resp))
50 def verifyPolicy(self, req: dict):
51 for i in ["policy_type_id", "operation", "policy_instance_id"]:
56 def buildPolicyResp(self, req: dict):
57 req["handler_id"] = self._rmr_xapp.config["xapp_name"]