Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Engage normal Cass Init, then check for data installation |
| 4 | # |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 5 | DIR="/opt/app/aaf/status" |
| 6 | |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 7 | if [ ! -e /aaf_cmd ]; then |
| 8 | ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd |
| 9 | chmod u+x /aaf_cmd |
| 10 | fi |
| 11 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 12 | # Always need startup status... |
| 13 | if [ ! -e "$DIR" ]; then |
| 14 | mkdir -p "$DIR" |
| 15 | fi |
| 16 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 17 | function status { |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 18 | echo "$@" |
| 19 | echo "$@" > $DIR/aaf_cass |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 20 | } |
| 21 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 22 | function wait_start { |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 23 | sleep 10 |
| 24 | status wait for cassandra to start |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 25 | for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do |
| 26 | if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then |
| 27 | echo "Waiting for Cassandra to start... Sleep 10" |
| 28 | sleep 10 |
| 29 | else |
| 30 | break |
| 31 | fi |
| 32 | done |
| 33 | } |
| 34 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 35 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 36 | function wait_cql { |
| 37 | status wait for keyspace to be initialized |
| 38 | for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do |
Instrumental | 235dd9a | 2018-10-03 21:36:44 -0500 | [diff] [blame] | 39 | if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 40 | break |
| 41 | else |
| 42 | echo "Waiting for Keyspaces to be loaded... Sleep 10" |
| 43 | sleep 10 |
| 44 | fi |
| 45 | done |
| 46 | } |
| 47 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 48 | function wait_ready { |
| 49 | status wait for cassandra to be fully ready |
| 50 | for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do |
| 51 | STATUS="$(cat $DIR/aaf_cass)" |
| 52 | if [ "$STATUS" = "ready" ]; then |
| 53 | break |
| 54 | else |
| 55 | echo "Waiting for Start, $STATUS... Sleep 10" |
| 56 | sleep 10 |
| 57 | fi |
| 58 | done |
| 59 | } |
| 60 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 61 | function install_cql { |
| 62 | wait_start started |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 63 | # Now, make sure data exists |
| 64 | if [ "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" = "" ]; then |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 65 | status install |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 66 | echo "Initializing Cassandra DB" |
| 67 | if [ "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" == "" ]; then |
| 68 | echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following " |
| 69 | echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently" |
| 70 | echo "" |
| 71 | echo " cd /opt/app/aaf/cass_init" |
| 72 | cd /opt/app/aaf/cass_init |
| 73 | echo " cqlsh -f keyspace.cql" |
| 74 | /usr/bin/cqlsh -f keyspace.cql |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 75 | status keyspace installed |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 76 | echo " cqlsh -f init.cql" |
| 77 | /usr/bin/cqlsh -f init.cql |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 78 | status data initialized |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 79 | echo "" |
| 80 | echo "The following will give you a temporary identity with which to start working, or emergency" |
| 81 | echo " cqlsh -f temp_identity.cql" |
| 82 | fi |
| 83 | fi |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 84 | status $1 |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 85 | } |
| 86 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 87 | function install_onap { |
| 88 | install_cql initialized |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 89 | |
| 90 | # Change date expiring dat files to more recent |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 91 | status Creating ONAP Identities |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 92 | ID_FILE=/opt/app/aaf/cass_init/sample.identities.dat |
| 93 | if [ -e $ID_FILE ]; then |
| 94 | DATE=$(date "+%Y-%m-%d %H:%M:%S.000+0000" -d "+6 months") |
| 95 | echo $DATE |
| 96 | CRED="/opt/app/aaf/cass_init/dats/cred.dat" |
| 97 | # Enter for People |
| 98 | echo "Default Passwords for Apps" |
| 99 | for ID in $(grep '|a|' $ID_FILE | sed -e "s/|.*//"); do |
| 100 | if [ "$ID" = "aaf" ]; then |
| 101 | DOMAIN="aaf.osaaf.org"; |
| 102 | else |
| 103 | DOMAIN="$ID.onap.org"; |
| 104 | fi |
| 105 | unset FIRST |
| 106 | for D in ${DOMAIN//./ }; do |
| 107 | if [ -z "$FIRST" ]; then |
| 108 | NS="$D" |
| 109 | FIRST="N" |
| 110 | else |
| 111 | NS="$D.$NS" |
| 112 | fi |
| 113 | done |
| 114 | echo "$ID@$DOMAIN|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|$NS|53344|" >> $CRED |
| 115 | done |
| 116 | |
| 117 | # Enter for People |
| 118 | for ID in $(grep '|e|' $ID_FILE | sed -e "s/|.*//"); do |
| 119 | echo "$ID@people.osaaf.org|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|org.osaaf.people|53344|" >> $CRED |
| 120 | done |
| 121 | |
| 122 | # Change UserRole |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 123 | status Setting up User Roles |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 124 | mv dats/user_role.dat tmp |
| 125 | sed "s/\(^.*|\)\(.*|\)\(.*|\)\(.*\)/\1${DATE}|\3\4/" tmp > dats/user_role.dat |
| 126 | |
| 127 | # Remove ID File, which is marker for initializing Creds |
| 128 | rm $ID_FILE |
| 129 | fi |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 130 | status Pushing data to cassandra |
| 131 | bash push.sh |
| 132 | status ready |
| 133 | } |
| 134 | |
| 135 | case "$1" in |
| 136 | start) |
| 137 | # start install_cql in background, waiting for process to start |
| 138 | install_cql ready & |
| 139 | |
| 140 | # Startup like normal |
| 141 | echo "Cassandra Startup" |
| 142 | /usr/local/bin/docker-entrypoint.sh |
| 143 | ;; |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 144 | wait) |
| 145 | # Wait for initialization. This can be called from Docker only as a check to make sure it is ready |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 146 | wait_ready |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 147 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 148 | ;; |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 149 | onap) |
| 150 | # start install_onap (which calls install_cql first) in background, waiting for process to start |
| 151 | install_onap & |
| 152 | |
| 153 | # Startup like normal |
| 154 | echo "Cassandra Startup" |
| 155 | /usr/local/bin/docker-entrypoint.sh |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 156 | ;; |
| 157 | esac |
| 158 | |