Silent post to get respnse code
[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 USER=root
29 export TZ
30 PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
31 export PATH
32 CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config}
33 CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf/dbc-client.env
34 REQUESTID=${REQUESTID:-dbc-client}
35 DBC=${DBC:-dmaap-bc}
36 PROTO=${PROTO:-https}
37 PORT=${PORT:-8443}
38
39
40
41
42 config() {
43         echo "ENTER config"
44         set -x
45         if [ ! -d $APP_ROOT ]
46         then
47                 echo "Expected app root directory $APP_ROOT does not exist"
48                 exit 1
49         fi
50         cd $APP_ROOT
51         find . -type f -exec ls -l {} \;
52         find $CONFIGMAP_ROOT -type f -exec ls -l {} \;
53         if [ !  -f $CONTAINER_CONFIG ]
54         then
55                 echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect"
56         else
57                 source $CONTAINER_CONFIG
58         fi
59
60         if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
61         then
62                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
63                 > $APP_ROOT/ok_to_exit
64         else
65                 echo "Not creating $APP_ROOT/ok_to_exit"
66         fi      
67         
68         set +x
69 }
70
71
72 init() {
73         echo "ENTER init"
74         if [ ! -d $CONFIGMAP_ROOT ]
75         then
76                 echo $CONFIGMAP_ROOT does not exist
77                 return
78         fi
79
80         #loop on get /dmaap until we get a good response to indicate other provisioning can continue
81         rc=${RESP:-999}
82         while [ $rc != "200" ]
83         do
84                 sleep 10
85                 rc=`curl -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`
86                 echo "get dmaap response=${rc}"
87         done
88 }
89 dopost() {
90         RETRY_TIME=60
91
92         loop=true
93
94         while [ $loop = true ]
95         do
96                 rc=`curl -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`
97                 case $rc in
98                 200 | 201 | 409 )
99                         echo "response=$rc"
100                         loop=false
101                         ;;
102                 * )
103                         echo "`date`: http response=$rc.  Will retry after $RETRY_TIME seconds"
104                         sleep $RETRY_TIME
105                         ;;
106                 esac
107         done
108
109 }
110 doprov() {
111
112         cd $CONFIGMAP_ROOT
113         pwd
114         # order is important in this next list
115         for uri in dmaap dcaeLocations mr_clusters topics mr_clients dr_nodes feeds dr_pubs dr_subs
116         do
117                 if [ -d ${uri} ]
118                 then
119                         for j in `ls ${uri}/*.json`
120                         do
121                                 echo "POST $j to $uri"
122                                 dopost $j $uri
123                         done
124                 fi
125         done
126 }
127 delay() {
128         echo "DELAY=$DELAY"
129         if [ ! -z "$DELAY" ]
130         then
131                 sleep $DELAY
132         fi
133 }
134
135 set -x
136 delay
137 config
138 init
139 doprov
140
141 echo "Check $APP_ROOT/ok_to_exit"
142 while [ ! -f $APP_ROOT/ok_to_exit ]
143 do
144         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
145         sleep 10
146 done
147 exit 0