blob: 3e9f3d4218995eaf33bde84993e42eb7200f08a4 [file] [log] [blame]
jhhde399b02019-04-29 20:17:45 -05001#!/bin/bash -x
Gary Wu9abb61c2018-09-27 10:38:50 -07002#
jhhde399b02019-04-29 20:17:45 -05003# Copyright 2017-2019 AT&T Intellectual Property. All rights reserved.
Gary Wu9abb61c2018-09-27 10:38:50 -07004#
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#
pdragosh3f9a0962019-04-16 13:19:45 -040017echo "This is ${WORKSPACE}/scripts/policy/engine.sh"
Gary Wu9abb61c2018-09-27 10:38:50 -070018
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
Martin Klozikf5ae3482019-09-04 10:24:25 +020040# download maven from automatically selected mirror server
41curl -vLO "https://www.apache.org/dyn/mirrors/mirrors.cgi?cca2=us&preferred=http://apache.claz.org/&action=download&filename=maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz"
42if ! tar -xzvf apache-maven-3.3.9-bin.tar.gz ; then
43 echo "Installation of maven has failed!"
44 exit 1
45fi
Gary Wu9abb61c2018-09-27 10:38:50 -070046ls -l
47export PATH=${PATH}:${WORK_DIR}/maven/apache-maven-3.3.9/bin
48${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn -v
49cd ..
50
51ifconfig
52
jh7358582f11f2018-12-12 17:10:03 -050053export IP=`ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}'`
54if [ -z "$IP" ]; then
55 echo "Could not determine IP address"
56 exit 1
Gary Wu9abb61c2018-09-27 10:38:50 -070057fi
58echo $IP
59
60if ! ifconfig docker0; then
jh7358582f11f2018-12-12 17:10:03 -050061 export DOCKER_IP="$IP"
Gary Wu9abb61c2018-09-27 10:38:50 -070062else
63 export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
64fi
65echo $DOCKER_IP
66
67git clone http://gerrit.onap.org/r/oparent
68
69git clone http://gerrit.onap.org/r/policy/engine
70cd engine/packages/docker
71${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml
72docker build -t onap/policy-pe target/policy-pe
73
74cd ${WORK_DIR}
75git clone http://gerrit.onap.org/r/policy/drools-pdp
76cd drools-pdp/packages/docker
77${WORK_DIR}/maven/apache-maven-3.3.9/bin/mvn prepare-package --settings ${WORK_DIR}/oparent/settings.xml
78docker build -t onap/policy-drools target/policy-drools
79
80cd ${WORK_DIR}
81git clone http://gerrit.onap.org/r/policy/docker
82cd docker
83
84chmod +x config/drools/drools-tweaks.sh
85
86echo $IP > config/pe/ip_addr.txt
87ls -l config/pe/ip_addr.txt
88cat config/pe/ip_addr.txt
89
90export MTU=9126
91
92export PRELOAD_POLICIES=false
93docker-compose -f docker-compose-integration.yml up -d
94
95if [ ! $? -eq 0 ]; then
96 echo "Docker compose failed"
97 exit 1
98fi
99
100docker ps
101
102POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools`
103echo ${POLICY_IP}
104
105PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp`
106echo ${PDP_IP}
107
108PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap`
109echo ${PAP_IP}
110
111BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw`
112echo ${BRMS_IP}
113
114NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus`
115echo ${NEXUS_IP}
116
117MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb`
118echo ${MARIADB_IP}
119
jh7358582f11f2018-12-12 17:10:03 -0500120sleep 3m
121
122docker logs mariadb 2>&1 | grep -q "mysqld: ready for connections"
123if [ $? -eq 0 ]; then
124 # mariadb is ok - sleep a little longer for others
125 sleep 2m
126
127else
128 echo mariadb is not ready
129 echo Restarting...
130
131 docker kill drools pdp pap brmsgw nexus mariadb
132 docker rm -f drools pdp pap brmsgw nexus mariadb
133
134 docker-compose -f docker-compose-integration.yml up -d
135
136 if [ ! $? -eq 0 ]; then
137 echo "Docker compose failed"
138 exit 1
139 fi
140
141 docker ps
142
143 POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools`
144 echo ${POLICY_IP}
145
146 PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp`
147 echo ${PDP_IP}
148
149 PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap`
150 echo ${PAP_IP}
151
152 BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw`
153 echo ${BRMS_IP}
154
155 NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus`
156 echo ${NEXUS_IP}
157
158 MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb`
159 echo ${MARIADB_IP}
160
161 sleep 5m
162fi
Gary Wu9abb61c2018-09-27 10:38:50 -0700163
164netstat -tnl
165
Gary Wu9abb61c2018-09-27 10:38:50 -0700166${DIR}/wait_for_port.sh ${MARIADB_IP} 3306
jhhde399b02019-04-29 20:17:45 -0500167rc=$?
168if [[ $rc != 0 ]]; then
169 echo "cannot open ${MARIADB_IP} 3306"
170 telnet ${MARIADB_IP} 3306 < /dev/null
171 nc -vz ${MARIADB_IP} 3306
172 docker logs mariadb
173 exit $rc
174fi
Gary Wu9abb61c2018-09-27 10:38:50 -0700175
Gary Wu9abb61c2018-09-27 10:38:50 -0700176${DIR}/wait_for_port.sh ${NEXUS_IP} 8081
jhhde399b02019-04-29 20:17:45 -0500177rc=$?
178if [[ $rc != 0 ]]; then
179 echo "cannot open ${NEXUS_IP} 8081"
180 netstat -tnl
181 telnet ${NEXUS_IP} 8081 < /dev/null
182 nc -vz ${NEXUS_IP} 8081
183 docker logs nexus
184 exit $rc
185fi
186
187${DIR}/wait_for_port.sh ${POLICY_IP} 9696
188rc=$?
189if [[ $rc != 0 ]]; then
190 echo "cannot open ${POLICY_IP} 9696"
191 netstat -tnl
192 telnet ${POLICY_IP} 9696 < /dev/null
193 nc -vz ${POLICY_IP} 9696
194 docker logs drools
195 exit $rc
196fi
197
198${DIR}/wait_for_port.sh ${PAP_IP} 9091
199rc=$?
200if [[ $rc != 0 ]]; then
201 echo "cannot open ${PAP_IP} 9091"
202 netstat -tnl
203 telnet ${PAP_IP} 9091 < /dev/null
204 nc -vz ${PAP_IP} 9091
205 docker logs pap
206 exit $rc
207fi
208
209${DIR}/wait_for_port.sh ${PDP_IP} 8081
210rc=$?
211if [[ $rc != 0 ]]; then
212 echo "cannot open ${PDP_IP} 8081"
213 netstat -tnl
214 telnet ${PDP_IP} 8081 < /dev/null
215 nc -vz ${PDP_IP} 8081
216 docker logs pdp
217 exit $rc
218fi
219
220${DIR}/wait_for_port.sh ${BRMS_IP} 9989
221rc=$?
222if [[ $rc != 0 ]]; then
223 echo "cannot open ${BRMS_IP} 9989"
224 netstat -tnl
225 telnet ${BRMS_IP} 9989" < /dev/null
226 nc -vz ${BRMS_IP} 9989"
227 docker logs brmsgw
228 exit $rc
229fi
Gary Wu9abb61c2018-09-27 10:38:50 -0700230
231docker logs drools
jhhde399b02019-04-29 20:17:45 -0500232docker logs pap
233docker logs pdp
234docker logs brmsgw
Gary Wu9abb61c2018-09-27 10:38:50 -0700235
jhhde399b02019-04-29 20:17:45 -0500236TIME_OUT=300
Gary Wu9abb61c2018-09-27 10:38:50 -0700237INTERVAL=20
238TIME=0
239while [ "$TIME" -lt "$TIME_OUT" ]; do
Jorge Hernandezfd98e3c2018-10-01 09:57:59 -0500240 curl -k -i --user "demo@people.osaaf.org:demo123456!" -H "ContentType: application/json" -H "Accept: application/json" https://${POLICY_IP}:6969/healthcheck && break
Gary Wu9abb61c2018-09-27 10:38:50 -0700241
242 echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
243 sleep $INTERVAL
244 TIME=$(($TIME+$INTERVAL))
245
246done
247
jhhde399b02019-04-29 20:17:45 -0500248TIME_OUT=300
Gary Wu9abb61c2018-09-27 10:38:50 -0700249INTERVAL=20
250TIME=0
251while [ "$TIME" -lt "$TIME_OUT" ]; do
252
jh7358582f11f2018-12-12 17:10:03 -0500253 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 Wu9abb61c2018-09-27 10:38:50 -0700254
255echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
256 sleep $INTERVAL
257 TIME=$(($TIME+$INTERVAL))
258
259done
260
261#
262# Add more sleep for everything to settle
263#
264sleep 3m