return not_processed
-def add_operation(item: dict, event_id: str = '') -> str:
+def add_operation(item: dict, l1_cooling_window_seconds: int,
+ l2_cooling_window_seconds: int, event_id: str = '') -> str:
"""
Add an operation coming from an inbound request to the operation dicts.
return the the key to locate the new operation in operations dict
return key
# reject UPLOAD SNAP operations with same level than other being processed
+ # if they are inside the cooling window time interval for the level
for op_key, op in operations.items():
if op['type'] == UPLOAD_SNAP and op['level'] == item['options']['level']:
- operations[key] = item['options']
- operations[key]['type']= item['operation']
- operations[key]['status'] = OPERATION_STATUS_REQUEST_REJECTED
- operations[key]['progress'] = 0
- operations[key]['description'] = f"Operations ({key}): <{item['operation']}> operation\
- <{item['options']['pmr']}>:There is another operation with identifier {op_key}\
- which has the same level and is already being processed"
- operations[key]['status_sent'] = ST_NOT_SENT
- operations[key]['event_id'] = event_id
- return key
+ # we have another log upload operation for same level
+ # verify if it is inside the "cooling window for the level"
+ if op['level'] == 1:
+ cooling_window_seconds = l1_cooling_window_seconds
+ else:
+ cooling_window_seconds = l2_cooling_window_seconds
+ if int(time.time() - op['created']) <= cooling_window_seconds:
+ operations[key] = item['options']
+ operations[key]['type']= item['operation']
+ operations[key]['status'] = OPERATION_STATUS_REQUEST_REJECTED
+ operations[key]['progress'] = 0
+ operations[key]['description'] = f"Operations ({key}): <{item['operation']}> operation\
+ <{item['options']['pmr']}>:There is another operation with identifier {op_key}\
+ which has the same level and is already being processed"
+ operations[key]['status_sent'] = ST_NOT_SENT
+ operations[key]['event_id'] = event_id
+ return key
#reject UPLOAD SNAP operations with same si_requestid than other being processed
if item['options']['si_requestid'] in operations.keys():
self.mgr.log.info(f"Operations: Added confirm response operation for {item}")
# Add the operation to operations dict
- key = add_operation(item, event_id)
+ key = add_operation(item,
+ self.mgr.level_one_upload_cooling_window_seconds,
+ self.mgr.level_two_upload_cooling_window_seconds,
+ event_id)
self.mgr.log.info(f"Operations: Added operation {item}")
+ else:
+ self.mgr.log.info(f"Operations: Rejected already processed operation with SI request id = {item.get('options', {}).get('si_requestid', '')}")
except Exception as ex:
self.mgr.log.error(f"Operations: error: {ex} adding {item}")
desc='Password obtained from the IBM Transfer ID service'
),
Option(
- name='upload_snap_cooling_window_seconds',
+ name='upload_ops_persistence_seconds',
+ type='int',
+ default=864000,
+ desc='Time interval during which requests with same SI request ID will not be processed'
+ ),
+ Option(
+ name='level_one_upload_cooling_window_seconds',
+ type='int',
+ default=300,
+ desc='Time interval needed to pass before a new diagnostics upload operation level one will be accepted'
+ ),
+ Option(
+ name='level_two_upload_cooling_window_seconds',
type='int',
- default=86400,
- desc='Discard operations with the same Storage Insigths request id during the cooling window'
+ default=3600,
+ desc='Time interval needed to pass before a new diagnostics upload operation level two(or upper) will be accepted'
),
]
# Other options not using env vars
self.valid_container_registry = self.get_module_option('valid_container_registry')
- self.upload_snap_cooling_window_seconds = self.get_module_option('upload_snap_cooling_window_seconds')
+ self.upload_ops_persistence_seconds = self.get_module_option('upload_ops_persistence_seconds')
+ self.level_one_upload_cooling_window_seconds = self.get_module_option('level_one_upload_cooling_window_seconds')
+ self.level_two_upload_cooling_window_seconds = self.get_module_option('level_two_upload_cooling_window_seconds')
# ecurep options:
self.ecurep_url = self.get_module_option('ecurep_url')
# Do not delete operations inside the upload snap cooling window
if operations[operation_key]['type'] == UPLOAD_SNAP and 'created' in operations[operation_key].keys():
- if int(time.time() - operations[operation_key]['created']) <= self.upload_snap_cooling_window_seconds:
+ if int(time.time() - operations[operation_key]['created']) <= self.upload_ops_persistence_seconds:
continue
self.log.info(f'Operations ({operation_key}): Removed finished <{operations[operation_key]["type"]}> operation with status <{operations[operation_key]["status"]}>')
'enable_status': 'true',
'version': 1}
}
- key = add_operation(request)
+ key = add_operation(request,
+ self.level_one_upload_cooling_window_seconds,
+ self.level_two_upload_cooling_window_seconds)
except Exception as ex:
return HandleCommandResult(stderr=str(ex))