apache-airflow-providers-google 17.2.0__py3-none-any.whl → 18.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of apache-airflow-providers-google might be problematic. Click here for more details.
- airflow/providers/google/__init__.py +1 -1
- airflow/providers/google/cloud/hooks/bigquery.py +6 -0
- airflow/providers/google/cloud/hooks/cloud_composer.py +79 -13
- airflow/providers/google/cloud/hooks/cloud_run.py +16 -8
- airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py +0 -173
- airflow/providers/google/cloud/log/gcs_task_handler.py +8 -2
- airflow/providers/google/cloud/operators/cloud_composer.py +84 -1
- airflow/providers/google/cloud/sensors/cloud_composer.py +1 -1
- airflow/providers/google/cloud/transfers/bigquery_to_mssql.py +0 -66
- airflow/providers/google/cloud/transfers/bigquery_to_mysql.py +12 -1
- airflow/providers/google/cloud/transfers/bigquery_to_postgres.py +18 -9
- airflow/providers/google/cloud/transfers/bigquery_to_sql.py +95 -0
- airflow/providers/google/cloud/transfers/gcs_to_bigquery.py +11 -0
- airflow/providers/google/cloud/triggers/cloud_composer.py +21 -15
- airflow/providers/google/cloud/utils/bigquery_get_data.py +1 -1
- airflow/providers/google/marketing_platform/hooks/display_video.py +0 -150
- airflow/providers/google/marketing_platform/operators/display_video.py +0 -510
- airflow/providers/google/marketing_platform/sensors/display_video.py +1 -68
- {apache_airflow_providers_google-17.2.0.dist-info → apache_airflow_providers_google-18.0.0.dist-info}/METADATA +35 -8
- {apache_airflow_providers_google-17.2.0.dist-info → apache_airflow_providers_google-18.0.0.dist-info}/RECORD +22 -22
- {apache_airflow_providers_google-17.2.0.dist-info → apache_airflow_providers_google-18.0.0.dist-info}/WHEEL +0 -0
- {apache_airflow_providers_google-17.2.0.dist-info → apache_airflow_providers_google-18.0.0.dist-info}/entry_points.txt +0 -0
|
@@ -19,20 +19,13 @@
|
|
|
19
19
|
|
|
20
20
|
from __future__ import annotations
|
|
21
21
|
|
|
22
|
-
import csv
|
|
23
|
-
import json
|
|
24
22
|
import os
|
|
25
|
-
import shutil
|
|
26
23
|
import tempfile
|
|
27
|
-
import urllib.request
|
|
28
24
|
import zipfile
|
|
29
25
|
from collections.abc import Sequence
|
|
30
26
|
from typing import TYPE_CHECKING, Any
|
|
31
|
-
from urllib.parse import urlsplit
|
|
32
27
|
|
|
33
|
-
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
|
|
34
28
|
from airflow.providers.google.cloud.hooks.gcs import GCSHook
|
|
35
|
-
from airflow.providers.google.common.deprecated import deprecated
|
|
36
29
|
from airflow.providers.google.marketing_platform.hooks.display_video import GoogleDisplayVideo360Hook
|
|
37
30
|
from airflow.providers.google.version_compat import BaseOperator
|
|
38
31
|
|
|
@@ -40,509 +33,6 @@ if TYPE_CHECKING:
|
|
|
40
33
|
from airflow.utils.context import Context
|
|
41
34
|
|
|
42
35
|
|
|
43
|
-
@deprecated(
|
|
44
|
-
planned_removal_date="September 01, 2025",
|
|
45
|
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator",
|
|
46
|
-
reason="Display & Video 360 API v2 has been deprecated and will be removed.",
|
|
47
|
-
category=AirflowProviderDeprecationWarning,
|
|
48
|
-
)
|
|
49
|
-
class GoogleDisplayVideo360CreateQueryOperator(BaseOperator):
|
|
50
|
-
"""
|
|
51
|
-
Creates a query.
|
|
52
|
-
|
|
53
|
-
.. seealso::
|
|
54
|
-
For more information on how to use this operator, take a look at the guide:
|
|
55
|
-
``GoogleDisplayVideo360CreateQueryOperator``
|
|
56
|
-
|
|
57
|
-
.. seealso::
|
|
58
|
-
Check also the official API docs:
|
|
59
|
-
`https://developers.google.com/bid-manager/v2/queries/create`
|
|
60
|
-
|
|
61
|
-
:param body: Report object passed to the request's body as described here:
|
|
62
|
-
https://developers.google.com/bid-manager/v2/queries#Query
|
|
63
|
-
:param api_version: The version of the api that will be requested for example 'v3'.
|
|
64
|
-
:param gcp_conn_id: The connection ID to use when fetching connection info.
|
|
65
|
-
:param impersonation_chain: Optional service account to impersonate using short-term
|
|
66
|
-
credentials, or chained list of accounts required to get the access_token
|
|
67
|
-
of the last account in the list, which will be impersonated in the request.
|
|
68
|
-
If set as a string, the account must grant the originating account
|
|
69
|
-
the Service Account Token Creator IAM role.
|
|
70
|
-
If set as a sequence, the identities from the list must grant
|
|
71
|
-
Service Account Token Creator IAM role to the directly preceding identity, with the first
|
|
72
|
-
account from the list granting this role to the originating account (templated).
|
|
73
|
-
"""
|
|
74
|
-
|
|
75
|
-
template_fields: Sequence[str] = (
|
|
76
|
-
"body",
|
|
77
|
-
"impersonation_chain",
|
|
78
|
-
)
|
|
79
|
-
template_ext: Sequence[str] = (".json",)
|
|
80
|
-
|
|
81
|
-
def __init__(
|
|
82
|
-
self,
|
|
83
|
-
*,
|
|
84
|
-
body: dict[str, Any],
|
|
85
|
-
api_version: str = "v2",
|
|
86
|
-
gcp_conn_id: str = "google_cloud_default",
|
|
87
|
-
impersonation_chain: str | Sequence[str] | None = None,
|
|
88
|
-
**kwargs,
|
|
89
|
-
) -> None:
|
|
90
|
-
super().__init__(**kwargs)
|
|
91
|
-
self.body = body
|
|
92
|
-
self.api_version = api_version
|
|
93
|
-
self.gcp_conn_id = gcp_conn_id
|
|
94
|
-
self.impersonation_chain = impersonation_chain
|
|
95
|
-
|
|
96
|
-
def prepare_template(self) -> None:
|
|
97
|
-
# If .json is passed then we have to read the file
|
|
98
|
-
if isinstance(self.body, str) and self.body.endswith(".json"):
|
|
99
|
-
with open(self.body) as file:
|
|
100
|
-
self.body = json.load(file)
|
|
101
|
-
|
|
102
|
-
def execute(self, context: Context) -> dict:
|
|
103
|
-
hook = GoogleDisplayVideo360Hook(
|
|
104
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
105
|
-
api_version=self.api_version,
|
|
106
|
-
impersonation_chain=self.impersonation_chain,
|
|
107
|
-
)
|
|
108
|
-
self.log.info("Creating Display & Video 360 query.")
|
|
109
|
-
response = hook.create_query(query=self.body)
|
|
110
|
-
query_id = response["queryId"]
|
|
111
|
-
context["task_instance"].xcom_push(key="query_id", value=query_id)
|
|
112
|
-
self.log.info("Created query with ID: %s", query_id)
|
|
113
|
-
return response
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
@deprecated(
|
|
117
|
-
planned_removal_date="September 01, 2025",
|
|
118
|
-
reason="Display & Video 360 API v2 has been deprecated and will be removed. "
|
|
119
|
-
"Reports were replaced with SDF export task in v4 of API.",
|
|
120
|
-
category=AirflowProviderDeprecationWarning,
|
|
121
|
-
)
|
|
122
|
-
class GoogleDisplayVideo360DeleteReportOperator(BaseOperator):
|
|
123
|
-
"""
|
|
124
|
-
Deletes a stored query as well as the associated stored reports.
|
|
125
|
-
|
|
126
|
-
.. seealso::
|
|
127
|
-
For more information on how to use this operator, take a look at the guide:
|
|
128
|
-
:ref:`howto/operator:GoogleDisplayVideo360DeleteReportOperator`
|
|
129
|
-
|
|
130
|
-
.. seealso::
|
|
131
|
-
Check also the official API docs:
|
|
132
|
-
`https://developers.google.com/bid-manager/v2/queries/delete`
|
|
133
|
-
|
|
134
|
-
:param report_id: Report ID to delete.
|
|
135
|
-
:param report_name: Name of the report to delete.
|
|
136
|
-
:param api_version: The version of the api that will be requested for example 'v3'.
|
|
137
|
-
:param gcp_conn_id: The connection ID to use when fetching connection info.
|
|
138
|
-
:param impersonation_chain: Optional service account to impersonate using short-term
|
|
139
|
-
credentials, or chained list of accounts required to get the access_token
|
|
140
|
-
of the last account in the list, which will be impersonated in the request.
|
|
141
|
-
If set as a string, the account must grant the originating account
|
|
142
|
-
the Service Account Token Creator IAM role.
|
|
143
|
-
If set as a sequence, the identities from the list must grant
|
|
144
|
-
Service Account Token Creator IAM role to the directly preceding identity, with first
|
|
145
|
-
account from the list granting this role to the originating account (templated).
|
|
146
|
-
"""
|
|
147
|
-
|
|
148
|
-
template_fields: Sequence[str] = (
|
|
149
|
-
"report_id",
|
|
150
|
-
"impersonation_chain",
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
def __init__(
|
|
154
|
-
self,
|
|
155
|
-
*,
|
|
156
|
-
report_id: str | None = None,
|
|
157
|
-
report_name: str | None = None,
|
|
158
|
-
api_version: str = "v2",
|
|
159
|
-
gcp_conn_id: str = "google_cloud_default",
|
|
160
|
-
impersonation_chain: str | Sequence[str] | None = None,
|
|
161
|
-
**kwargs,
|
|
162
|
-
) -> None:
|
|
163
|
-
super().__init__(**kwargs)
|
|
164
|
-
self.report_id = report_id
|
|
165
|
-
self.report_name = report_name
|
|
166
|
-
self.api_version = api_version
|
|
167
|
-
self.gcp_conn_id = gcp_conn_id
|
|
168
|
-
self.impersonation_chain = impersonation_chain
|
|
169
|
-
|
|
170
|
-
if report_name and report_id:
|
|
171
|
-
raise AirflowException("Use only one value - `report_name` or `report_id`.")
|
|
172
|
-
|
|
173
|
-
if not (report_name or report_id):
|
|
174
|
-
raise AirflowException("Provide one of the values: `report_name` or `report_id`.")
|
|
175
|
-
|
|
176
|
-
def execute(self, context: Context) -> None:
|
|
177
|
-
hook = GoogleDisplayVideo360Hook(
|
|
178
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
179
|
-
api_version=self.api_version,
|
|
180
|
-
impersonation_chain=self.impersonation_chain,
|
|
181
|
-
)
|
|
182
|
-
if self.report_id:
|
|
183
|
-
reports_ids_to_delete = [self.report_id]
|
|
184
|
-
else:
|
|
185
|
-
reports = hook.list_queries()
|
|
186
|
-
reports_ids_to_delete = [
|
|
187
|
-
report["queryId"] for report in reports if report["metadata"]["title"] == self.report_name
|
|
188
|
-
]
|
|
189
|
-
|
|
190
|
-
for report_id in reports_ids_to_delete:
|
|
191
|
-
self.log.info("Deleting report with id: %s", report_id)
|
|
192
|
-
hook.delete_query(query_id=report_id)
|
|
193
|
-
self.log.info("Report deleted.")
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
@deprecated(
|
|
197
|
-
planned_removal_date="September 01, 2025",
|
|
198
|
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator",
|
|
199
|
-
reason="Display & Video 360 API v2 has been deprecated and will be removed.",
|
|
200
|
-
category=AirflowProviderDeprecationWarning,
|
|
201
|
-
)
|
|
202
|
-
class GoogleDisplayVideo360DownloadReportV2Operator(BaseOperator):
|
|
203
|
-
"""
|
|
204
|
-
Retrieves a stored query.
|
|
205
|
-
|
|
206
|
-
.. seealso::
|
|
207
|
-
For more information on how to use this operator, take a look at the guide:
|
|
208
|
-
:ref:`howto/operator:GoogleDisplayVideo360DownloadReportV2Operator`
|
|
209
|
-
|
|
210
|
-
.. seealso::
|
|
211
|
-
Check also the official API docs:
|
|
212
|
-
`https://developers.google.com/bid-manager/v2/queries/get`
|
|
213
|
-
|
|
214
|
-
:param report_id: Report ID to retrieve.
|
|
215
|
-
:param bucket_name: The bucket to upload to.
|
|
216
|
-
:param report_name: The report name to set when uploading the local file.
|
|
217
|
-
:param chunk_size: File will be downloaded in chunks of this many bytes.
|
|
218
|
-
:param gzip: Option to compress local file or file data for upload
|
|
219
|
-
:param api_version: The version of the api that will be requested for example 'v3'.
|
|
220
|
-
:param gcp_conn_id: The connection ID to use when fetching connection info.
|
|
221
|
-
:param impersonation_chain: Optional service account to impersonate using short-term
|
|
222
|
-
credentials, or chained list of accounts required to get the access_token
|
|
223
|
-
of the last account in the list, which will be impersonated in the request.
|
|
224
|
-
If set as a string, the account must grant the originating account
|
|
225
|
-
the Service Account Token Creator IAM role.
|
|
226
|
-
If set as a sequence, the identities from the list must grant
|
|
227
|
-
Service Account Token Creator IAM role to the directly preceding identity, with first
|
|
228
|
-
account from the list granting this role to the originating account (templated).
|
|
229
|
-
"""
|
|
230
|
-
|
|
231
|
-
template_fields: Sequence[str] = (
|
|
232
|
-
"query_id",
|
|
233
|
-
"report_id",
|
|
234
|
-
"bucket_name",
|
|
235
|
-
"report_name",
|
|
236
|
-
"impersonation_chain",
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
def __init__(
|
|
240
|
-
self,
|
|
241
|
-
*,
|
|
242
|
-
query_id: str,
|
|
243
|
-
report_id: str,
|
|
244
|
-
bucket_name: str,
|
|
245
|
-
report_name: str | None = None,
|
|
246
|
-
gzip: bool = True,
|
|
247
|
-
chunk_size: int = 10 * 1024 * 1024,
|
|
248
|
-
api_version: str = "v2",
|
|
249
|
-
gcp_conn_id: str = "google_cloud_default",
|
|
250
|
-
impersonation_chain: str | Sequence[str] | None = None,
|
|
251
|
-
**kwargs,
|
|
252
|
-
) -> None:
|
|
253
|
-
super().__init__(**kwargs)
|
|
254
|
-
self.query_id = query_id
|
|
255
|
-
self.report_id = report_id
|
|
256
|
-
self.chunk_size = chunk_size
|
|
257
|
-
self.gzip = gzip
|
|
258
|
-
self.bucket_name = bucket_name
|
|
259
|
-
self.report_name = report_name
|
|
260
|
-
self.api_version = api_version
|
|
261
|
-
self.gcp_conn_id = gcp_conn_id
|
|
262
|
-
self.impersonation_chain = impersonation_chain
|
|
263
|
-
|
|
264
|
-
def _resolve_file_name(self, name: str) -> str:
|
|
265
|
-
new_name = name if name.endswith(".csv") else f"{name}.csv"
|
|
266
|
-
new_name = f"{new_name}.gz" if self.gzip else new_name
|
|
267
|
-
return new_name
|
|
268
|
-
|
|
269
|
-
@staticmethod
|
|
270
|
-
def _set_bucket_name(name: str) -> str:
|
|
271
|
-
bucket = name if not name.startswith("gs://") else name[5:]
|
|
272
|
-
return bucket.strip("/")
|
|
273
|
-
|
|
274
|
-
def execute(self, context: Context):
|
|
275
|
-
hook = GoogleDisplayVideo360Hook(
|
|
276
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
277
|
-
api_version=self.api_version,
|
|
278
|
-
impersonation_chain=self.impersonation_chain,
|
|
279
|
-
)
|
|
280
|
-
gcs_hook = GCSHook(
|
|
281
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
282
|
-
impersonation_chain=self.impersonation_chain,
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
resource = hook.get_report(query_id=self.query_id, report_id=self.report_id)
|
|
286
|
-
status = resource.get("metadata", {}).get("status", {}).get("state")
|
|
287
|
-
if resource and status not in ["DONE", "FAILED"]:
|
|
288
|
-
raise AirflowException(f"Report {self.report_id} for query {self.query_id} is still running")
|
|
289
|
-
|
|
290
|
-
# If no custom report_name provided, use DV360 name
|
|
291
|
-
file_url = resource["metadata"]["googleCloudStoragePath"]
|
|
292
|
-
if urllib.parse.urlparse(file_url).scheme == "file":
|
|
293
|
-
raise AirflowException("Accessing local file is not allowed in this operator")
|
|
294
|
-
report_name = self.report_name or urlsplit(file_url).path.split("/")[-1]
|
|
295
|
-
report_name = self._resolve_file_name(report_name)
|
|
296
|
-
|
|
297
|
-
# Download the report
|
|
298
|
-
self.log.info("Starting downloading report %s", self.report_id)
|
|
299
|
-
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
|
300
|
-
with urllib.request.urlopen(file_url) as response: # nosec
|
|
301
|
-
shutil.copyfileobj(response, temp_file, length=self.chunk_size)
|
|
302
|
-
|
|
303
|
-
temp_file.flush()
|
|
304
|
-
# Upload the local file to bucket
|
|
305
|
-
bucket_name = self._set_bucket_name(self.bucket_name)
|
|
306
|
-
gcs_hook.upload(
|
|
307
|
-
bucket_name=bucket_name,
|
|
308
|
-
object_name=report_name,
|
|
309
|
-
gzip=self.gzip,
|
|
310
|
-
filename=temp_file.name,
|
|
311
|
-
mime_type="text/csv",
|
|
312
|
-
)
|
|
313
|
-
self.log.info(
|
|
314
|
-
"Report %s was saved in bucket %s as %s.",
|
|
315
|
-
self.report_id,
|
|
316
|
-
self.bucket_name,
|
|
317
|
-
report_name,
|
|
318
|
-
)
|
|
319
|
-
context["task_instance"].xcom_push(key="report_name", value=report_name)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
@deprecated(
|
|
323
|
-
planned_removal_date="September 01, 2025",
|
|
324
|
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator",
|
|
325
|
-
reason="Display & Video 360 API v2 has been deprecated and will be removed.",
|
|
326
|
-
category=AirflowProviderDeprecationWarning,
|
|
327
|
-
)
|
|
328
|
-
class GoogleDisplayVideo360RunQueryOperator(BaseOperator):
|
|
329
|
-
"""
|
|
330
|
-
Runs a stored query to generate a report.
|
|
331
|
-
|
|
332
|
-
.. seealso::
|
|
333
|
-
For more information on how to use this operator, take a look at the guide:
|
|
334
|
-
:ref:`howto/operator:GoogleDisplayVideo360RunQueryOperator`
|
|
335
|
-
|
|
336
|
-
.. seealso::
|
|
337
|
-
Check also the official API docs:
|
|
338
|
-
`https://developers.google.com/bid-manager/v2/queries/run`
|
|
339
|
-
|
|
340
|
-
:param report_id: Report ID to run.
|
|
341
|
-
:param parameters: Parameters for running a report as described here:
|
|
342
|
-
https://developers.google.com/bid-manager/v2/queries/run
|
|
343
|
-
:param api_version: The version of the api that will be requested for example 'v3'.
|
|
344
|
-
:param gcp_conn_id: The connection ID to use when fetching connection info.
|
|
345
|
-
:param impersonation_chain: Optional service account to impersonate using short-term
|
|
346
|
-
credentials, or chained list of accounts required to get the access_token
|
|
347
|
-
of the last account in the list, which will be impersonated in the request.
|
|
348
|
-
If set as a string, the account must grant the originating account
|
|
349
|
-
the Service Account Token Creator IAM role.
|
|
350
|
-
If set as a sequence, the identities from the list must grant
|
|
351
|
-
Service Account Token Creator IAM role to the directly preceding identity, with first
|
|
352
|
-
account from the list granting this role to the originating account (templated).
|
|
353
|
-
"""
|
|
354
|
-
|
|
355
|
-
template_fields: Sequence[str] = (
|
|
356
|
-
"query_id",
|
|
357
|
-
"parameters",
|
|
358
|
-
"impersonation_chain",
|
|
359
|
-
)
|
|
360
|
-
|
|
361
|
-
def __init__(
|
|
362
|
-
self,
|
|
363
|
-
*,
|
|
364
|
-
query_id: str,
|
|
365
|
-
parameters: dict[str, Any] | None = None,
|
|
366
|
-
api_version: str = "v2",
|
|
367
|
-
gcp_conn_id: str = "google_cloud_default",
|
|
368
|
-
impersonation_chain: str | Sequence[str] | None = None,
|
|
369
|
-
**kwargs,
|
|
370
|
-
) -> None:
|
|
371
|
-
super().__init__(**kwargs)
|
|
372
|
-
self.query_id = query_id
|
|
373
|
-
self.api_version = api_version
|
|
374
|
-
self.gcp_conn_id = gcp_conn_id
|
|
375
|
-
self.parameters = parameters
|
|
376
|
-
self.impersonation_chain = impersonation_chain
|
|
377
|
-
|
|
378
|
-
def execute(self, context: Context) -> dict:
|
|
379
|
-
hook = GoogleDisplayVideo360Hook(
|
|
380
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
381
|
-
api_version=self.api_version,
|
|
382
|
-
impersonation_chain=self.impersonation_chain,
|
|
383
|
-
)
|
|
384
|
-
self.log.info(
|
|
385
|
-
"Running query %s with the following parameters:\n %s",
|
|
386
|
-
self.query_id,
|
|
387
|
-
self.parameters,
|
|
388
|
-
)
|
|
389
|
-
response = hook.run_query(query_id=self.query_id, params=self.parameters)
|
|
390
|
-
context["task_instance"].xcom_push(key="query_id", value=response["key"]["queryId"])
|
|
391
|
-
context["task_instance"].xcom_push(key="report_id", value=response["key"]["reportId"])
|
|
392
|
-
return response
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
@deprecated(
|
|
396
|
-
planned_removal_date="September 01, 2025",
|
|
397
|
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator",
|
|
398
|
-
reason="Display & Video 360 API v2 has been deprecated and will be removed.",
|
|
399
|
-
category=AirflowProviderDeprecationWarning,
|
|
400
|
-
)
|
|
401
|
-
class GoogleDisplayVideo360DownloadLineItemsOperator(BaseOperator):
|
|
402
|
-
"""
|
|
403
|
-
Retrieves line items in CSV format.
|
|
404
|
-
|
|
405
|
-
.. seealso::
|
|
406
|
-
For more information on how to use this operator, take a look at the guide:
|
|
407
|
-
:ref:`howto/operator:GoogleDisplayVideo360DownloadLineItemsOperator`
|
|
408
|
-
|
|
409
|
-
.. seealso::
|
|
410
|
-
Check also the official API docs:
|
|
411
|
-
`https://developers.google.com/bid-manager/v1.1/lineitems/downloadlineitems`
|
|
412
|
-
|
|
413
|
-
:param request_body: dictionary with parameters that should be passed into.
|
|
414
|
-
More information about it can be found here:
|
|
415
|
-
https://developers.google.com/bid-manager/v1.1/lineitems/downloadlineitems
|
|
416
|
-
"""
|
|
417
|
-
|
|
418
|
-
template_fields: Sequence[str] = (
|
|
419
|
-
"request_body",
|
|
420
|
-
"bucket_name",
|
|
421
|
-
"object_name",
|
|
422
|
-
"impersonation_chain",
|
|
423
|
-
)
|
|
424
|
-
|
|
425
|
-
def __init__(
|
|
426
|
-
self,
|
|
427
|
-
*,
|
|
428
|
-
request_body: dict[str, Any],
|
|
429
|
-
bucket_name: str,
|
|
430
|
-
object_name: str,
|
|
431
|
-
gzip: bool = False,
|
|
432
|
-
api_version: str = "v1.1",
|
|
433
|
-
gcp_conn_id: str = "google_cloud_default",
|
|
434
|
-
impersonation_chain: str | Sequence[str] | None = None,
|
|
435
|
-
**kwargs,
|
|
436
|
-
) -> None:
|
|
437
|
-
super().__init__(**kwargs)
|
|
438
|
-
self.request_body = request_body
|
|
439
|
-
self.object_name = object_name
|
|
440
|
-
self.bucket_name = bucket_name
|
|
441
|
-
self.gzip = gzip
|
|
442
|
-
self.api_version = api_version
|
|
443
|
-
self.gcp_conn_id = gcp_conn_id
|
|
444
|
-
self.impersonation_chain = impersonation_chain
|
|
445
|
-
|
|
446
|
-
def execute(self, context: Context) -> str:
|
|
447
|
-
gcs_hook = GCSHook(
|
|
448
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
449
|
-
impersonation_chain=self.impersonation_chain,
|
|
450
|
-
)
|
|
451
|
-
hook = GoogleDisplayVideo360Hook(
|
|
452
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
453
|
-
api_version=self.api_version,
|
|
454
|
-
impersonation_chain=self.impersonation_chain,
|
|
455
|
-
)
|
|
456
|
-
|
|
457
|
-
self.log.info("Retrieving report...")
|
|
458
|
-
content: list[str] = hook.download_line_items(request_body=self.request_body)
|
|
459
|
-
|
|
460
|
-
with tempfile.NamedTemporaryFile("w+") as temp_file:
|
|
461
|
-
writer = csv.writer(temp_file)
|
|
462
|
-
writer.writerows(content)
|
|
463
|
-
temp_file.flush()
|
|
464
|
-
gcs_hook.upload(
|
|
465
|
-
bucket_name=self.bucket_name,
|
|
466
|
-
object_name=self.object_name,
|
|
467
|
-
filename=temp_file.name,
|
|
468
|
-
mime_type="text/csv",
|
|
469
|
-
gzip=self.gzip,
|
|
470
|
-
)
|
|
471
|
-
return f"{self.bucket_name}/{self.object_name}"
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
@deprecated(
|
|
475
|
-
planned_removal_date="September 01, 2025",
|
|
476
|
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator",
|
|
477
|
-
reason="Display & Video 360 API v2 has been deprecated and will be removed.",
|
|
478
|
-
category=AirflowProviderDeprecationWarning,
|
|
479
|
-
)
|
|
480
|
-
class GoogleDisplayVideo360UploadLineItemsOperator(BaseOperator):
|
|
481
|
-
"""
|
|
482
|
-
Uploads line items in CSV format.
|
|
483
|
-
|
|
484
|
-
.. seealso::
|
|
485
|
-
For more information on how to use this operator, take a look at the guide:
|
|
486
|
-
:ref:`howto/operator:GoogleDisplayVideo360UploadLineItemsOperator`
|
|
487
|
-
|
|
488
|
-
.. seealso::
|
|
489
|
-
Check also the official API docs:
|
|
490
|
-
`https://developers.google.com/bid-manager/v1.1/lineitems/uploadlineitems`
|
|
491
|
-
|
|
492
|
-
:param request_body: request to upload line items.
|
|
493
|
-
:param bucket_name: The bucket form data is downloaded.
|
|
494
|
-
:param object_name: The object to fetch.
|
|
495
|
-
:param filename: The filename to fetch.
|
|
496
|
-
:param dry_run: Upload status without actually persisting the line items.
|
|
497
|
-
"""
|
|
498
|
-
|
|
499
|
-
template_fields: Sequence[str] = (
|
|
500
|
-
"bucket_name",
|
|
501
|
-
"object_name",
|
|
502
|
-
"impersonation_chain",
|
|
503
|
-
)
|
|
504
|
-
|
|
505
|
-
def __init__(
|
|
506
|
-
self,
|
|
507
|
-
*,
|
|
508
|
-
bucket_name: str,
|
|
509
|
-
object_name: str,
|
|
510
|
-
api_version: str = "v1.1",
|
|
511
|
-
gcp_conn_id: str = "google_cloud_default",
|
|
512
|
-
impersonation_chain: str | Sequence[str] | None = None,
|
|
513
|
-
**kwargs,
|
|
514
|
-
) -> None:
|
|
515
|
-
super().__init__(**kwargs)
|
|
516
|
-
self.bucket_name = bucket_name
|
|
517
|
-
self.object_name = object_name
|
|
518
|
-
self.api_version = api_version
|
|
519
|
-
self.gcp_conn_id = gcp_conn_id
|
|
520
|
-
self.impersonation_chain = impersonation_chain
|
|
521
|
-
|
|
522
|
-
def execute(self, context: Context) -> None:
|
|
523
|
-
gcs_hook = GCSHook(
|
|
524
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
525
|
-
impersonation_chain=self.impersonation_chain,
|
|
526
|
-
)
|
|
527
|
-
hook = GoogleDisplayVideo360Hook(
|
|
528
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
529
|
-
api_version=self.api_version,
|
|
530
|
-
impersonation_chain=self.impersonation_chain,
|
|
531
|
-
)
|
|
532
|
-
|
|
533
|
-
self.log.info("Uploading file %s...")
|
|
534
|
-
# Saving file in the temporary directory,
|
|
535
|
-
# downloaded file from the GCS could be a 1GB size or even more
|
|
536
|
-
with tempfile.NamedTemporaryFile("w+") as f:
|
|
537
|
-
line_items = gcs_hook.download(
|
|
538
|
-
bucket_name=self.bucket_name,
|
|
539
|
-
object_name=self.object_name,
|
|
540
|
-
filename=f.name,
|
|
541
|
-
)
|
|
542
|
-
f.flush()
|
|
543
|
-
hook.upload_line_items(line_items=line_items)
|
|
544
|
-
|
|
545
|
-
|
|
546
36
|
class GoogleDisplayVideo360CreateSDFDownloadTaskOperator(BaseOperator):
|
|
547
37
|
"""
|
|
548
38
|
Creates an SDF operation task.
|
|
@@ -21,8 +21,7 @@ from __future__ import annotations
|
|
|
21
21
|
from collections.abc import Sequence
|
|
22
22
|
from typing import TYPE_CHECKING
|
|
23
23
|
|
|
24
|
-
from airflow.exceptions import AirflowException
|
|
25
|
-
from airflow.providers.google.common.deprecated import deprecated
|
|
24
|
+
from airflow.exceptions import AirflowException
|
|
26
25
|
from airflow.providers.google.marketing_platform.hooks.display_video import GoogleDisplayVideo360Hook
|
|
27
26
|
from airflow.providers.google.version_compat import AIRFLOW_V_3_0_PLUS
|
|
28
27
|
|
|
@@ -94,69 +93,3 @@ class GoogleDisplayVideo360GetSDFDownloadOperationSensor(BaseSensorOperator):
|
|
|
94
93
|
if operation and operation.get("done"):
|
|
95
94
|
return True
|
|
96
95
|
return False
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@deprecated(
|
|
100
|
-
planned_removal_date="September 01, 2025",
|
|
101
|
-
reason="Display & Video 360 API v2 has been deprecated and will be removed. "
|
|
102
|
-
"Reports were replaced with SDF export task in v4 of API.",
|
|
103
|
-
category=AirflowProviderDeprecationWarning,
|
|
104
|
-
)
|
|
105
|
-
class GoogleDisplayVideo360RunQuerySensor(BaseSensorOperator):
|
|
106
|
-
"""
|
|
107
|
-
Sensor for detecting the completion of DV360 reports for API v2.
|
|
108
|
-
|
|
109
|
-
.. seealso::
|
|
110
|
-
For more information on how to use this operator, take a look at the guide:
|
|
111
|
-
:ref:`howto/operator:GoogleDisplayVideo360RunQuerySensor`
|
|
112
|
-
|
|
113
|
-
:param query_id: Query ID for which report was generated
|
|
114
|
-
:param report_id: Report ID for which you want to wait
|
|
115
|
-
:param api_version: The version of the api that will be requested for example 'v3'.
|
|
116
|
-
:param gcp_conn_id: The connection ID to use when fetching connection info.
|
|
117
|
-
:param impersonation_chain: Optional service account to impersonate using short-term
|
|
118
|
-
credentials, or chained list of accounts required to get the access_token
|
|
119
|
-
of the last account in the list, which will be impersonated in the request.
|
|
120
|
-
If set as a string, the account must grant the originating account
|
|
121
|
-
the Service Account Token Creator IAM role.
|
|
122
|
-
If set as a sequence, the identities from the list must grant
|
|
123
|
-
Service Account Token Creator IAM role to the directly preceding identity, with first
|
|
124
|
-
account from the list granting this role to the originating account (templated).
|
|
125
|
-
"""
|
|
126
|
-
|
|
127
|
-
template_fields: Sequence[str] = (
|
|
128
|
-
"query_id",
|
|
129
|
-
"report_id",
|
|
130
|
-
"impersonation_chain",
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
def __init__(
|
|
134
|
-
self,
|
|
135
|
-
*,
|
|
136
|
-
query_id: str,
|
|
137
|
-
report_id: str,
|
|
138
|
-
api_version: str = "v2",
|
|
139
|
-
gcp_conn_id: str = "google_cloud_default",
|
|
140
|
-
impersonation_chain: str | Sequence[str] | None = None,
|
|
141
|
-
**kwargs,
|
|
142
|
-
) -> None:
|
|
143
|
-
super().__init__(**kwargs)
|
|
144
|
-
self.query_id = query_id
|
|
145
|
-
self.report_id = report_id
|
|
146
|
-
self.api_version = api_version
|
|
147
|
-
self.gcp_conn_id = gcp_conn_id
|
|
148
|
-
self.impersonation_chain = impersonation_chain
|
|
149
|
-
|
|
150
|
-
def poke(self, context: Context) -> bool:
|
|
151
|
-
hook = GoogleDisplayVideo360Hook(
|
|
152
|
-
gcp_conn_id=self.gcp_conn_id,
|
|
153
|
-
api_version=self.api_version,
|
|
154
|
-
impersonation_chain=self.impersonation_chain,
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
response = hook.get_report(query_id=self.query_id, report_id=self.report_id)
|
|
158
|
-
status = response.get("metadata", {}).get("status", {}).get("state")
|
|
159
|
-
self.log.info("STATUS OF THE REPORT %s FOR QUERY %s: %s", self.report_id, self.query_id, status)
|
|
160
|
-
if response and status in ["DONE", "FAILED"]:
|
|
161
|
-
return True
|
|
162
|
-
return False
|