Skip to content
Snippets Groups Projects
Commit ac285875 authored by garciadeblas's avatar garciadeblas
Browse files

Delete KSU from DB without sending Kafka message when profile does not exist


Change-Id: I534596b9927b4a0a1c1e70f8474dd1bb7b1e875c
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent 3fb820da
No related branches found
No related tags found
No related merge requests found
......@@ -951,15 +951,18 @@ class KsusTopic(BaseTopic):
for ksus in indata["ksus"]:
content = ksus
_id = content["_id"]
_id_list.append(_id)
content.pop("_id")
op_id = self.delete(session, _id)
op_id, not_send_msg_ksu = self.delete(session, _id)
if not not_send_msg_ksu:
_id_list.append(_id)
else:
_id_list.append(_id)
op_id = self.delete(session, _id)
op_id, not_send_msg_ksu = self.delete(session, _id)
if not not_send_msg_ksu:
_id_list.append(_id)
data = {"ksus_list": _id_list, "operation_id": op_id}
self._send_msg("delete", data)
if _id_list:
data = {"ksus_list": _id_list, "operation_id": op_id}
self._send_msg("delete", data, not_send_msg)
return op_id
def delete(self, session, _id):
......@@ -1006,7 +1009,24 @@ class KsusTopic(BaseTopic):
{"_id": oka_id},
{"_admin.usageState": "NOT_IN_USE"},
)
return op_id
# Check if the profile exists. If it doesn't, no message should be sent to Kafka
not_send_msg = None
profile_id = item_content["profile"]["_id"]
profile_type = item_content["profile"]["profile_type"]
profile_collection_map = {
"app_profiles": "k8sapp",
"resource_profiles": "k8sresource",
"infra_controller_profiles": "k8sinfra_controller",
"infra_config_profiles": "k8sinfra_config",
}
profile_collection = profile_collection_map[profile_type]
profile_content = self.db.get_one(
profile_collection, {"_id": profile_id}, fail_on_empty=False
)
if not profile_content:
self.db.del_one(self.topic, filter_q)
not_send_msg = True
return op_id, not_send_msg
class OkaTopic(DescriptorTopic):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment