- try:
- return func()
- except ValidationError as exc:
- logger.exception(exc)
- return "", 400
- except exceptions.PolicyNotFound as exc:
- logger.exception(exc)
- return "", 404
- except exceptions.MissingManifest as exc:
- logger.exception(exc)
- return "A1 was unable to find the required RIC manifest. report this!", 500
- except exceptions.MissingRmrString as exc:
- logger.exception(exc)
- return "A1 does not have a mapping for the desired rmr string. report this!", 500
- except exceptions.MessageSendFailure as exc:
- logger.exception(exc)
- return "A1 was unable to send a needed message to a downstream subscriber", 504
- except exceptions.ExpectedAckNotReceived as exc:
- logger.exception(exc)
- return "A1 was expecting an ACK back but it didn't receive one or didn't recieve the expected ACK", 504
- except BaseException as exc:
- # catch all, should never happen...
- logger.exception(exc)
- return Response(status=500)
-
-
-def _put_handler(policyname, data):
- """
- Handles policy put
- """
-
- mtype_send, schema, mtype_return = _get_needed_policy_info(policyname)
-
- # validate the PUT against the schema, or if there is no shema, make sure the pUT is empty
- if schema:
- utils.validate_json(data, schema)
- elif data != {}:
- return "BODY SUPPLIED BUT POLICY HAS NO EXPECTED BODY", 400
-
- # send rmr, wait for ACK
- return_payload = a1rmr.send_ack_retry(json.dumps(data), message_type=mtype_send, expected_ack_message_type=mtype_return)
-
- # right now it is assumed that xapps respond with JSON payloads
- # it is further assumed that they include a field "status" and that the value "SUCCESS" indicates a good policy change
- try:
- rpj = json.loads(return_payload)
- return (rpj, 200) if rpj["status"] == "SUCCESS" else ({"reason": "BAD STATUS", "return_payload": rpj}, 502)
- except json.decoder.JSONDecodeError:
- return {"reason": "NOT JSON", "return_payload": return_payload}, 502
- except KeyError:
- return {"reason": "NO STATUS", "return_payload": rpj}, 502