26
26
from google .api_core .exceptions import ServerError
27
27
from google .api_core .retry import Retry
28
28
from google .cloud .dataproc_v1beta2 import ( # pylint: disable=no-name-in-module
29
- ClusterControllerClient ,
30
- JobControllerClient ,
31
- WorkflowTemplateServiceClient ,
32
- )
33
- from google .cloud .dataproc_v1beta2 .types import ( # pylint: disable=no-name-in-module
34
29
Cluster ,
35
- Duration ,
36
- FieldMask ,
30
+ ClusterControllerClient ,
37
31
Job ,
32
+ JobControllerClient ,
38
33
JobStatus ,
39
34
WorkflowTemplate ,
35
+ WorkflowTemplateServiceClient ,
40
36
)
37
+ from google .protobuf .duration_pb2 import Duration
38
+ from google .protobuf .field_mask_pb2 import FieldMask
41
39
42
40
from airflow .exceptions import AirflowException
43
41
from airflow .providers .google .common .hooks .base_google import GoogleBaseHook
@@ -291,10 +289,12 @@ def create_cluster(
291
289
292
290
client = self .get_cluster_client (location = region )
293
291
result = client .create_cluster (
294
- project_id = project_id ,
295
- region = region ,
296
- cluster = cluster ,
297
- request_id = request_id ,
292
+ request = {
293
+ 'project_id' : project_id ,
294
+ 'region' : region ,
295
+ 'cluster' : cluster ,
296
+ 'request_id' : request_id ,
297
+ },
298
298
retry = retry ,
299
299
timeout = timeout ,
300
300
metadata = metadata ,
@@ -340,11 +340,13 @@ def delete_cluster(
340
340
"""
341
341
client = self .get_cluster_client (location = region )
342
342
result = client .delete_cluster (
343
- project_id = project_id ,
344
- region = region ,
345
- cluster_name = cluster_name ,
346
- cluster_uuid = cluster_uuid ,
347
- request_id = request_id ,
343
+ request = {
344
+ 'project_id' : project_id ,
345
+ 'region' : region ,
346
+ 'cluster_name' : cluster_name ,
347
+ 'cluster_uuid' : cluster_uuid ,
348
+ 'request_id' : request_id ,
349
+ },
348
350
retry = retry ,
349
351
timeout = timeout ,
350
352
metadata = metadata ,
@@ -382,9 +384,7 @@ def diagnose_cluster(
382
384
"""
383
385
client = self .get_cluster_client (location = region )
384
386
operation = client .diagnose_cluster (
385
- project_id = project_id ,
386
- region = region ,
387
- cluster_name = cluster_name ,
387
+ request = {'project_id' : project_id , 'region' : region , 'cluster_name' : cluster_name },
388
388
retry = retry ,
389
389
timeout = timeout ,
390
390
metadata = metadata ,
@@ -423,9 +423,7 @@ def get_cluster(
423
423
"""
424
424
client = self .get_cluster_client (location = region )
425
425
result = client .get_cluster (
426
- project_id = project_id ,
427
- region = region ,
428
- cluster_name = cluster_name ,
426
+ request = {'project_id' : project_id , 'region' : region , 'cluster_name' : cluster_name },
429
427
retry = retry ,
430
428
timeout = timeout ,
431
429
metadata = metadata ,
@@ -467,10 +465,7 @@ def list_clusters(
467
465
"""
468
466
client = self .get_cluster_client (location = region )
469
467
result = client .list_clusters (
470
- project_id = project_id ,
471
- region = region ,
472
- filter_ = filter_ ,
473
- page_size = page_size ,
468
+ request = {'project_id' : project_id , 'region' : region , 'filter' : filter_ , 'page_size' : page_size },
474
469
retry = retry ,
475
470
timeout = timeout ,
476
471
metadata = metadata ,
@@ -551,13 +546,15 @@ def update_cluster( # pylint: disable=too-many-arguments
551
546
"""
552
547
client = self .get_cluster_client (location = location )
553
548
operation = client .update_cluster (
554
- project_id = project_id ,
555
- region = location ,
556
- cluster_name = cluster_name ,
557
- cluster = cluster ,
558
- update_mask = update_mask ,
559
- graceful_decommission_timeout = graceful_decommission_timeout ,
560
- request_id = request_id ,
549
+ request = {
550
+ 'project_id' : project_id ,
551
+ 'region' : location ,
552
+ 'cluster_name' : cluster_name ,
553
+ 'cluster' : cluster ,
554
+ 'update_mask' : update_mask ,
555
+ 'graceful_decommission_timeout' : graceful_decommission_timeout ,
556
+ 'request_id' : request_id ,
557
+ },
561
558
retry = retry ,
562
559
timeout = timeout ,
563
560
metadata = metadata ,
@@ -593,10 +590,11 @@ def create_workflow_template(
593
590
:param metadata: Additional metadata that is provided to the method.
594
591
:type metadata: Sequence[Tuple[str, str]]
595
592
"""
593
+ metadata = metadata or ()
596
594
client = self .get_template_client (location )
597
- parent = client . region_path ( project_id , location )
595
+ parent = f'projects/ { project_id } /regions/ { location } '
598
596
return client .create_workflow_template (
599
- parent = parent , template = template , retry = retry , timeout = timeout , metadata = metadata
597
+ request = { ' parent' : parent , ' template' : template } , retry = retry , timeout = timeout , metadata = metadata
600
598
)
601
599
602
600
@GoogleBaseHook .fallback_to_default_project_id
@@ -643,13 +641,11 @@ def instantiate_workflow_template(
643
641
:param metadata: Additional metadata that is provided to the method.
644
642
:type metadata: Sequence[Tuple[str, str]]
645
643
"""
644
+ metadata = metadata or ()
646
645
client = self .get_template_client (location )
647
- name = client . workflow_template_path ( project_id , location , template_name )
646
+ name = f'projects/ { project_id } /regions/ { location } /workflowTemplates/ { template_name } '
648
647
operation = client .instantiate_workflow_template (
649
- name = name ,
650
- version = version ,
651
- parameters = parameters ,
652
- request_id = request_id ,
648
+ request = {'name' : name , 'version' : version , 'request_id' : request_id , 'parameters' : parameters },
653
649
retry = retry ,
654
650
timeout = timeout ,
655
651
metadata = metadata ,
@@ -690,12 +686,11 @@ def instantiate_inline_workflow_template(
690
686
:param metadata: Additional metadata that is provided to the method.
691
687
:type metadata: Sequence[Tuple[str, str]]
692
688
"""
689
+ metadata = metadata or ()
693
690
client = self .get_template_client (location )
694
- parent = client . region_path ( project_id , location )
691
+ parent = f'projects/ { project_id } /regions/ { location } '
695
692
operation = client .instantiate_inline_workflow_template (
696
- parent = parent ,
697
- template = template ,
698
- request_id = request_id ,
693
+ request = {'parent' : parent , 'template' : template , 'request_id' : request_id },
699
694
retry = retry ,
700
695
timeout = timeout ,
701
696
metadata = metadata ,
@@ -722,19 +717,19 @@ def wait_for_job(
722
717
"""
723
718
state = None
724
719
start = time .monotonic ()
725
- while state not in (JobStatus .ERROR , JobStatus .DONE , JobStatus .CANCELLED ):
720
+ while state not in (JobStatus .State . ERROR , JobStatus .State . DONE , JobStatus . State .CANCELLED ):
726
721
if timeout and start + timeout < time .monotonic ():
727
722
raise AirflowException (f"Timeout: dataproc job { job_id } is not ready after { timeout } s" )
728
723
time .sleep (wait_time )
729
724
try :
730
- job = self .get_job (location = location , job_id = job_id , project_id = project_id )
725
+ job = self .get_job (project_id = project_id , location = location , job_id = job_id )
731
726
state = job .status .state
732
727
except ServerError as err :
733
728
self .log .info ("Retrying. Dataproc API returned server error when waiting for job: %s" , err )
734
729
735
- if state == JobStatus .ERROR :
730
+ if state == JobStatus .State . ERROR :
736
731
raise AirflowException (f'Job failed:\n { job } ' )
737
- if state == JobStatus .CANCELLED :
732
+ if state == JobStatus .State . CANCELLED :
738
733
raise AirflowException (f'Job was cancelled:\n { job } ' )
739
734
740
735
@GoogleBaseHook .fallback_to_default_project_id
@@ -767,9 +762,7 @@ def get_job(
767
762
"""
768
763
client = self .get_job_client (location = location )
769
764
job = client .get_job (
770
- project_id = project_id ,
771
- region = location ,
772
- job_id = job_id ,
765
+ request = {'project_id' : project_id , 'region' : location , 'job_id' : job_id },
773
766
retry = retry ,
774
767
timeout = timeout ,
775
768
metadata = metadata ,
@@ -812,10 +805,7 @@ def submit_job(
812
805
"""
813
806
client = self .get_job_client (location = location )
814
807
return client .submit_job (
815
- project_id = project_id ,
816
- region = location ,
817
- job = job ,
818
- request_id = request_id ,
808
+ request = {'project_id' : project_id , 'region' : location , 'job' : job , 'request_id' : request_id },
819
809
retry = retry ,
820
810
timeout = timeout ,
821
811
metadata = metadata ,
@@ -884,9 +874,7 @@ def cancel_job(
884
874
client = self .get_job_client (location = location )
885
875
886
876
job = client .cancel_job (
887
- project_id = project_id ,
888
- region = location ,
889
- job_id = job_id ,
877
+ request = {'project_id' : project_id , 'region' : location , 'job_id' : job_id },
890
878
retry = retry ,
891
879
timeout = timeout ,
892
880
metadata = metadata ,
0 commit comments