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)
24 WORKFLOW_TABLE_NAME="workflow"
25 TABLE_EXISTS_QUERY="select count(*) from information_schema.tables WHERE table_schema='$CATALOG_DB' AND table_name='$WORKFLOW_TABLE_NAME';"
27 FLY_WAY_MIGRATION_QUERY="SELECT COUNT(*) FROM flyway_schema_history WHERE script LIKE '%R__MacroData%' AND installed_on IS NOT NULL;"
28 TIME_OUT_DEFAULT_VALUE_SEC=1200 #20 mins
29 SCRIPT_NAME=$(basename $0)
33 date +"%Y-%m-%d %H:%M:%S"
36 wait_for_database_availability()
38 echo "$SCRIPT_NAME $(current_timestamp): Checking for database availability"
39 until echo '\q' | mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB; do
40 >&2 echo "$SCRIPT_NAME $(current_timestamp): Database is unavailable - sleeping for ${SLEEP_TIME} seconds"
45 echo "$SCRIPT_NAME $(current_timestamp): Database is available now"
48 wait_container_to_create_table()
50 while [ $(mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB -sse "$TABLE_EXISTS_QUERY") -eq "0" ] ; do
51 echo "$SCRIPT_NAME $(current_timestamp): Waiting for so-catalog container to create tables - sleeping for ${SLEEP_TIME} seconds"
56 echo "$SCRIPT_NAME $(current_timestamp): $CATALOG_DB tables available now . . ."
61 echo "$SCRIPT_NAME $(current_timestamp): Applying workaround . . ."
63 wait_for_database_availability
64 wait_container_to_create_table
65 echo "$SCRIPT_NAME $(current_timestamp): Will insert data into $CATALOG_DB"
66 mysql -h $DB_HOST -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB << EOF
69 insert into $WORKFLOW_TABLE_NAME(artifact_uuid, artifact_name, name, operation_name, version, description, body, resource_target, source) values
70 ('4752c287-c5a8-40a6-8fce-077e1d54104b','GenericPnfSoftwareUpgrade','GenericPnfSoftwareUpgrade','GenericPnfSoftwareUpgrade',1.0,'Pnf Workflow to upgrade software',null,'pnf','native');
72 insert into $WORKFLOW_TABLE_NAME(artifact_uuid, artifact_name, name, operation_name, version, description, body, resource_target, source) values
73 ('02bffbd9-6af0-4f8d-bf9b-d1dfccd28c84','GenericPnfSWUPDownload','GenericPnfSWUPDownload','GenericPnfSWUPDownload',1.0,'Pnf Workflow to download software',null,'pnf','native');
75 insert into $WORKFLOW_TABLE_NAME(artifact_uuid, artifact_name, name, operation_name, version, description, body, resource_target, source) values
76 ('03fcdjf2-6af0-4f8d-bf9b-s3frzca23c19','ServiceLevelUpgrade','ServiceLevelUpgrade','ServiceLevelUpgrade',1.0,'ServiceLevel Upgrade Workflow to upgrade software',null,'service','native');
82 echo "$SCRIPT_NAME $(current_timestamp): Failed to execute workaround . . ."
86 echo "$SCRIPT_NAME $(current_timestamp): Finished applying workaround . . ."
91 if [ `date +%s` -gt $TIME_OUT_END_TIME_IN_SECONDS ]; then
92 echo "$SCRIPT_NAME $(current_timestamp): workaround script timed out . . ."
98 if [ -z "$TIME_OUT_IN_SECONDS"]; then
99 echo "$SCRIPT_NAME $(current_timestamp): TIME_OUT_IN_SECONDS attribute is empty will use default val: $TIME_OUT_DEFAULT_VALUE_SEC"
100 TIME_OUT_IN_SECONDS=$TIME_OUT_DEFAULT_VALUE_SEC
103 DIGITS_REGEX='^[0-9]+$'
104 if ! [[ $TIME_OUT_IN_SECONDS =~ $DIGIT_REGEX ]] ; then
105 echo "$SCRIPT_NAME $(current_timestamp): TIME_OUT_IN_SECONDS attribute Must be number: $TIME_OUT_IN_SECONDS, will use default val: $TIME_OUT_DEFAULT_VALUE_SEC"
106 TIME_OUT_IN_SECONDS=$TIME_OUT_DEFAULT_VALUE_SEC
109 START_TIME_IN_SECONDS=`date +%s`
110 TIME_OUT_END_TIME_IN_SECONDS=$(($START_TIME_IN_SECONDS+$TIME_OUT_IN_SECONDS));
111 echo "$SCRIPT_NAME $(current_timestamp): Workaround script will time out at `date -d @$TIME_OUT_END_TIME_IN_SECONDS`"