+ self.engine.del_item(
+ self.internal_session,
+ "nsrs",
+ _id=params["nsr_id"],
+ not_send_msg=msg_to_send,
+ )
+ self.logger.debug(
+ "ns={} deleted from database".format(params["nsr_id"])
+ )
+ # Check for nslcm notification
+ if isinstance(params, dict):
+ # Check availability of operationState and command
+ if (
+ (not params.get("operationState"))
+ or (not command)
+ or (not params.get("operationParams"))
+ ):
+ self.logger.debug(
+ "Message can not be used for notification of nslcm"
+ )
+ else:
+ nsd_id = params["operationParams"].get("nsdId")
+ ns_instance_id = params["operationParams"].get("nsInstanceId")
+ # Any one among nsd_id, ns_instance_id should be present.
+ if not (nsd_id or ns_instance_id):
+ self.logger.debug(
+ "Message can not be used for notification of nslcm"
+ )
+ else:
+ op_state = params["operationState"]
+ event_details = {
+ "topic": topic,
+ "command": command.upper(),
+ "params": params,
+ }
+ subscribers = self.nslcm.get_subscribers(
+ nsd_id,
+ ns_instance_id,
+ command.upper(),
+ op_state,
+ event_details,
+ )
+ # self.logger.debug("subscribers list: ")
+ # self.logger.debug(subscribers)
+ if subscribers:
+ asyncio.ensure_future(
+ self.nslcm.send_notifications(subscribers),
+ )
+ else:
+ self.logger.debug(
+ "Message can not be used for notification of nslcm"
+ )
+ elif topic == "vnf":
+ if isinstance(params, dict):
+ vnfd_id = params["vnfdId"]
+ vnf_instance_id = params["vnfInstanceId"]
+ if command == "create" or command == "delete":
+ op_state = command
+ else:
+ op_state = params["operationState"]
+ event_details = {
+ "topic": topic,
+ "command": command.upper(),
+ "params": params,
+ }
+ subscribers = self.vnflcm.get_subscribers(
+ vnfd_id,
+ vnf_instance_id,
+ command.upper(),
+ op_state,
+ event_details,
+ )
+ if subscribers:
+ asyncio.ensure_future(
+ self.vnflcm.send_notifications(subscribers),
+ )
+ elif topic == "nsi":
+ if command == "terminated" and params["operationState"] in (
+ "COMPLETED",
+ "PARTIALLY_COMPLETED",
+ ):
+ self.logger.debug("received nsi terminated {}".format(params))
+ if params.get("autoremove"):
+ self.engine.del_item(
+ self.internal_session,
+ "nsis",
+ _id=params["nsir_id"],
+ not_send_msg=msg_to_send,
+ )
+ self.logger.debug(
+ "nsis={} deleted from database".format(params["nsir_id"])
+ )
+ elif topic == "admin":
+ self.logger.debug("received {} {} {}".format(topic, command, params))
+ if command in ["echo", "ping"]: # ignored commands
+ pass
+ elif command == "revoke_token":
+ if params:
+ if isinstance(params, dict) and "_id" in params:
+ tid = params.get("_id")
+ self.engine.authenticator.tokens_cache.pop(tid, None)
+ self.logger.debug(
+ "token '{}' removed from token_cache".format(tid)
+ )
+ else:
+ self.logger.debug(
+ "unrecognized params in command '{} {}': {}".format(
+ topic, command, params
+ )
+ )
+ else:
+ self.engine.authenticator.tokens_cache.clear()
+ self.logger.debug("token_cache cleared")
+ else:
+ self.logger.debug(
+ "unrecognized command '{} {}'".format(topic, command)
+ )
+ # writing to kafka must be done with our own loop. For this reason it is not allowed Engine to do that,
+ # but content to be written is stored at msg_to_send
+ for msg in msg_to_send:
+ await self.msg.aiowrite(*msg)