Ejemplo n.º 1
0
    def update_aws_summary_tables(self, openshift_provider_uuid,
                                  aws_provider_uuid, start_date, end_date):
        """Update operations specifically for OpenShift on AWS."""
        cluster_id = get_cluster_id_from_provider(openshift_provider_uuid)
        aws_bills = aws_get_bills_from_provider(
            aws_provider_uuid, self._schema,
            datetime.datetime.strptime(start_date, '%Y-%m-%d'),
            datetime.datetime.strptime(end_date, '%Y-%m-%d'))
        aws_bill_ids = []
        with schema_context(self._schema):
            aws_bill_ids = [str(bill.id) for bill in aws_bills]

        with CostModelDBAccessor(self._schema, aws_provider_uuid,
                                 self._column_map) as cost_model_accessor:
            markup = cost_model_accessor.get_markup()
            markup_value = Decimal(markup.get('value', 0)) / 100

        # OpenShift on AWS
        with AWSReportDBAccessor(self._schema, self._column_map) as accessor:
            LOG.info(
                'Updating OpenShift on AWS summary table for '
                '\n\tSchema: %s \n\tProvider: %s \n\tDates: %s - %s'
                '\n\tCluster ID: %s, AWS Bill IDs: %s', self._schema,
                self._provider.uuid, start_date, end_date, cluster_id,
                str(aws_bill_ids))
            accessor.populate_ocp_on_aws_cost_daily_summary(
                start_date, end_date, cluster_id, aws_bill_ids)
            accessor.populate_ocp_on_aws_markup_cost(markup_value,
                                                     aws_bill_ids)

        with OCPReportDBAccessor(self._schema, self._column_map) as accessor:
            # This call just sends the infrastructure cost to the
            # OCP usage daily summary table
            accessor.update_summary_infrastructure_cost(
                cluster_id, start_date, end_date)
Ejemplo n.º 2
0
    def update_aws_summary_tables(self, openshift_provider_uuid,
                                  aws_provider_uuid, start_date, end_date):
        """Update operations specifically for OpenShift on AWS."""
        if isinstance(start_date, str):
            start_date = parser.parse(start_date).date()
        if isinstance(end_date, str):
            end_date = parser.parse(end_date).date()

        cluster_id = get_cluster_id_from_provider(openshift_provider_uuid)
        with OCPReportDBAccessor(self._schema) as accessor:
            report_period = accessor.report_periods_for_provider_uuid(
                openshift_provider_uuid, start_date)
            accessor.delete_infrastructure_raw_cost_from_daily_summary(
                openshift_provider_uuid, report_period.id, start_date,
                end_date)
        aws_bills = aws_get_bills_from_provider(aws_provider_uuid,
                                                self._schema, start_date,
                                                end_date)
        with schema_context(self._schema):
            aws_bill_ids = [str(bill.id) for bill in aws_bills]
            current_aws_bill_id = aws_bills.first().id if aws_bills else None
            current_ocp_report_period_id = report_period.id

        with CostModelDBAccessor(self._schema,
                                 aws_provider_uuid) as cost_model_accessor:
            markup = cost_model_accessor.markup
            markup_value = Decimal(markup.get("value", 0)) / 100

        # OpenShift on AWS
        with AWSReportDBAccessor(self._schema) as accessor:
            for start, end in date_range_pair(start_date,
                                              end_date,
                                              step=settings.TRINO_DATE_STEP):
                LOG.info(
                    "Updating OpenShift on AWS summary table for "
                    "\n\tSchema: %s \n\tProvider: %s \n\tDates: %s - %s"
                    "\n\tCluster ID: %s, AWS Bill ID: %s",
                    self._schema,
                    self._provider.uuid,
                    start,
                    end,
                    cluster_id,
                    current_aws_bill_id,
                )
                accessor.populate_ocp_on_aws_cost_daily_summary_presto(
                    start,
                    end,
                    openshift_provider_uuid,
                    aws_provider_uuid,
                    current_ocp_report_period_id,
                    current_aws_bill_id,
                    markup_value,
                )
            accessor.back_populate_ocp_on_aws_daily_summary(
                start_date, end_date, current_ocp_report_period_id)
            accessor.populate_ocp_on_aws_tags_summary_table(
                aws_bill_ids, start_date, end_date)
Ejemplo n.º 3
0
    def update_aws_summary_tables(self, openshift_provider_uuid,
                                  aws_provider_uuid, start_date, end_date):
        """Update operations specifically for OpenShift on AWS."""
        if isinstance(start_date, str):
            start_date = parser.parse(start_date).date()
        if isinstance(end_date, str):
            end_date = parser.parse(end_date).date()

        cluster_id = get_cluster_id_from_provider(openshift_provider_uuid)
        aws_bills = aws_get_bills_from_provider(aws_provider_uuid,
                                                self._schema, start_date,
                                                end_date)
        with schema_context(self._schema):
            current_aws_bill_id = aws_bills.first().id if aws_bills else None

        with CostModelDBAccessor(self._schema,
                                 aws_provider_uuid) as cost_model_accessor:
            markup = cost_model_accessor.markup
            markup_value = Decimal(markup.get("value", 0)) / 100

        # OpenShift on AWS
        with AWSReportDBAccessor(self._schema) as accessor:
            LOG.info(
                "Updating OpenShift on AWS summary table for "
                "\n\tSchema: %s \n\tProvider: %s \n\tDates: %s - %s"
                "\n\tCluster ID: %s, AWS Bill ID: %s",
                self._schema,
                self._provider.uuid,
                start_date,
                end_date,
                cluster_id,
                current_aws_bill_id,
            )
            accessor.populate_ocp_on_aws_cost_daily_summary_presto(
                start_date,
                end_date,
                openshift_provider_uuid,
                aws_provider_uuid,
                cluster_id,
                current_aws_bill_id,
                markup_value,
            )
            accessor.populate_ocp_on_aws_tags_summary_table()

        with OCPReportDBAccessor(self._schema) as accessor:
            # This call just sends the infrastructure cost to the
            # OCP usage daily summary table
            accessor.update_summary_infrastructure_cost(
                cluster_id, start_date, end_date)
Ejemplo n.º 4
0
    def update_aws_summary_tables(self, openshift_provider_uuid,
                                  aws_provider_uuid, start_date, end_date):
        """Update operations specifically for OpenShift on AWS."""
        if isinstance(start_date, str):
            start_date = parser.parse(start_date)
        if isinstance(end_date, str):
            end_date = parser.parse(end_date)

        cluster_id = get_cluster_id_from_provider(openshift_provider_uuid)
        aws_bills = aws_get_bills_from_provider(aws_provider_uuid,
                                                self._schema, start_date,
                                                end_date)
        aws_bill_ids = []
        with schema_context(self._schema):
            aws_bill_ids = [str(bill.id) for bill in aws_bills]

        with CostModelDBAccessor(self._schema,
                                 aws_provider_uuid) as cost_model_accessor:
            markup = cost_model_accessor.markup
            markup_value = Decimal(markup.get("value", 0)) / 100

        # OpenShift on AWS
        with AWSReportDBAccessor(self._schema) as accessor:
            for start, end in date_range_pair(start_date, end_date):
                LOG.info(
                    "Updating OpenShift on AWS summary table for "
                    "\n\tSchema: %s \n\tProvider: %s \n\tDates: %s - %s"
                    "\n\tCluster ID: %s, AWS Bill IDs: %s",
                    self._schema,
                    self._provider.uuid,
                    start,
                    end,
                    cluster_id,
                    str(aws_bill_ids),
                )
                accessor.populate_ocp_on_aws_cost_daily_summary(
                    start, end, cluster_id, aws_bill_ids, markup_value)
            accessor.populate_ocp_on_aws_tags_summary_table()
        self.refresh_openshift_on_infrastructure_views(
            OCP_ON_AWS_MATERIALIZED_VIEWS)

        with OCPReportDBAccessor(self._schema) as accessor:
            # This call just sends the infrastructure cost to the
            # OCP usage daily summary table
            accessor.update_summary_infrastructure_cost(
                cluster_id, start_date, end_date)
    def update_aws_summary_tables(self, openshift_provider_uuid,
                                  aws_provider_uuid, start_date, end_date):
        """Update operations specifically for OpenShift on AWS."""
        if isinstance(start_date, str):
            start_date = parser.parse(start_date).date()
        if isinstance(end_date, str):
            end_date = parser.parse(end_date).date()

        cluster_id = get_cluster_id_from_provider(openshift_provider_uuid)
        cluster_alias = get_cluster_alias_from_cluster_id(cluster_id)

        with OCPReportDBAccessor(self._schema) as accessor:
            if not accessor.get_cluster_for_provider(openshift_provider_uuid):
                LOG.info(
                    f"No cluster information available for OCP Provider: {openshift_provider_uuid}, "
                    f"skipping OCP on Cloud summary table update for AWS source: {aws_provider_uuid}."
                )
                return
            report_period = accessor.report_periods_for_provider_uuid(
                openshift_provider_uuid, start_date)
            if not report_period:
                LOG.info(
                    f"No report period for AWS provider {openshift_provider_uuid} with start date {start_date}"
                )
                return

            accessor.delete_infrastructure_raw_cost_from_daily_summary(
                openshift_provider_uuid, report_period.id, start_date,
                end_date)
        aws_bills = aws_get_bills_from_provider(aws_provider_uuid,
                                                self._schema, start_date,
                                                end_date)
        with schema_context(self._schema):
            self._handle_partitions(
                self._schema,
                (
                    "reporting_ocpawscostlineitem_daily_summary_p",
                    "reporting_ocpawscostlineitem_project_daily_summary_p",
                    "reporting_ocpaws_compute_summary_p",
                    "reporting_ocpaws_cost_summary_p",
                    "reporting_ocpaws_cost_summary_by_account_p",
                    "reporting_ocpaws_cost_summary_by_region_p",
                    "reporting_ocpaws_cost_summary_by_service_p",
                    "reporting_ocpaws_storage_summary_p",
                    "reporting_ocpaws_database_summary_p",
                    "reporting_ocpaws_network_summary_p",
                    "reporting_ocpallcostlineitem_daily_summary_p",
                    "reporting_ocpallcostlineitem_project_daily_summary_p",
                    "reporting_ocpall_compute_summary_pt",
                    "reporting_ocpall_cost_summary_pt",
                ),
                start_date,
                end_date,
            )

            aws_bill_ids = [str(bill.id) for bill in aws_bills]
            current_aws_bill_id = aws_bills.first().id if aws_bills else None
            current_ocp_report_period_id = report_period.id

        with CostModelDBAccessor(self._schema,
                                 aws_provider_uuid) as cost_model_accessor:
            markup = cost_model_accessor.markup
            markup_value = Decimal(markup.get("value", 0)) / 100

        with CostModelDBAccessor(
                self._schema, openshift_provider_uuid) as cost_model_accessor:
            distribution = cost_model_accessor.distribution

        # OpenShift on AWS
        sql_params = {
            "schema_name": self._schema,
            "start_date": start_date,
            "end_date": end_date,
            "source_uuid": aws_provider_uuid,
            "cluster_id": cluster_id,
            "cluster_alias": cluster_alias,
        }
        with AWSReportDBAccessor(self._schema) as accessor:
            for start, end in date_range_pair(start_date,
                                              end_date,
                                              step=settings.TRINO_DATE_STEP):
                LOG.info(
                    "Updating OpenShift on AWS summary table for "
                    "\n\tSchema: %s \n\tProvider: %s \n\tDates: %s - %s"
                    "\n\tCluster ID: %s, AWS Bill ID: %s",
                    self._schema,
                    self._provider.uuid,
                    start,
                    end,
                    cluster_id,
                    current_aws_bill_id,
                )
                filters = {
                    "report_period_id": current_ocp_report_period_id
                }  # Use report_period_id to leverage DB index on DELETE
                accessor.delete_line_item_daily_summary_entries_for_date_range_raw(
                    self._provider.uuid,
                    start,
                    end,
                    filters,
                    table=OCPAWSCostLineItemProjectDailySummaryP)
                accessor.populate_ocp_on_aws_cost_daily_summary_presto(
                    start,
                    end,
                    openshift_provider_uuid,
                    aws_provider_uuid,
                    current_ocp_report_period_id,
                    current_aws_bill_id,
                    markup_value,
                    distribution,
                )
            accessor.back_populate_ocp_on_aws_daily_summary(
                start_date, end_date, current_ocp_report_period_id)
            accessor.populate_ocp_on_aws_tags_summary_table(
                aws_bill_ids, start_date, end_date)
            accessor.populate_ocp_on_aws_ui_summary_tables(sql_params)

            with OCPReportDBAccessor(self._schema) as ocp_accessor:
                sql_params["source_type"] = "AWS"
                LOG.info(
                    f"Processing OCP-ALL for AWS (T)  (s={start_date} e={end_date})"
                )
                ocp_accessor.populate_ocp_on_all_project_daily_summary(
                    "aws", sql_params)
                ocp_accessor.populate_ocp_on_all_daily_summary(
                    "aws", sql_params)
                ocp_accessor.populate_ocp_on_all_ui_summary_tables(sql_params)

                ocp_accessor.populate_ui_summary_tables(
                    start, end, openshift_provider_uuid,
                    UI_SUMMARY_TABLES_MARKUP_SUBSET)

        LOG.info(
            "Updating ocp_on_cloud_updated_datetime OpenShift report periods")
        with schema_context(self._schema):
            report_period.ocp_on_cloud_updated_datetime = self._date_accessor.today_with_timezone(
                "UTC")
            report_period.save()