Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2016-2017 Huawei Technologies Co., Ltd. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | # |
| 19 | # add here eventual scripts needed for music |
| 20 | # |
| 21 | echo "########## music scripts calling ##########"; |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 22 | source ${WORKSPACE}/scripts/music/music-scripts/music_script.sh |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 23 | |
| 24 | # |
| 25 | # add here all the configuration steps eventually needed to be carried out for music CSIT testing |
| 26 | # |
| 27 | echo "########## music configuration step ##########"; |
Thomas Nelson | 4a9119a | 2018-10-22 02:26:04 -0400 | [diff] [blame] | 28 | CASS_IMG=nexus3.onap.org:10001/onap/music/cassandra_3_11:3.0.23 |
| 29 | CASS_IMG_JOB=nexus3.onap.org:10001/onap/music/cassandra_job:3.0.23 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 30 | TOMCAT_IMG=nexus3.onap.org:10001/library/tomcat:8.5 |
| 31 | ZK_IMG=nexus3.onap.org:10001/library/zookeeper:3.4 |
| 32 | BUSYBOX_IMG=nexus3.onap.org:10001/library/busybox:latest |
Thomas Nelson | 4a9119a | 2018-10-22 02:26:04 -0400 | [diff] [blame] | 33 | MUSIC_IMG=nexus3.onap.org:10001/onap/music/music:3.0.23 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 34 | TT=10 |
| 35 | WORK_DIR=/tmp/music |
| 36 | CASS_USERNAME=nelson24 |
| 37 | CASS_PASSWORD=winman123 |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 38 | MUSIC_SOURCE_PROPERTIES=${WORKSPACE}/scripts/music/music-properties |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 39 | MUSIC_PROPERTIES=/tmp/music/properties |
| 40 | MUSIC_LOGS=/tmp/music/logs |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 41 | CQL_FILES=${WORKSPACE}/scripts/music/cql |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 42 | MUSIC_TRIGGER_DIR=/tmp/triggers |
| 43 | TRIGGER_JAR=musictrigger-0.1.0.jar |
| 44 | TRIGGER_JAR_URL=https://nexus.onap.org/service/local/repositories/autorelease-72298/content/org/onap/music/musictrigger/0.1.0/musictrigger-0.1.0.jar |
| 45 | |
| 46 | mkdir -p ${MUSIC_PROPERTIES} |
| 47 | mkdir -p ${MUSIC_LOGS} |
| 48 | mkdir -p ${MUSIC_LOGS}/MUSIC |
| 49 | mkdir -p /tmp/triggers |
| 50 | |
| 51 | # Get Trigger |
| 52 | echo "########## Get Trigger Jar ##########" |
| 53 | curl -o $MUSIC_TRIGGER_DIR/$TRIGGER_JAR $TRIGGER_JAR_URL |
| 54 | |
| 55 | cp ${MUSIC_SOURCE_PROPERTIES}/* ${WORK_DIR}/properties |
| 56 | |
| 57 | # Create Volume for mapping war file and tomcat |
| 58 | echo "########## create music-vol ##########" |
| 59 | docker volume create --name music-vol; |
| 60 | |
| 61 | # Create a network for all the containers to run in. |
| 62 | echo "########## create music-net ##########" |
| 63 | docker network create music-net; |
| 64 | |
| 65 | # Start Cassandra |
| 66 | echo "########## Start Cassandra (music-db) ##########" |
| 67 | docker run -d --name music-db --network music-net -p "7000:7000" -p "7001:7001" -p "7199:7199" -p "9042:9042" -p "9160:9160" \ |
| 68 | -v $MUSIC_TRIGGER_DIR/$TRIGGER_JAR:/etc/cassandra/triggers/$TRIGGER_JAR \ |
| 69 | ${CASS_IMG}; |
| 70 | |
| 71 | CASSA_IP=`docker inspect -f '{{ $network := index .NetworkSettings.Networks "music-net" }}{{ $network.IPAddress}}' music-db` |
| 72 | echo "CASSANDRA_IP=${CASSA_IP}" |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 73 | ${WORKSPACE}/scripts/optf-has/has/wait_for_port.sh ${CASSA_IP} 9042 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 74 | |
| 75 | # See if cassandra is up. |
| 76 | echo "########## Running Test to see if Cassandra is up ##########" |
| 77 | docker run --name music-casstest --network music-net \ |
| 78 | $BUSYBOX_IMG sh -c "until nc -z music-db 9042 && echo "success"; do echo 'No connection .. Sleeping for $TT seconds';sleep $TT; done;" |
| 79 | |
Thomas Nelson | 4a9119a | 2018-10-22 02:26:04 -0400 | [diff] [blame] | 80 | # Sleep 60 seconds to ensure Cassandra is up and running. |
| 81 | sleep 60; |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 82 | # Check to see if Keyspaces are there. |
| 83 | docker exec music-db cqlsh -u cassandra -p cassandra -e "DESCRIBE keyspaces;" |
| 84 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 85 | # Load data into Cassandra via Cassandra Job |
| 86 | echo "########## Running Cassandra Job (music-job) to load cql files ##########" |
| 87 | docker run -d --name music-job --network music-net \ |
| 88 | -v $CQL_FILES/admin.cql:/cql/admin.cql \ |
| 89 | -v $CQL_FILES/admin_pw.cql:/cql/admin_pw.cql \ |
| 90 | -v $CQL_FILES/extra:/cql/extra \ |
| 91 | -e PORT=9042 \ |
| 92 | -e CASS_HOSTNAME=music-db \ |
| 93 | -e USERNAME=$CASS_USERNAME \ |
| 94 | -e PASSWORD=$CASS_PASSWORD \ |
Thomas Nelson | 4a9119a | 2018-10-22 02:26:04 -0400 | [diff] [blame] | 95 | $CASS_IMG_JOB |
| 96 | |
| 97 | sleep 70; |
| 98 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 99 | # Logs |
| 100 | echo "########## Cassandra Job logs ##########" |
| 101 | docker logs music-job |
Thomas Nelson | 4a9119a | 2018-10-22 02:26:04 -0400 | [diff] [blame] | 102 | # Check to see if Keyspaces are there. |
| 103 | # "############## Check if new username and password work ##########" |
| 104 | docker exec music-db cqlsh -u $CASS_USERNAME -p $CASS_PASSWORD -e "DESCRIBE keyspaces;" |
| 105 | # Check to see if Keyspaces are there. |
| 106 | # "############## Check if original username and password work ##########" |
| 107 | docker exec music-db cqlsh -u cassandra -p cassandra -e "DESCRIBE keyspaces;" |
| 108 | # Check to see if Keyspaces are there. |
| 109 | # "############## Check if new cassandra username and password work ##########" |
| 110 | docker exec music-db cqlsh -u cassandra -p SomeLongRandomStringNoonewillthinkof -e "DESCRIBE keyspaces;" |
| 111 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 112 | |
| 113 | # Start Music war |
| 114 | echo "########## Start music-war ##########" |
| 115 | docker run -d --name music-war -v music-vol:/app ${MUSIC_IMG}; |
| 116 | |
| 117 | # Start Zookeeper |
| 118 | echo "########## Start zookeeper (music-zk) ##########" |
| 119 | docker run -d --name music-zk --network music-net -p "2181:2181" -p "2888:2888" -p "3888:3888" ${ZK_IMG}; |
| 120 | |
| 121 | ZOO_IP=`docker inspect -f '{{ $network := index .NetworkSettings.Networks "music-net" }}{{ $network.IPAddress}}' music-zk` |
| 122 | echo "ZOOKEEPER_IP=${ZOO_IP}" |
| 123 | |
| 124 | # Delay between Cassandra/Zookeeper and Tomcat |
Thomas Nelson | 4a9119a | 2018-10-22 02:26:04 -0400 | [diff] [blame] | 125 | sleep 120; |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 126 | |
| 127 | # Start Up tomcat - Needs to have properties,logs dir and war file volume mapped. |
| 128 | echo "########## Start Tomcat (music-tomcat) ##########" |
| 129 | docker run -d --name music-tomcat --network music-net -p "8080:8080" -v music-vol:/usr/local/tomcat/webapps -v ${WORK_DIR}/properties:/opt/app/music/etc:ro -v ${WORK_DIR}/logs:/opt/app/music/logs ${TOMCAT_IMG}; |
| 130 | |
| 131 | # Connect tomcat to host bridge network so that its port can be seen. |
| 132 | echo "########## Create Bridge for Tomcat ##########" |
| 133 | docker network connect bridge music-tomcat; |
| 134 | |
| 135 | TOMCAT_IP=`docker inspect --format '{{ .NetworkSettings.Networks.bridge.IPAddress}}' music-tomcat` |
| 136 | echo "TOMCAT_IP=${TOMCAT_IP}" |
| 137 | |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 138 | ${WORKSPACE}/scripts/music/music-scripts/wait_for_port.sh ${TOMCAT_IP} 8080 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 139 | |
| 140 | sleep 20; |
| 141 | echo "########## TOMCAT Logs ##########" |
| 142 | docker logs music-tomcat |
| 143 | # Needed only if we need to look at localhost logs. |
| 144 | echo "########## MUSIC localhost Log ##########" |
| 145 | docker exec music-tomcat /bin/bash -c "cat /usr/local/tomcat/logs/localhost*" |
| 146 | |
| 147 | echo "########## MUSIC Log ##########" |
| 148 | ls -al $MUSIC_LOGS/MUSIC |
| 149 | docker exec music-tomcat /bin/bash -c "cat /opt/app/music/logs/MUSIC/music.log" |
| 150 | #echo "########## MUSIC error log ##########" |
| 151 | #docker exec music-tomcat /bin/bash -c "cat /opt/app/music/logs/MUSIC/error.log" |
| 152 | |
| 153 | echo "########## inspect docker things for tracing purpose ##########" |
| 154 | docker inspect music-db |
| 155 | docker inspect music-zk |
| 156 | docker inspect music-tomcat |
| 157 | docker inspect music-war |
| 158 | docker volume inspect music-vol |
| 159 | docker network inspect music-net |
| 160 | |
| 161 | echo "########## dump music content just after music is started ##########" |
| 162 | docker exec music-db /usr/bin/nodetool status |
| 163 | docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'SELECT * FROM system_schema.keyspaces' |
| 164 | docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'DESCRIBE keyspace admin' |
| 165 | docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'SELECT * FROM admin.keyspace_master' |
| 166 | |
| 167 | |
| 168 | # |
| 169 | # add here all ROBOT_VARIABLES settings |
| 170 | # |
| 171 | echo "########## music robot variables settings ##########"; |
| 172 | ROBOT_VARIABLES="-v MUSIC_HOSTNAME:http://${TOMCAT_IP} -v MUSIC_PORT:8080 -v COND_HOSTNAME:http://localhost -v COND_PORT:8091" |
| 173 | |
| 174 | echo ${ROBOT_VARIABLES} |
| 175 | |
| 176 | |
| 177 | |