blob: ef02be5afff3252f20140a88c4e753e6992b011b [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
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
jh7358582f11f2018-12-12 17:10:03 -050049export 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
Gary Wu9abb61c2018-09-27 10:38:50 -070053fi
54echo $IP
55
56if ! ifconfig docker0; then
jh7358582f11f2018-12-12 17:10:03 -050057 export DOCKER_IP="$IP"
Gary Wu9abb61c2018-09-27 10:38:50 -070058else
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
jh7358582f11f2018-12-12 17:10:03 -0500116sleep 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
Gary Wu9abb61c2018-09-27 10:38:50 -0700159
160netstat -tnl
161
Gary Wu9abb61c2018-09-27 10:38:50 -0700162${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
Gary Wu9abb61c2018-09-27 10:38:50 -0700171
Gary Wu9abb61c2018-09-27 10:38:50 -0700172${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 netstat -tnl
177 telnet ${NEXUS_IP} 8081 < /dev/null
178 nc -vz ${NEXUS_IP} 8081
179 docker logs nexus
180 exit $rc
181fi
182
183${DIR}/wait_for_port.sh ${POLICY_IP} 9696
184rc=$?
185if [[ $rc != 0 ]]; then
186 echo "cannot open ${POLICY_IP} 9696"
187 netstat -tnl
188 telnet ${POLICY_IP} 9696 < /dev/null
189 nc -vz ${POLICY_IP} 9696
190 docker logs drools
191 exit $rc
192fi
193
194${DIR}/wait_for_port.sh ${PAP_IP} 9091
195rc=$?
196if [[ $rc != 0 ]]; then
197 echo "cannot open ${PAP_IP} 9091"
198 netstat -tnl
199 telnet ${PAP_IP} 9091 < /dev/null
200 nc -vz ${PAP_IP} 9091
201 docker logs pap
202 exit $rc
203fi
204
205${DIR}/wait_for_port.sh ${PDP_IP} 8081
206rc=$?
207if [[ $rc != 0 ]]; then
208 echo "cannot open ${PDP_IP} 8081"
209 netstat -tnl
210 telnet ${PDP_IP} 8081 < /dev/null
211 nc -vz ${PDP_IP} 8081
212 docker logs pdp
213 exit $rc
214fi
215
216${DIR}/wait_for_port.sh ${BRMS_IP} 9989
217rc=$?
218if [[ $rc != 0 ]]; then
219 echo "cannot open ${BRMS_IP} 9989"
220 netstat -tnl
221 telnet ${BRMS_IP} 9989" < /dev/null
222 nc -vz ${BRMS_IP} 9989"
223 docker logs brmsgw
224 exit $rc
225fi
Gary Wu9abb61c2018-09-27 10:38:50 -0700226
227docker logs drools
jhhde399b02019-04-29 20:17:45 -0500228docker logs pap
229docker logs pdp
230docker logs brmsgw
Gary Wu9abb61c2018-09-27 10:38:50 -0700231
jhhde399b02019-04-29 20:17:45 -0500232TIME_OUT=300
Gary Wu9abb61c2018-09-27 10:38:50 -0700233INTERVAL=20
234TIME=0
235while [ "$TIME" -lt "$TIME_OUT" ]; do
Jorge Hernandezfd98e3c2018-10-01 09:57:59 -0500236 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 -0700237
238 echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
239 sleep $INTERVAL
240 TIME=$(($TIME+$INTERVAL))
241
242done
243
jhhde399b02019-04-29 20:17:45 -0500244TIME_OUT=300
Gary Wu9abb61c2018-09-27 10:38:50 -0700245INTERVAL=20
246TIME=0
247while [ "$TIME" -lt "$TIME_OUT" ]; do
248
jh7358582f11f2018-12-12 17:10:03 -0500249 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 -0700250
251echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
252 sleep $INTERVAL
253 TIME=$(($TIME+$INTERVAL))
254
255done
256
257#
258# Add more sleep for everything to settle
259#
260sleep 3m