blob: 58a07811e6ef711b153cb9ea98f98205b3608f53 [file] [log] [blame]
waqas.ikrama5aeeda2019-08-07 16:03:14 +00001#!/bin/bash
2#
3# ============LICENSE_START=======================================================
4# Copyright (C) 2019 Nordix Foundation.
5# ================================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# SPDX-License-Identifier: Apache-2.0
19# ============LICENSE_END=========================================================
20#
21
22# @author Waqas Ikram (waqas.ikram@est.tech)
23
24SLEEP_TIME=5
25SUCCESSFUL_TEXT="AAI Simulator Populated Successfully"
26FAILURE_TEXT="ERROR:"
27TIME_OUT_TEXT="Time out"
28CONTAINER_NAME=$(docker ps -aqf "name=populate-aai-config" --format "{{.Names}}")
29SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
30SCRIPT_NAME=$(basename $0)
31
32current_timestamp()
33{
34 date +"%Y-%m-%d %H:%M:%S"
35}
36
37# main body
38if [ -z $TIME_OUT_DEFAULT_VALUE_SEC ]; then
39 echo "$SCRIPT_NAME $(current_timestamp): ERROR: Undefined value for TIME_OUT_DEFAULT_VALUE_SEC attribute"
40 exit 1
41fi
42
43if [ -z $CONTAINER_NAME ]; then
44 echo "$SCRIPT_NAME $(current_timestamp): Unable to find docker container id "
45 exit 1
46fi
47
48START_TIME_IN_SECONDS=`date +%s`
49TIME_OUT_END_TIME_IN_SECONDS=$(($START_TIME_IN_SECONDS+$TIME_OUT_DEFAULT_VALUE_SEC));
50
51
52echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME script Start Time `date -d @$START_TIME_IN_SECONDS`"
53echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME will time out at `date -d @$TIME_OUT_END_TIME_IN_SECONDS`"
54
55while [ `date +%s` -lt "$TIME_OUT_END_TIME_IN_SECONDS" ]; do
56 echo "$(current_timestamp): Waiting for $CONTAINER_NAME to finish ..."
57
58 result=$(docker logs $CONTAINER_NAME 2>&1 | grep -E "$SUCCESSFUL_TEXT|$FAILURE_TEXT|$TIME_OUT_TEXT")
59 if [ ! -z "$result" ]; then
60 echo "$SCRIPT_NAME $(current_timestamp): Found result: $result"
61 break;
62 fi
63 echo "$(current_timestamp): Sleeping for ${SLEEP_TIME} seconds"
64 sleep ${SLEEP_TIME}
65done
66
67if [ -z "$result" ]; then
68 echo "$SCRIPT_NAME $(current_timestamp): ERROR: failed to populate AAI Simulator . . . "
69 echo "-------------- $CONTAINER_NAME logs -------------"
70 docker logs $CONTAINER_NAME
71 echo "------------------------------------------------------------"
72 exit 1
73fi
74
75if echo "$result" | grep -E "$FAILURE_TEXT|$TIME_OUT_TEXT"; then
76 echo "$SCRIPT_NAME $(current_timestamp): populate-aai-simulator.sh failed"
77 echo "-------------- $CONTAINER_NAME logs -------------"
78 docker logs $CONTAINER_NAME
79 echo "------------------------------------------------------------"
80 exit 1
81fi
82
83echo "$SCRIPT_NAME $(current_timestamp): Successfully populated AAI Simulator . . ."
84exit 0