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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
22 # @author Waqas Ikram (waqas.ikram@est.tech)
25 SUCCESSFUL_TEXT="AAI Simulator Populated Successfully"
27 TIME_OUT_TEXT="Time out"
28 CONTAINER_NAME=$(docker ps -aqf "name=populate-aai-config" --format "{{.Names}}")
29 SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
30 SCRIPT_NAME=$(basename $0)
34 date +"%Y-%m-%d %H:%M:%S"
38 if [ -z $TIME_OUT_DEFAULT_VALUE_SEC ]; then
39 echo "$SCRIPT_NAME $(current_timestamp): ERROR: Undefined value for TIME_OUT_DEFAULT_VALUE_SEC attribute"
43 if [ -z $CONTAINER_NAME ]; then
44 echo "$SCRIPT_NAME $(current_timestamp): Unable to find docker container id "
48 START_TIME_IN_SECONDS=`date +%s`
49 TIME_OUT_END_TIME_IN_SECONDS=$(($START_TIME_IN_SECONDS+$TIME_OUT_DEFAULT_VALUE_SEC));
52 echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME script Start Time `date -d @$START_TIME_IN_SECONDS`"
53 echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME will time out at `date -d @$TIME_OUT_END_TIME_IN_SECONDS`"
55 while [ `date +%s` -lt "$TIME_OUT_END_TIME_IN_SECONDS" ]; do
56 echo "$(current_timestamp): Waiting for $CONTAINER_NAME to finish ..."
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"
63 echo "$(current_timestamp): Sleeping for ${SLEEP_TIME} seconds"
67 if [ -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 "------------------------------------------------------------"
75 if 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 "------------------------------------------------------------"
83 echo "$SCRIPT_NAME $(current_timestamp): Successfully populated AAI Simulator . . ."