Skip to content

Commit

Permalink
Dashboard must be deletedbefore (re) creating it. Otherwise things br…
Browse files Browse the repository at this point in the history
…eak.
  • Loading branch information
dbernstein committed Nov 22, 2023
1 parent 2ed36a6 commit 322467b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
6 changes: 3 additions & 3 deletions core/operation/baseoperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, qs_client, aws_account_id: str):
def execute(self) -> dict:
pass

def _create_or_update_template(self, template_data: dict) -> TemplateResponse:
def _recreate_template(self, template_data: dict) -> TemplateResponse:
"""
Creates new or updates existing template.
:param template_data:
Expand Down Expand Up @@ -76,11 +76,11 @@ def _create_or_update_template(self, template_data: dict) -> TemplateResponse:
response["Arn"], response["VersionArn"], response["TemplateId"]
)

def _create_or_update_template_from_template_definition(
def _recreate_template_from_template_definition(
self, template_definition: dict
) -> TemplateResponse:
template_definition["AwsAccountId"] = self._aws_account_id
return self._create_or_update_template(template_data=template_definition)
return self._recreate_template(template_data=template_definition)

def _resolve_data_set_id_from_placeholder(
self, namespace: str, placeholder: str
Expand Down
2 changes: 1 addition & 1 deletion core/operation/export_analysis_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _create_or_update_template_from_analysis(
},
},
}
return self._create_or_update_template(template_data=params)
return self._recreate_template(template_data=params)

def _save_dataset_to_file(self, di) -> str:
"""
Expand Down
6 changes: 3 additions & 3 deletions core/operation/import_from_json_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def execute(self) -> dict:
# create or update template
template_data["Name"] = self._target_namespace + "-" + self._template_name
template_data["TemplateId"] = template_data["Name"]
template_response = self._create_or_update_template_from_template_definition(
template_response = self._recreate_template_from_template_definition(
template_definition=template_data
)

Expand Down Expand Up @@ -73,7 +73,7 @@ def execute(self) -> dict:
placeholder=placeholder, namespace=self._target_namespace
)
dataset["Name"] = dataset["Name"]
ds_response = self._create_or_update_data_set(dataset_definition=dataset)
ds_response = self._recreate_data_set(dataset_definition=dataset)

data_sets_created.append(
{
Expand All @@ -92,7 +92,7 @@ def execute(self) -> dict:
},
}

def _create_or_update_data_set(self, dataset_definition: dict):
def _recreate_data_set(self, dataset_definition: dict):
"""
Create new or updates existing DataSet
:param dataset_definition:
Expand Down
14 changes: 11 additions & 3 deletions core/operation/publish_dashboard_from_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def execute(self) -> dict:
)

# publish dashboard
dashboard_arn, dashboard_id = self._create_or_update_dashboard(
dashboard_arn, dashboard_id = self._recreate_dashboard(
dashboard_params=parameters
)

Expand Down Expand Up @@ -142,12 +142,20 @@ def execute(self) -> dict:

return result

def _create_or_update_dashboard(self, dashboard_params: dict) -> tuple[str, str]:
def _recreate_dashboard(self, dashboard_params: dict) -> tuple[str, str]:
"""
Creates new or updates existing template.
Creates new or recreates existing template.
:param dashboard_params:
:return: Dashboard ARN, Dashboard ID
"""
try:
response = self._qs_client.delete_dashboard(
AwsAccountId=dashboard_params["AwsAccountId"],
DashboardId=dashboard_params["DashboardId"],
)
except self._qs_client.exceptions.ResourceNotFoundException as e:
pass

try:
response = self._qs_client.create_dashboard(**dashboard_params)
except self._qs_client.exceptions.ResourceExistsException as e:
Expand Down
9 changes: 9 additions & 0 deletions tests/core/operation/test_publish_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ def test(self):
},
)

qs_stub.add_response(
"delete_dashboard",
service_response={},
expected_params={
"AwsAccountId": account,
"DashboardId": template_id,
},
)

qs_stub.add_response(
"create_dashboard",
service_response={
Expand Down

0 comments on commit 322467b

Please sign in to comment.