Skip to content

Commit 69f8ef6

Browse files
committed
fix: delete event is also inserting a reord to ES
1 parent a05298f commit 69f8ef6

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

cumulus_lambda_functions/granules_to_es/granules_indexer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def start(self):
7373
result = JsonValidator(self.CUMULUS_SCHEMA).validate(incoming_msg)
7474
if result is not None:
7575
raise ValueError(f'input json has CUMULUS validation errors: {result}')
76+
if 'event' not in incoming_msg or incoming_msg['event'].upper() == 'DELETE':
77+
LOGGER.debug(f'missing event or it is DELETE event. Not inserting to ES')
78+
return
7679
self.__cumulus_record = incoming_msg['record']
7780
if len(self.__cumulus_record['files']) < 1:
7881
# TODO ingest updating stage?

cumulus_lambda_functions/uds_api/granules_api.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -214,36 +214,36 @@ async def get_granules_dapa(request: Request, collection_id: str, limit: Union[i
214214
raise HTTPException(status_code=granules_result['statusCode'], detail=granules_result['body'])
215215

216216

217-
@router.get("/{collection_id}/items/{granule_id}")
218-
@router.get("/{collection_id}/items/{granule_id}/")
219-
async def get_single_granule_dapa(request: Request, collection_id: str, granule_id: str):
220-
authorizer: UDSAuthorizorAbstract = UDSAuthorizerFactory() \
221-
.get_instance(UDSAuthorizerFactory.cognito,
222-
es_url=os.getenv('ES_URL'),
223-
es_port=int(os.getenv('ES_PORT', '443'))
224-
)
225-
auth_info = FastApiUtils.get_authorization_info(request)
226-
collection_identifier = UdsCollections.decode_identifier(collection_id)
227-
if not authorizer.is_authorized_for_collection(DBConstants.read, collection_id,
228-
auth_info['ldap_groups'],
229-
collection_identifier.tenant,
230-
collection_identifier.venue):
231-
LOGGER.debug(f'user: {auth_info["username"]} is not authorized for {collection_id}')
232-
raise HTTPException(status_code=403, detail=json.dumps({
233-
'message': 'not authorized to execute this action'
234-
}))
235-
try:
236-
api_base_prefix = FastApiUtils.get_api_base_prefix()
237-
pg_link_generator = PaginationLinksGenerator(request)
238-
granules_dapa_query = GranulesDapaQueryEs(collection_id, 1, None, None, filter, None, f'{pg_link_generator.base_url}/{api_base_prefix}')
239-
granules_result = granules_dapa_query.get_single_granule(granule_id)
240-
except Exception as e:
241-
LOGGER.exception('failed during get_granules_dapa')
242-
raise HTTPException(status_code=500, detail=str(e))
243-
return granules_result
217+
# @router.get("/{collection_id}/items/{granule_id}")
218+
# @router.get("/{collection_id}/items/{granule_id}/")
219+
# async def get_single_granule_dapa(request: Request, collection_id: str, granule_id: str):
220+
# authorizer: UDSAuthorizorAbstract = UDSAuthorizerFactory() \
221+
# .get_instance(UDSAuthorizerFactory.cognito,
222+
# es_url=os.getenv('ES_URL'),
223+
# es_port=int(os.getenv('ES_PORT', '443'))
224+
# )
225+
# auth_info = FastApiUtils.get_authorization_info(request)
226+
# collection_identifier = UdsCollections.decode_identifier(collection_id)
227+
# if not authorizer.is_authorized_for_collection(DBConstants.read, collection_id,
228+
# auth_info['ldap_groups'],
229+
# collection_identifier.tenant,
230+
# collection_identifier.venue):
231+
# LOGGER.debug(f'user: {auth_info["username"]} is not authorized for {collection_id}')
232+
# raise HTTPException(status_code=403, detail=json.dumps({
233+
# 'message': 'not authorized to execute this action'
234+
# }))
235+
# try:
236+
# api_base_prefix = FastApiUtils.get_api_base_prefix()
237+
# pg_link_generator = PaginationLinksGenerator(request)
238+
# granules_dapa_query = GranulesDapaQueryEs(collection_id, 1, None, None, filter, None, f'{pg_link_generator.base_url}/{api_base_prefix}')
239+
# granules_result = granules_dapa_query.get_single_granule(granule_id)
240+
# except Exception as e:
241+
# LOGGER.exception('failed during get_granules_dapa')
242+
# raise HTTPException(status_code=500, detail=str(e))
243+
# return granules_result
244244

245-
@router.delete("/{collection_id}/items/{granule_id}/actual")
246-
@router.delete("/{collection_id}/items/{granule_id}/actual/")
245+
@router.delete("/{collection_id}/items/{granule_id}")
246+
@router.delete("/{collection_id}/items/{granule_id}/")
247247
async def delete_single_granule_dapa_actual(request: Request, collection_id: str, granule_id: str):
248248
authorizer: UDSAuthorizorAbstract = UDSAuthorizerFactory() \
249249
.get_instance(UDSAuthorizerFactory.cognito,
@@ -267,7 +267,6 @@ async def delete_single_granule_dapa_actual(request: Request, collection_id: str
267267
cumulus.with_collection_id(collection_id)
268268
cumulus_delete_result = cumulus.delete_entry(cumulus_lambda_prefix, granule_id) # TODO not sure it is correct granule ID
269269
LOGGER.debug(f'cumulus_delete_result: {cumulus_delete_result}')
270-
sleep(3) # Testing if this helps
271270
es_delete_result = GranulesDbIndex().delete_entry(collection_identifier.tenant,
272271
collection_identifier.venue,
273272
granule_id

tests/integration_tests/test_granules_deletion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_delete_all(self):
7575

7676
asset_urls = [v['href'] for k, v in response_json['features'][0]['assets'].items()]
7777
print(asset_urls)
78-
post_url = f'{self.uds_url}collections/{collection_id}/items/{deleting_granule_id}/actual' # MCP Dev
78+
post_url = f'{self.uds_url}collections/{collection_id}/items/{deleting_granule_id}/' # MCP Dev
7979
print(post_url)
8080
query_result = requests.delete(url=post_url,
8181
headers=headers,

0 commit comments

Comments
 (0)