blob: fc8556ffe34508303f8d7ba0a75878a1bf73e1db [file] [log] [blame]
jhhde399b02019-04-29 20:17:45 -05001#!/bin/bash -x
Bilal Ab4bf5da2019-03-14 16:45:23 +00002#
jhhde399b02019-04-29 20:17:45 -05003# Copyright 2017-2019 AT&T Intellectual Property. All rights reserved.
Bilal Ab4bf5da2019-03-14 16:45:23 +00004#
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#
17echo "This is ${WORKSPACE}/scripts/policy/drools-pdp-script.sh"
18
19
20# the directory of the script
21DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
22echo ${DIR}
23
24# the temp directory used, within $DIR
25# omit the -p parameter to create a temporal directory in the default location
26WORK_DIR=`mktemp -d -p "$DIR"`
27echo ${WORK_DIR}
28
29cd ${WORK_DIR}
30
31# check if tmp dir was created
32if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
33 echo "Could not create temp dir"
34 exit 1
35fi
36
37# bring down maven
38mkdir maven
39cd maven
40curl -O http://apache.claz.org/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
41tar -xzvf apache-maven-3.3.9-bin.tar.gz
42ls -l
43export PATH=${PATH}:${WORK_DIR}/maven/apache-maven-3.3.9/bin
44${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn -v
45cd ..
46
47ifconfig
48
49export IP=`ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}'`
50if [ -z "$IP" ]; then
51 echo "Could not determine IP address"
52 exit 1
53fi
54echo $IP
55
56if ! ifconfig docker0; then
57 export DOCKER_IP="$IP"
58else
59 export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
60fi
61echo $DOCKER_IP
62
63git clone http://gerrit.onap.org/r/oparent
64
65git clone http://gerrit.onap.org/r/policy/engine
66cd engine/packages/docker
67${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml
68docker build -t onap/policy-pe target/policy-pe
69
70cd ${WORK_DIR}
71git clone http://gerrit.onap.org/r/policy/drools-pdp
72cd drools-pdp/packages/docker
73${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml
74docker build -t onap/policy-drools target/policy-drools
75
76cd ${WORK_DIR}
77git clone http://gerrit.onap.org/r/policy/docker
78cd docker
79
80chmod +x config/drools/drools-tweaks.sh
81
82echo $IP > config/pe/ip_addr.txt
83ls -l config/pe/ip_addr.txt
84cat config/pe/ip_addr.txt
85
86export MTU=9126
87
88export PRELOAD_POLICIES=false
89docker-compose -f docker-compose-integration.yml up -d
90
91if [ ! $? -eq 0 ]; then
92 echo "Docker compose failed"
93 exit 1
94fi
95
96docker ps
97
98POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools`
99echo ${POLICY_IP}
100
101PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp`
102echo ${PDP_IP}
103
104PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap`
105echo ${PAP_IP}
106
107BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw`
108echo ${BRMS_IP}
109
110NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus`
111echo ${NEXUS_IP}
112
113MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb`
114echo ${MARIADB_IP}
115
116sleep 3m
117
118docker logs mariadb 2>&1 | grep -q "mysqld: ready for connections"
119if [ $? -eq 0 ]; then
120 # mariadb is ok - sleep a little longer for others
121 sleep 2m
122
123else
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
158fi
159
160netstat -tnl
161
Bilal Ab4bf5da2019-03-14 16:45:23 +0000162${DIR}/wait_for_port.sh ${MARIADB_IP} 3306
jhhde399b02019-04-29 20:17:45 -0500163rc=$?
164if [[ $rc != 0 ]]; then
165 echo "cannot open ${MARIADB_IP} 3306"
166 telnet ${MARIADB_IP} 3306 < /dev/null
167 nc -vz ${MARIADB_IP} 3306
168 docker logs mariadb
169 exit $rc
170fi
Bilal Ab4bf5da2019-03-14 16:45:23 +0000171
Bilal Ab4bf5da2019-03-14 16:45:23 +0000172${DIR}/wait_for_port.sh ${NEXUS_IP} 8081
jhhde399b02019-04-29 20:17:45 -0500173rc=$?
174if [[ $rc != 0 ]]; then
175 echo "cannot open ${NEXUS_IP} 8081"
176 telnet ${NEXUS_IP} 8081 < /dev/null
177 nc -vz ${NEXUS_IP} 8081
178 docker logs nexus
179 exit $rc
180fi
181
182${DIR}/wait_for_port.sh ${POLICY_IP} 9696
183rc=$?
184if [[ $rc != 0 ]]; then
185 echo "cannot open ${POLICY_IP} 9696"
186 telnet ${POLICY_IP} 9696 < /dev/null
187 nc -vz ${POLICY_IP} 9696
188 docker logs drools
189 exit $rc
190fi
191
192${DIR}/wait_for_port.sh ${PAP_IP} 9091
193rc=$?
194if [[ $rc != 0 ]]; then
195 echo "cannot open ${PAP_IP} 9091"
196 telnet ${PAP_IP} 9091 < /dev/null
197 nc -vz ${PAP_IP} 9091
198 docker logs pap
199 exit $rc
200fi
201
202${DIR}/wait_for_port.sh ${PDP_IP} 8081
203rc=$?
204if [[ $rc != 0 ]]; then
205 echo "cannot open ${PDP_IP} 8081"
206 telnet ${PDP_IP} 8081 < /dev/null
207 nc -vz ${PDP_IP} 8081
208 docker logs pdp
209 exit $rc
210fi
211
212${DIR}/wait_for_port.sh ${BRMS_IP} 9989
213rc=$?
214if [[ $rc != 0 ]]; then
215 echo "cannot open ${BRMS_IP} 9989"
216 telnet ${BRMS_IP} 9989" < /dev/null
217 nc -vz ${BRMS_IP} 9989"
218 docker logs brmsgw
219 exit $rc
220fi
Bilal Ab4bf5da2019-03-14 16:45:23 +0000221
222docker logs drools
jhhde399b02019-04-29 20:17:45 -0500223docker logs pap
224docker logs pdp
225docker logs brmsgw
Bilal Ab4bf5da2019-03-14 16:45:23 +0000226
jhhde399b02019-04-29 20:17:45 -0500227TIME_OUT=300
Bilal Ab4bf5da2019-03-14 16:45:23 +0000228INTERVAL=20
229TIME=0
230while [ "$TIME" -lt "$TIME_OUT" ]; do
231 curl -k -i --user "demo@people.osaaf.org:demo123456!" -H "ContentType: application/json" -H "Accept: application/json" https://${POLICY_IP}:9696/healthcheck && break
232
233 echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
234 sleep $INTERVAL
235 TIME=$(($TIME+$INTERVAL))
236
237done
238
Bilal Ab4bf5da2019-03-14 16:45:23 +0000239#
240# Add more sleep for everything to settle
241#
242sleep 3m