store deprecated event handling & other fixes
@@ -104,9 +104,16 @@ async def deprecate_asset_track_entry(request: web.Request) -> web.Response:
if response[0]['deprecated_ts'] == "":
# Update deprecated_ts column entry
current_time = common_utils.local_timestamp()
+ if event_name in ('Ingest', 'store'):
+ update_payload = PayloadBuilder().SET(deprecated_ts=current_time).WHERE(
+ ['service', '=', svc_name]).AND_WHERE(['asset', '=', asset_name]).AND_WHERE(
+ ['event', 'in', ["Ingest", "store"]]).AND_WHERE(['deprecated_ts', 'isnull']).payload()
+ audit_event_name = "Ingest & store"
+ else:
update_payload = PayloadBuilder().SET(deprecated_ts=current_time).WHERE(
['service', '=', svc_name]).AND_WHERE(['asset', '=', asset_name]).AND_WHERE(
['event', '=', event_name]).AND_WHERE(['deprecated_ts', 'isnull']).payload()
+ audit_event_name = event_name
update_result = await storage_client.update_tbl("asset_tracker", update_payload)
if 'response' in update_result:
response = update_result['response']
@@ -115,22 +122,22 @@ async def deprecate_asset_track_entry(request: web.Request) -> web.Response:
svc_name, asset_name, event_name))
try:
audit = AuditLogger(storage_client)
- audit_details = {'asset': asset_name, 'service': svc_name, 'event' : event_name}
+ audit_details = {'asset': asset_name, 'service': svc_name, 'event': audit_event_name}
await audit.information('ASTDP', audit_details)
except:
- _logger.warning("Failed to log the audit entry for {} deprecation".format(asset_name))
+ _logger.warning("Failed to log the audit entry for {} deprecation.".format(asset_name))
pass
else:
raise StorageServerError
else:
- raise KeyError('Asset record already deprecated.')
+ raise KeyError('{} asset record already deprecated.'.format(asset_name))
else:
raise ValueError('No record found in asset tracker for given service: {} asset: {} event: {}'.format(
svc_name, asset_name, event_name))
else:
raise StorageServerError
except StorageServerError as err:
- msg = str(err)
+ msg = err.error
raise web.HTTPInternalServerError(reason=msg, body=json.dumps({"message": "Storage error: {}".format(msg)}))
except KeyError as err:
msg = str(err)
@@ -142,8 +149,8 @@ async def deprecate_asset_track_entry(request: web.Request) -> web.Response:
msg = str(ex)
raise web.HTTPInternalServerError(reason=msg, body=json.dumps({"message": msg}))
else:
- _logger.info("Asset '{}' has been deprecated".format(asset_name))
- return web.json_response({'success': "Asset record entry has been deprecated."})
+ _logger.info("Asset '{}' has been deprecated.".format(asset_name))
+ return web.json_response({'success': "{} asset record entry has been deprecated.".format(asset_name)})
async def get_datapoint_usage(request: web.Request) -> web.Response:
