Пример #1
0
 def execute(self, context: dict) -> None:
     hook = GoogleCampaignManagerHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         api_version=self.api_version,
         impersonation_chain=self.impersonation_chain,
     )
     if self.report_name:
         reports = hook.list_reports(profile_id=self.profile_id)
         reports_with_name = [
             r for r in reports if r["name"] == self.report_name
         ]
         for report in reports_with_name:
             report_id = report["id"]
             self.log.info("Deleting Campaign Manager report: %s",
                           report_id)
             hook.delete_report(profile_id=self.profile_id,
                                report_id=report_id)
             self.log.info("Report deleted.")
     elif self.report_id:
         self.log.info("Deleting Campaign Manager report: %s",
                       self.report_id)
         hook.delete_report(profile_id=self.profile_id,
                            report_id=self.report_id)
         self.log.info("Report deleted.")
Пример #2
0
 def setUp(self):
     with mock.patch(
             "airflow.providers.google.common.hooks.base_google.GoogleBaseHook.__init__",
             new=mock_base_gcp_hook_default_project_id,
     ):
         self.hook = GoogleCampaignManagerHook(gcp_conn_id=GCP_CONN_ID,
                                               api_version=API_VERSION)
Пример #3
0
 def poke(self, context: Dict) -> bool:
     hook = GoogleCampaignManagerHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         api_version=self.api_version,
     )
     response = hook.get_report(profile_id=self.profile_id,
                                report_id=self.report_id,
                                file_id=self.file_id)
     self.log.info("Report status: %s", response["status"])
     return response["status"] != "PROCESSING"
Пример #4
0
 def execute(self, context: Dict):
     hook = GoogleCampaignManagerHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         api_version=self.api_version,
     )
     self.log.info("Inserting Campaign Manager report.")
     response = hook.insert_report(profile_id=self.profile_id,
                                   report=self.report)
     report_id = response.get("id")
     self.xcom_push(context, key="report_id", value=report_id)
     self.log.info("Report successfully inserted. Report id: %s", report_id)
     return response
Пример #5
0
 def execute(self, context: Dict):
     hook = GoogleCampaignManagerHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         api_version=self.api_version,
     )
     response = hook.conversions_batch_update(
         profile_id=self.profile_id,
         conversions=self.conversions,
         encryption_entity_type=self.encryption_entity_type,
         encryption_entity_id=self.encryption_entity_id,
         encryption_source=self.encryption_source,
         max_failed_updates=self.max_failed_updates)
     return response
Пример #6
0
 def execute(self, context: Dict):
     hook = GoogleCampaignManagerHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         api_version=self.api_version,
         impersonation_chain=self.impersonation_chain,
     )
     self.log.info("Running report %s", self.report_id)
     response = hook.run_report(
         profile_id=self.profile_id, report_id=self.report_id, synchronous=self.synchronous,
     )
     file_id = response.get("id")
     self.xcom_push(context, key="file_id", value=file_id)
     self.log.info("Report file id: %s", file_id)
     return response
Пример #7
0
 def execute(self, context: 'Context'):
     hook = GoogleCampaignManagerHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         api_version=self.api_version,
         impersonation_chain=self.impersonation_chain,
     )
     response = hook.conversions_batch_insert(
         profile_id=self.profile_id,
         conversions=self.conversions,
         encryption_entity_type=self.encryption_entity_type,
         encryption_entity_id=self.encryption_entity_id,
         encryption_source=self.encryption_source,
         max_failed_inserts=self.max_failed_inserts,
     )
     return response
Пример #8
0
    def execute(self, context: dict) -> None:
        hook = GoogleCampaignManagerHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            api_version=self.api_version,
            impersonation_chain=self.impersonation_chain,
        )
        gcs_hook = GCSHook(
            google_cloud_storage_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )
        # Get name of the report
        report = hook.get_report(file_id=self.file_id,
                                 profile_id=self.profile_id,
                                 report_id=self.report_id)
        report_name = self.report_name or report.get("fileName",
                                                     str(uuid.uuid4()))
        report_name = self._resolve_file_name(report_name)

        # Download the report
        self.log.info("Starting downloading report %s", self.report_id)
        request = hook.get_report_file(profile_id=self.profile_id,
                                       report_id=self.report_id,
                                       file_id=self.file_id)
        with tempfile.NamedTemporaryFile() as temp_file:
            downloader = http.MediaIoBaseDownload(fd=temp_file,
                                                  request=request,
                                                  chunksize=self.chunk_size)
            download_finished = False
            while not download_finished:
                _, download_finished = downloader.next_chunk()

            temp_file.flush()
            # Upload the local file to bucket
            gcs_hook.upload(
                bucket_name=self.bucket_name,
                object_name=report_name,
                gzip=self.gzip,
                filename=temp_file.name,
                mime_type="text/csv",
            )

        self.xcom_push(context, key="report_name", value=report_name)