Skip to main content

Provider for Apache Airflow schedule Apache Mesos

Docs Chat Docs

This provider for Apache Airflow contain the following features:

  • MesosExecuter - A scheduler to run Airflow DAG's on mesos
  • MesosOperator - To execute individual Airflow tasks on Mesos.

Issues

To open an issue, please use this place: https://github.com/m3scluster/airflow-provider-mesos/issues

Requirements

  • Airflow 3.x
  • Apache Mesos minimum 1.6.x

How to install and configure

On the Airflow Server, we have to install the mesos provider.

pip install avmesos_airflow_provider

Then we will configure Airflow.

vim airflow.cfg

executor = avmesos_airflow_provider.executors.mesos_executor.MesosExecutor

[mesos]
mesos_ssl = True
master = leader.mesos:5050
framework_name = Airflow
checkpoint = True
mesos_attributes = ["airflow:true", "gpu:true?:cpu:true"]
failover_timeout = 604800
command_shell = True
task_cpu = 1
task_memory = 20000
authenticate = True
default_principal = <MESOS USER>
default_secret = <MESOS PASSWORD>
docker_image_slave = <AIRFLOW DOCKER IMAGE>
docker_volume_driver = local
docker_volume_dag_name = airflowdags
docker_volume_dag_container_path = /airflow/airflow/dags/
docker_sock = /var/run/docker.sock
docker_volume_logs_name = airflowlogs
docker_volume_logs_container_path = /airflow/airflow/
docker_user_group_id = 998
docker_environment = [{ "name":"<KEY>", "value":"<VALUE>" }, { ... }]
api_username = <USERNAME FOR THIS API>
api_password = <PASSWORD FOR THIS API>

DAG example with mesos executor

from airflow import DAG
from datetime import datetime, timedelta
from airflow.operators.dummy_operator import DummyOperator
from airflow.providers.docker.operators.docker import DockerOperator
from airflow.operators.python import PythonOperator

default_args = {
        'owner'                 : 'airflow',
        'description'           : 'Use of the DockerOperator',
        'depend_on_past'        : True,
}

with DAG('docker_dag2', default_args=default_args, schedule_interval="*/10 * * * * ", catchup=True, start_date=datetime.now()) as dag:
        t2 = DockerOperator(
                task_id='docker_command',
                image='centos:latest',
                api_version='auto',
                auto_remove=False,
                command="/bin/sleep 600",
                docker_url='unix:///var/run/docker.sock',
                executor_config={
                                "cpus": 2.0,
                                "mem_limit": 2048,
                                "attributes": ["gpu:true"]
                }         
        )

        t2

Using MesosOperator

MesosOperator is modelled after DockerOperator, but submits one container task to the Mesos executor framework API and waits for its terminal Mesos status. The executor API listens on port 11000 by default; override it with mesos.operator_api_url or the operator's airflow_scheduler_url.

from datetime import datetime
from airflow import DAG
from avmesos_airflow_provider.operators.mesos import MesosOperator

with DAG("mesos_operator", schedule=None, start_date=datetime(2024, 1, 1), catchup=False) as dag:
    MesosOperator(
        task_id="hello",
        image="alpine:3.20",
        command="echo hello from Mesos",
        cpus=0.1,
        mem_limit="128m",
        attributes=["airflow:true"],
    )

Using Mesos attributes

Within the airflow.cfg file, you can define default Mesos attributes that are applied to every task.

As example:

mesos_attributes = ["airflow:true", "gpu:true?:cpu:true"]

When you add task-specific attributes within your DAG,...

executor_config={
  "cpus": 2.0,
  "mem_limit": 2048,
  "attributes": ["gpu:true"]
}

... they are combined with these default attributes. This allows you to both supplement and override the default settings.

Specifically, what is the reasoning behind the convention used in the gpu:true?:cpu:true attribute string?

The intention is that if a Mesos offer does include gpu=true, the task will automatically default to using a CPU-only server, preventing the Data Science team from needing to manually add attributes to each task. If a Data Science team need GPU, they only has to add that specific attribute.

This is simply an illustrative example, and the GPU and CPU attributes can be any valid string value.

Development

For development and testing we deliver a nix-shell file to install airflow, our airflow provider and postgresql. To use it, please follow the following steps:

  1. Run mesos-mini:
docker run --rm --name mesos --privileged=true --shm-size=30gb -it --net host avhost/mesos-mini:1.11.0-0.2.0-1 /lib/systemd/systemd
  1. Use nix-shell:
nix-shell

> airflow scheduler
  1. On the mesos-ui (http://localhost:5050) you will see Airflow as framework.

Metadata

Release files for avmesos-airflow-provider 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for avmesos-airflow-provider 0.4.0
File Size Uploaded
avmesos_airflow_provider-0.4.0.tar.gz 54.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for avmesos-airflow-provider 0.4.0
File Interpreter ABI Platform
avmesos_airflow_provider-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 70.2 kB

Release files / avmesos_airflow_provider-0.4.0.tar.gz

Download URL avmesos_airflow_provider-0.4.0.tar.gz
Size 54.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b6fd7e273a2a351ada073fd330982bb43c28c3b360397580eea616e8a677ed54
BLAKE2b-256 checksum
How to use checksums
6dec400879a965d2ec2f0db1612947b4dd05943add7561e142c02d369317ff7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / avmesos_airflow_provider-0.4.0-py3-none-any.whl

Download URL avmesos_airflow_provider-0.4.0-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78ffda3840cec337a8ac46fbe51c015e5e96a2196e2e81eb0e001ae35bc2ee8f
BLAKE2b-256 checksum
How to use checksums
1e86dc4785a9631041beadd7aa3d6a7f530699f93317a50b61ccee1a2f2522fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page