Fix problem with post install job
[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
44
45
46
47 config() {
48         echo "ENTER config"
49         set -x
50         if [ ! -d $APP_ROOT ]
51         then
52                 echo "Expected app root directory $APP_ROOT does not exist"
53                 exit 1
54         fi
55         cd $PEMDIR
56         pwd
57         ls -l
58         if [ -f $CAPEM  -a -f $CLIENTPEM -a -f $KEYPEM ]
59         then
60                 printf "key \"$PEMDIR/$KEYPEM\"\ncacert \"$PEMDIR/$CAPEM\"\ncert \"$PEMDIR/${CLIENTPEM}:${CERTPWD}\"" > $PEMDIR/curl.cred
61                 CURLCRED="-K $PEMDIR/curl.cred"
62         else
63                 echo "Warning: PEM files for authorization not found!"
64                 CURLCRED=""
65         fi
66         echo "CURLCRED=$CURLCRED"
67         cd $APP_ROOT
68         find . -type f -exec ls -l {} \;
69         find $CONFIGMAP_ROOT -type f -exec ls -l {} \;
70         if [ !  -f $CONTAINER_CONFIG ]
71         then
72                 echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect"
73         else
74                 source $CONTAINER_CONFIG
75         fi
76
77         if [ "$WAIT_TO_EXIT" != "Y" ]
78         then
79                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
80                 > $APP_ROOT/ok_to_exit
81         else
82                 echo "Not creating $APP_ROOT/ok_to_exit"
83         fi      
84         
85         set +x
86 }
87
88
89 init() {
90         set -x
91         echo "ENTER init"
92         if [ ! -d $CONFIGMAP_ROOT ]
93         then
94                 echo $CONFIGMAP_ROOT does not exist
95                 return
96         fi
97
98         #loop on get /dmaap until we get a good response to indicate other provisioning can continue
99         rc=${RESP:-999}
100         while [ $rc != "200" ]
101         do
102                 sleep 10
103                 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`
104                 echo "get dmaap response=${rc}"
105         done
106         set +x
107 }
108 dopost() {
109         set -x
110         RETRY_TIME=60
111
112         loop=true
113
114         while [ $loop = true ]
115         do
116                 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`
117                 case $rc in
118                 200 | 201 | 409 )
119                         echo "response=$rc"
120                         loop=false
121                         ;;
122                 * )
123                         echo "`date`: http response=$rc.  Will retry after $RETRY_TIME seconds"
124                         sleep $RETRY_TIME
125                         ;;
126                 esac
127         done
128         set +x
129
130 }
131 doprov() {
132
133         set -x
134         cd $CONFIGMAP_ROOT
135         pwd
136         # order is important in this next list
137         for uri in dmaap dcaeLocations mr_clusters topics mr_clients dr_nodes feeds dr_pubs dr_subs
138         do
139                 if [ -d ${uri} ]
140                 then
141                         for j in `ls ${uri}/*.json`
142                         do
143                                 echo "POST $j to $uri"
144                                 dopost $j $uri
145                         done
146                 fi
147         done
148         set +x
149 }
150 delay() {
151         echo "DELAY=$DELAY"
152         if [ ! -z "$DELAY" ]
153         then
154                 sleep $DELAY
155         fi
156 }
157
158 delay
159 config
160 init
161 doprov
162
163 echo "Check $APP_ROOT/ok_to_exit"
164 while [ ! -f $APP_ROOT/ok_to_exit ]
165 do
166         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
167         sleep 10
168 done
169 exit 0