Workaround for deployment problem
[dmaap/buscontroller.git] / dbc-client / misc / dbc-client
1 #!/bin/sh
2 #
3 # ============LICENSE_START==========================================
4 # org.onap.dmaap
5 # ===================================================================
6 # Copyright © 2019 AT&T Intellectual Property. All rights reserved.
7 # ===================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #        http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END============================================
20 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 #
22 #
23
24 umask 0022
25 TZ=GMT0
26 COMPONENT=dbc-client
27 APP_ROOT=${APP_ROOT:-/opt/app/$COMPONENT}
28 export TZ
29 PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
30 export PATH
31 CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config}
32 CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf/dbc-client.env
33 REQUESTID=${REQUESTID:-dbc-client}
34 DBC=${DBC:-dmaap-bc}
35 PROTO=${PROTO:-https}
36 PORT=${PORT:-8443}
37 WAIT_TO_EXIT=${WAIT_TO_EXIT:-N}
38 PEMDIR=${PEMDIR:-/opt/app/osaaf/local}
39 CAPEM=${CAPEM:-ca.pem}
40 CLIENTPEM=${CLIENTPEM:-client.pem}
41 KEYPEM=${KEYPEM:-key.pem}
42 CERTPWD=${CERTPWD:-'2U[iOZzMHI:.#tdCwlBqc;}S'}
43 AUTH_METHOD=${AUTH_METHOD:-basicAuth}
44 BA_IDENTITY=${BA_IDENTITY:-dmaap-bc@dmaap-bc.onap.org}
45 BA_PWD=${BA_PWD:-'demo123456!'}
46
47
48
49
50 config() {
51         echo "ENTER config"
52         set -x
53         if [ ! -d $APP_ROOT ]
54         then
55                 echo "Expected app root directory $APP_ROOT does not exist"
56                 exit 1
57         fi
58         cd $PEMDIR
59         pwd
60         ls -l
61         echo "AUTH_METHOD=$AUTH_METHOD"
62         if [ "$AUTH_METHOD"  =  "basicAuth" ]
63         then
64                 echo "-u ${BA_IDENTITY}:${BA_PWD}" > $PEMDIR/curl.cred
65                 CURLCRED="-K $PEMDIR/curl.cred"
66         elif [ -f $CAPEM  -a -f $CLIENTPEM -a -f $KEYPEM ]
67         then
68                 echo "--key $PEMDIR/$KEYPEM --cacert $PEMDIR/$CAPEM --cert $PEMDIR/${CLIENTPEM}:${CERTPWD}" > $PEMDIR/curl.cred
69                 CURLCRED="-K $PEMDIR/curl.cred"
70         else
71                 echo "Warning: PEM files for authorization not found!"
72                 CURLCRED=""
73         fi
74         echo "CURLCRED=$CURLCRED"
75         cd $APP_ROOT
76         find . -type f -exec ls -l {} \;
77         find $CONFIGMAP_ROOT -type f -exec ls -l {} \;
78         if [ !  -f $CONTAINER_CONFIG ]
79         then
80                 echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect"
81         else
82                 source $CONTAINER_CONFIG
83         fi
84
85         if [ "$WAIT_TO_EXIT" != "Y" ]
86         then
87                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
88                 > $APP_ROOT/ok_to_exit
89         else
90                 echo "Not creating $APP_ROOT/ok_to_exit"
91         fi      
92         
93         set +x
94 }
95
96
97 init() {
98         set -x
99         echo "ENTER init"
100         if [ ! -d $CONFIGMAP_ROOT ]
101         then
102                 echo $CONFIGMAP_ROOT does not exist
103                 return
104         fi
105
106         #loop on get /dmaap until we get a good response to indicate other provisioning can continue
107         rc=${RESP:-999}
108         while [ $rc != "200" ]
109         do
110                 sleep 10
111                 rc=`curl $CURLCRED -s -o /dev/null -I -w "%{http_code}" -X GET -H "X-ECOMP-RequestID: $REQUESTID" -H "Content-Type: application/json" ${PROTO}://${DBC}:${PORT}/webapi/dmaap`
112                 echo "get dmaap response=${rc}"
113         done
114         set +x
115 }
116 dopost() {
117         set -x
118         RETRY_TIME=60
119
120         loop=true
121
122         while [ $loop = true ]
123         do
124                 rc=`curl $CURLCRED -s -X POST -w "%{http_code}" -H "X-ECOMP-RequestID: $REQUESTID" -H "Content-Type: application/json" -d @${1} ${PROTO}://${DBC}:${PORT}/webapi/${2} -o /dev/null`
125                 case $rc in
126                 200 | 201 | 409 )
127                         echo "response=$rc"
128                         loop=false
129                         ;;
130                 * )
131                         echo "`date`: http response=$rc.  Will retry after $RETRY_TIME seconds"
132                         sleep $RETRY_TIME
133                         ;;
134                 esac
135         done
136         set +x
137
138 }
139 doprov() {
140
141         set -x
142         cd $CONFIGMAP_ROOT
143         pwd
144         # order is important in this next list
145         for uri in dmaap dcaeLocations mr_clusters topics mr_clients dr_nodes feeds dr_pubs dr_subs
146         do
147                 if [ -d ${uri} ]
148                 then
149                         for j in `ls ${uri}/*.json`
150                         do
151                                 echo "POST $j to $uri"
152                                 dopost $j $uri
153                         done
154                 fi
155         done
156         set +x
157 }
158 delay() {
159         echo "DELAY=$DELAY"
160         if [ ! -z "$DELAY" ]
161         then
162                 sleep $DELAY
163         fi
164 }
165
166 delay
167 config
168 init
169 doprov
170
171 echo "Check $APP_ROOT/ok_to_exit"
172 while [ ! -f $APP_ROOT/ok_to_exit ]
173 do
174         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
175         sleep 10
176 done
177 exit 0