blob: 0a128faf8fe133b41890f59d6a5bfbd2f2ceb29d [file] [log] [blame]
Bilal Ab4bf5da2019-03-14 16:45:23 +00001#!/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#
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
162docker logs mariadb
163${DIR}/wait_for_port.sh ${MARIADB_IP} 3306
164
165docker logs pap
166${DIR}/wait_for_port.sh ${PAP_IP} 9091
167
168docker logs pdp
169${DIR}/wait_for_port.sh ${PDP_IP} 8081
170
171docker logs brmsgw
172${DIR}/wait_for_port.sh ${BRMS_IP} 9989
173
174docker logs nexus
175${DIR}/wait_for_port.sh ${NEXUS_IP} 8081
176
177docker logs drools
178${DIR}/wait_for_port.sh ${POLICY_IP} 9696
179
180TIME_OUT=600
181INTERVAL=20
182TIME=0
183while [ "$TIME" -lt "$TIME_OUT" ]; do
184 curl -k -i --user "demo@people.osaaf.org:demo123456!" -H "ContentType: application/json" -H "Accept: application/json" https://${POLICY_IP}:9696/healthcheck && break
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
190done
191
192TIME_OUT=600
193INTERVAL=20
194TIME=0
195while [ "$TIME" -lt "$TIME_OUT" ]; do
196
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
198
199echo 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
203done
204
205#
206# Add more sleep for everything to settle
207#
208sleep 3m