blob: afb66774ccc83bc8161b8035dfa5e7231385a1de [file] [log] [blame]
Instrumentalbc299c02018-09-25 06:42:31 -05001#!/bin/bash
2#
3# Engage normal Cass Init, then check for data installation
4#
Instrumental08e93402018-10-03 08:38:52 -05005DIR="/opt/app/aaf/status"
6
Instrumentalbc299c02018-09-25 06:42:31 -05007if [ ! -e /aaf_cmd ]; then
8 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
9 chmod u+x /aaf_cmd
10fi
11
Instrumental08e93402018-10-03 08:38:52 -050012function status {
13 if [ -d "$DIR" ]; then
14 echo "$@"
15 echo "$@" > $DIR/aaf_cass
16 fi
17}
18
Instrumental1e3be602018-10-03 19:40:44 -050019function wait_start {
Instrumental08e93402018-10-03 08:38:52 -050020 sleep 10
21 status wait for cassandra to start
Instrumental1e3be602018-10-03 19:40:44 -050022 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
23 if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
24 echo "Waiting for Cassandra to start... Sleep 10"
25 sleep 10
26 else
27 break
28 fi
29 done
30}
31
32function wait_cql {
33 status wait for keyspace to be initialized
34 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
35 if [ "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" == "" ]; then
36 break
37 else
38 echo "Waiting for Keyspaces to be loaded... Sleep 10"
39 sleep 10
40 fi
41 done
42}
43
44function install_cql {
45 wait_start started
Instrumentalbc299c02018-09-25 06:42:31 -050046 # Now, make sure data exists
47 if [ "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" = "" ]; then
Instrumental1e3be602018-10-03 19:40:44 -050048 status install
Instrumentalbc299c02018-09-25 06:42:31 -050049 echo "Initializing Cassandra DB"
50 if [ "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" == "" ]; then
51 echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following "
52 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
53 echo ""
54 echo " cd /opt/app/aaf/cass_init"
55 cd /opt/app/aaf/cass_init
56 echo " cqlsh -f keyspace.cql"
57 /usr/bin/cqlsh -f keyspace.cql
Instrumental08e93402018-10-03 08:38:52 -050058 status keyspace installed
Instrumentalbc299c02018-09-25 06:42:31 -050059 echo " cqlsh -f init.cql"
60 /usr/bin/cqlsh -f init.cql
Instrumental08e93402018-10-03 08:38:52 -050061 status data initialized
Instrumentalbc299c02018-09-25 06:42:31 -050062 echo ""
63 echo "The following will give you a temporary identity with which to start working, or emergency"
64 echo " cqlsh -f temp_identity.cql"
65 fi
66 fi
Instrumental08e93402018-10-03 08:38:52 -050067 status $1
Instrumentalbc299c02018-09-25 06:42:31 -050068}
69
Instrumental08e93402018-10-03 08:38:52 -050070function install_onap {
71 install_cql initialized
Instrumentalbc299c02018-09-25 06:42:31 -050072
73 # Change date expiring dat files to more recent
Instrumental08e93402018-10-03 08:38:52 -050074 status Creating ONAP Identities
Instrumentalbc299c02018-09-25 06:42:31 -050075 ID_FILE=/opt/app/aaf/cass_init/sample.identities.dat
76 if [ -e $ID_FILE ]; then
77 DATE=$(date "+%Y-%m-%d %H:%M:%S.000+0000" -d "+6 months")
78 echo $DATE
79 CRED="/opt/app/aaf/cass_init/dats/cred.dat"
80 # Enter for People
81 echo "Default Passwords for Apps"
82 for ID in $(grep '|a|' $ID_FILE | sed -e "s/|.*//"); do
83 if [ "$ID" = "aaf" ]; then
84 DOMAIN="aaf.osaaf.org";
85 else
86 DOMAIN="$ID.onap.org";
87 fi
88 unset FIRST
89 for D in ${DOMAIN//./ }; do
90 if [ -z "$FIRST" ]; then
91 NS="$D"
92 FIRST="N"
93 else
94 NS="$D.$NS"
95 fi
96 done
97 echo "$ID@$DOMAIN|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|$NS|53344|" >> $CRED
98 done
99
100 # Enter for People
101 for ID in $(grep '|e|' $ID_FILE | sed -e "s/|.*//"); do
102 echo "$ID@people.osaaf.org|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|org.osaaf.people|53344|" >> $CRED
103 done
104
105 # Change UserRole
Instrumental08e93402018-10-03 08:38:52 -0500106 status Setting up User Roles
Instrumentalbc299c02018-09-25 06:42:31 -0500107 mv dats/user_role.dat tmp
108 sed "s/\(^.*|\)\(.*|\)\(.*|\)\(.*\)/\1${DATE}|\3\4/" tmp > dats/user_role.dat
109
110 # Remove ID File, which is marker for initializing Creds
111 rm $ID_FILE
112 fi
Instrumental08e93402018-10-03 08:38:52 -0500113 status Pushing data to cassandra
114 bash push.sh
115 status ready
116}
117
118case "$1" in
119 start)
120 # start install_cql in background, waiting for process to start
121 install_cql ready &
122
123 # Startup like normal
124 echo "Cassandra Startup"
125 /usr/local/bin/docker-entrypoint.sh
126 ;;
Instrumental1e3be602018-10-03 19:40:44 -0500127 wait)
128 # Wait for initialization. This can be called from Docker only as a check to make sure it is ready
129 wait_start started
130
131 # Make sure Keyspace is loaded
132 wait_cql
133 status ready
134 ;;
Instrumental08e93402018-10-03 08:38:52 -0500135 onap)
136 # start install_onap (which calls install_cql first) in background, waiting for process to start
137 install_onap &
138
139 # Startup like normal
140 echo "Cassandra Startup"
141 /usr/local/bin/docker-entrypoint.sh
Instrumentalbc299c02018-09-25 06:42:31 -0500142 ;;
143esac
144