Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2017-2018 AT&T Intellectual Property. All rights reserved. |
| 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/policy/script1.sh" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 18 | |
| 19 | |
| 20 | # the directory of the script |
| 21 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 22 | echo ${DIR} |
| 23 | |
| 24 | # the temp directory used, within $DIR |
| 25 | # omit the -p parameter to create a temporal directory in the default location |
| 26 | WORK_DIR=`mktemp -d -p "$DIR"` |
| 27 | echo ${WORK_DIR} |
| 28 | |
| 29 | cd ${WORK_DIR} |
| 30 | |
| 31 | # check if tmp dir was created |
| 32 | if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then |
| 33 | echo "Could not create temp dir" |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | # bring down maven |
| 38 | mkdir maven |
| 39 | cd maven |
| 40 | curl -O http://apache.claz.org/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz |
| 41 | tar -xzvf apache-maven-3.3.9-bin.tar.gz |
| 42 | ls -l |
| 43 | export PATH=${PATH}:${WORK_DIR}/maven/apache-maven-3.3.9/bin |
| 44 | ${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn -v |
| 45 | cd .. |
| 46 | |
| 47 | ifconfig |
| 48 | |
jh7358 | 582f11f | 2018-12-12 17:10:03 -0500 | [diff] [blame] | 49 | export IP=`ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}'` |
| 50 | if [ -z "$IP" ]; then |
| 51 | echo "Could not determine IP address" |
| 52 | exit 1 |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 53 | fi |
| 54 | echo $IP |
| 55 | |
| 56 | if ! ifconfig docker0; then |
jh7358 | 582f11f | 2018-12-12 17:10:03 -0500 | [diff] [blame] | 57 | export DOCKER_IP="$IP" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 58 | else |
| 59 | export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` |
| 60 | fi |
| 61 | echo $DOCKER_IP |
| 62 | |
| 63 | git clone http://gerrit.onap.org/r/oparent |
| 64 | |
| 65 | git clone http://gerrit.onap.org/r/policy/engine |
| 66 | cd engine/packages/docker |
| 67 | ${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml |
| 68 | docker build -t onap/policy-pe target/policy-pe |
| 69 | |
| 70 | cd ${WORK_DIR} |
| 71 | git clone http://gerrit.onap.org/r/policy/drools-pdp |
| 72 | cd drools-pdp/packages/docker |
| 73 | ${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml |
| 74 | docker build -t onap/policy-drools target/policy-drools |
| 75 | |
| 76 | cd ${WORK_DIR} |
| 77 | git clone http://gerrit.onap.org/r/policy/docker |
| 78 | cd docker |
| 79 | |
| 80 | chmod +x config/drools/drools-tweaks.sh |
| 81 | |
| 82 | echo $IP > config/pe/ip_addr.txt |
| 83 | ls -l config/pe/ip_addr.txt |
| 84 | cat config/pe/ip_addr.txt |
| 85 | |
| 86 | export MTU=9126 |
| 87 | |
| 88 | export PRELOAD_POLICIES=false |
| 89 | docker-compose -f docker-compose-integration.yml up -d |
| 90 | |
| 91 | if [ ! $? -eq 0 ]; then |
| 92 | echo "Docker compose failed" |
| 93 | exit 1 |
| 94 | fi |
| 95 | |
| 96 | docker ps |
| 97 | |
| 98 | POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools` |
| 99 | echo ${POLICY_IP} |
| 100 | |
| 101 | PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp` |
| 102 | echo ${PDP_IP} |
| 103 | |
| 104 | PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap` |
| 105 | echo ${PAP_IP} |
| 106 | |
| 107 | BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw` |
| 108 | echo ${BRMS_IP} |
| 109 | |
| 110 | NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus` |
| 111 | echo ${NEXUS_IP} |
| 112 | |
| 113 | MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb` |
| 114 | echo ${MARIADB_IP} |
| 115 | |
jh7358 | 582f11f | 2018-12-12 17:10:03 -0500 | [diff] [blame] | 116 | sleep 3m |
| 117 | |
| 118 | docker logs mariadb 2>&1 | grep -q "mysqld: ready for connections" |
| 119 | if [ $? -eq 0 ]; then |
| 120 | # mariadb is ok - sleep a little longer for others |
| 121 | sleep 2m |
| 122 | |
| 123 | else |
| 124 | echo mariadb is not ready |
| 125 | echo Restarting... |
| 126 | |
| 127 | docker kill drools pdp pap brmsgw nexus mariadb |
| 128 | docker rm -f drools pdp pap brmsgw nexus mariadb |
| 129 | |
| 130 | docker-compose -f docker-compose-integration.yml up -d |
| 131 | |
| 132 | if [ ! $? -eq 0 ]; then |
| 133 | echo "Docker compose failed" |
| 134 | exit 1 |
| 135 | fi |
| 136 | |
| 137 | docker ps |
| 138 | |
| 139 | POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools` |
| 140 | echo ${POLICY_IP} |
| 141 | |
| 142 | PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp` |
| 143 | echo ${PDP_IP} |
| 144 | |
| 145 | PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap` |
| 146 | echo ${PAP_IP} |
| 147 | |
| 148 | BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw` |
| 149 | echo ${BRMS_IP} |
| 150 | |
| 151 | NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus` |
| 152 | echo ${NEXUS_IP} |
| 153 | |
| 154 | MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb` |
| 155 | echo ${MARIADB_IP} |
| 156 | |
| 157 | sleep 5m |
| 158 | fi |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 159 | |
| 160 | netstat -tnl |
| 161 | |
| 162 | docker logs mariadb |
| 163 | ${DIR}/wait_for_port.sh ${MARIADB_IP} 3306 |
| 164 | |
| 165 | docker logs pap |
| 166 | ${DIR}/wait_for_port.sh ${PAP_IP} 9091 |
| 167 | |
| 168 | docker logs pdp |
| 169 | ${DIR}/wait_for_port.sh ${PDP_IP} 8081 |
| 170 | |
| 171 | docker logs brmsgw |
| 172 | ${DIR}/wait_for_port.sh ${BRMS_IP} 9989 |
| 173 | |
| 174 | docker logs nexus |
| 175 | ${DIR}/wait_for_port.sh ${NEXUS_IP} 8081 |
| 176 | |
| 177 | docker logs drools |
| 178 | ${DIR}/wait_for_port.sh ${POLICY_IP} 6969 |
| 179 | |
| 180 | TIME_OUT=600 |
| 181 | INTERVAL=20 |
| 182 | TIME=0 |
| 183 | while [ "$TIME" -lt "$TIME_OUT" ]; do |
Jorge Hernandez | fd98e3c | 2018-10-01 09:57:59 -0500 | [diff] [blame] | 184 | curl -k -i --user "demo@people.osaaf.org:demo123456!" -H "ContentType: application/json" -H "Accept: application/json" https://${POLICY_IP}:6969/healthcheck && break |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 185 | |
| 186 | echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds |
| 187 | sleep $INTERVAL |
| 188 | TIME=$(($TIME+$INTERVAL)) |
| 189 | |
| 190 | done |
| 191 | |
| 192 | TIME_OUT=600 |
| 193 | INTERVAL=20 |
| 194 | TIME=0 |
| 195 | while [ "$TIME" -lt "$TIME_OUT" ]; do |
| 196 | |
jh7358 | 582f11f | 2018-12-12 17:10:03 -0500 | [diff] [blame] | 197 | curl -k -i -v -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -H 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' -H 'Environment: TEST' -d '{"policyName": ".*"}' https://${PDP_IP}:8081/pdp/api/getConfig && break |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 198 | |
| 199 | echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds |
| 200 | sleep $INTERVAL |
| 201 | TIME=$(($TIME+$INTERVAL)) |
| 202 | |
| 203 | done |
| 204 | |
| 205 | # |
| 206 | # Add more sleep for everything to settle |
| 207 | # |
| 208 | sleep 3m |