+def a1_request_handler(self, summary, sbuf):
+ logger.info("A1 policy received")
+ try:
+ req = json.loads(summary[rmr.RMR_MS_PAYLOAD]) # input should be a json encoded as bytes
+ logger.debug("A1PolicyHandler.resp_handler:: Handler processing request")
+ except (json.decoder.JSONDecodeError, KeyError):
+ logger.error("A1PolicyManager.resp_handler:: Handler failed to parse request")
+ return
+
+ if verifyPolicy(req):
+ logger.info("A1PolicyHandler.resp_handler:: Handler processed request: {}".format(req))
+ else:
+ logger.error("A1PolicyHandler.resp_handler:: Request verification failed: {}".format(req))
+ logger.debug("A1PolicyHandler.resp_handler:: Request verification success: {}".format(req))
+ change_threshold(self, req)
+ resp = buildPolicyResp(self, req)
+ self.rmr_send(json.dumps(resp).encode(), 20011)
+ logger.info("A1PolicyHandler.resp_handler:: Response sent: {}".format(resp))
+ self.rmr_free(sbuf)
+
+
+def change_threshold(self, req: dict):
+ if req["operation"] == "CREATE":
+ payload = req["payload"]
+ threshold = json.loads(payload)[db.a1_param]
+ logger.info("throughput threshold parameter updated to: {}% ".format(threshold))
+
+
+def verifyPolicy(req: dict):
+ for i in ["policy_type_id", "operation", "policy_instance_id"]:
+ if i not in req:
+ return False
+ return True
+
+
+def buildPolicyResp(self, req: dict):
+ req["handler_id"] = "ad"
+ del req["operation"]
+ del req["payload"]
+ req["status"] = "OK"
+ return req
+
+