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 | # |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 17 | echo "### This is ${WORKSPACE}/scripts/optf-has/has/music_script.sh" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 18 | # |
| 19 | # add here whatever commands is needed to prepare the music setup for optf-has CSIT testing |
| 20 | # |
| 21 | |
| 22 | # |
| 23 | # add here all the configuration steps eventually needed to be carried out for music CSIT testing |
| 24 | # |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 25 | echo "########## music configuration step ##########"; |
Dileep Ranganathan | bc84247 | 2018-10-24 05:26:24 -0700 | [diff] [blame] | 26 | CASS_IMG=nexus3.onap.org:10001/onap/music/cassandra_3_11:3.0.23 |
| 27 | CASS_IMG_JOB=nexus3.onap.org:10001/onap/music/cassandra_job:3.0.23 |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 28 | TOMCAT_IMG=nexus3.onap.org:10001/library/tomcat:8.5 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 29 | ZK_IMG=nexus3.onap.org:10001/library/zookeeper:3.4 |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 30 | BUSYBOX_IMG=nexus3.onap.org:10001/library/busybox:latest |
Dileep Ranganathan | bc84247 | 2018-10-24 05:26:24 -0700 | [diff] [blame] | 31 | MUSIC_IMG=nexus3.onap.org:10001/onap/music/music:3.0.23 |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 32 | TT=10 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 33 | WORK_DIR=/tmp/music |
| 34 | CASS_USERNAME=nelson24 |
| 35 | CASS_PASSWORD=winman123 |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 36 | MUSIC_SOURCE_PROPERTIES=${WORKSPACE}/scripts/optf-has/has/music-properties |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 37 | MUSIC_PROPERTIES=/tmp/music/properties |
| 38 | MUSIC_LOGS=/tmp/music/logs |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 39 | CQL_FILES=${WORKSPACE}/scripts/music/cql |
| 40 | MUSIC_TRIGGER_DIR=/tmp/triggers |
| 41 | TRIGGER_JAR=musictrigger-0.1.0.jar |
| 42 | 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 |
| 43 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 44 | mkdir -p ${MUSIC_PROPERTIES} |
| 45 | mkdir -p ${MUSIC_LOGS} |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 46 | mkdir -p ${MUSIC_LOGS}/MUSIC |
| 47 | mkdir -p /tmp/triggers |
| 48 | |
| 49 | # Get Trigger |
| 50 | echo "########## Get Trigger Jar ##########" |
| 51 | curl -o $MUSIC_TRIGGER_DIR/$TRIGGER_JAR $TRIGGER_JAR_URL |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 52 | |
| 53 | cp ${MUSIC_SOURCE_PROPERTIES}/* ${WORK_DIR}/properties |
| 54 | |
| 55 | # Create Volume for mapping war file and tomcat |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 56 | echo "########## create music-vol ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 57 | docker volume create --name music-vol; |
| 58 | |
| 59 | # Create a network for all the containers to run in. |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 60 | echo "########## create music-net ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 61 | docker network create music-net; |
| 62 | |
| 63 | # Start Cassandra |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 64 | echo "########## Start Cassandra (music-db) ##########" |
| 65 | docker run -d --name music-db --network music-net -p "7000:7000" -p "7001:7001" -p "7199:7199" -p "9042:9042" -p "9160:9160" \ |
| 66 | -v $MUSIC_TRIGGER_DIR/$TRIGGER_JAR:/etc/cassandra/triggers/$TRIGGER_JAR \ |
| 67 | ${CASS_IMG}; |
| 68 | |
Dileep Ranganathan | 72141ca | 2018-11-05 07:26:32 -0800 | [diff] [blame] | 69 | # See if cassandra is up. |
| 70 | echo "########## Running Test to see if Cassandra is up ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 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 |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 74 | |
Dileep Ranganathan | bc84247 | 2018-10-24 05:26:24 -0700 | [diff] [blame] | 75 | # Sleep 60 seconds to ensure Cassandra is up and running. |
| 76 | sleep 60; |
Dileep Ranganathan | 72141ca | 2018-11-05 07:26:32 -0800 | [diff] [blame] | 77 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 78 | # Check to see if Keyspaces are there. |
| 79 | docker exec music-db cqlsh -u cassandra -p cassandra -e "DESCRIBE keyspaces;" |
| 80 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 81 | # Load data into Cassandra via Cassandra Job |
| 82 | echo "########## Running Cassandra Job (music-job) to load cql files ##########" |
| 83 | docker run -d --name music-job --network music-net \ |
| 84 | -v $CQL_FILES/admin.cql:/cql/admin.cql \ |
| 85 | -v $CQL_FILES/admin_pw.cql:/cql/admin_pw.cql \ |
| 86 | -v $CQL_FILES/extra:/cql/extra \ |
| 87 | -e PORT=9042 \ |
| 88 | -e CASS_HOSTNAME=music-db \ |
| 89 | -e USERNAME=$CASS_USERNAME \ |
| 90 | -e PASSWORD=$CASS_PASSWORD \ |
| 91 | $CASS_IMG_JOB |
Dileep Ranganathan | bc84247 | 2018-10-24 05:26:24 -0700 | [diff] [blame] | 92 | |
| 93 | sleep 70; |
| 94 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 95 | # Logs |
| 96 | echo "########## Cassandra Job logs ##########" |
| 97 | docker logs music-job |
Dileep Ranganathan | bc84247 | 2018-10-24 05:26:24 -0700 | [diff] [blame] | 98 | # Check to see if Keyspaces are there. |
| 99 | # "############## Check if new username and password work ##########" |
| 100 | docker exec music-db cqlsh -u $CASS_USERNAME -p $CASS_PASSWORD -e "DESCRIBE keyspaces;" |
| 101 | # Check to see if Keyspaces are there. |
| 102 | # "############## Check if original username and password work ##########" |
| 103 | docker exec music-db cqlsh -u cassandra -p cassandra -e "DESCRIBE keyspaces;" |
| 104 | # Check to see if Keyspaces are there. |
| 105 | # "############## Check if new cassandra username and password work ##########" |
| 106 | docker exec music-db cqlsh -u cassandra -p SomeLongRandomStringNoonewillthinkof -e "DESCRIBE keyspaces;" |
| 107 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 108 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 109 | # Start Music war |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 110 | echo "########## Start music-war ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 111 | docker run -d --name music-war -v music-vol:/app ${MUSIC_IMG}; |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 112 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 113 | # Start Zookeeper |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 114 | echo "########## Start zookeeper (music-zk) ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 115 | docker run -d --name music-zk --network music-net -p "2181:2181" -p "2888:2888" -p "3888:3888" ${ZK_IMG}; |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 116 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 117 | ZOO_IP=`docker inspect -f '{{ $network := index .NetworkSettings.Networks "music-net" }}{{ $network.IPAddress}}' music-zk` |
| 118 | echo "ZOOKEEPER_IP=${ZOO_IP}" |
| 119 | |
| 120 | # Delay between Cassandra/Zookeeper and Tomcat |
Dileep Ranganathan | bc84247 | 2018-10-24 05:26:24 -0700 | [diff] [blame] | 121 | sleep 120; |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 122 | |
| 123 | # Start Up tomcat - Needs to have properties,logs dir and war file volume mapped. |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 124 | echo "########## Start Tomcat (music-tomcat) ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 125 | 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}; |
| 126 | |
| 127 | # Connect tomcat to host bridge network so that its port can be seen. |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 128 | echo "########## Create Bridge for Tomcat ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 129 | docker network connect bridge music-tomcat; |
| 130 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 131 | TOMCAT_IP=`docker inspect --format '{{ .NetworkSettings.Networks.bridge.IPAddress}}' music-tomcat` |
| 132 | echo "TOMCAT_IP=${TOMCAT_IP}" |
| 133 | |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 134 | ${WORKSPACE}/scripts/optf-has/has/wait_for_port.sh ${TOMCAT_IP} 8080 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 135 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 136 | sleep 20; |
| 137 | echo "########## TOMCAT Logs ##########" |
| 138 | docker logs music-tomcat |
| 139 | # Needed only if we need to look at localhost logs. |
| 140 | echo "########## MUSIC localhost Log ##########" |
| 141 | docker exec music-tomcat /bin/bash -c "cat /usr/local/tomcat/logs/localhost*" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 142 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 143 | echo "########## MUSIC Log ##########" |
| 144 | ls -al $MUSIC_LOGS/MUSIC |
| 145 | docker exec music-tomcat /bin/bash -c "cat /opt/app/music/logs/MUSIC/music.log" |
| 146 | #echo "########## MUSIC error log ##########" |
| 147 | #docker exec music-tomcat /bin/bash -c "cat /opt/app/music/logs/MUSIC/error.log" |
| 148 | |
| 149 | echo "########## inspect docker things for tracing purpose ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 150 | docker inspect music-db |
| 151 | docker inspect music-zk |
| 152 | docker inspect music-tomcat |
| 153 | docker inspect music-war |
| 154 | docker volume inspect music-vol |
| 155 | docker network inspect music-net |
| 156 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 157 | echo "########## dump music content just after music is started ##########" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 158 | docker exec music-db /usr/bin/nodetool status |
| 159 | docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'SELECT * FROM system_schema.keyspaces' |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 160 | docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'DESCRIBE keyspace admin' |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 161 | docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'SELECT * FROM admin.keyspace_master' |
| 162 | |
| 163 | |
Dileep Ranganathan | 5dc29ae | 2018-10-06 16:35:11 -0700 | [diff] [blame] | 164 | # |
| 165 | # add here all ROBOT_VARIABLES settings |
| 166 | # |
| 167 | echo "########## music robot variables settings ##########"; |
| 168 | ROBOT_VARIABLES="-v MUSIC_HOSTNAME:http://${TOMCAT_IP} -v MUSIC_PORT:8080 -v COND_HOSTNAME:http://localhost -v COND_PORT:8091" |
| 169 | |
| 170 | echo ${ROBOT_VARIABLES} |
| 171 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 172 | |
| 173 | |