Skip to content

Commit e7da37f

Browse files
authored
Merge pull request #7 from teamclairvoyant/feature
Feature
2 parents 11b39eb + f648476 commit e7da37f

File tree

5 files changed

+167
-8
lines changed

5 files changed

+167
-8
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
target/
22
*.swp
3+
.gitignore
4+
*.DS_Store
5+
.idea/*
6+
*.iml

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ This repository allows you to install [Apache Airflow](https://airflow.apache.or
55
## Requirements
66
- A supported operating system.
77
- MySQL or PostgreSQL database in which to store Airflow metadata.
8+
- RabbitMQ
9+
- [Airflow Parcel](https://github.com/teamclairvoyant/apache-airflow-parcels)
810

911
### Currently Supported Versions of Airflow
10-
- Airflow 1.10
12+
- Airflow 1.9.0
13+
- Airflow 1.10.3
1114

1215
### Currently Supported Operating Systems
1316
- CentOS/RHEL 6 & 7
@@ -56,6 +59,7 @@ create_postgresql_dbs-airflow.sh --host <host_name> --user <username> --password
5659
```
5760

5861
## Roles
62+
5963
There are six roles available for deployment:
6064

6165
1. Webserver
@@ -132,19 +136,16 @@ Update the `version` file before running `make dist` if creating a new release.
132136
2. Only 'airflow.contrib.auth.backends.password_auth' mechanism is supported for Airflow user authentication.
133137

134138
## Future work:
135-
1. Test Database connection.
136-
2. Add the support for more Airflow user authentication methods.
139+
1. Build RabbitMQ parcel.
140+
2. Test Database connection.
141+
3. Add the support for more Airflow user authentication methods.
137142

138143
## Known Errors:
139144

140145
### Markup already exists Error:
141146

142147
Upon many deployments, you may face an error called 'Markup file already exists' while trying to stop a role and the process never stops. In that case, stop the process using the "Abort" command and navigate to `/var/run/cloudera-scm-agent/process` and delete all the `GracefulRoleStopRunner` directories.
143148

144-
### Lag in DAG Execution:
145-
146-
Occasionally, we experienced some delay in DAG execution. We are working to fix this.
147-
148149
## Resources:
149150
1. https://github.com/teamclairvoyant/apache-airflow-parcels
150151
2. https://github.com/cloudera/cm_ext/wiki/The-Structure-of-a-CSD

src/descriptor/service.sdl

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{
1515
"name" : "AIRFLOW",
1616
"label" : "Airflow",
17-
"description" : "Airflow is a platform to programmatically author, schedule and monitor workflows. <span class=\"error\">Before adding this service, ensure that the Airflow parcel has been activated.</span>",
17+
"description" : "Airflow is a platform to programmatically author, schedule and monitor workflows. <span class=\"error\">Before adding this service, please ensure that the Airflow parcel is activated and RabbitMQ is installed</span>",
1818
"version" : "{{ version }}",
1919
"runAs" : {
2020
"user" : "root",
@@ -136,6 +136,22 @@
136136
"type" : "string",
137137
"default" : ""
138138
},
139+
{
140+
"name" : "Airflow.password",
141+
"label" : "Airflow Password",
142+
"description" : "Password of the Airflow user.",
143+
"type" : "password",
144+
"default" : ""
145+
},
146+
{
147+
"name" : "broker_url",
148+
"label" : "Broker URL",
149+
"description" : "Broker URL value for Celery ",
150+
"type" : "string",
151+
"default" : "sqla+mysql://username:password@host:3306/dbname",
152+
"configurableInWizard": true,
153+
"required" : "true"
154+
},
139155
{
140156
"name" : "celery_broker_port",
141157
"label" : "Celery Broker Port",
@@ -483,6 +499,40 @@
483499
"program" : "scripts/control.sh",
484500
"args" : [ "client" ],
485501
"environmentVariables" : {
502+
"dbType" : "${dbType}",
503+
"dbHost" : "${dbHost}",
504+
"dbUser" : "${dbUser}",
505+
"dbName" : "${dbName}",
506+
"dbPort" : "${dbPort}",
507+
"dbPass" : "${dbPass}",
508+
"broker_url": "${broker_url}",
509+
"authenticate" : "${Airflow.authenticate}",
510+
"AIRFLOW_USER" : "${Airflow.username}",
511+
"AIRFLOW_PASS" : "${Airflow.password}",
512+
"AIRFLOW_EMAIL" : "${Airflow.email}",
513+
"airflow_home" : "${airflow_home}",
514+
"AIRFLOW_HOME" : "${airflow_home}",
515+
"dags_folder" : "${dags_folder}",
516+
"base_log_folder" : "${base_log_folder}",
517+
"remote_base_log_folder" : "${remote_base_log_folder}",
518+
"remote_log_conn_id" : "${remote_log_conn_id}",
519+
"encrypt_s3_logs" : "${encrypt_s3_logs}",
520+
"executor" : "${executor}",
521+
"sql_alchemy_pool_size" : "${sql_alchemy_pool_size}",
522+
"sql_alchemy_pool_recycle" : "${sql_alchemy_pool_recycle}",
523+
"parallelism" : "${parallelism}",
524+
"dag_concurrency" : "${dag_concurrency}",
525+
"dags_are_paused_at_creation" : "${dags_are_paused_at_creation}",
526+
"non_pooled_task_slot_count" : "${non_pooled_task_slot_count}",
527+
"max_active_runs_per_dag" : "${max_active_runs_per_dag}",
528+
"default_owner" : "${default_owner}",
529+
"web_server_port" : "${web_server_port}",
530+
"security" : "${security}",
531+
"keytab" : "${keytab}",
532+
"reinit_frequency" : "${reinit_frequency}",
533+
"principal" : "${principal}",
534+
"expose_config" : "${expose_config}",
535+
"load_examples" : "${load_examples}"
486536
"AIRFLOW_CONFIG" : "/etc/airflow/conf/airflow.cfg",
487537
"DB_PASS" : "${database_password}",
488538
"CELERY_BROKER_PASS" : "${celery_broker_password}"
@@ -811,6 +861,11 @@
811861
}
812862
]
813863
},
864+
"stopRunner" : {
865+
"runner" : {
866+
"program" : "scripts/stop_airflow_scheduler.sh"
867+
}
868+
},
814869
"parameters" : [
815870
{
816871
"name" : "job_heartbeat_sec",

src/scripts/stop_airflow_scheduler.sh

100755100644
File mode changed.

src/scripts/update_cfg.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
3+
4+
# Creating the AIRFLOW_HOME directory
5+
if [ ! -d ${airflow_home} ]; then
6+
mkdir -p ${airflow_home}
7+
chown -R airflow:airflow ${airflow_home}
8+
fi
9+
10+
# Creating the Airflow log directory
11+
if [ ! -d ${base_log_folder} ]; then
12+
mkdir -p ${base_log_folder}
13+
chown -R airflow:airflow ${base_log_folder}
14+
fi
15+
16+
# Creating dags folder
17+
if [ ! -d ${dags_folder} ]; then
18+
mkdir -p ${dags_folder}
19+
chown -R airflow:airflow ${dags_folder}
20+
chmod 775 ${dags_folder}
21+
fi
22+
23+
# Initializing the Airflow database if not existed
24+
if [ ! -f ${airflow_home}/airflow.cfg ]; then
25+
sudo -Eu airflow bash -c 'export PATH=${AIRFLOW_DIR}/usr/bin:$PATH;
26+
exec airflow initdb'
27+
fi
28+
29+
# Building connection string
30+
if [ "$dbType" == "mysql" ]; then
31+
sql_alchemy_conn="mysql://${dbUser}:${dbPass}@${dbHost}:${dbPort}/${dbName}"
32+
elif [ "$dbType" == "postgresql" ]; then
33+
sql_alchemy_conn="postgresql+psycopg2://${dbUser}:${dbPass}@${dbHost}:${dbPort}/${dbName}"
34+
fi
35+
36+
echo $sql_alchemy_conn
37+
38+
# Updating airflow.cfg
39+
40+
#broker_url="amqp://${RABBITMQ_USER}:${RABBITMQ_PASS}@${RABBITMQ_HOST}:${RABBITMQ_PORT}/"
41+
celery_result_backend="db+${sql_alchemy_conn}"
42+
43+
PWCMD='< /dev/urandom tr -dc A-Za-z0-9 | head -c 20;echo'
44+
secret_key=`eval $PWCMD`
45+
46+
function replace {
47+
sed -i "s#${1}#${2}#g" $3
48+
}
49+
50+
function remove_line {
51+
sed -i "/${1}/d" $2
52+
}
53+
54+
echo "Updating airflow.cfg..."
55+
auth_backend_flag=false
56+
auth_backend=airflow.contrib.auth.backends.password_auth
57+
58+
# Updating airflow.cfg
59+
while read line; do
60+
key=$(cut -d "=" -f1 <<< "$line" | xargs)
61+
value=$(cut -d "=" -f2 <<< "$line")
62+
if [[ ${!key} ]]; then
63+
if [[ "$key" != "#" ]]; then
64+
if [[ "$key" == "authenticate" ]]; then
65+
replace "$key =${value}" "$key = ${!key}\nauth_backend = airflow.contrib.auth.backends.password_auth" ${airflow_home}/airflow.cfg
66+
elif [[ "$key" == "auth_backend" ]]; then
67+
if [[ "$auth_backend_flag" = true ]]; then
68+
sed -i "/auth_backend = airflow.contrib.auth.backends.password_auth/d" ${airflow_home}/airflow.cfg
69+
fi
70+
auth_backend_flag=true
71+
else
72+
replace "$key =${value}" "$key = ${!key}" ${airflow_home}/airflow.cfg
73+
fi
74+
fi
75+
fi
76+
done < ${airflow_home}/airflow.cfg
77+
78+
79+
echo "Creating Airflow user..."
80+
# Creating Airflow User
81+
82+
if [[ ! -z "$AIRFLOW_USER" ]];
83+
then
84+
${AIRFLOW_DIR}/usr/bin/python2.7 ../scripts/mkuser.py $AIRFLOW_USER $AIRFLOW_EMAIL $AIRFLOW_PASS
85+
fi
86+
87+
88+
echo "Updating AIRFLOW_HOME in binaries..."
89+
# Creating the airflow binary
90+
91+
sed -i "1s+.*+export AIRFLOW_HOME=${AIRFLOW_HOME}\n+" ${AIRFLOW_DIR}/bin/airflow.sh
92+
chmod 777 ${AIRFLOW_DIR}/bin/airflow.sh
93+
94+
echo "export PYTHONPATH=${PYTHONPATH}" > /usr/bin/airflow-mkuser
95+
echo "export PATH=${AIRFLOW_DIR}/bin:\$PATH" >> /usr/bin/airflow-mkuser
96+
echo "${AIRFLOW_DIR}/bin/mkuser.sh \$@" >> /usr/bin/airflow-mkuser
97+
98+
99+
echo "update.cfg script ends"

0 commit comments

Comments
 (0)