Skip to content

Commit b855307

Browse files
authored
Merge pull request #194 from ImMin5/feature-cost-report
Modify delete cost_reports_data location
2 parents 9d9c1d9 + 4d3c070 commit b855307

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/spaceone/cost_analysis/service/cost_report_data_service.py

-23
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ def create_cost_report_data(self, cost_report_vo: CostReport):
132132
workspace_name = self._get_workspace_name(domain_id, workspace_id)
133133
is_confirmed = True if cost_report_vo.status == "SUCCESS" else False
134134

135-
self._delete_old_is_confirmed_cost_report_data(
136-
domain_id, cost_report_config_id, report_month, is_confirmed
137-
)
138-
139135
cost_report_config_vo = cost_report_config_mgr.get_cost_report_config(
140136
domain_id=domain_id, cost_report_config_id=cost_report_config_id
141137
)
@@ -293,25 +289,6 @@ def _get_service_account_name_map(self, workspace_id: str, domain_id: str) -> di
293289
] = service_account["name"]
294290
return service_account_name_map
295291

296-
def _delete_old_is_confirmed_cost_report_data(
297-
self,
298-
domain_id: str,
299-
cost_report_config_id,
300-
report_month: str,
301-
is_confirmed: bool,
302-
):
303-
if is_confirmed:
304-
cost_report_data_vos = self.cost_report_data_mgr.filter_cost_reports_data(
305-
domain_id=domain_id,
306-
cost_report_config_id=cost_report_config_id,
307-
report_month=report_month,
308-
is_confirmed=is_confirmed,
309-
)
310-
_LOGGER.debug(
311-
f"[delete_cost_report_data] delete is_confirmed cost report data ({cost_report_config_id, report_month}) {cost_report_data_vos.count()}"
312-
)
313-
cost_report_data_vos.delete()
314-
315292
@staticmethod
316293
def _get_data_source_currency_map(
317294
data_source_filter: dict, workspace_id: str, domain_id: str

src/spaceone/cost_analysis/service/cost_report_serivce.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
)
1919
from spaceone.cost_analysis.manager.cost_manager import CostManager
2020
from spaceone.cost_analysis.manager.cost_report_manager import CostReportManager
21+
from spaceone.cost_analysis.manager.cost_report_data_manager import (
22+
CostReportDataManager,
23+
)
2124
from spaceone.cost_analysis.manager.currency_manager import CurrencyManager
2225
from spaceone.cost_analysis.manager.data_source_manager import DataSourceManager
2326
from spaceone.cost_analysis.manager.email_manager import EmailManager
@@ -41,6 +44,7 @@ def __init__(self, *args, **kwargs):
4144
self.cost_mgr = CostManager()
4245
self.cost_report_config_mgr = CostReportConfigManager()
4346
self.cost_report_mgr = CostReportManager()
47+
self.cost_report_data_mgr = CostReportDataManager()
4448
self.currency_map: Union[dict, None] = None
4549
self.currency_date: Union[str, None] = None
4650

@@ -247,10 +251,13 @@ def _aggregate_monthly_cost_report(
247251
) -> None:
248252
report_year = report_month.split("-")[0]
249253

250-
# delete old cost_reports
254+
# delete old cost_reports and cost_reports_data
251255
self._delete_old_cost_reports(
252256
report_month, domain_id, cost_report_config_id, status
253257
)
258+
self._delete_old_is_confirmed_cost_report_data(
259+
domain_id, cost_report_config_id, report_month, status
260+
)
254261

255262
# collect enabled data sources
256263
query = {
@@ -353,6 +360,25 @@ def _delete_old_cost_reports(
353360
)
354361
cost_reports_vos.delete()
355362

363+
def _delete_old_is_confirmed_cost_report_data(
364+
self,
365+
domain_id: str,
366+
cost_report_config_id,
367+
report_month: str,
368+
status: str,
369+
):
370+
if status == "SUCCESS":
371+
cost_report_data_vos = self.cost_report_data_mgr.filter_cost_reports_data(
372+
domain_id=domain_id,
373+
cost_report_config_id=cost_report_config_id,
374+
report_month=report_month,
375+
is_confirmed=True,
376+
)
377+
_LOGGER.debug(
378+
f"[delete_cost_report_data] delete is_confirmed cost report data ({cost_report_config_id, report_month}) {cost_report_data_vos.count()}"
379+
)
380+
cost_report_data_vos.delete()
381+
356382
def send_cost_report(self, cost_report_vo: CostReport) -> None:
357383
domain_id = cost_report_vo.domain_id
358384
workspace_id = cost_report_vo.workspace_id

0 commit comments

Comments
 (0)