Skip to content

Commit

Permalink
Improve logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Oct 3, 2023
1 parent 60111c2 commit 1960ba5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 11 additions & 3 deletions core/operation/baseoperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,40 @@ def _create_or_update_template(self, template_data: dict) -> TemplateResponse:
:return: Template ARN, Template Version ARN, and the Template ID
"""

template_id = template_data["TemplateId"]
try:
self._log.info(f"ready to delete template ({template_id}) if exists.")

self._qs_client.delete_template(
**{
"TemplateId": template_data["TemplateId"],
"TemplateId": template_id,
"AwsAccountId": template_data["AwsAccountId"],
}
)

# there can be some latency between the completion of the deletion command
# and the complete backend deletion operation.
time.sleep(3)
self._log.info(f"template ({template_id}) deletion complete.")

except self._qs_client.exceptions.ResourceNotFoundException as e:
pass
self._log.info(f"template ({template_id}) not found: no deletion needed.")

response = self._qs_client.create_template(**template_data)

http_status = response["ResponseMetadata"]["HTTPStatusCode"]
if http_status != 202:
self._log.error(
f"Unexpected response from create_template request: {http_status} "
f"Unexpected response from create_template request: "
f"template_id = {template_id}, http_status = {http_status}"
)
raise Exception(
f"Unexpected response from trying to create/update template : {json.dumps(response, indent=4)} "
)
else:
self._log.info(
f"Template ({template_id}) created successfully: http_status = {http_status}"
)
return TemplateResponse(
response["Arn"], response["VersionArn"], response["TemplateId"]
)
Expand Down
16 changes: 13 additions & 3 deletions core/operation/import_from_json_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,39 @@ def _create_or_update_data_set(self, dataset_definition: dict):
:return: DataSet ARN and DataSet Id
"""

data_set_id = dataset_definition["DataSetId"]
try:
self._log.info(f"ready to delete data set ({data_set_id}) if exists.")
self._qs_client.delete_data_set(
**{
"DataSetId": dataset_definition["DataSetId"],
"DataSetId": data_set_id,
"AwsAccountId": dataset_definition["AwsAccountId"],
}
)

# there can be some latency between the completion of the deletion command
# and the complete backend deletion operation.
time.sleep(3)
self._log.info(f"Deletion complete for {data_set_id}.")

except self._qs_client.exceptions.ResourceNotFoundException as e:
pass
self._log.info(
f"No deletion necessary: data set {data_set_id} does not exist."
)

response = self._qs_client.create_data_set(**dataset_definition)
http_status = response["ResponseMetadata"]["HTTPStatusCode"]
if http_status != 201 and http_status != 200:
self._log.error(
f"Unexpected response from create_dataset request: {http_status} "
f"Unexpected response from create_dataset request: "
f"data_set_id = {data_set_id}, http_status = {http_status}"
)
raise Exception(
f"Unexpected response from trying to create/update dataset : {json.dumps(response, indent=4)} "
)
else:
self._log.info(
f"Data set ({data_set_id}) created successfully: http_status = {http_status}"
)

return DataSetResponse(response["Arn"], response["DataSetId"])

0 comments on commit 1960ba5

Please sign in to comment.