blob: 4257dad74ec8c1797d31b944acfea98d3a6aa944 [file] [log] [blame]
Gary Wu9abb61c2018-09-27 10:38:50 -07001#!/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 Wu13111e92018-09-27 11:31:33 -070017echo "### This is ${WORKSPACE}/scripts/optf-has/has/music_script.sh"
Gary Wu9abb61c2018-09-27 10:38:50 -070018#
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 Ranganathan5dc29ae2018-10-06 16:35:11 -070025echo "########## music configuration step ##########";
Dileep Ranganathanbc842472018-10-24 05:26:24 -070026CASS_IMG=nexus3.onap.org:10001/onap/music/cassandra_3_11:3.0.23
27CASS_IMG_JOB=nexus3.onap.org:10001/onap/music/cassandra_job:3.0.23
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070028TOMCAT_IMG=nexus3.onap.org:10001/library/tomcat:8.5
Gary Wu9abb61c2018-09-27 10:38:50 -070029ZK_IMG=nexus3.onap.org:10001/library/zookeeper:3.4
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070030BUSYBOX_IMG=nexus3.onap.org:10001/library/busybox:latest
Dileep Ranganathanbc842472018-10-24 05:26:24 -070031MUSIC_IMG=nexus3.onap.org:10001/onap/music/music:3.0.23
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070032TT=10
Gary Wu9abb61c2018-09-27 10:38:50 -070033WORK_DIR=/tmp/music
34CASS_USERNAME=nelson24
35CASS_PASSWORD=winman123
Gary Wu13111e92018-09-27 11:31:33 -070036MUSIC_SOURCE_PROPERTIES=${WORKSPACE}/scripts/optf-has/has/music-properties
Gary Wu9abb61c2018-09-27 10:38:50 -070037MUSIC_PROPERTIES=/tmp/music/properties
38MUSIC_LOGS=/tmp/music/logs
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070039CQL_FILES=${WORKSPACE}/scripts/music/cql
40MUSIC_TRIGGER_DIR=/tmp/triggers
41TRIGGER_JAR=musictrigger-0.1.0.jar
42TRIGGER_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 Wu9abb61c2018-09-27 10:38:50 -070044mkdir -p ${MUSIC_PROPERTIES}
45mkdir -p ${MUSIC_LOGS}
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070046mkdir -p ${MUSIC_LOGS}/MUSIC
47mkdir -p /tmp/triggers
48
49# Get Trigger
50echo "########## Get Trigger Jar ##########"
51curl -o $MUSIC_TRIGGER_DIR/$TRIGGER_JAR $TRIGGER_JAR_URL
Gary Wu9abb61c2018-09-27 10:38:50 -070052
53cp ${MUSIC_SOURCE_PROPERTIES}/* ${WORK_DIR}/properties
54
55# Create Volume for mapping war file and tomcat
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070056echo "########## create music-vol ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -070057docker volume create --name music-vol;
58
59# Create a network for all the containers to run in.
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070060echo "########## create music-net ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -070061docker network create music-net;
62
63# Start Cassandra
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070064echo "########## Start Cassandra (music-db) ##########"
65docker 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 Ranganathan72141ca2018-11-05 07:26:32 -080069# See if cassandra is up.
70echo "########## Running Test to see if Cassandra is up ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -070071CASSA_IP=`docker inspect -f '{{ $network := index .NetworkSettings.Networks "music-net" }}{{ $network.IPAddress}}' music-db`
72echo "CASSANDRA_IP=${CASSA_IP}"
Gary Wu13111e92018-09-27 11:31:33 -070073${WORKSPACE}/scripts/optf-has/has/wait_for_port.sh ${CASSA_IP} 9042
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070074
Dileep Ranganathanbc842472018-10-24 05:26:24 -070075# Sleep 60 seconds to ensure Cassandra is up and running.
76sleep 60;
Dileep Ranganathan72141ca2018-11-05 07:26:32 -080077
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070078# Check to see if Keyspaces are there.
79docker exec music-db cqlsh -u cassandra -p cassandra -e "DESCRIBE keyspaces;"
80
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070081# Load data into Cassandra via Cassandra Job
82echo "########## Running Cassandra Job (music-job) to load cql files ##########"
83docker 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 Ranganathanbc842472018-10-24 05:26:24 -070092
93sleep 70;
94
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -070095# Logs
96echo "########## Cassandra Job logs ##########"
97docker logs music-job
Dileep Ranganathanbc842472018-10-24 05:26:24 -070098# Check to see if Keyspaces are there.
99# "############## Check if new username and password work ##########"
100docker 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 ##########"
103docker 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 ##########"
106docker exec music-db cqlsh -u cassandra -p SomeLongRandomStringNoonewillthinkof -e "DESCRIBE keyspaces;"
107
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700108
Gary Wu9abb61c2018-09-27 10:38:50 -0700109# Start Music war
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700110echo "########## Start music-war ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -0700111docker run -d --name music-war -v music-vol:/app ${MUSIC_IMG};
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700112
Gary Wu9abb61c2018-09-27 10:38:50 -0700113# Start Zookeeper
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700114echo "########## Start zookeeper (music-zk) ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -0700115docker run -d --name music-zk --network music-net -p "2181:2181" -p "2888:2888" -p "3888:3888" ${ZK_IMG};
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700116
Gary Wu9abb61c2018-09-27 10:38:50 -0700117ZOO_IP=`docker inspect -f '{{ $network := index .NetworkSettings.Networks "music-net" }}{{ $network.IPAddress}}' music-zk`
118echo "ZOOKEEPER_IP=${ZOO_IP}"
119
120# Delay between Cassandra/Zookeeper and Tomcat
Dileep Ranganathanbc842472018-10-24 05:26:24 -0700121sleep 120;
Gary Wu9abb61c2018-09-27 10:38:50 -0700122
123# Start Up tomcat - Needs to have properties,logs dir and war file volume mapped.
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700124echo "########## Start Tomcat (music-tomcat) ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -0700125docker 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 Ranganathan5dc29ae2018-10-06 16:35:11 -0700128echo "########## Create Bridge for Tomcat ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -0700129docker network connect bridge music-tomcat;
130
Gary Wu9abb61c2018-09-27 10:38:50 -0700131TOMCAT_IP=`docker inspect --format '{{ .NetworkSettings.Networks.bridge.IPAddress}}' music-tomcat`
132echo "TOMCAT_IP=${TOMCAT_IP}"
133
Gary Wu13111e92018-09-27 11:31:33 -0700134${WORKSPACE}/scripts/optf-has/has/wait_for_port.sh ${TOMCAT_IP} 8080
Gary Wu9abb61c2018-09-27 10:38:50 -0700135
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700136sleep 20;
137echo "########## TOMCAT Logs ##########"
138docker logs music-tomcat
139# Needed only if we need to look at localhost logs.
140echo "########## MUSIC localhost Log ##########"
141docker exec music-tomcat /bin/bash -c "cat /usr/local/tomcat/logs/localhost*"
Gary Wu9abb61c2018-09-27 10:38:50 -0700142
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700143echo "########## MUSIC Log ##########"
144ls -al $MUSIC_LOGS/MUSIC
145docker 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
149echo "########## inspect docker things for tracing purpose ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -0700150docker inspect music-db
151docker inspect music-zk
152docker inspect music-tomcat
153docker inspect music-war
154docker volume inspect music-vol
155docker network inspect music-net
156
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700157echo "########## dump music content just after music is started ##########"
Gary Wu9abb61c2018-09-27 10:38:50 -0700158docker exec music-db /usr/bin/nodetool status
159docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'SELECT * FROM system_schema.keyspaces'
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700160docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'DESCRIBE keyspace admin'
Gary Wu9abb61c2018-09-27 10:38:50 -0700161docker exec music-db /usr/bin/cqlsh -unelson24 -pwinman123 -e 'SELECT * FROM admin.keyspace_master'
162
163
Dileep Ranganathan5dc29ae2018-10-06 16:35:11 -0700164#
165# add here all ROBOT_VARIABLES settings
166#
167echo "########## music robot variables settings ##########";
168ROBOT_VARIABLES="-v MUSIC_HOSTNAME:http://${TOMCAT_IP} -v MUSIC_PORT:8080 -v COND_HOSTNAME:http://localhost -v COND_PORT:8091"
169
170echo ${ROBOT_VARIABLES}
171
Gary Wu9abb61c2018-09-27 10:38:50 -0700172
173