summaryrefslogtreecommitdiffstats
path: root/src/main/scripts/VESConfigPoller.sh
blob: 75c2b585e42ae22994456c950425e81e19825cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh -x
###
# ============LICENSE_START=======================================================
# PROJECT
# ================================================================================
# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
###
# redirect stdout/stderr to a file
#exec &> /opt/app/VESCollector/logs/console.txt

usage() {
        echo "VESConfigPoller.sh"
}


## Remove singel execution logic (loop 0)
## On configupdate function, remove LoadDynamicConfig and invoke VESrestfulCollector stop/start

BASEDIR=/opt/app/VESCollector/
CONFIGFILENAME=/opt/app/KV-Configuration.json


collector_configupdate() {

        echo `date +"%Y%m%d.%H%M%S%3N"` - VESConfigPoller.sh:collector_configupdate
        if [ -z "$CONSUL_HOST" ] || [ -z "$CONFIG_BINDING_SERVICE" ] || [ -z "$HOSTNAME" ]; then
                echo "INFO: USING STANDARD CONTROLLER CONFIGURATION"
        else
            # move into base directory
            cd $BASEDIR

            CONFIG_FETCH=org.onap.dcae.controller.FetchDynamicConfig
            $JAVA -cp "etc${PATHSEP}lib/*"  $CONFIG_FETCH $*
            if [ $? -ne 0 ]; then
                echo "ERROR: Failed to fetch dynamic configuration from consul into container $CONFIGFILENAME"
            else
               echo "INFO: Dynamic config fetched successfully"
            fi
                sleep 10s
                FLAG=0

            if [ -f $CONFIGFILENAME ]; then
                if [[ $(find $CONFIGFILENAME -mmin -$CBSPOLLTIMER -print) ]]; then
                        echo "File  $CONFIGFILENAME  is updated under $CBSPOLLTIMER minutes; Loader to be invoked"
                        FLAG=1
                else
                        echo "File  $CONFIGFILENAME  NOT updated in last $CBSPOLLTIMER minutes; no configuration update!"
                        FLAG=0
                fi

                if [ $FLAG -eq 1 ]; then
                        echo "INFO: CONFIGFILE updated; triggering restart"
                        /opt/app/VESCollector/bin/VESrestfulCollector.sh stop
                        /opt/app/VESCollector/bin/VESrestfulCollector.sh start &
                else
                        echo "INFO: CONFIGFILE load skipped"
                fi
            else
                echo "ERROR: Configuration file $CONFIGFILENAME missing"
            fi
        fi
}



if [ -z "$CBSPOLLTIMER" ]; then
        echo "CBSPOLLTIMER not set; set this to polling frequency in minutes"
        exit 1
fi


## Pre-setting

# use JAVA_HOME if provided
if [ -z "$JAVA_HOME" ]; then
        echo "ERROR: JAVA_HOME not setup"
        echo "Startup Aborted!!"
        exit 1
        #JAVA=java
else
        JAVA=$JAVA_HOME/bin/java
fi



# determine a path separator that works for this platform
PATHSEP=":"
case "$(uname -s)" in

        Darwin)
                ;;

         Linux)
                ;;

         CYGWIN*|MINGW32*|MSYS*)
                PATHSEP=";"
                ;;

        *)
                ;;
esac



##Run in loop the config pull and check
while true
do
        sleep $(echo $CBSPOLLTIMER)m
        collector_configupdate | tee -a ${BASEDIR}/logs/console.txt
done