2021-10-09 23:28:33 +05:30
#!/bin/bash
2021-12-01 12:46:28 +05:30
# Copyright 2021 Collate
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2021-10-09 23:28:33 +05:30
2025-09-26 15:30:15 +02:00
RED = '\033[0;31m'
2022-08-31 21:30:24 +02:00
cd " $( dirname " ${ BASH_SOURCE [0] } " ) " || exit
2022-07-26 17:47:03 +02:00
2022-08-31 21:30:24 +02:00
helpFunction( )
{
echo ""
echo " Usage: $0 -m mode -d database "
2024-01-11 14:23:33 +05:30
echo "\t-m Running mode: [ui, no-ui]. Default [ui]\n"
echo "\t-d Database: [mysql, postgresql]. Default [mysql]\n"
echo "\t-s Skip maven build: [true, false]. Default [false]\n"
echo "\t-x Open JVM debug port on 5005: [true, false]. Default [false]\n"
echo "\t-h For usage help\n"
echo "\t-r For Cleaning DB Volumes. [true, false]. Default [true]\n"
2022-08-31 21:30:24 +02:00
exit 1 # Exit script after printing help
}
2023-06-26 15:44:53 +05:30
while getopts "m:d:s:x:r:h" opt
2022-08-31 21:30:24 +02:00
do
case " $opt " in
m ) mode = " $OPTARG " ; ;
d ) database = " $OPTARG " ; ;
s ) skipMaven = " $OPTARG " ; ;
2022-10-10 22:43:15 -07:00
x ) debugOM = " $OPTARG " ; ;
2022-11-18 18:35:33 +05:30
r ) cleanDbVolumes = " $OPTARG " ; ;
2022-08-31 21:30:24 +02:00
h ) helpFunction ; ;
? ) helpFunction ; ;
esac
done
mode = " ${ mode : =ui } "
database = " ${ database : =mysql } "
skipMaven = " ${ skipMaven : =false } "
2022-10-10 22:43:15 -07:00
debugOM = " ${ debugOM : =false } "
2022-09-23 23:52:28 +05:30
authorizationToken = "eyJraWQiOiJHYjM4OWEtOWY3Ni1nZGpzLWE5MmotMDI0MmJrOTQzNTYiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlzQm90IjpmYWxzZSwiaXNzIjoib3Blbi1tZXRhZGF0YS5vcmciLCJpYXQiOjE2NjM5Mzg0NjIsImVtYWlsIjoiYWRtaW5Ab3Blbm1ldGFkYXRhLm9yZyJ9.tS8um_5DKu7HgzGBzS1VTA5uUjKWOCU0B_j08WXBiEC0mr0zNREkqVfwFDD-d24HlNEbrqioLsBuFRiwIWKc1m_ZlVQbG7P36RUxhuv2vbSp80FKyNM-Tj93FDzq91jsyNmsQhyNv_fNr3TXfzzSPjHt8Go0FMMP66weoKMgW2PbXlhVKwEuXUHyakLLzewm9UMeQaEiRzhiTMU3UkLXcKbYEJJvfNFcLwSl9W8JCO_l0Yj3ud-qt_nQYEZwqW6u5nfdQllN133iikV4fM5QZsMCnm8Rq1mvLR0y9bmJiD7fwM1tmJ791TUWqmKaTnP49U493VanKpUAfzIiOiIbhg"
2023-06-26 15:44:53 +05:30
cleanDbVolumes = " ${ cleanDbVolumes : =true } "
2022-08-31 21:30:24 +02:00
2023-06-26 15:44:53 +05:30
echo " Running local docker using mode [ $mode ] database [ $database ] and skipping maven build [ $skipMaven ] with cleanDB as [ $cleanDbVolumes ] "
2022-08-31 21:30:24 +02:00
cd ../
2023-06-12 15:51:05 +05:30
echo "Stopping any previous Local Docker Containers"
2024-10-15 16:29:43 +02:00
docker compose -f docker/development/docker-compose-postgres.yml down --remove-orphans
docker compose -f docker/development/docker-compose.yml down --remove-orphans
2023-06-12 15:51:05 +05:30
2022-08-31 21:30:24 +02:00
if [ [ $skipMaven = = "false" ] ] ; then
if [ [ $mode = = "no-ui" ] ] ; then
echo "Maven Build - Skipping Tests and UI"
2024-09-20 19:30:06 +05:30
mvn -DskipTests -DonlyBackend clean package -pl !openmetadata-ui
2022-08-31 21:30:24 +02:00
else
echo "Maven Build - Skipping Tests"
2024-09-20 19:30:06 +05:30
mvn -DskipTests clean package
2022-08-31 21:30:24 +02:00
fi
2022-07-26 17:47:03 +02:00
else
2022-08-31 21:30:24 +02:00
echo "Skipping Maven Build"
2022-07-26 17:47:03 +02:00
fi
2022-12-23 17:33:30 +01:00
RESULT = $?
if [ $RESULT -ne 0 ] ; then
echo "Failed to run Maven build!"
exit 1
fi
2022-08-31 21:30:24 +02:00
2022-10-10 22:43:15 -07:00
if [ [ $debugOM = = "true" ] ] ; then
export OPENMETADATA_DEBUG = true
fi
2022-11-18 18:35:33 +05:30
if [ [ $cleanDbVolumes = = "true" ] ]
then
2023-06-26 15:44:53 +05:30
if [ [ -d " $PWD /docker/development/docker-volume/ " ] ]
2022-11-18 18:35:33 +05:30
then
2023-06-26 15:44:53 +05:30
rm -rf $PWD /docker/development/docker-volume
2022-11-18 18:35:33 +05:30
fi
fi
2022-11-22 11:19:22 +05:30
2022-12-23 17:33:30 +01:00
if [ [ $VIRTUAL_ENV = = "" ] ] ;
then
echo "Please Use Virtual Environment and make sure to generate Pydantic Models" ;
2022-11-22 11:19:22 +05:30
else
2022-12-23 17:33:30 +01:00
echo "Generating Pydantic Models" ;
2022-11-22 11:19:22 +05:30
make install_dev generate
fi
2022-08-31 21:30:24 +02:00
2021-11-13 00:00:28 +05:30
echo "Starting Local Docker Containers"
2022-08-31 19:01:00 +02:00
echo " Using ingestion dependency: ${ INGESTION_DEPENDENCY :- all } "
2022-08-31 21:30:24 +02:00
if [ [ $database = = "postgresql" ] ] ; then
2023-03-06 08:58:53 -08:00
docker compose -f docker/development/docker-compose-postgres.yml build --build-arg INGESTION_DEPENDENCY = " ${ INGESTION_DEPENDENCY :- all } " && docker compose -f docker/development/docker-compose-postgres.yml up -d
2024-03-12 06:23:05 +01:00
elif [ [ $database = = "mysql" ] ] ; then
2023-03-06 08:58:53 -08:00
docker compose -f docker/development/docker-compose.yml build --build-arg INGESTION_DEPENDENCY = " ${ INGESTION_DEPENDENCY :- all } " && docker compose -f docker/development/docker-compose.yml up -d
2024-03-12 06:23:05 +01:00
else
echo " Invalid database type: $database "
exit 1
2022-08-31 21:30:24 +02:00
fi
2022-03-28 11:08:13 +05:30
2022-12-23 17:33:30 +01:00
RESULT = $?
if [ $RESULT -ne 0 ] ; then
echo "Failed to start Docker instances!"
exit 1
fi
2024-08-10 23:56:49 +05:30
until curl -s -f "http://localhost:9200/_cat/indices/openmetadata_team_search_index" ; do
2024-01-11 14:23:33 +05:30
echo 'Checking if Elastic Search instance is up...\n'
2022-03-28 11:08:13 +05:30
sleep 5
done
2022-12-23 17:33:30 +01:00
2025-11-21 16:58:28 +05:30
# Function to get OAuth access token for Airflow API
get_airflow_token( ) {
local token_response = $( curl -s -X POST 'http://localhost:8080/auth/token' \
-H 'Content-Type: application/json' \
-d '{"username": "admin", "password": "admin"}' )
local access_token = $( echo " $token_response " | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('access_token', ''))" 2>/dev/null || echo "" )
if [ -z " $access_token " ] ; then
echo "✗ Failed to get access token" >& 2
echo " Response: ${ token_response } " >& 2
return 1
fi
echo " $access_token "
}
# Wait for Airflow API to be ready and get initial token
echo "Waiting for Airflow API to be ready..."
until AIRFLOW_ACCESS_TOKEN = $( get_airflow_token) 2>/dev/null && [ -n " $AIRFLOW_ACCESS_TOKEN " ] ; do
echo 'Checking if Airflow API is reachable...'
sleep 5
done
echo "✓ Airflow API is ready, token obtained"
# Check if sample_data DAG is available
echo "Checking if Sample Data DAG is available..."
until curl -s -f -H " Authorization: Bearer $AIRFLOW_ACCESS_TOKEN " "http://localhost:8080/api/v2/dags/sample_data" >/dev/null 2>& 1; do
# Check for import errors
IMPORT_ERRORS = $( curl -s -H " Authorization: Bearer $AIRFLOW_ACCESS_TOKEN " "http://localhost:8080/api/v2/importErrors" 2>/dev/null)
if [ -n " $IMPORT_ERRORS " ] ; then
echo " $IMPORT_ERRORS " | grep "/airflow_sample_data.py" > /dev/null 2>& 1
if [ " $? " = = "0" ] ; then
echo -e " ${ RED } Airflow found an error importing \`sample_data\` DAG "
echo " $IMPORT_ERRORS " | python3 -c "import sys, json; data=json.load(sys.stdin); [print(json.dumps(e, indent=2)) for e in data.get('import_errors', []) if e.get('filename', '').endswith('airflow_sample_data.py')]" 2>/dev/null || echo " $IMPORT_ERRORS "
exit 1
fi
2025-09-26 15:30:15 +02:00
fi
2025-11-21 16:58:28 +05:30
echo 'Checking if Sample Data DAG is reachable...'
2024-01-11 14:23:33 +05:30
sleep 5
2025-11-21 16:58:28 +05:30
# Refresh token if needed (tokens expire after 24h)
AIRFLOW_ACCESS_TOKEN = $( get_airflow_token) 2>/dev/null
2024-01-11 14:23:33 +05:30
done
2025-11-21 16:58:28 +05:30
echo "✓ Sample Data DAG is available"
2024-01-11 14:23:33 +05:30
until curl -s -f --header " Authorization: Bearer $authorizationToken " "http://localhost:8585/api/v1/tables" ; do
echo 'Checking if OM Server is reachable...\n'
2022-03-28 11:08:13 +05:30
sleep 5
done
2022-12-23 17:33:30 +01:00
2025-11-21 16:58:28 +05:30
# Function to unpause DAG using Airflow API with OAuth Bearer token
unpause_dag( ) {
local dag_id = $1
echo " Unpausing DAG: ${ dag_id } "
# Get fresh token if not already set
if [ -z " $AIRFLOW_ACCESS_TOKEN " ] ; then
AIRFLOW_ACCESS_TOKEN = $( get_airflow_token)
if [ -z " $AIRFLOW_ACCESS_TOKEN " ] ; then
return 1
fi
echo "✓ OAuth token obtained"
fi
response = $( curl -s -w "\n%{http_code}" --location --request PATCH " http://localhost:8080/api/v2/dags/ ${ dag_id } " \
--header " Authorization: Bearer $AIRFLOW_ACCESS_TOKEN " \
--header 'Content-Type: application/json' \
--data-raw '{"is_paused": false}' )
2022-07-18 14:44:50 +02:00
2025-11-21 16:58:28 +05:30
http_code = $( echo " $response " | tail -n1)
body = $( echo " $response " | sed '$d' )
if [ " $http_code " = "200" ] || [ " $http_code " = "201" ] ; then
echo " ✓ Successfully unpaused ${ dag_id } "
else
echo " ✗ Failed to unpause ${ dag_id } (HTTP ${ http_code } ) "
echo " Response: ${ body } "
# Token might be expired, try refreshing once
if [ " $http_code " = "401" ] ; then
echo " Refreshing token and retrying..."
AIRFLOW_ACCESS_TOKEN = $( get_airflow_token)
if [ -n " $AIRFLOW_ACCESS_TOKEN " ] ; then
response = $( curl -s -w "\n%{http_code}" --location --request PATCH " http://localhost:8080/api/v2/dags/ ${ dag_id } " \
--header " Authorization: Bearer $AIRFLOW_ACCESS_TOKEN " \
--header 'Content-Type: application/json' \
--data-raw '{"is_paused": false}' )
http_code = $( echo " $response " | tail -n1)
if [ " $http_code " = "200" ] || [ " $http_code " = "201" ] ; then
echo " ✓ Successfully unpaused ${ dag_id } after retry "
fi
fi
fi
fi
}
unpause_dag "sample_data"
unpause_dag "extended_sample_data"
# Trigger sample_data DAG to run
echo "Triggering sample_data DAG..."
LOGICAL_DATE = $( date -u +"%Y-%m-%dT%H:%M:%SZ" )
response = $( curl -s -w "\n%{http_code}" -X POST "http://localhost:8080/api/v2/dags/sample_data/dagRuns" \
--header " Authorization: Bearer $AIRFLOW_ACCESS_TOKEN " \
2024-01-11 14:23:33 +05:30
--header 'Content-Type: application/json' \
2025-11-21 16:58:28 +05:30
--data-raw " {\"logical_date\": \" $LOGICAL_DATE \"} " )
http_code = $( echo " $response " | tail -n1)
if [ " $http_code " = "200" ] || [ " $http_code " = "201" ] ; then
echo "✓ Successfully triggered sample_data DAG"
else
echo " ⚠ Could not trigger sample_data DAG (HTTP ${ http_code } ) "
echo " Response: $( echo " $response " | sed '$d' ) "
echo " Note: DAG may run automatically on schedule"
fi
2024-01-11 14:23:33 +05:30
echo 'Validate sample data DAG...'
2022-07-18 14:44:50 +02:00
sleep 5
2024-04-11 14:30:40 +02:00
# This validates the sample data DAG flow
make install
2025-11-21 16:58:28 +05:30
# Run validation with timeout to avoid hanging indefinitely
echo "Running DAG validation (this may take a few minutes)..."
timeout 300 python docker/validate_compose.py || {
exit_code = $?
if [ $exit_code -eq 124 ] ; then
echo "⚠ Warning: DAG validation timed out after 5 minutes"
echo " The DAG may still be running. Check Airflow UI at http://localhost:8080"
else
echo " ⚠ Warning: DAG validation failed with exit code $exit_code "
fi
echo " Continuing with remaining setup..."
}
2022-07-18 14:44:50 +02:00
2022-03-28 11:08:13 +05:30
sleep 5
2025-11-21 16:58:28 +05:30
unpause_dag "sample_usage"
2022-03-28 11:08:13 +05:30
sleep 5
2025-11-21 16:58:28 +05:30
unpause_dag "index_metadata"
2022-03-28 11:08:13 +05:30
sleep 2
2025-11-21 16:58:28 +05:30
unpause_dag "sample_lineage"
2024-01-11 14:23:33 +05:30
2023-06-22 16:55:05 +05:30
echo "✔running reindexing"
# Trigger ElasticSearch ReIndexing from UI
2023-10-10 17:05:07 +05:30
curl --location --request POST 'http://localhost:8585/api/v1/apps/trigger/SearchIndexingApplication' \
--header 'Authorization: Bearer eyJraWQiOiJHYjM4OWEtOWY3Ni1nZGpzLWE5MmotMDI0MmJrOTQzNTYiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlzQm90IjpmYWxzZSwiaXNzIjoib3Blbi1tZXRhZGF0YS5vcmciLCJpYXQiOjE2NjM5Mzg0NjIsImVtYWlsIjoiYWRtaW5Ab3Blbm1ldGFkYXRhLm9yZyJ9.tS8um_5DKu7HgzGBzS1VTA5uUjKWOCU0B_j08WXBiEC0mr0zNREkqVfwFDD-d24HlNEbrqioLsBuFRiwIWKc1m_ZlVQbG7P36RUxhuv2vbSp80FKyNM-Tj93FDzq91jsyNmsQhyNv_fNr3TXfzzSPjHt8Go0FMMP66weoKMgW2PbXlhVKwEuXUHyakLLzewm9UMeQaEiRzhiTMU3UkLXcKbYEJJvfNFcLwSl9W8JCO_l0Yj3ud-qt_nQYEZwqW6u5nfdQllN133iikV4fM5QZsMCnm8Rq1mvLR0y9bmJiD7fwM1tmJ791TUWqmKaTnP49U493VanKpUAfzIiOiIbhg'
2023-06-22 16:55:05 +05:30
sleep 60 # Sleep for 60 seconds to make sure the elasticsearch reindexing from UI finishes
2022-03-28 11:08:13 +05:30
tput setaf 2
echo "✔ OpenMetadata is up and running"