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):
{"_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):