blob: 6e14931f7d5a6efa5a81ebd70151b931734b000f [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
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
Bilal Ab4bf5da2019-03-14 16:45:23 +000046ls -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
53export 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
57fi
58echo $IP
59
60if ! ifconfig docker0; then
61 export DOCKER_IP="$IP"
62else
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
120sleep 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
163
164netstat -tnl
165
Bilal Ab4bf5da2019-03-14 16:45:23 +0000166${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
Bilal Ab4bf5da2019-03-14 16:45:23 +0000175
Bilal Ab4bf5da2019-03-14 16:45:23 +0000176${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 telnet ${NEXUS_IP} 8081 < /dev/null
181 nc -vz ${NEXUS_IP} 8081
182 docker logs nexus
183 exit $rc
184fi
185
186${DIR}/wait_for_port.sh ${POLICY_IP} 9696
187rc=$?
188if [[ $rc != 0 ]]; then
189 echo "cannot open ${POLICY_IP} 9696"
190 telnet ${POLICY_IP} 9696 < /dev/null
191 nc -vz ${POLICY_IP} 9696
192 docker logs drools
193 exit $rc
194fi
195
196${DIR}/wait_for_port.sh ${PAP_IP} 9091
197rc=$?
198if [[ $rc != 0 ]]; then
199 echo "cannot open ${PAP_IP} 9091"
200 telnet ${PAP_IP} 9091 < /dev/null
201 nc -vz ${PAP_IP} 9091
202 docker logs pap
203 exit $rc
204fi
205
206${DIR}/wait_for_port.sh ${PDP_IP} 8081
207rc=$?
208if [[ $rc != 0 ]]; then
209 echo "cannot open ${PDP_IP} 8081"
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 telnet ${BRMS_IP} 9989" < /dev/null
221 nc -vz ${BRMS_IP} 9989"
222 docker logs brmsgw
223 exit $rc
224fi
Bilal Ab4bf5da2019-03-14 16:45:23 +0000225
226docker logs drools
jhhde399b02019-04-29 20:17:45 -0500227docker logs pap
228docker logs pdp
229docker logs brmsgw
Bilal Ab4bf5da2019-03-14 16:45:23 +0000230
jhhde399b02019-04-29 20:17:45 -0500231TIME_OUT=300
Bilal Ab4bf5da2019-03-14 16:45:23 +0000232INTERVAL=20
233TIME=0
234while [ "$TIME" -lt "$TIME_OUT" ]; do
235 curl -k -i --user "demo@people.osaaf.org:demo123456!" -H "ContentType: application/json" -H "Accept: application/json" https://${POLICY_IP}:9696/healthcheck && break
236
237 echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
238 sleep $INTERVAL
239 TIME=$(($TIME+$INTERVAL))
240
241done
242
Bilal Ab4bf5da2019-03-14 16:45:23 +0000243#
244# Add more sleep for everything to settle
245#
246sleep 3m