From e3771a15f99cc3c7b85d4965ef1c86da9250b590 Mon Sep 17 00:00:00 2001 From: Thirumalesh Aaraveti Date: Fri, 26 Jan 2024 10:44:00 +0530 Subject: [PATCH] Fixed the upload error --- .../clouds/aws/ec2/collect_cro_reports.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/collect_cro_reports.py b/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/collect_cro_reports.py index cfbb2c46..3366fd78 100644 --- a/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/collect_cro_reports.py +++ b/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/collect_cro_reports.py @@ -216,14 +216,19 @@ def __upload_cro_report_to_es(self, monitor_data: dict): user_forecast = self.get_user_cost_data(group_by_tag_name=group_by_tag_name, group_by_tag_value=ticket_id, requested_date=datetime.utcnow(), extra_filter_key_values={'Project': user_project}, forecast=True, duration=duration) cost_estimation = float(instance_data[self.ZERO].get('estimated_cost', self.ZERO)) if self.__cost_over_usage.es_operations.verify_elastic_index_doc_id(index=self.__cost_over_usage.es_index_cro, doc_id=ticket_id): + es_data = self.__cost_over_usage.es_operations.get_es_data_by_id(id=ticket_id,index=self.__cost_over_usage.es_index_cro) + es_data['_source']['ticket_opened_date'] = ticket_opened_date.date() + es_data['_source']['forecast'] = user_forecast + es_data['_source']['user'] = user + source = self.__prepare_update_es_data(source=es_data.get('_source'), instance_data=instance_data,cost_estimation=cost_estimation, user_cost=user_cost) if self.__check_value_in_es(tag_key='ticket_id_state', tag_value='in-progress', ticket_id=ticket_id): - es_data = self.__cost_over_usage.es_operations.get_es_data_by_id(id=ticket_id, index=self.__cost_over_usage.es_index_cro) - es_data['_source']['ticket_opened_date'] = ticket_opened_date.date() - es_data['_source']['forecast'] = user_forecast - es_data['_source']['user'] = user - source = self.__prepare_update_es_data(source=es_data.get('_source'), instance_data=instance_data, cost_estimation=cost_estimation, user_cost=user_cost) self.__cost_over_usage.es_operations.update_elasticsearch_index(index=self.__es_index_cro, id=ticket_id, metadata=source) upload_data[ticket_id] = source + else: + if self.__check_value_in_es(tag_key='ticket_id_state', tag_value='manager-approved', ticket_id=ticket_id): + es_data['_source']['ticket_id_state'] = 'in-progress' + self.__cost_over_usage.es_operations.update_elasticsearch_index(index=self.__es_index_cro, id=ticket_id, metadata=source) + upload_data[ticket_id] = source else: if ticket_id not in upload_data: source = self.prepare_instance_data(instance_data=instance_data, ticket_id=ticket_id, cost_estimation=cost_estimation, user=user, user_cost=user_cost, ticket_opened_date=ticket_opened_date)