You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.1 KiB

# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
from ITOA.itoa_object import ItoaObject
from ITOA.setup_logging import logger
from itsi.duplicate_entities_manager.utils import construct_filter_with_in_operator
class ItsiDuplicateEntitiesCache(ItoaObject):
"""
Implements KV store collection itsi_duplicate_entities_cache
Fields in this collection are:
"""
def __init__(self, session_key, current_user_name='nobody', transaction_id=None):
self.collection_name = 'itsi_duplicate_entities_cache'
self.owner = 'nobody'
self.current_user_name = current_user_name
self.session_key = session_key
self.transaction_id = transaction_id
super(ItsiDuplicateEntitiesCache, self).__init__(self.session_key,
current_user_name,
self.collection_name,
collection_name=self.collection_name,
title_validation_required=False)
def retrieve_existing_entities_cache_by_key_list(self, entity_key_list, log_prefix='[ItsiDuplicateEntitiesCache]'):
"""
Filter from itsi_duplicate_entities_cache by entity_key_list to return a list of cache objects if exist
:param entity_key_list: A list of unique entity keys
:return: itsi_duplicate_entities_cache objects
[
{
"_key": "entity_key1",
"title": "entity_title1",
"duplicate_aliases": ["host=acron", "vcenter=east"],
"service_keys": [
{
"key": "service1",
"title": "xxxxx"
}
],
"duplicate_types": ["alias", "merge_field"],
"entity_type_ids": [],
"status": "Active",
"retired": false,
"_itsi_identifier_lookups": [
"itsi_entity_id=ip-10-202-9-66",
"entity_name=ip-10-202-9-66",
"host=ip-10-202-9-66"
],
}, ...
]
"""
try:
logger.info(f'tid={self.transaction_id}, {log_prefix} filter from entities cache if object exists')
filter_data = construct_filter_with_in_operator(self.session_key,
entity_key_list,
'_key',
transaction_id=self.transaction_id,
log_prefix=log_prefix)
entities_cache = self.get_bulk(self.owner, filter_data=filter_data, transaction_id=self.transaction_id)
return entities_cache
except Exception as ex:
logger.exception(f'tid={self.transaction_id}, {log_prefix}'
f' Encountered exception while read from itsi_duplicate_entities_cache by keys: {ex}')
raise ex