blob: f6bf906b58f1d398a15e08444ff6b68d4aefe718 [file] [log] [blame]
waqas.ikram7d753292019-07-18 16:41:17 +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
24BUIDLING_BLOCK_TABLE_NAME="building_block_detail"
25ORCH_FLOW_TABLE_NAME="orchestration_flow_reference"
26NORTH_BOUND_TABLE_NAME="northbound_request_ref_lookup"
27TABLE_EXISTS_QUERY="select count(*) from information_schema.tables WHERE table_schema='$CATALOG_DB' AND table_name='$BUIDLING_BLOCK_TABLE_NAME';"
28BUILDING_BLOCK_COUNT_QUERY="select count(*) from $BUIDLING_BLOCK_TABLE_NAME;"
29FLY_WAY_MIGRATION_QUERY="SELECT COUNT(*) FROM flyway_schema_history WHERE script LIKE '%R__MacroData%' AND installed_on IS NOT NULL;"
30
31
32current_timestamp()
33{
34 date +"%Y-%m-%d %H:%M:%S"
35}
36
37wait_for_database_availability()
38{
39 echo "$(current_timestamp): Checking for database availability"
40 until echo '\q' | mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB; do
41 >&2 echo "$(current_timestamp): Database is unavailable - sleeping for 5 seconds"
42 sleep 5
43 done
44
45 echo "$(current_timestamp): Database is available now"
46}
47
48wait_container_to_create_table()
49{
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 "$(current_timestamp): Waiting for so-catalog container to create tables - sleeping for 5 seconds"
52 sleep 5
53 done
54
55 while [ $(mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB -sse "$BUILDING_BLOCK_COUNT_QUERY") -eq "0" ] ; do
56 echo "$(current_timestamp): Waiting for so-catalog container to insert records in $BUIDLING_BLOCK_TABLE_NAME - sleeping for 5 seconds"
57 sleep 5
58 done
59
60 echo "$(current_timestamp): $CATALOG_DB tables available now . . ."
61}
62
63wait_for_flyway_migration_to_finish()
64{
65 while [ $(mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB -sse "$FLY_WAY_MIGRATION_QUERY") -ne "1" ] ; do
66 echo "$(current_timestamp): Waiting for flyway migration sql statement to finish with success - sleeping for 5 seconds"
67 sleep 5
68 done
69 echo "$(current_timestamp): flyway migration finished . . . "
70}
71
72
73apply_workaround()
74{
75 echo "$(current_timestamp): Applying workaround . . ."
76
77 wait_for_database_availability
78 wait_container_to_create_table
79 wait_for_flyway_migration_to_finish
80
81 echo "$(current_timestamp): Will insert data into $CATALOG_DB"
82mysql -h $DB_HOST -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB << EOF
83 BEGIN;
84 INSERT INTO $BUIDLING_BLOCK_TABLE_NAME (BUILDING_BLOCK_NAME,RESOURCE_TYPE,TARGET_ACTION) values ("EtsiVnfInstantiateBB", "VNF", "ACTIVATE");
85 INSERT INTO $BUIDLING_BLOCK_TABLE_NAME (BUILDING_BLOCK_NAME,RESOURCE_TYPE,TARGET_ACTION) values ("EtsiVnfDeleteBB", "VNF", "DEACTIVATE");
86
87 DELETE FROM $ORCH_FLOW_TABLE_NAME where COMPOSITE_ACTION = "VNF-Create";
88
89 INSERT INTO $ORCH_FLOW_TABLE_NAME (COMPOSITE_ACTION,SEQ_NO,FLOW_NAME,FLOW_VERSION,NB_REQ_REF_LOOKUP_ID ) SELECT "VNF-Create" AS COMPOSITE_ACTION, 1 AS SEQ_NO, "AssignVnfBB" AS FLOW_NAME, 1 AS FLOW_VERSION, id AS NB_REQ_REF_LOOKUP_ID FROM $NORTH_BOUND_TABLE_NAME WHERE REQUEST_SCOPE='Vnf' AND IS_ALACARTE is true AND ACTION="createInstance";
90
91 INSERT INTO $ORCH_FLOW_TABLE_NAME (COMPOSITE_ACTION,SEQ_NO,FLOW_NAME,FLOW_VERSION,NB_REQ_REF_LOOKUP_ID ) SELECT "VNF-Create" AS COMPOSITE_ACTION, 2 AS SEQ_NO, "EtsiVnfInstantiateBB" AS FLOW_NAME, 1 AS FLOW_VERSION, id AS NB_REQ_REF_LOOKUP_ID FROM $NORTH_BOUND_TABLE_NAME WHERE REQUEST_SCOPE='Vnf' AND IS_ALACARTE is true AND ACTION="createInstance";
92
93 INSERT INTO $ORCH_FLOW_TABLE_NAME (COMPOSITE_ACTION,SEQ_NO,FLOW_NAME,FLOW_VERSION,NB_REQ_REF_LOOKUP_ID ) SELECT "VNF-Create" AS COMPOSITE_ACTION, 3 AS SEQ_NO, "ActivateVnfBB" AS FLOW_NAME, 1 AS FLOW_VERSION, id AS NB_REQ_REF_LOOKUP_ID FROM $NORTH_BOUND_TABLE_NAME WHERE REQUEST_SCOPE='Vnf' AND IS_ALACARTE is true AND ACTION="createInstance";
94
95 DELETE FROM $ORCH_FLOW_TABLE_NAME where COMPOSITE_ACTION = "VNF-Delete";
96
97 INSERT INTO $ORCH_FLOW_TABLE_NAME (COMPOSITE_ACTION,SEQ_NO,FLOW_NAME,FLOW_VERSION,NB_REQ_REF_LOOKUP_ID ) SELECT "VNF-Delete" AS COMPOSITE_ACTION, 1 AS SEQ_NO, "EtsiVnfDeleteBB" AS FLOW_NAME, 1 AS FLOW_VERSION, id AS NB_REQ_REF_LOOKUP_ID FROM $NORTH_BOUND_TABLE_NAME WHERE REQUEST_SCOPE='Vnf' AND IS_ALACARTE is true AND ACTION="deleteInstance";
98
99 INSERT INTO $ORCH_FLOW_TABLE_NAME (COMPOSITE_ACTION,SEQ_NO,FLOW_NAME,FLOW_VERSION,NB_REQ_REF_LOOKUP_ID ) SELECT "VNF-Delete" AS COMPOSITE_ACTION, 2 AS SEQ_NO, "UnassignVnfBB" AS FLOW_NAME, 1 AS FLOW_VERSION, id AS NB_REQ_REF_LOOKUP_ID FROM $NORTH_BOUND_TABLE_NAME WHERE REQUEST_SCOPE='Vnf' AND IS_ALACARTE is true AND ACTION="deleteInstance";
100
101 UPDATE orchestration_status_state_transition_directive SET FLOW_DIRECTIVE='CONTINUE' WHERE RESOURCE_TYPE='VNF' AND ORCHESTRATION_STATUS='CREATED' AND TARGET_ACTION='ACTIVATE' AND FLOW_DIRECTIVE='FAIL';
102
103 COMMIT;
104EOF
105
106 if [ $? -ne 0 ]; then
107 echo "$(current_timestamp): Failed to execute workaround . . ."
108 exit 1
109 fi
110
111 echo "$(current_timestamp): Finished applying workaround . . ."
112}
113
114# main body
115apply_workaround
116