airflow.contrib.operators.dataproc_operator
¶
Module Contents¶
-
class
airflow.contrib.operators.dataproc_operator.
DataprocClusterCreateOperator
(cluster_name, project_id, num_workers, zone, network_uri=None, subnetwork_uri=None, internal_ip_only=None, tags=None, storage_bucket=None, init_actions_uris=None, init_action_timeout='10m', metadata=None, custom_image=None, image_version=None, properties=None, master_machine_type='n1-standard-4', master_disk_type='pd-standard', master_disk_size=500, worker_machine_type='n1-standard-4', worker_disk_type='pd-standard', worker_disk_size=500, num_preemptible_workers=0, labels=None, region='global', gcp_conn_id='google_cloud_default', delegate_to=None, service_account=None, service_account_scopes=None, idle_delete_ttl=None, auto_delete_time=None, auto_delete_ttl=None, *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Create a new cluster on Google Cloud Dataproc. The operator will wait until the creation is successful or an error occurs in the creation process.
The parameters allow to configure the cluster. Please refer to
https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.clusters
for a detailed explanation on the different parameters. Most of the configuration parameters detailed in the link are available as a parameter to this operator.
- Parameters
cluster_name (str) – The name of the DataProc cluster to create. (templated)
project_id (str) – The ID of the google cloud project in which to create the cluster. (templated)
num_workers (int) – The # of workers to spin up. If set to zero will spin up cluster in a single node mode
storage_bucket (str) – The storage bucket to use, setting to None lets dataproc generate a custom one for you
init_actions_uris (list[str]) – List of GCS uri’s containing dataproc initialization scripts
init_action_timeout (str) – Amount of time executable scripts in init_actions_uris has to complete
metadata (dict) – dict of key-value google compute engine metadata entries to add to all instances
image_version (str) – the version of software inside the Dataproc cluster
custom_image – custom Dataproc image for more info see https://cloud.google.com/dataproc/docs/guides/dataproc-images
properties (dict) – dict of properties to set on config files (e.g. spark-defaults.conf), see https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.clusters#SoftwareConfig
master_machine_type (str) – Compute engine machine type to use for the master node
master_disk_type (str) – Type of the boot disk for the master node (default is
pd-standard
). Valid values:pd-ssd
(Persistent Disk Solid State Drive) orpd-standard
(Persistent Disk Hard Disk Drive).master_disk_size (int) – Disk size for the master node
worker_machine_type (str) – Compute engine machine type to use for the worker nodes
worker_disk_type (str) – Type of the boot disk for the worker node (default is
pd-standard
). Valid values:pd-ssd
(Persistent Disk Solid State Drive) orpd-standard
(Persistent Disk Hard Disk Drive).worker_disk_size (int) – Disk size for the worker nodes
num_preemptible_workers (int) – The # of preemptible worker nodes to spin up
labels (dict) – dict of labels to add to the cluster
zone (str) – The zone where the cluster will be located. (templated)
network_uri (str) – The network uri to be used for machine communication, cannot be specified with subnetwork_uri
subnetwork_uri (str) – The subnetwork uri to be used for machine communication, cannot be specified with network_uri
internal_ip_only (bool) – If true, all instances in the cluster will only have internal IP addresses. This can only be enabled for subnetwork enabled networks
region (str) – leave as ‘global’, might become relevant in the future. (templated)
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
service_account (str) – The service account of the dataproc instances.
service_account_scopes (list[str]) – The URIs of service account scopes to be included.
idle_delete_ttl (int) – The longest duration that cluster would keep alive while staying idle. Passing this threshold will cause cluster to be auto-deleted. A duration in seconds.
auto_delete_time (datetime.datetime) – The time when cluster will be auto-deleted.
auto_delete_ttl (int) – The life duration of cluster, the cluster will be auto-deleted at the end of this duration. A duration in seconds. (If auto_delete_time is set this parameter will be ignored)
- Type
custom_image: str
-
class
airflow.contrib.operators.dataproc_operator.
DataprocClusterScaleOperator
(cluster_name, project_id, region='global', gcp_conn_id='google_cloud_default', delegate_to=None, num_workers=2, num_preemptible_workers=0, graceful_decommission_timeout=None, *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Scale, up or down, a cluster on Google Cloud Dataproc. The operator will wait until the cluster is re-scaled.
Example:
t1 = DataprocClusterScaleOperator( task_id='dataproc_scale', project_id='my-project', cluster_name='cluster-1', num_workers=10, num_preemptible_workers=10, graceful_decommission_timeout='1h', dag=dag)
See also
For more detail on about scaling clusters have a look at the reference: https://cloud.google.com/dataproc/docs/concepts/configuring-clusters/scaling-clusters
- Parameters
cluster_name (str) – The name of the cluster to scale. (templated)
project_id (str) – The ID of the google cloud project in which the cluster runs. (templated)
region (str) – The region for the dataproc cluster. (templated)
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
num_workers (int) – The new number of workers
num_preemptible_workers (int) – The new number of preemptible workers
graceful_decommission_timeout (str) – Timeout for graceful YARN decomissioning. Maximum value is 1d
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
-
class
airflow.contrib.operators.dataproc_operator.
DataprocClusterDeleteOperator
(cluster_name, project_id, region='global', gcp_conn_id='google_cloud_default', delegate_to=None, *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Delete a cluster on Google Cloud Dataproc. The operator will wait until the cluster is destroyed.
- Parameters
cluster_name (str) – The name of the cluster to create. (templated)
project_id (str) – The ID of the google cloud project in which the cluster runs. (templated)
region (str) – leave as ‘global’, might become relevant in the future. (templated)
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
-
class
airflow.contrib.operators.dataproc_operator.
DataProcPigOperator
(query=None, query_uri=None, variables=None, job_name='{{task.task_id}}_{{ds_nodash}}', cluster_name='cluster-1', dataproc_pig_properties=None, dataproc_pig_jars=None, gcp_conn_id='google_cloud_default', delegate_to=None, region='global', job_error_states=['ERROR'], *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Start a Pig query Job on a Cloud DataProc cluster. The parameters of the operation will be passed to the cluster.
It’s a good practice to define dataproc_* parameters in the default_args of the dag like the cluster name and UDFs.
default_args = { 'cluster_name': 'cluster-1', 'dataproc_pig_jars': [ 'gs://example/udf/jar/datafu/1.2.0/datafu.jar', 'gs://example/udf/jar/gpig/1.2/gpig.jar' ] }
You can pass a pig script as string or file reference. Use variables to pass on variables for the pig script to be resolved on the cluster or use the parameters to be resolved in the script as template parameters.
Example:
t1 = DataProcPigOperator( task_id='dataproc_pig', query='a_pig_script.pig', variables={'out': 'gs://example/output/{{ds}}'}, dag=dag)
See also
For more detail on about job submission have a look at the reference: https://cloud.google.com/dataproc/reference/rest/v1/projects.regions.jobs
- Parameters
query (str) – The query or reference to the query file (pg or pig extension). (templated)
query_uri (str) – The uri of a pig script on Cloud Storage.
variables (dict) – Map of named parameters for the query. (templated)
job_name (str) – The job name used in the DataProc cluster. This name by default is the task_id appended with the execution data, but can be templated. The name will always be appended with a random number to avoid name clashes. (templated)
cluster_name (str) – The name of the DataProc cluster. (templated)
dataproc_pig_properties (dict) – Map for the Pig properties. Ideal to put in default arguments
dataproc_pig_jars (list) – URIs to jars provisioned in Cloud Storage (example: for UDFs and libs) and are ideal to put in default arguments.
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
region (str) – The specified region where the dataproc cluster is created.
job_error_states (list) – Job states that should be considered error states. Any states in this list will result in an error being raised and failure of the task. Eg, if the
CANCELLED
state should also be considered a task failure, pass in['ERROR', 'CANCELLED']
. Possible values are currently only'ERROR'
and'CANCELLED'
, but could change in the future. Defaults to['ERROR']
.
- Variables
dataproc_job_id (str) – The actual “jobId” as submitted to the Dataproc API. This is useful for identifying or linking to the job in the Google Cloud Console Dataproc UI, as the actual “jobId” submitted to the Dataproc API is appended with an 8 character random string.
-
class
airflow.contrib.operators.dataproc_operator.
DataProcHiveOperator
(query=None, query_uri=None, variables=None, job_name='{{task.task_id}}_{{ds_nodash}}', cluster_name='cluster-1', dataproc_hive_properties=None, dataproc_hive_jars=None, gcp_conn_id='google_cloud_default', delegate_to=None, region='global', job_error_states=['ERROR'], *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Start a Hive query Job on a Cloud DataProc cluster.
- Parameters
query (str) – The query or reference to the query file (q extension).
query_uri (str) – The uri of a hive script on Cloud Storage.
variables (dict) – Map of named parameters for the query.
job_name (str) – The job name used in the DataProc cluster. This name by default is the task_id appended with the execution data, but can be templated. The name will always be appended with a random number to avoid name clashes.
cluster_name (str) – The name of the DataProc cluster.
dataproc_hive_properties (dict) – Map for the Pig properties. Ideal to put in default arguments
dataproc_hive_jars (list) – URIs to jars provisioned in Cloud Storage (example: for UDFs and libs) and are ideal to put in default arguments.
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
region (str) – The specified region where the dataproc cluster is created.
job_error_states (list) – Job states that should be considered error states. Any states in this list will result in an error being raised and failure of the task. Eg, if the
CANCELLED
state should also be considered a task failure, pass in['ERROR', 'CANCELLED']
. Possible values are currently only'ERROR'
and'CANCELLED'
, but could change in the future. Defaults to['ERROR']
.
- Variables
dataproc_job_id (str) – The actual “jobId” as submitted to the Dataproc API. This is useful for identifying or linking to the job in the Google Cloud Console Dataproc UI, as the actual “jobId” submitted to the Dataproc API is appended with an 8 character random string.
-
class
airflow.contrib.operators.dataproc_operator.
DataProcSparkSqlOperator
(query=None, query_uri=None, variables=None, job_name='{{task.task_id}}_{{ds_nodash}}', cluster_name='cluster-1', dataproc_spark_properties=None, dataproc_spark_jars=None, gcp_conn_id='google_cloud_default', delegate_to=None, region='global', job_error_states=['ERROR'], *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Start a Spark SQL query Job on a Cloud DataProc cluster.
- Parameters
query (str) – The query or reference to the query file (q extension). (templated)
query_uri (str) – The uri of a spark sql script on Cloud Storage.
variables (dict) – Map of named parameters for the query. (templated)
job_name (str) – The job name used in the DataProc cluster. This name by default is the task_id appended with the execution data, but can be templated. The name will always be appended with a random number to avoid name clashes. (templated)
cluster_name (str) – The name of the DataProc cluster. (templated)
dataproc_spark_properties (dict) – Map for the Pig properties. Ideal to put in default arguments
dataproc_spark_jars (list) – URIs to jars provisioned in Cloud Storage (example: for UDFs and libs) and are ideal to put in default arguments.
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
region (str) – The specified region where the dataproc cluster is created.
job_error_states (list) – Job states that should be considered error states. Any states in this list will result in an error being raised and failure of the task. Eg, if the
CANCELLED
state should also be considered a task failure, pass in['ERROR', 'CANCELLED']
. Possible values are currently only'ERROR'
and'CANCELLED'
, but could change in the future. Defaults to['ERROR']
.
- Variables
dataproc_job_id (str) – The actual “jobId” as submitted to the Dataproc API. This is useful for identifying or linking to the job in the Google Cloud Console Dataproc UI, as the actual “jobId” submitted to the Dataproc API is appended with an 8 character random string.
-
class
airflow.contrib.operators.dataproc_operator.
DataProcSparkOperator
(main_jar=None, main_class=None, arguments=None, archives=None, files=None, job_name='{{task.task_id}}_{{ds_nodash}}', cluster_name='cluster-1', dataproc_spark_properties=None, dataproc_spark_jars=None, gcp_conn_id='google_cloud_default', delegate_to=None, region='global', job_error_states=['ERROR'], *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Start a Spark Job on a Cloud DataProc cluster.
- Parameters
main_jar (str) – URI of the job jar provisioned on Cloud Storage. (use this or the main_class, not both together).
main_class (str) – Name of the job class. (use this or the main_jar, not both together).
arguments (list) – Arguments for the job. (templated)
archives (list) – List of archived files that will be unpacked in the work directory. Should be stored in Cloud Storage.
files (list) – List of files to be copied to the working directory
job_name (str) – The job name used in the DataProc cluster. This name by default is the task_id appended with the execution data, but can be templated. The name will always be appended with a random number to avoid name clashes. (templated)
cluster_name (str) – The name of the DataProc cluster. (templated)
dataproc_spark_properties (dict) – Map for the Pig properties. Ideal to put in default arguments
dataproc_spark_jars (list) – URIs to jars provisioned in Cloud Storage (example: for UDFs and libs) and are ideal to put in default arguments.
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
region (str) – The specified region where the dataproc cluster is created.
job_error_states (list) – Job states that should be considered error states. Any states in this list will result in an error being raised and failure of the task. Eg, if the
CANCELLED
state should also be considered a task failure, pass in['ERROR', 'CANCELLED']
. Possible values are currently only'ERROR'
and'CANCELLED'
, but could change in the future. Defaults to['ERROR']
.
- Variables
dataproc_job_id (str) – The actual “jobId” as submitted to the Dataproc API. This is useful for identifying or linking to the job in the Google Cloud Console Dataproc UI, as the actual “jobId” submitted to the Dataproc API is appended with an 8 character random string.
-
class
airflow.contrib.operators.dataproc_operator.
DataProcHadoopOperator
(main_jar=None, main_class=None, arguments=None, archives=None, files=None, job_name='{{task.task_id}}_{{ds_nodash}}', cluster_name='cluster-1', dataproc_hadoop_properties=None, dataproc_hadoop_jars=None, gcp_conn_id='google_cloud_default', delegate_to=None, region='global', job_error_states=['ERROR'], *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Start a Hadoop Job on a Cloud DataProc cluster.
- Parameters
main_jar (str) – URI of the job jar provisioned on Cloud Storage. (use this or the main_class, not both together).
main_class (str) – Name of the job class. (use this or the main_jar, not both together).
arguments (list) – Arguments for the job. (templated)
archives (list) – List of archived files that will be unpacked in the work directory. Should be stored in Cloud Storage.
files (list) – List of files to be copied to the working directory
job_name (str) – The job name used in the DataProc cluster. This name by default is the task_id appended with the execution data, but can be templated. The name will always be appended with a random number to avoid name clashes. (templated)
cluster_name (str) – The name of the DataProc cluster. (templated)
dataproc_hadoop_properties (dict) – Map for the Pig properties. Ideal to put in default arguments
dataproc_hadoop_jars (list) – URIs to jars provisioned in Cloud Storage (example: for UDFs and libs) and are ideal to put in default arguments.
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
region (str) – The specified region where the dataproc cluster is created.
job_error_states (list) – Job states that should be considered error states. Any states in this list will result in an error being raised and failure of the task. Eg, if the
CANCELLED
state should also be considered a task failure, pass in['ERROR', 'CANCELLED']
. Possible values are currently only'ERROR'
and'CANCELLED'
, but could change in the future. Defaults to['ERROR']
.
- Variables
dataproc_job_id (str) – The actual “jobId” as submitted to the Dataproc API. This is useful for identifying or linking to the job in the Google Cloud Console Dataproc UI, as the actual “jobId” submitted to the Dataproc API is appended with an 8 character random string.
-
class
airflow.contrib.operators.dataproc_operator.
DataProcPySparkOperator
(main, arguments=None, archives=None, pyfiles=None, files=None, job_name='{{task.task_id}}_{{ds_nodash}}', cluster_name='cluster-1', dataproc_pyspark_properties=None, dataproc_pyspark_jars=None, gcp_conn_id='google_cloud_default', delegate_to=None, region='global', job_error_states=['ERROR'], *args, **kwargs)[source]¶ Bases:
airflow.models.BaseOperator
Start a PySpark Job on a Cloud DataProc cluster.
- Parameters
main (str) – [Required] The Hadoop Compatible Filesystem (HCFS) URI of the main Python file to use as the driver. Must be a .py file.
arguments (list) – Arguments for the job. (templated)
archives (list) – List of archived files that will be unpacked in the work directory. Should be stored in Cloud Storage.
files (list) – List of files to be copied to the working directory
pyfiles (list) – List of Python files to pass to the PySpark framework. Supported file types: .py, .egg, and .zip
job_name (str) – The job name used in the DataProc cluster. This name by default is the task_id appended with the execution data, but can be templated. The name will always be appended with a random number to avoid name clashes. (templated)
cluster_name (str) – The name of the DataProc cluster.
dataproc_pyspark_properties (dict) – Map for the Pig properties. Ideal to put in default arguments
dataproc_pyspark_jars (list) – URIs to jars provisioned in Cloud Storage (example: for UDFs and libs) and are ideal to put in default arguments.
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
region (str) – The specified region where the dataproc cluster is created.
job_error_states (list) – Job states that should be considered error states. Any states in this list will result in an error being raised and failure of the task. Eg, if the
CANCELLED
state should also be considered a task failure, pass in['ERROR', 'CANCELLED']
. Possible values are currently only'ERROR'
and'CANCELLED'
, but could change in the future. Defaults to['ERROR']
.
- Variables
dataproc_job_id (str) – The actual “jobId” as submitted to the Dataproc API. This is useful for identifying or linking to the job in the Google Cloud Console Dataproc UI, as the actual “jobId” submitted to the Dataproc API is appended with an 8 character random string.
-
class
airflow.contrib.operators.dataproc_operator.
DataprocWorkflowTemplateBaseOperator
(project_id, region='global', gcp_conn_id='google_cloud_default', delegate_to=None, *args, **kwargs)[source]¶
-
class
airflow.contrib.operators.dataproc_operator.
DataprocWorkflowTemplateInstantiateOperator
(template_id, *args, **kwargs)[source]¶ Bases:
airflow.contrib.operators.dataproc_operator.DataprocWorkflowTemplateBaseOperator
Instantiate a WorkflowTemplate on Google Cloud Dataproc. The operator will wait until the WorkflowTemplate is finished executing.
See also
Please refer to: https://cloud.google.com/dataproc/docs/reference/rest/v1beta2/projects.regions.workflowTemplates/instantiate
- Parameters
template_id (str) – The id of the template. (templated)
project_id (str) – The ID of the google cloud project in which the template runs
region (str) – leave as ‘global’, might become relevant in the future
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.
-
class
airflow.contrib.operators.dataproc_operator.
DataprocWorkflowTemplateInstantiateInlineOperator
(template, *args, **kwargs)[source]¶ Bases:
airflow.contrib.operators.dataproc_operator.DataprocWorkflowTemplateBaseOperator
Instantiate a WorkflowTemplate Inline on Google Cloud Dataproc. The operator will wait until the WorkflowTemplate is finished executing.
See also
Please refer to: https://cloud.google.com/dataproc/docs/reference/rest/v1beta2/projects.regions.workflowTemplates/instantiateInline
- Parameters
template (map) – The template contents. (templated)
project_id (str) – The ID of the google cloud project in which the template runs
region (str) – leave as ‘global’, might become relevant in the future
gcp_conn_id (str) – The connection ID to use connecting to Google Cloud Platform.
delegate_to (str) – The account to impersonate, if any. For this to work, the service account making the request must have domain-wide delegation enabled.