Skip to content

Commit

Permalink
Merge pull request #115 from whdalsrnt/master
Browse files Browse the repository at this point in the history
feat: add cost_data_keys to DataSource model
  • Loading branch information
whdalsrnt authored Nov 8, 2023
2 parents 7de6a09 + 7352f94 commit 605d852
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/spaceone/cost_analysis/info/data_source_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def DataSourceInfo(data_source_vo: DataSource, minimal=False):
'tags': change_struct_type(data_source_vo.tags),
'cost_tag_keys': data_source_vo.cost_tag_keys,
'cost_additional_info_keys': data_source_vo.cost_additional_info_keys,
'cost_data_keys': data_source_vo.cost_data_keys,
'domain_id': data_source_vo.domain_id,
'created_at': utils.datetime_to_iso8601(data_source_vo.created_at),
'last_synchronized_at': utils.datetime_to_iso8601(data_source_vo.last_synchronized_at)
Expand Down
8 changes: 4 additions & 4 deletions src/spaceone/cost_analysis/model/data_source_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DataSource(MongoModel):
tags = DictField(default={})
cost_tag_keys = ListField(StringField())
cost_additional_info_keys = ListField(StringField())
cost_data_keys = ListField(StringField())
domain_id = StringField(max_length=40)
created_at = DateTimeField(auto_now_add=True)
last_synchronized_at = DateTimeField(default=None, null=True)
Expand All @@ -53,7 +54,8 @@ class DataSource(MongoModel):
'tags',
'last_synchronized_at',
'cost_tag_keys',
'cost_additional_info_keys'
'cost_additional_info_keys',
'cost_data_keys'
],
'minimal_fields': [
'data_source_id',
Expand All @@ -71,8 +73,6 @@ class DataSource(MongoModel):
'state',
'data_source_type',
'provider',
'domain_id',
'cost_tag_keys',
'cost_additional_info_keys',
'domain_id'
]
}
18 changes: 15 additions & 3 deletions src/spaceone/cost_analysis/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def get_cost_data(self, params):
schema = plugin_info.get('schema')
tag_keys = data_source_vo.cost_tag_keys
additional_info_keys = data_source_vo.cost_additional_info_keys
data_keys = data_source_vo.cost_data_keys
secret_type = data_source_vo.secret_type
options.update({'secret_type': secret_type})

Expand Down Expand Up @@ -216,6 +217,7 @@ def get_cost_data(self, params):

tag_keys = self._append_tag_keys(tag_keys, cost_data)
additional_info_keys = self._append_additional_info_keys(additional_info_keys, cost_data)
data_keys = self._append_data_keys(data_keys, cost_data)

if self._is_job_canceled(job_id, domain_id):
self.job_task_mgr.change_canceled_status(job_task_vo)
Expand All @@ -229,7 +231,7 @@ def get_cost_data(self, params):
_LOGGER.debug(f'[get_cost_data] end job ({job_task_id}): {end_dt}')
_LOGGER.debug(f'[get_cost_data] total job time ({job_task_id}): {end_dt - start_dt}')

self._update_tag_and_additional_info_keys(data_source_vo, tag_keys, additional_info_keys)
self._update_keys(data_source_vo, tag_keys, additional_info_keys, data_keys)
self.job_task_mgr.change_success_status(job_task_vo, count)

except Exception as e:
Expand Down Expand Up @@ -387,6 +389,15 @@ def _append_additional_info_keys(additional_info_keys, cost_data):
additional_info_keys.append(key)
return additional_info_keys

@staticmethod
def _append_data_keys(data_keys, cost_data):
cost_data_info = cost_data.get('data') or {}

for key in cost_data_info.keys():
if key not in data_keys:
data_keys.append(key)
return data_keys

def _get_secret_data(self, secret_id, domain_id):
secret_mgr: SecretManager = self.locator.get_manager('SecretManager')
if secret_id:
Expand Down Expand Up @@ -474,10 +485,11 @@ def _close_job(self, job_id, domain_id, data_source_id):
elif job_vo.status == 'CANCELED':
self._rollback_cost_data(job_vo)

def _update_tag_and_additional_info_keys(self, data_source_vo, tag_keys, additional_info_keys):
def _update_keys(self, data_source_vo, tag_keys, additional_info_keys, data_keys):
self.data_source_mgr.update_data_source_by_vo({
'cost_tag_keys': tag_keys,
'cost_additional_info_keys': additional_info_keys
'cost_additional_info_keys': additional_info_keys,
'cost_data_keys': data_keys
}, data_source_vo)

def _rollback_cost_data(self, job_vo: Job):
Expand Down

0 comments on commit 605d852

Please sign in to comment.