Apache Airflow connector for Ocean for Apache Spark
Project description
Airflow connector to Ocean for Apache Spark
An Airflow plugin and provider to launch and monitor Spark applications on Ocean for Apache Spark.
Compatibility
ocean-spark-airflow-provider
is compatible with both Airflow 1 and
Airflow 2. It is detected as an Airflow plugin by Airflow 1 and up,
and as a provider by Airflow 2.
Installation
pip install ocean-spark-airflow-provider
Usage
For general usage of Ocean for Apache Spark, refer to the official documentation.
Setting up the connection
In the connection menu, register a new connection of type Ocean for
Apache Spark. The default connection name is ocean_spark_default
. You will
need to have:
- The Ocean Spark cluster ID of the cluster you just created (of the
format
osc-e4089a00
). You can find it in the Spot console in the list of clusters, or by using the Cluster List API. - A Spot token to interact with the Spot API.
The Ocean for Apache Spark connection type is not available for Airflow 1, instead create an HTTP connection and fill your cluster id as host, and your API token as password.
You will need to create a separate connection for each Ocean Spark
cluster that you want to use with Airflow. In the
OceanSparkOperator
, you can select which Ocean Spark connection to
use with the connection_name
argument (defaults to
ocean_spark_default
). For example, you may choose to have one
Ocean Spark cluster per environment (dev, staging, prod), and you
can easily target an environment by picking the correct Airflow connection.
Using the operator
from airflow import __version__ as airflow_version
if airflow_version.startswith("1."):
# Airflow 1, import as plugin
from airflow.operators.ocean_spark import OceanSparkOperator
else:
# Airflow 2
from ocean_spark.operators import OceanSparkOperator
# DAG creation
spark_pi_task = OceanSparkOperator(
job_id="spark-pi",
task_id="compute-pi",
dag=dag,
config_overrides={
"type": "Scala",
"sparkVersion": "3.2.0",
"image": "gcr.io/datamechanics/spark:platform-3.2-latest",
"imagePullPolicy": "IfNotPresent",
"mainClass": "org.apache.spark.examples.SparkPi",
"mainApplicationFile": "local:///opt/spark/examples/jars/examples.jar",
"arguments": ["10000"],
"driver": {
"cores": 1,
"spot": false
},
"executor": {
"cores": 4,
"instances": 1,
"spot": true,
"instanceSelector": "r5"
},
},
)
more examples are available for Airflow 1 and Airflow 2.
Test locally
You can test the plugin locally using the docker compose setup in this
repository. Run make serve_airflow2
at the root of the repository to
launch an instance of Airflow 2 with the provider already installed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ocean_spark_airflow_provider-0.1.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2b1367e7d1b62480b57cc105b8c26b74fca533aa37b4029f0c72a39db8a2a80 |
|
MD5 | cc9c65b0f400b430ca83b5e0430e46c0 |
|
BLAKE2b-256 | dcd2d08e92d20e155d6ab62a555dd5d50f49a8771a0d6860cfaade06e1440c9c |
Hashes for ocean_spark_airflow_provider-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0feed747bc3dffc5634f8102d03d7e66486174b80dfce786b08e4d9b73523311 |
|
MD5 | b3477bca1099b9e84295fc540d0fa2f0 |
|
BLAKE2b-256 | d2f653c2a56531c7d5c7921075a966cde297303429894aa452f6308b553ae306 |