Skip to content

Commit

Permalink
add service pre condition
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondavindev committed Nov 25, 2021
1 parent 9d26597 commit d3e8051
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
35 changes: 35 additions & 0 deletions airflow/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@ function bootstrap {
done
}

function wait_for_it()
{
local serviceport=$1
local service=${serviceport%%:*}
local port=${serviceport#*:}
local retry_seconds=5
local max_try=100
let i=1

nc -z $service $port
result=$?

until [ $result -eq 0 ]; do
echo "[$i/$max_try] check for ${service}:${port}..."
echo "[$i/$max_try] ${service}:${port} is not available yet"
if (( $i == $max_try )); then
echo "[$i/$max_try] ${service}:${port} is still not available; giving up after ${max_try} tries. :/"
exit 1
fi

echo "[$i/$max_try] try in ${retry_seconds}s once again ..."
let "i++"
sleep $retry_seconds

nc -z $service $port
result=$?
done
echo "[$i/$max_try] $service:${port} is available."
}

for i in ${SERVICE_PRECONDITION[@]}
do
wait_for_it ${i}
done

case "$1" in
webserver)
bootstrap
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ x-airflow-common: &airflow-common
HDFS_PORT: "8020"
INGESTION_API_URL: "http://api:3000"
SCRIPTS_PATH_PREFIX: /scripts/spark/
SERVICE_PRECONDITION: airflow-db:5432
depends_on:
- airflow-db

Expand Down Expand Up @@ -77,6 +78,7 @@ services:
command: "hive --service metastore"
environment:
NODE_TYPE: metastore
SERVICE_PRECONDITION: hive-postgres:5432 namenode:50070
ports:
- 9083:9083

Expand Down
35 changes: 35 additions & 0 deletions hadoop/docker/hive/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
#!/bin/bash
function wait_for_it()
{
local serviceport=$1
local service=${serviceport%%:*}
local port=${serviceport#*:}
local retry_seconds=5
local max_try=100
let i=1

nc -z $service $port
result=$?

until [ $result -eq 0 ]; do
echo "[$i/$max_try] check for ${service}:${port}..."
echo "[$i/$max_try] ${service}:${port} is not available yet"
if (( $i == $max_try )); then
echo "[$i/$max_try] ${service}:${port} is still not available; giving up after ${max_try} tries. :/"
exit 1
fi

echo "[$i/$max_try] try in ${retry_seconds}s once again ..."
let "i++"
sleep $retry_seconds

nc -z $service $port
result=$?
done
echo "[$i/$max_try] $service:${port} is available."
}

for i in ${SERVICE_PRECONDITION[@]}
do
wait_for_it ${i}
done

if [ ! -f populated -a "$NODE_TYPE" == "metastore" ]; then
schematool -dbType postgres -initSchema
touch populated
Expand Down
2 changes: 2 additions & 0 deletions kubernetes/airflow/scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ spec:
value: airflow-postgres-svc.airflow.svc.cluster.local
- name: POSTGRES_PORT
value: "5432"
- name: SERVICE_PRECONDITION
value: airflow-postgres-svc.airflow.svc.cluster.local:5432
- name: EXECUTOR
value: KubernetesExecutor
- name: HDFS_HOST
Expand Down
2 changes: 2 additions & 0 deletions kubernetes/airflow/webserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ spec:
value: airflow-postgres-svc.airflow.svc.cluster.local
- name: POSTGRES_PORT
value: "5432"
- name: SERVICE_PRECONDITION
value: airflow-postgres-svc.airflow.svc.cluster.local:5432
- name: EXECUTOR
value: KubernetesExecutor
- name: HDFS_HOST
Expand Down
2 changes: 2 additions & 0 deletions kubernetes/hive/metastore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ spec:
env:
- name: NODE_TYPE
value: metastore
- name: SERVICE_PRECONDITION
value: hive-postgres-svc.dataplatform.svc.cluster.local:5432 namenode-svc.dataplatform.svc.cluster.local:50070
args:
- "bash"
- "-c"
Expand Down

0 comments on commit d3e8051

Please sign in to comment.