3 # ============LICENSE_START====================================================
5 # ===========================================================================
6 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7 # ===========================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END====================================================
22 # Engage normal Cass Init, then check for data installation
24 DIR="/opt/app/aaf/status"
25 INSTALLED_VERSION=/var/lib/cassandra/AAF_VERSION
26 AAF_INIT_DATA=/var/lib/cassandra/AAF_INIT_DATA
27 CQLSH=${CQLSH:=/usr/bin/cqlsh}
29 if [ ! -e /aaf_cmd ]; then
30 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
34 # Always need startup status...
35 if [ ! -e "$DIR" ]; then
42 echo "$@" > $DIR/aaf-cass
47 status wait for cassandra to start
48 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
49 if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
50 echo "Waiting for Cassandra to start... Sleep 10"
53 status cassandra started
57 # Logs state Cassandra is up. Now use cqlsh to ensure responsive
58 echo "Cassandra started, wait until it is responsive"
59 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
60 if [ -z "$(cqlsh -e 'describe keyspaces')" ]; then
61 echo "Waiting for Cassandra to be responsive... Sleep 10"
64 echo "Cassandra responded"
65 status cassandra responsive
73 status wait for keyspace to be initialized
74 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
75 if [ -n "$($CQLSH -e 'describe keyspaces' | grep authz)" ]; then
78 echo "Waiting for Keyspaces to be loaded... Sleep 10"
85 status wait for cassandra to be fully ready
86 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
87 STATUS="$(cat $DIR/aaf-cass)"
88 if [ "$STATUS" = "ready" ]; then
91 echo "Waiting for Start, $STATUS... Sleep 10"
97 function install_cql {
98 wait_start cassandra responsive
99 # Now, make sure data exists
100 if [ ! -e $INSTALLED_VERSION ] && [ -n "$($CQLSH -e 'describe keyspaces' | grep authz)" ]; then
101 $CQLSH --request-timeout=60 -e 'DROP KEYSPACE authz'
104 if [ -z "$($CQLSH --request-timeout 60 -e 'describe keyspaces' | grep authz)" ]; then
106 echo "Initializing Cassandra DB"
107 echo "Docker Installed Basic Cassandra on aaf.cass. Executing the following "
108 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
110 echo " cd /opt/app/aaf/cass_init"
111 cd /opt/app/aaf/cass_init
112 echo " cqlsh -f keyspace.cql"
113 $CQLSH --request-timeout=100 -f keyspace.cql
114 status keyspace installed
115 echo " cqlsh -f init.cql"
116 $CQLSH --request-timeout=100 -f init.cql
117 status data initialized
119 echo "The following will give you a temporary identity with which to start working, or emergency"
120 echo " cqlsh -f temp_identity.cql"
121 echo "frankfurt" > $INSTALLED_VERSION
123 echo "Cassandra DB already includes 'authz' keyspace"
128 function install_onap {
129 echo " cd /opt/app/aaf/cass_init"
130 install_cql initialized
131 if [ -e "$AAF_INIT_DATA" ]; then
132 echo "AAF Data already initialized on this Cassandra"
134 status prep data for bootstrapping
135 cd /opt/app/aaf/cass_init
138 status push data to cassandra
142 echo $(date) > $AAF_INIT_DATA
149 # start install_cql in background, waiting for process to start
152 # Startup like normal
153 echo "Cassandra Startup"
154 exec -c "/usr/local/bin/docker-entrypoint.sh"
157 # Wait for initialization. This can be called from Docker only as a check to make sure it is ready
162 cd /opt/app/aaf/cass_init
163 # start install_onap (which calls install_cql first) in background, waiting for process to start
166 # Startup like normal
167 echo "Cassandra Startup"
168 if ! cat /etc/cassandra/cassandra.yaml | grep "write_request_timeout_in_ms: 20000"; then
169 sed -i 's/write_request_timeout_in_ms: 2000/write_request_timeout_in_ms: 20000/' /etc/cassandra/cassandra.yaml
171 exec /usr/local/bin/docker-entrypoint.sh