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.

60 lines
2.7 KiB

# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved.
from ITOA.itoa_common import is_feature_enabled
from ITOA.setup_logging import logger
from itsi.itsi_utils import ITOAInterfaceUtils
from itsi.objects.itsi_sandbox import ItsiSandbox, Status
from itsi.objects.itsi_sandbox_sync_log import ItsiSandboxSyncLog
class ServiceSandboxStatusUpdater(object):
def __init__(self, session_key, app='SA-ITOA', user='nobody'):
'''
Constructor
@type: string
@param session_key:
@type: string
@param app: context of app invoking the request
@type: string
@param owner: "owner" user invoking this call
@return: None
'''
self._session_key = session_key
self._app = app
self._user = user
self.sandbox_interface = ItsiSandbox(self._session_key, self._user)
self.sandbox_sync_log_interface = ItsiSandboxSyncLog(self._session_key, self._user)
def update_service_sandbox_status(self):
"""
The Function is used to check if the Sandbox status is set to Non-Edit mode.
If so set the status back to Edit mode. This mod input is called only on start of itsi.
@return None - modification is made directly to the Sandbox object
"""
transaction_id = ITOAInterfaceUtils.generate_backend_key()
logger.info('Start updating Status for Service Sandbox Objects (%s)' % transaction_id)
# fetch only the Sandbox thatt are not in edit, successful publish and partial publish status
filter_data = {'$and': [
{'status': {'$ne': Status.STATUS_EDIT}},
{'status': {'$ne': Status.STATUS_PUBLISH_SUCCESS}},
{'status': {'$ne': Status.STATUS_PARTIAL_PUBLISH}}
]}
all_sandbox_objects = self.sandbox_interface.get_bulk(self._user, filter_data=filter_data)
logger.info('Updating the statuses of {0} Service Sandboxes.'.format(len(all_sandbox_objects)))
for sandbox in all_sandbox_objects:
sandbox_id = sandbox.get('_key')
self.sandbox_interface.update(owner=self._user, object_id=sandbox_id, data={'status': Status.STATUS_EDIT},
is_partial_data=True, transaction_id=transaction_id)
record = {
'action_type': 'ModInput Status Updater',
}
self.sandbox_sync_log_interface.create_record(self._user, mod_object_id=sandbox_id, record=record,
mod_object_type=self.sandbox_interface.object_type,
transaction_id=transaction_id)
logger.info('Status Update complete for Service Sandbox with Id= {0}'.format(sandbox_id))