bolkedebruin closed pull request #4139: [AIRFLOW-2715] Pick up the region
setting while launching Dataflow templates
URL: https://github.com/apache/incubator-airflow/pull/4139
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/airflow/contrib/hooks/gcp_dataflow_hook.py
b/airflow/contrib/hooks/gcp_dataflow_hook.py
index 4fdb07c74d..0eee769d61 100644
--- a/airflow/contrib/hooks/gcp_dataflow_hook.py
+++ b/airflow/contrib/hooks/gcp_dataflow_hook.py
@@ -220,6 +220,7 @@ def label_formatter(labels_dict):
def start_template_dataflow(self, job_name, variables, parameters,
dataflow_template,
append_job_name=True):
+ variables = self._set_variables(variables)
name = self._build_dataflow_job_name(job_name, append_job_name)
self._start_template_dataflow(
name, variables, parameters, dataflow_template)
@@ -278,8 +279,9 @@ def _start_template_dataflow(self, name, variables,
parameters,
"parameters": parameters,
"environment": environment}
service = self.get_conn()
- request = service.projects().templates().launch(
+ request = service.projects().locations().templates().launch(
projectId=variables['project'],
+ location=variables['region'],
gcsPath=dataflow_template,
body=body
)
diff --git a/airflow/contrib/operators/dataflow_operator.py
b/airflow/contrib/operators/dataflow_operator.py
index 5378735f94..2a9020f2e2 100644
--- a/airflow/contrib/operators/dataflow_operator.py
+++ b/airflow/contrib/operators/dataflow_operator.py
@@ -187,6 +187,7 @@ class DataflowTemplateOperator(BaseOperator):
default_args = {
'dataflow_default_options': {
'project': 'my-gcp-project',
+ 'region': 'europe-west1',
'zone': 'europe-west1-d',
'tempLocation': 'gs://my-staging-bucket/staging/',
}
diff --git a/tests/contrib/hooks/test_gcp_dataflow_hook.py
b/tests/contrib/hooks/test_gcp_dataflow_hook.py
index 653993a7de..57932c47f6 100644
--- a/tests/contrib/hooks/test_gcp_dataflow_hook.py
+++ b/tests/contrib/hooks/test_gcp_dataflow_hook.py
@@ -255,8 +255,10 @@ def test_start_template_dataflow(self,
internal_dataflow_mock):
self.dataflow_hook.start_template_dataflow(
job_name=JOB_NAME, variables=DATAFLOW_OPTIONS_TEMPLATE,
parameters=PARAMETERS,
dataflow_template=TEMPLATE)
+ options_with_region = {'region': 'us-central1'}
+ options_with_region.update(DATAFLOW_OPTIONS_TEMPLATE)
internal_dataflow_mock.assert_called_once_with(
- mock.ANY, DATAFLOW_OPTIONS_TEMPLATE, PARAMETERS, TEMPLATE)
+ mock.ANY, options_with_region, PARAMETERS, TEMPLATE)
class DataFlowJobTest(unittest.TestCase):
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services