apache-airflow-providers-google 10.16.0rc1__py3-none-any.whl → 10.17.0rc1__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.
Files changed (196) hide show
  1. airflow/providers/google/__init__.py +1 -1
  2. airflow/providers/google/ads/hooks/ads.py +5 -4
  3. airflow/providers/google/ads/operators/ads.py +1 -0
  4. airflow/providers/google/cloud/example_dags/example_cloud_sql_query.py +1 -0
  5. airflow/providers/google/cloud/example_dags/example_cloud_task.py +1 -0
  6. airflow/providers/google/cloud/example_dags/example_facebook_ads_to_gcs.py +1 -0
  7. airflow/providers/google/cloud/example_dags/example_looker.py +1 -0
  8. airflow/providers/google/cloud/example_dags/example_presto_to_gcs.py +1 -0
  9. airflow/providers/google/cloud/example_dags/example_salesforce_to_gcs.py +1 -0
  10. airflow/providers/google/cloud/fs/gcs.py +1 -2
  11. airflow/providers/google/cloud/hooks/automl.py +1 -0
  12. airflow/providers/google/cloud/hooks/bigquery.py +87 -24
  13. airflow/providers/google/cloud/hooks/bigquery_dts.py +1 -0
  14. airflow/providers/google/cloud/hooks/bigtable.py +1 -0
  15. airflow/providers/google/cloud/hooks/cloud_build.py +1 -0
  16. airflow/providers/google/cloud/hooks/cloud_memorystore.py +1 -0
  17. airflow/providers/google/cloud/hooks/cloud_sql.py +1 -0
  18. airflow/providers/google/cloud/hooks/cloud_storage_transfer_service.py +9 -4
  19. airflow/providers/google/cloud/hooks/compute.py +1 -0
  20. airflow/providers/google/cloud/hooks/compute_ssh.py +2 -2
  21. airflow/providers/google/cloud/hooks/dataflow.py +6 -5
  22. airflow/providers/google/cloud/hooks/datafusion.py +1 -0
  23. airflow/providers/google/cloud/hooks/datapipeline.py +1 -0
  24. airflow/providers/google/cloud/hooks/dataplex.py +1 -0
  25. airflow/providers/google/cloud/hooks/dataprep.py +1 -0
  26. airflow/providers/google/cloud/hooks/dataproc.py +3 -2
  27. airflow/providers/google/cloud/hooks/dataproc_metastore.py +1 -0
  28. airflow/providers/google/cloud/hooks/datastore.py +1 -0
  29. airflow/providers/google/cloud/hooks/dlp.py +1 -0
  30. airflow/providers/google/cloud/hooks/functions.py +1 -0
  31. airflow/providers/google/cloud/hooks/gcs.py +12 -5
  32. airflow/providers/google/cloud/hooks/kms.py +1 -0
  33. airflow/providers/google/cloud/hooks/kubernetes_engine.py +178 -300
  34. airflow/providers/google/cloud/hooks/life_sciences.py +1 -0
  35. airflow/providers/google/cloud/hooks/looker.py +1 -0
  36. airflow/providers/google/cloud/hooks/mlengine.py +1 -0
  37. airflow/providers/google/cloud/hooks/natural_language.py +1 -0
  38. airflow/providers/google/cloud/hooks/os_login.py +1 -0
  39. airflow/providers/google/cloud/hooks/pubsub.py +1 -0
  40. airflow/providers/google/cloud/hooks/secret_manager.py +1 -0
  41. airflow/providers/google/cloud/hooks/spanner.py +1 -0
  42. airflow/providers/google/cloud/hooks/speech_to_text.py +1 -0
  43. airflow/providers/google/cloud/hooks/stackdriver.py +1 -0
  44. airflow/providers/google/cloud/hooks/text_to_speech.py +1 -0
  45. airflow/providers/google/cloud/hooks/translate.py +1 -0
  46. airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py +1 -0
  47. airflow/providers/google/cloud/hooks/vertex_ai/batch_prediction_job.py +255 -3
  48. airflow/providers/google/cloud/hooks/vertex_ai/custom_job.py +1 -0
  49. airflow/providers/google/cloud/hooks/vertex_ai/dataset.py +1 -0
  50. airflow/providers/google/cloud/hooks/vertex_ai/endpoint_service.py +1 -0
  51. airflow/providers/google/cloud/hooks/vertex_ai/generative_model.py +197 -0
  52. airflow/providers/google/cloud/hooks/vertex_ai/hyperparameter_tuning_job.py +9 -9
  53. airflow/providers/google/cloud/hooks/vertex_ai/pipeline_job.py +231 -12
  54. airflow/providers/google/cloud/hooks/video_intelligence.py +1 -0
  55. airflow/providers/google/cloud/hooks/vision.py +1 -0
  56. airflow/providers/google/cloud/links/automl.py +1 -0
  57. airflow/providers/google/cloud/links/bigquery.py +1 -0
  58. airflow/providers/google/cloud/links/bigquery_dts.py +1 -0
  59. airflow/providers/google/cloud/links/cloud_memorystore.py +1 -0
  60. airflow/providers/google/cloud/links/cloud_sql.py +1 -0
  61. airflow/providers/google/cloud/links/cloud_tasks.py +1 -0
  62. airflow/providers/google/cloud/links/compute.py +1 -0
  63. airflow/providers/google/cloud/links/datacatalog.py +1 -0
  64. airflow/providers/google/cloud/links/dataflow.py +1 -0
  65. airflow/providers/google/cloud/links/dataform.py +1 -0
  66. airflow/providers/google/cloud/links/datafusion.py +1 -0
  67. airflow/providers/google/cloud/links/dataplex.py +1 -0
  68. airflow/providers/google/cloud/links/dataproc.py +1 -0
  69. airflow/providers/google/cloud/links/kubernetes_engine.py +28 -0
  70. airflow/providers/google/cloud/links/mlengine.py +1 -0
  71. airflow/providers/google/cloud/links/pubsub.py +1 -0
  72. airflow/providers/google/cloud/links/spanner.py +1 -0
  73. airflow/providers/google/cloud/links/stackdriver.py +1 -0
  74. airflow/providers/google/cloud/links/workflows.py +1 -0
  75. airflow/providers/google/cloud/log/stackdriver_task_handler.py +18 -4
  76. airflow/providers/google/cloud/operators/automl.py +1 -0
  77. airflow/providers/google/cloud/operators/bigquery.py +21 -0
  78. airflow/providers/google/cloud/operators/bigquery_dts.py +1 -0
  79. airflow/providers/google/cloud/operators/bigtable.py +1 -0
  80. airflow/providers/google/cloud/operators/cloud_base.py +1 -0
  81. airflow/providers/google/cloud/operators/cloud_build.py +1 -0
  82. airflow/providers/google/cloud/operators/cloud_memorystore.py +1 -0
  83. airflow/providers/google/cloud/operators/cloud_sql.py +1 -0
  84. airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py +11 -5
  85. airflow/providers/google/cloud/operators/compute.py +1 -0
  86. airflow/providers/google/cloud/operators/dataflow.py +1 -0
  87. airflow/providers/google/cloud/operators/datafusion.py +1 -0
  88. airflow/providers/google/cloud/operators/datapipeline.py +1 -0
  89. airflow/providers/google/cloud/operators/dataprep.py +1 -0
  90. airflow/providers/google/cloud/operators/dataproc.py +3 -2
  91. airflow/providers/google/cloud/operators/dataproc_metastore.py +1 -0
  92. airflow/providers/google/cloud/operators/datastore.py +1 -0
  93. airflow/providers/google/cloud/operators/functions.py +1 -0
  94. airflow/providers/google/cloud/operators/gcs.py +1 -0
  95. airflow/providers/google/cloud/operators/kubernetes_engine.py +600 -4
  96. airflow/providers/google/cloud/operators/life_sciences.py +1 -0
  97. airflow/providers/google/cloud/operators/looker.py +1 -0
  98. airflow/providers/google/cloud/operators/mlengine.py +283 -259
  99. airflow/providers/google/cloud/operators/natural_language.py +1 -0
  100. airflow/providers/google/cloud/operators/pubsub.py +1 -0
  101. airflow/providers/google/cloud/operators/spanner.py +1 -0
  102. airflow/providers/google/cloud/operators/speech_to_text.py +1 -0
  103. airflow/providers/google/cloud/operators/text_to_speech.py +1 -0
  104. airflow/providers/google/cloud/operators/translate.py +1 -0
  105. airflow/providers/google/cloud/operators/translate_speech.py +1 -0
  106. airflow/providers/google/cloud/operators/vertex_ai/auto_ml.py +14 -7
  107. airflow/providers/google/cloud/operators/vertex_ai/batch_prediction_job.py +67 -13
  108. airflow/providers/google/cloud/operators/vertex_ai/custom_job.py +26 -8
  109. airflow/providers/google/cloud/operators/vertex_ai/dataset.py +1 -0
  110. airflow/providers/google/cloud/operators/vertex_ai/generative_model.py +306 -0
  111. airflow/providers/google/cloud/operators/vertex_ai/hyperparameter_tuning_job.py +29 -48
  112. airflow/providers/google/cloud/operators/vertex_ai/pipeline_job.py +52 -17
  113. airflow/providers/google/cloud/operators/video_intelligence.py +1 -0
  114. airflow/providers/google/cloud/operators/vision.py +1 -0
  115. airflow/providers/google/cloud/secrets/secret_manager.py +1 -0
  116. airflow/providers/google/cloud/sensors/bigquery.py +1 -0
  117. airflow/providers/google/cloud/sensors/bigquery_dts.py +1 -0
  118. airflow/providers/google/cloud/sensors/bigtable.py +1 -0
  119. airflow/providers/google/cloud/sensors/cloud_storage_transfer_service.py +1 -0
  120. airflow/providers/google/cloud/sensors/dataflow.py +1 -0
  121. airflow/providers/google/cloud/sensors/dataform.py +1 -0
  122. airflow/providers/google/cloud/sensors/datafusion.py +1 -0
  123. airflow/providers/google/cloud/sensors/dataplex.py +1 -0
  124. airflow/providers/google/cloud/sensors/dataprep.py +1 -0
  125. airflow/providers/google/cloud/sensors/dataproc.py +1 -0
  126. airflow/providers/google/cloud/sensors/gcs.py +1 -0
  127. airflow/providers/google/cloud/sensors/looker.py +1 -0
  128. airflow/providers/google/cloud/sensors/pubsub.py +1 -0
  129. airflow/providers/google/cloud/sensors/tasks.py +1 -0
  130. airflow/providers/google/cloud/transfers/bigquery_to_bigquery.py +1 -0
  131. airflow/providers/google/cloud/transfers/bigquery_to_gcs.py +1 -0
  132. airflow/providers/google/cloud/transfers/bigquery_to_mssql.py +1 -0
  133. airflow/providers/google/cloud/transfers/bigquery_to_mysql.py +1 -0
  134. airflow/providers/google/cloud/transfers/bigquery_to_postgres.py +1 -0
  135. airflow/providers/google/cloud/transfers/bigquery_to_sql.py +1 -0
  136. airflow/providers/google/cloud/transfers/facebook_ads_to_gcs.py +1 -0
  137. airflow/providers/google/cloud/transfers/gcs_to_bigquery.py +3 -2
  138. airflow/providers/google/cloud/transfers/gcs_to_gcs.py +1 -0
  139. airflow/providers/google/cloud/transfers/gcs_to_sftp.py +1 -0
  140. airflow/providers/google/cloud/transfers/local_to_gcs.py +1 -0
  141. airflow/providers/google/cloud/transfers/mssql_to_gcs.py +1 -0
  142. airflow/providers/google/cloud/transfers/mysql_to_gcs.py +1 -0
  143. airflow/providers/google/cloud/transfers/postgres_to_gcs.py +19 -1
  144. airflow/providers/google/cloud/transfers/s3_to_gcs.py +3 -5
  145. airflow/providers/google/cloud/transfers/sftp_to_gcs.py +1 -0
  146. airflow/providers/google/cloud/transfers/sql_to_gcs.py +4 -2
  147. airflow/providers/google/cloud/triggers/bigquery.py +4 -3
  148. airflow/providers/google/cloud/triggers/cloud_batch.py +1 -1
  149. airflow/providers/google/cloud/triggers/cloud_run.py +1 -0
  150. airflow/providers/google/cloud/triggers/cloud_sql.py +2 -0
  151. airflow/providers/google/cloud/triggers/cloud_storage_transfer_service.py +14 -2
  152. airflow/providers/google/cloud/triggers/dataplex.py +1 -0
  153. airflow/providers/google/cloud/triggers/dataproc.py +1 -0
  154. airflow/providers/google/cloud/triggers/kubernetes_engine.py +72 -2
  155. airflow/providers/google/cloud/triggers/mlengine.py +2 -0
  156. airflow/providers/google/cloud/triggers/pubsub.py +3 -3
  157. airflow/providers/google/cloud/triggers/vertex_ai.py +107 -15
  158. airflow/providers/google/cloud/utils/field_sanitizer.py +2 -1
  159. airflow/providers/google/cloud/utils/field_validator.py +1 -0
  160. airflow/providers/google/cloud/utils/helpers.py +1 -0
  161. airflow/providers/google/cloud/utils/mlengine_operator_utils.py +1 -0
  162. airflow/providers/google/cloud/utils/mlengine_prediction_summary.py +1 -0
  163. airflow/providers/google/cloud/utils/openlineage.py +1 -0
  164. airflow/providers/google/common/auth_backend/google_openid.py +1 -0
  165. airflow/providers/google/common/hooks/base_google.py +2 -1
  166. airflow/providers/google/common/hooks/discovery_api.py +1 -0
  167. airflow/providers/google/common/links/storage.py +1 -0
  168. airflow/providers/google/common/utils/id_token_credentials.py +1 -0
  169. airflow/providers/google/firebase/hooks/firestore.py +1 -0
  170. airflow/providers/google/get_provider_info.py +9 -3
  171. airflow/providers/google/go_module_utils.py +1 -0
  172. airflow/providers/google/leveldb/hooks/leveldb.py +8 -7
  173. airflow/providers/google/marketing_platform/example_dags/example_display_video.py +1 -0
  174. airflow/providers/google/marketing_platform/hooks/analytics_admin.py +1 -0
  175. airflow/providers/google/marketing_platform/hooks/campaign_manager.py +1 -0
  176. airflow/providers/google/marketing_platform/hooks/display_video.py +1 -0
  177. airflow/providers/google/marketing_platform/hooks/search_ads.py +1 -0
  178. airflow/providers/google/marketing_platform/operators/analytics.py +1 -0
  179. airflow/providers/google/marketing_platform/operators/analytics_admin.py +4 -2
  180. airflow/providers/google/marketing_platform/operators/campaign_manager.py +1 -0
  181. airflow/providers/google/marketing_platform/operators/display_video.py +1 -0
  182. airflow/providers/google/marketing_platform/operators/search_ads.py +1 -0
  183. airflow/providers/google/marketing_platform/sensors/campaign_manager.py +1 -0
  184. airflow/providers/google/marketing_platform/sensors/display_video.py +2 -1
  185. airflow/providers/google/marketing_platform/sensors/search_ads.py +1 -0
  186. airflow/providers/google/suite/hooks/calendar.py +1 -0
  187. airflow/providers/google/suite/hooks/drive.py +1 -0
  188. airflow/providers/google/suite/hooks/sheets.py +1 -0
  189. airflow/providers/google/suite/sensors/drive.py +1 -0
  190. airflow/providers/google/suite/transfers/gcs_to_gdrive.py +7 -0
  191. airflow/providers/google/suite/transfers/gcs_to_sheets.py +4 -1
  192. airflow/providers/google/suite/transfers/local_to_drive.py +1 -0
  193. {apache_airflow_providers_google-10.16.0rc1.dist-info → apache_airflow_providers_google-10.17.0rc1.dist-info}/METADATA +22 -17
  194. {apache_airflow_providers_google-10.16.0rc1.dist-info → apache_airflow_providers_google-10.17.0rc1.dist-info}/RECORD +196 -194
  195. {apache_airflow_providers_google-10.16.0rc1.dist-info → apache_airflow_providers_google-10.17.0rc1.dist-info}/WHEEL +0 -0
  196. {apache_airflow_providers_google-10.16.0rc1.dist-info → apache_airflow_providers_google-10.17.0rc1.dist-info}/entry_points.txt +0 -0
@@ -16,6 +16,7 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains Google Cloud Language operators."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from typing import TYPE_CHECKING, Sequence, Tuple
@@ -22,6 +22,7 @@ This module contains Google PubSub operators.
22
22
 
23
23
  MessageStoragePolicy
24
24
  """
25
+
25
26
  from __future__ import annotations
26
27
 
27
28
  from typing import TYPE_CHECKING, Any, Callable, Sequence
@@ -16,6 +16,7 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains Google Spanner operators."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from typing import TYPE_CHECKING, Sequence
@@ -16,6 +16,7 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains a Google Speech to Text operator."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from typing import TYPE_CHECKING, Sequence
@@ -16,6 +16,7 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains a Google Text to Speech operator."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from tempfile import NamedTemporaryFile
@@ -16,6 +16,7 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains Google Translate operators."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from typing import TYPE_CHECKING, Sequence
@@ -16,6 +16,7 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains a Google Cloud Translate Speech operator."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from typing import TYPE_CHECKING, Sequence
@@ -22,12 +22,14 @@ from __future__ import annotations
22
22
 
23
23
  from typing import TYPE_CHECKING, Sequence
24
24
 
25
+ from deprecated import deprecated
25
26
  from google.api_core.exceptions import NotFound
26
27
  from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
27
28
  from google.cloud.aiplatform import datasets
28
29
  from google.cloud.aiplatform.models import Model
29
30
  from google.cloud.aiplatform_v1.types.training_pipeline import TrainingPipeline
30
31
 
32
+ from airflow.exceptions import AirflowProviderDeprecationWarning
31
33
  from airflow.providers.google.cloud.hooks.vertex_ai.auto_ml import AutoMLHook
32
34
  from airflow.providers.google.cloud.links.vertex_ai import (
33
35
  VertexAIModelLink,
@@ -174,7 +176,6 @@ class CreateAutoMLForecastingTrainingJobOperator(AutoMLTrainingJobBaseOperator):
174
176
  gcp_conn_id=self.gcp_conn_id,
175
177
  impersonation_chain=self.impersonation_chain,
176
178
  )
177
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
178
179
  model, training_id = self.hook.create_auto_ml_forecasting_training_job(
179
180
  project_id=self.project_id,
180
181
  region=self.region,
@@ -282,7 +283,6 @@ class CreateAutoMLImageTrainingJobOperator(AutoMLTrainingJobBaseOperator):
282
283
  gcp_conn_id=self.gcp_conn_id,
283
284
  impersonation_chain=self.impersonation_chain,
284
285
  )
285
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
286
286
  model, training_id = self.hook.create_auto_ml_image_training_job(
287
287
  project_id=self.project_id,
288
288
  region=self.region,
@@ -391,7 +391,6 @@ class CreateAutoMLTabularTrainingJobOperator(AutoMLTrainingJobBaseOperator):
391
391
  impersonation_chain=self.impersonation_chain,
392
392
  )
393
393
  credentials, _ = self.hook.get_credentials_and_project_id()
394
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
395
394
  model, training_id = self.hook.create_auto_ml_tabular_training_job(
396
395
  project_id=self.project_id,
397
396
  region=self.region,
@@ -486,7 +485,6 @@ class CreateAutoMLTextTrainingJobOperator(AutoMLTrainingJobBaseOperator):
486
485
  gcp_conn_id=self.gcp_conn_id,
487
486
  impersonation_chain=self.impersonation_chain,
488
487
  )
489
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
490
488
  model, training_id = self.hook.create_auto_ml_text_training_job(
491
489
  project_id=self.project_id,
492
490
  region=self.region,
@@ -563,7 +561,6 @@ class CreateAutoMLVideoTrainingJobOperator(AutoMLTrainingJobBaseOperator):
563
561
  gcp_conn_id=self.gcp_conn_id,
564
562
  impersonation_chain=self.impersonation_chain,
565
563
  )
566
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
567
564
  model, training_id = self.hook.create_auto_ml_video_training_job(
568
565
  project_id=self.project_id,
569
566
  region=self.region,
@@ -607,7 +604,7 @@ class DeleteAutoMLTrainingJobOperator(GoogleCloudBaseOperator):
607
604
  AutoMLTabularTrainingJob, AutoMLTextTrainingJob, or AutoMLVideoTrainingJob.
608
605
  """
609
606
 
610
- template_fields = ("training_pipeline", "region", "project_id", "impersonation_chain")
607
+ template_fields = ("training_pipeline_id", "region", "project_id", "impersonation_chain")
611
608
 
612
609
  def __init__(
613
610
  self,
@@ -623,7 +620,7 @@ class DeleteAutoMLTrainingJobOperator(GoogleCloudBaseOperator):
623
620
  **kwargs,
624
621
  ) -> None:
625
622
  super().__init__(**kwargs)
626
- self.training_pipeline = training_pipeline_id
623
+ self.training_pipeline_id = training_pipeline_id
627
624
  self.region = region
628
625
  self.project_id = project_id
629
626
  self.retry = retry
@@ -632,6 +629,16 @@ class DeleteAutoMLTrainingJobOperator(GoogleCloudBaseOperator):
632
629
  self.gcp_conn_id = gcp_conn_id
633
630
  self.impersonation_chain = impersonation_chain
634
631
 
632
+ @property
633
+ @deprecated(
634
+ reason="`training_pipeline` is deprecated and will be removed in the future. "
635
+ "Please use `training_pipeline_id` instead.",
636
+ category=AirflowProviderDeprecationWarning,
637
+ )
638
+ def training_pipeline(self):
639
+ """Alias for ``training_pipeline_id``, used for compatibility (deprecated)."""
640
+ return self.training_pipeline_id
641
+
635
642
  def execute(self, context: Context):
636
643
  hook = AutoMLHook(
637
644
  gcp_conn_id=self.gcp_conn_id,
@@ -20,22 +20,27 @@
20
20
 
21
21
  from __future__ import annotations
22
22
 
23
- from typing import TYPE_CHECKING, Sequence
23
+ import warnings
24
+ from functools import cached_property
25
+ from typing import TYPE_CHECKING, Any, Sequence
24
26
 
25
27
  from google.api_core.exceptions import NotFound
26
28
  from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
27
29
  from google.cloud.aiplatform_v1.types import BatchPredictionJob
28
30
 
31
+ from airflow.configuration import conf
32
+ from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
29
33
  from airflow.providers.google.cloud.hooks.vertex_ai.batch_prediction_job import BatchPredictionJobHook
30
34
  from airflow.providers.google.cloud.links.vertex_ai import (
31
35
  VertexAIBatchPredictionJobLink,
32
36
  VertexAIBatchPredictionJobListLink,
33
37
  )
34
38
  from airflow.providers.google.cloud.operators.cloud_base import GoogleCloudBaseOperator
39
+ from airflow.providers.google.cloud.triggers.vertex_ai import CreateBatchPredictionJobTrigger
35
40
 
36
41
  if TYPE_CHECKING:
37
42
  from google.api_core.retry import Retry
38
- from google.cloud.aiplatform import Model, explain
43
+ from google.cloud.aiplatform import BatchPredictionJob as BatchPredictionJobObject, Model, explain
39
44
 
40
45
  from airflow.utils.context import Context
41
46
 
@@ -131,7 +136,7 @@ class CreateBatchPredictionJobOperator(GoogleCloudBaseOperator):
131
136
  If this is set, then all resources created by the BatchPredictionJob will be encrypted with the
132
137
  provided encryption key.
133
138
  Overrides encryption_spec_key_name set in aiplatform.init.
134
- :param sync: Whether to execute this method synchronously. If False, this method will be executed in
139
+ :param sync: (Deprecated) Whether to execute this method synchronously. If False, this method will be executed in
135
140
  concurrent Future and any downstream object will be immediately returned and synced when the
136
141
  Future has completed.
137
142
  :param create_request_timeout: Optional. The timeout for the create request in seconds.
@@ -154,6 +159,8 @@ class CreateBatchPredictionJobOperator(GoogleCloudBaseOperator):
154
159
  If set as a sequence, the identities from the list must grant
155
160
  Service Account Token Creator IAM role to the directly preceding identity, with first
156
161
  account from the list granting this role to the originating account (templated).
162
+ :param deferrable: Optional. Run operator in the deferrable mode.
163
+ :param poll_interval: Interval size which defines how often job status is checked in deferrable mode.
157
164
  """
158
165
 
159
166
  template_fields = ("region", "project_id", "model_name", "impersonation_chain")
@@ -188,6 +195,8 @@ class CreateBatchPredictionJobOperator(GoogleCloudBaseOperator):
188
195
  batch_size: int | None = None,
189
196
  gcp_conn_id: str = "google_cloud_default",
190
197
  impersonation_chain: str | Sequence[str] | None = None,
198
+ deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
199
+ poll_interval: int = 10,
191
200
  **kwargs,
192
201
  ) -> None:
193
202
  super().__init__(**kwargs)
@@ -217,15 +226,24 @@ class CreateBatchPredictionJobOperator(GoogleCloudBaseOperator):
217
226
  self.batch_size = batch_size
218
227
  self.gcp_conn_id = gcp_conn_id
219
228
  self.impersonation_chain = impersonation_chain
220
- self.hook: BatchPredictionJobHook | None = None
229
+ self.deferrable = deferrable
230
+ self.poll_interval = poll_interval
221
231
 
222
- def execute(self, context: Context):
223
- self.log.info("Creating Batch prediction job")
224
- self.hook = BatchPredictionJobHook(
232
+ @cached_property
233
+ def hook(self) -> BatchPredictionJobHook:
234
+ return BatchPredictionJobHook(
225
235
  gcp_conn_id=self.gcp_conn_id,
226
236
  impersonation_chain=self.impersonation_chain,
227
237
  )
228
- result = self.hook.create_batch_prediction_job(
238
+
239
+ def execute(self, context: Context):
240
+ warnings.warn(
241
+ "The 'sync' parameter is deprecated and will be removed after 28.08.2024.",
242
+ AirflowProviderDeprecationWarning,
243
+ stacklevel=2,
244
+ )
245
+ self.log.info("Creating Batch prediction job")
246
+ batch_prediction_job: BatchPredictionJobObject = self.hook.submit_batch_prediction_job(
229
247
  region=self.region,
230
248
  project_id=self.project_id,
231
249
  job_display_name=self.job_display_name,
@@ -247,26 +265,62 @@ class CreateBatchPredictionJobOperator(GoogleCloudBaseOperator):
247
265
  explanation_parameters=self.explanation_parameters,
248
266
  labels=self.labels,
249
267
  encryption_spec_key_name=self.encryption_spec_key_name,
250
- sync=self.sync,
251
268
  create_request_timeout=self.create_request_timeout,
252
269
  batch_size=self.batch_size,
253
270
  )
254
-
255
- batch_prediction_job = result.to_dict()
256
- batch_prediction_job_id = self.hook.extract_batch_prediction_job_id(batch_prediction_job)
271
+ batch_prediction_job.wait_for_resource_creation()
272
+ batch_prediction_job_id = batch_prediction_job.name
257
273
  self.log.info("Batch prediction job was created. Job id: %s", batch_prediction_job_id)
258
274
 
259
275
  self.xcom_push(context, key="batch_prediction_job_id", value=batch_prediction_job_id)
260
276
  VertexAIBatchPredictionJobLink.persist(
261
277
  context=context, task_instance=self, batch_prediction_job_id=batch_prediction_job_id
262
278
  )
263
- return batch_prediction_job
279
+
280
+ if self.deferrable:
281
+ self.defer(
282
+ trigger=CreateBatchPredictionJobTrigger(
283
+ conn_id=self.gcp_conn_id,
284
+ project_id=self.project_id,
285
+ location=self.region,
286
+ job_id=batch_prediction_job.name,
287
+ poll_interval=self.poll_interval,
288
+ impersonation_chain=self.impersonation_chain,
289
+ ),
290
+ method_name="execute_complete",
291
+ )
292
+
293
+ batch_prediction_job.wait_for_completion()
294
+ self.log.info("Batch prediction job was completed. Job id: %s", batch_prediction_job_id)
295
+ return batch_prediction_job.to_dict()
264
296
 
265
297
  def on_kill(self) -> None:
266
298
  """Act as a callback called when the operator is killed; cancel any running job."""
267
299
  if self.hook:
268
300
  self.hook.cancel_batch_prediction_job()
269
301
 
302
+ def execute_complete(self, context: Context, event: dict[str, Any]) -> dict[str, Any]:
303
+ if event and event["status"] == "error":
304
+ raise AirflowException(event["message"])
305
+ job: dict[str, Any] = event["job"]
306
+ self.log.info("Batch prediction job %s created and completed successfully.", job["name"])
307
+ job_id = self.hook.extract_batch_prediction_job_id(job)
308
+ self.xcom_push(
309
+ context,
310
+ key="batch_prediction_job_id",
311
+ value=job_id,
312
+ )
313
+ self.xcom_push(
314
+ context,
315
+ key="training_conf",
316
+ value={
317
+ "training_conf_id": job_id,
318
+ "region": self.region,
319
+ "project_id": self.project_id,
320
+ },
321
+ )
322
+ return event["job"]
323
+
270
324
 
271
325
  class DeleteBatchPredictionJobOperator(GoogleCloudBaseOperator):
272
326
  """
@@ -16,16 +16,19 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains Google Vertex AI operators."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from typing import TYPE_CHECKING, Sequence
22
23
 
24
+ from deprecated import deprecated
23
25
  from google.api_core.exceptions import NotFound
24
26
  from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
25
27
  from google.cloud.aiplatform.models import Model
26
28
  from google.cloud.aiplatform_v1.types.dataset import Dataset
27
29
  from google.cloud.aiplatform_v1.types.training_pipeline import TrainingPipeline
28
30
 
31
+ from airflow.exceptions import AirflowProviderDeprecationWarning
29
32
  from airflow.providers.google.cloud.hooks.vertex_ai.custom_job import CustomJobHook
30
33
  from airflow.providers.google.cloud.links.vertex_ai import (
31
34
  VertexAIModelLink,
@@ -465,8 +468,6 @@ class CreateCustomContainerTrainingJobOperator(CustomTrainingJobBaseOperator):
465
468
  gcp_conn_id=self.gcp_conn_id,
466
469
  impersonation_chain=self.impersonation_chain,
467
470
  )
468
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
469
-
470
471
  model, training_id, custom_job_id = self.hook.create_custom_container_training_job(
471
472
  project_id=self.project_id,
472
473
  region=self.region,
@@ -847,7 +848,6 @@ class CreateCustomPythonPackageTrainingJobOperator(CustomTrainingJobBaseOperator
847
848
  gcp_conn_id=self.gcp_conn_id,
848
849
  impersonation_chain=self.impersonation_chain,
849
850
  )
850
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
851
851
  model, training_id, custom_job_id = self.hook.create_custom_python_package_training_job(
852
852
  project_id=self.project_id,
853
853
  region=self.region,
@@ -1231,8 +1231,6 @@ class CreateCustomTrainingJobOperator(CustomTrainingJobBaseOperator):
1231
1231
  gcp_conn_id=self.gcp_conn_id,
1232
1232
  impersonation_chain=self.impersonation_chain,
1233
1233
  )
1234
- self.parent_model = self.parent_model.rpartition("@")[0] if self.parent_model else None
1235
-
1236
1234
  model, training_id, custom_job_id = self.hook.create_custom_training_job(
1237
1235
  project_id=self.project_id,
1238
1236
  region=self.region,
@@ -1328,7 +1326,7 @@ class DeleteCustomTrainingJobOperator(GoogleCloudBaseOperator):
1328
1326
  account from the list granting this role to the originating account (templated).
1329
1327
  """
1330
1328
 
1331
- template_fields = ("training_pipeline", "custom_job", "region", "project_id", "impersonation_chain")
1329
+ template_fields = ("training_pipeline_id", "custom_job_id", "region", "project_id", "impersonation_chain")
1332
1330
 
1333
1331
  def __init__(
1334
1332
  self,
@@ -1345,8 +1343,8 @@ class DeleteCustomTrainingJobOperator(GoogleCloudBaseOperator):
1345
1343
  **kwargs,
1346
1344
  ) -> None:
1347
1345
  super().__init__(**kwargs)
1348
- self.training_pipeline = training_pipeline_id
1349
- self.custom_job = custom_job_id
1346
+ self.training_pipeline_id = training_pipeline_id
1347
+ self.custom_job_id = custom_job_id
1350
1348
  self.region = region
1351
1349
  self.project_id = project_id
1352
1350
  self.retry = retry
@@ -1355,6 +1353,26 @@ class DeleteCustomTrainingJobOperator(GoogleCloudBaseOperator):
1355
1353
  self.gcp_conn_id = gcp_conn_id
1356
1354
  self.impersonation_chain = impersonation_chain
1357
1355
 
1356
+ @property
1357
+ @deprecated(
1358
+ reason="`training_pipeline` is deprecated and will be removed in the future. "
1359
+ "Please use `training_pipeline_id` instead.",
1360
+ category=AirflowProviderDeprecationWarning,
1361
+ )
1362
+ def training_pipeline(self):
1363
+ """Alias for ``training_pipeline_id``, used for compatibility (deprecated)."""
1364
+ return self.training_pipeline_id
1365
+
1366
+ @property
1367
+ @deprecated(
1368
+ reason="`custom_job` is deprecated and will be removed in the future. "
1369
+ "Please use `custom_job_id` instead.",
1370
+ category=AirflowProviderDeprecationWarning,
1371
+ )
1372
+ def custom_job(self):
1373
+ """Alias for ``custom_job_id``, used for compatibility (deprecated)."""
1374
+ return self.custom_job_id
1375
+
1358
1376
  def execute(self, context: Context):
1359
1377
  hook = CustomJobHook(
1360
1378
  gcp_conn_id=self.gcp_conn_id,
@@ -16,6 +16,7 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  """This module contains Google Vertex AI operators."""
19
+
19
20
  from __future__ import annotations
20
21
 
21
22
  from typing import TYPE_CHECKING, Sequence