Add env vars to script
[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=/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
36
37
38
39 config() {
40         echo "ENTER config"
41         set -x
42         if [ ! -d $APP_ROOT ]
43         then
44                 echo "Expected app root directory $APP_ROOT does not exist"
45                 exit 1
46         fi
47         cd $APP_ROOT
48         find . -type f -exec ls -l {} \;
49         find $CONFIGMAP_ROOT -type f -exec ls -l {} \;
50         if [ !  -f $CONTAINER_CONFIG ]
51         then
52                 echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect"
53         else
54                 source $CONTAINER_CONFIG
55         fi
56
57         if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
58         then
59                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
60                 > $APP_ROOT/ok_to_exit
61         else
62                 echo "Not creating $APP_ROOT/ok_to_exit"
63         fi      
64         
65         if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
66         then
67                 echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
68                 exit 1
69         fi
70         $APP_ROOT/misc/cert-client-init.sh
71
72         set +x
73 }
74
75
76 init() {
77         echo "ENTER init"
78         if [ ! -d $CONFIGMAP_ROOT ]
79         then
80                 echo $CONFIGMAP_ROOT does not exist
81                 return
82         fi
83
84         #loop on get /dmaap until we get a good response to indicate other provisioning can continue
85         rc=999
86         while [ $rc != "200" ]
87         do
88                 sleep 10
89                 rc=`curl -s -o /dev/null -I -w "%{http_code}" -X GET -H "X-ECOMP-RequestID: $REQUESTID" -H "Content-Type: application/json" http://dmaap-bc:8080/webapi/dmaap`
90                 echo "get dmaap response=${rc}"
91         done
92 }
93 doprov() {
94
95         cd $CONFIGMAP_ROOT
96         pwd
97         # order is important in this next list
98         for uri in dmaap dcaeLocations mr_clusters topics mr_clients dr_nodes feeds dr_pubs dr_subs
99         do
100                 if [ -d ${uri} ]
101                 then
102                         for j in `ls ${uri}/*.json`
103                         do
104                                 echo "POST $j to $uri"
105                                 rc=`curl -v -X POST -w "%{http_code}" -H "X-ECOMP-RequestID: $REQUESTID" -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri}`
106                                 echo "response=$rc"
107                         done
108                 fi
109         done
110 }
111 delay() {
112         echo "DELAY=$DELAY"
113         if [ ! -z "$DELAY" ]
114         then
115                 sleep $DELAY
116         fi
117 }
118
119 set -x
120 delay
121 config
122 init
123 doprov
124
125 echo "Check $APP_ROOT/ok_to_exit"
126 while [ ! -f $APP_ROOT/ok_to_exit ]
127 do
128         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
129         sleep 10
130 done
131 exit 0