forked from RealImpactAnalytics/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5455fbc
commit f991783
Showing
26 changed files
with
184 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,81 @@ | ||
from ConfigParser import ConfigParser | ||
import errno | ||
import logging | ||
import os | ||
|
||
from ConfigParser import ConfigParser, NoOptionError, NoSectionError | ||
|
||
class AirflowConfigParser(ConfigParser): | ||
NO_DEFAULT = object() | ||
_instance = None | ||
_config_paths = ['airflow.cfg'] | ||
if 'AIRFLOW_CONFIG_PATH' in os.environ: | ||
_config_paths.append(os.environ['AIRFLOW_CONFIG_PATH']) | ||
logging.info("Config paths is " + str(_config_paths)) | ||
|
||
@classmethod | ||
def add_config_paths(cls, path): | ||
cls._config_paths.append(path) | ||
cls.reload() | ||
|
||
@classmethod | ||
def instance(cls, *args, **kwargs): | ||
if cls._instance is None: | ||
cls._instance = cls(*args, **kwargs) | ||
cls._instance.reload() | ||
|
||
return cls._instance | ||
|
||
@classmethod | ||
def reload(cls): | ||
loaded_obj = cls.instance().read(cls._config_paths) | ||
logging.info("the config object after loading is " + str(loaded_obj)) | ||
return loaded_obj | ||
|
||
def get_with_default(self, method, section, option, default): | ||
try: | ||
return method(self, section, option) | ||
except (NoOptionError, NoSectionError): | ||
if default is AirflowConfigParser.NO_DEFAULT: | ||
raise | ||
return default | ||
|
||
def get(self, section, option, default=NO_DEFAULT): | ||
return self.get_with_default(ConfigParser.get, section, option, default) | ||
|
||
def getint(self, section, option, default=NO_DEFAULT): | ||
return self.get_with_default(ConfigParser.getint, section, option, default) | ||
|
||
def getboolean(self, section, option, default=NO_DEFAULT): | ||
return self.get_with_default(ConfigParser.getboolean, section, option, default) | ||
|
||
def set(self, section, option, value): | ||
if not ConfigParser.has_section(self, section): | ||
ConfigParser.add_section(self, section) | ||
return ConfigParser.set(self, section, option, value) | ||
|
||
def getconf(): | ||
return AirflowConfigParser.instance() | ||
|
||
conf = getconf() | ||
DEFAULT_CONFIG = """\ | ||
[core] | ||
airflow_home = {AIRFLOW_HOME} | ||
authenticate = False | ||
dags_folder = {AIRFLOW_HOME}/dags | ||
base_folder = {AIRFLOW_HOME}/airflow | ||
base_url = http://localhost:8080 | ||
executor = LocalExecutor | ||
sql_alchemy_conn = sqlite:///{AIRFLOW_HOME}/airflow.db | ||
[server] | ||
web_server_host = 0.0.0.0 | ||
web_server_port = 8080 | ||
[smtp] | ||
smtp_host = localhost | ||
smtp_user = airflow | ||
smtp_port = 25 | ||
smtp_password = airflow | ||
smtp_mail_from = [email protected] | ||
[celery] | ||
celery_app_name = airflow.executors.celery_executor | ||
celeryd_concurrency = 16 | ||
worker_log_server_port = 8793 | ||
broker_url = sqla+mysql://airflow:airflow@localhost:3306/airflow | ||
celery_result_backend = db+mysql://airflow:airflow@localhost:3306/airflow | ||
[hooks] | ||
presto_default_conn_id = presto_default | ||
hive_default_conn_id = hive_default | ||
[misc] | ||
job_heartbeat_sec = 5 | ||
id_len = 250 | ||
""" | ||
|
||
def mkdir_p(path): | ||
try: | ||
os.makedirs(path) | ||
except OSError as exc: # Python >2.5 | ||
if exc.errno == errno.EEXIST and os.path.isdir(path): | ||
pass | ||
else: raise | ||
|
||
''' | ||
Setting AIRFLOW_HOME and AIRFLOW_CONFIG from environment variables, using | ||
"~/airflow" and "~/airflow/airflow.cfg" repectively as defaults. | ||
''' | ||
|
||
if 'AIRFLOW_HOME' not in os.environ: | ||
AIRFLOW_HOME = os.path.expanduser('~/airflow') | ||
else: | ||
AIRFLOW_HOME = os.environ['AIRFLOW_HOME'] | ||
|
||
mkdir_p(AIRFLOW_HOME) | ||
|
||
if 'AIRFLOW_CONFIG' not in os.environ: | ||
AIRFLOW_CONFIG = AIRFLOW_HOME + '/airflow.cfg' | ||
else: | ||
AIRFLOW_CONFIG = os.environ['AIRFLOW_CONFIG'] | ||
|
||
conf = ConfigParser() | ||
if not os.path.isfile(AIRFLOW_CONFIG): | ||
''' | ||
These configuration are used to generate a default configuration when | ||
it is missing. The right way to change your configuration is to alter your | ||
configuration file, not this code. | ||
''' | ||
logging.info("Createing new config file in: " + AIRFLOW_CONFIG) | ||
f = open(AIRFLOW_CONFIG, 'w') | ||
f.write(DEFAULT_CONFIG.format(**locals())) | ||
f.close() | ||
|
||
logging.info("Reading the config from " + AIRFLOW_CONFIG) | ||
conf.read(AIRFLOW_CONFIG) |
File renamed without changes.
34 changes: 20 additions & 14 deletions
34
dags/examples/example1.py → airflow/example_dags/example1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,57 @@ | ||
from airflow.operators import BashOperator, MySqlOperator, DummyOperator | ||
from airflow.models import DAG | ||
from airflow.executors import SequentialExecutor | ||
from airflow.executors import LocalExecutor | ||
from datetime import datetime | ||
|
||
default_args = { | ||
'owner': 'max', | ||
'start_date': datetime(2014, 11, 1), | ||
'mysql_dbid': 'local_mysql', | ||
'mysql_conn_id': 'local_mysql', | ||
} | ||
|
||
dag = DAG(dag_id='example_1', executor=LocalExecutor()) | ||
dag = DAG(dag_id='example_1') | ||
# dag = DAG(dag_id='example_1', executor=SequentialExecutor()) | ||
|
||
cmd = 'ls -l' | ||
run_this_last = DummyOperator( | ||
task_id='run_this_last', | ||
**default_args) | ||
default_args=default_args) | ||
dag.add_task(run_this_last) | ||
|
||
run_this = BashOperator( | ||
task_id='run_after_loop', bash_command='echo 1', **default_args) | ||
task_id='run_after_loop', bash_command='echo 1', | ||
default_args=default_args) | ||
dag.add_task(run_this) | ||
run_this.set_downstream(run_this_last) | ||
|
||
for i in range(9): | ||
i = str(i) | ||
task = BashOperator( | ||
task_id='runme_'+i, | ||
bash_command='sleep 20', | ||
**default_args) | ||
task_id='runme_'+i, | ||
bash_command='sleep 20', | ||
default_args=default_args) | ||
task.set_downstream(run_this) | ||
dag.add_task(task) | ||
|
||
task = BashOperator( | ||
task_id='also_run_this', bash_command='ls -l', **default_args) | ||
task_id='also_run_this', | ||
bash_command='ls -l', | ||
default_args=default_args) | ||
dag.add_task(task) | ||
task.set_downstream(run_this_last) | ||
|
||
sql = "CREATE TABLE IF NOT EXISTS deleteme (col INT);" | ||
create_table = MySqlOperator( | ||
task_id='create_table_mysql', sql=sql, **default_args) | ||
task_id='create_table_mysql', | ||
sql=sql, | ||
default_args=default_args) | ||
dag.add_task(create_table) | ||
|
||
''' | ||
sql = "INSERT INTO deleteme SELECT 1;" | ||
task = MySqlOperator(task_id='also_run_mysql', sql=sql, **default_args) | ||
task = MySqlOperator(task_id='also_run_mysql', | ||
sql=sql, | ||
default_args=default_args) | ||
dag.add_task(task) | ||
task.set_downstream(run_this_last) | ||
task.set_upstream(create_table) | ||
|
||
''' |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.