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
28 if [ ! -e /aaf_cmd ]; then
29 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
33 # Always need startup status...
34 if [ ! -e "$DIR" ]; then
41 echo "$@" > $DIR/aaf-cass
46 status wait for cassandra to start
47 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
48 if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
49 echo "Waiting for Cassandra to start... Sleep 10"
52 status cassandra started
56 # Logs state Cassandra is up. Now use cqlsh to ensure responsive
57 echo "Cassandra started, wait until it is responsive"
58 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
59 if [ -z "$(cqlsh -e 'describe keyspaces')" ]; then
60 echo "Waiting for Cassandra to be responsive... Sleep 10"
63 echo "Cassandra responded"
64 status cassandra responsive
72 status wait for keyspace to be initialized
73 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
74 if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
77 echo "Waiting for Keyspaces to be loaded... Sleep 10"
84 status wait for cassandra to be fully ready
85 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
86 STATUS="$(cat $DIR/aaf-cass)"
87 if [ "$STATUS" = "ready" ]; then
90 echo "Waiting for Start, $STATUS... Sleep 10"
96 function install_cql {
97 wait_start cassandra responsive
98 # Now, make sure data exists
99 if [ ! -e $INSTALLED_VERSION ] && [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
100 /usr/bin/cqlsh --request-timeout=60 -e 'DROP KEYSPACE authz'
103 if [ -z "`/usr/bin/cqlsh --request-timeout 60 -e 'describe keyspaces' | grep authz`" ]; then
105 echo "Initializing Cassandra DB"
106 echo "Docker Installed Basic Cassandra on aaf.cass. Executing the following "
107 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
109 echo " cd /opt/app/aaf/cass_init"
110 cd /opt/app/aaf/cass_init
111 echo " cqlsh -f keyspace.cql"
112 /usr/bin/cqlsh --request-timeout=100 -f keyspace.cql
113 status keyspace installed
114 echo " cqlsh -f init.cql"
115 /usr/bin/cqlsh --request-timeout=100 -f init.cql
116 status data initialized
118 echo "The following will give you a temporary identity with which to start working, or emergency"
119 echo " cqlsh -f temp_identity.cql"
120 echo "casablanca" > $INSTALLED_VERSION
122 echo "Cassandra DB already includes 'authz' keyspace"
127 function install_onap {
128 echo " cd /opt/app/aaf/cass_init"
129 install_cql initialized
130 if [ -e "$AAF_INIT_DATA" ]; then
131 echo "AAF Data already initialized on this Cassandra"
133 status prep data for bootstrapping
134 cd /opt/app/aaf/cass_init
137 status push data to cassandra
140 echo $(date) > $AAF_INIT_DATA
147 # start install_cql in background, waiting for process to start
150 # Startup like normal
151 echo "Cassandra Startup"
152 exec -c "/usr/local/bin/docker-entrypoint.sh"
155 # Wait for initialization. This can be called from Docker only as a check to make sure it is ready
160 cd /opt/app/aaf/cass_init
161 # start install_onap (which calls install_cql first) in background, waiting for process to start
164 # Startup like normal
165 echo "Cassandra Startup"
166 if ! cat /etc/cassandra/cassandra.yaml | grep "write_request_timeout_in_ms: 20000"; then
167 sed -i 's/write_request_timeout_in_ms: 2000/write_request_timeout_in_ms: 20000/' /etc/cassandra/cassandra.yaml
169 exec /usr/local/bin/docker-entrypoint.sh