Skip to content

Commit

Permalink
Merge pull request #779 from Klarrio/elasticsearch_init_reset
Browse files Browse the repository at this point in the history
elasticsearch init script: add mechanism to avoid a reset of the indexes
  • Loading branch information
shintasmith committed Jan 30, 2017
2 parents ad9ad28 + 8f34b92 commit 93e75dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions blueflood-elasticsearch/src/main/resources/init-es.sh
Expand Up @@ -6,21 +6,22 @@
#WARNING: this script will destroy existing ES data and reset it to the proper init state
# Example:
# Local ES: ./init-es.sh
# ES on OR: ./init-es.sh -u <url for OR:ES> -n <username> -p <password>
# ES on OR: ./init-es.sh -u <url for OR:ES> -n <username> -p <password> -r <boolean to reset>

# Set default ES URL
ELASTICSEARCH_URL=http://localhost:9200

usage() {
echo "Usage: $0 [-u <remote ES url:string>(default: localhost:9200)] [-n <username:string>] [-p <password:string>]" 1>&2;
echo "Usage: $0 [-u <remote ES url:string>(default: localhost:9200)] [-n <username:string>] [-p <password:string>] [-r <reset:boolean>(default: true)]" 1>&2;
exit 1
}

while getopts "p:u:n:" o; do
while getopts "p:u:n:r:" o; do
case "${o}" in
p) ES_PASSWD=$OPTARG ;;
u) ELASTICSEARCH_URL=$OPTARG ;;
n) ES_USERNAME=$OPTARG ;;
r) ES_RESET=$OPTARG ;;
*) usage ;;
esac
done
Expand All @@ -42,11 +43,24 @@ function checkFile
fi
}

# Exit initialization script when Blueflood is already initialized in ES and we don't need to reset it
if [ "$ES_RESET" = false ]; then
#verify whether blueflood was already initialized by checking its marker index
BLUEFLOOD_INITIALIZED=$(curl $AUTH -XHEAD --write-out %{http_code} $ELASTICSEARCH_URL'/blueflood_initialized_marker')

if [ $BLUEFLOOD_INITIALIZED = 200 ]; then
echo "ES already initialized for Blueflood. Skipping initialization process."
exit 0
fi
fi


checkFile index_settings.json
checkFile metrics_mapping.json
checkFile events_mapping.json

#delete the old indices
curl $AUTH -XDELETE $ELASTICSEARCH_URL'/blueflood_initialized_marker/' >& /dev/null
curl $AUTH -XDELETE $ELASTICSEARCH_URL'/events/' >& /dev/null
curl $AUTH -XDELETE $ELASTICSEARCH_URL'/metric_metadata/' >& /dev/null
curl $AUTH -XDELETE $ELASTICSEARCH_URL'/metric_metadata_v2/' >& /dev/null
Expand Down Expand Up @@ -85,3 +99,6 @@ curl $AUTH -XPUT $ELASTICSEARCH_URL'/metric_metadata/_mapping/metrics' -d @metri
curl $AUTH -XDELETE $ELASTICSEARCH_URL'/events/_mapping/graphite_event' >& /dev/null
curl $AUTH -XPUT $ELASTICSEARCH_URL'/events/_mapping/graphite_event' -d @events_mapping.json

#mark ES initialized for Blueflood by creating a marker index
curl $AUTH -XPUT $ELASTICSEARCH_URL'/blueflood_initialized_marker'

2 changes: 1 addition & 1 deletion contrib/blueflood-docker/docker-entrypoint.sh
Expand Up @@ -71,7 +71,7 @@ done
export ELASTICSEARCH_HOSTS="$ELASTICSEARCH_HOST:9300"

cd ES-Setup
./init-es.sh -u $ELASTICSEARCH_HOST:9200
./init-es.sh -u $ELASTICSEARCH_HOST:9200 -r false
cd ..

printenv > blueflood.conf
Expand Down

0 comments on commit 93e75dc

Please sign in to comment.