aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/scripts
diff options
context:
space:
mode:
authorPawelSzalapski <pawel.szalapski@nokia.com>2018-08-02 10:31:56 +0200
committerPawelSzalapski <pawel.szalapski@nokia.com>2018-08-06 09:43:32 +0200
commit7752c2d818e6d19e4d805c2fd6760b4a13d601bc (patch)
tree053cbc5afd76a8b9644ec62298053aad8cf5e2a8 /src/main/scripts
parent654ebdff4c9ec2487b819d2b76273732759de4c7 (diff)
Implement second part of dynamic DMaaP config
VESCollector app can now fetch CBS configuration and rebuilt the part regarding sending events dynamically, without restarting application. Application will still be restarted by a .sh script, if there were changes regarding collector.properties file. The decision of whether dynamic configuration should be triggered is now based on existence of env vars CONSUL_HOST, CONFIG_BINDING_SERVICE, HOSTNAME, not as previously on CBSPOLLTIME. Frequency at which the config check should happen is now exposed via property from collector.properties Change-Id: I98ff160fa51d08d84a23c716d90ceaacbe17ada6 Signed-off-by: PawelSzalapski <pawel.szalapski@nokia.com> Issue-ID: DCAEGEN2-519
Diffstat (limited to 'src/main/scripts')
-rw-r--r--src/main/scripts/VESConfigPoller.sh125
-rw-r--r--src/main/scripts/VESrestfulCollector.sh102
-rw-r--r--src/main/scripts/appController.sh86
-rw-r--r--src/main/scripts/configurationPoller.sh46
-rw-r--r--src/main/scripts/docker-entry.sh129
5 files changed, 195 insertions, 293 deletions
diff --git a/src/main/scripts/VESConfigPoller.sh b/src/main/scripts/VESConfigPoller.sh
deleted file mode 100644
index 75c2b585..00000000
--- a/src/main/scripts/VESConfigPoller.sh
+++ /dev/null
@@ -1,125 +0,0 @@
-#!/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
-
diff --git a/src/main/scripts/VESrestfulCollector.sh b/src/main/scripts/VESrestfulCollector.sh
deleted file mode 100644
index 7f6d17cb..00000000
--- a/src/main/scripts/VESrestfulCollector.sh
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/bash
-
-###
-# ============LICENSE_START=======================================================
-# PROJECT
-# ================================================================================
-# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
-# Copyright (C) 2018 Nokia Networks 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=========================================================
-###
-source bin/logger.sh
-
-start() {
- log "Starting application"
- appPids=`pidof java`
-
- if [ ! -z ${appPids} ]; then
- logWarn "Tried to start an application, but it is already running on PID(s): ${appPids}. Startup aborted."
- exit 1
- fi
-
- ${JAVA_HOME}/bin/java -cp "etc:lib/*" \
- -Xms256m -Xmx512m \
- -XX:ErrorFile=logs/java_error%p.log \
- -XX:+HeapDumpOnOutOfMemoryError \
- -Dhttps.protocols=TLSv1.1,TLSv1.2 \
- org.onap.dcae.VesApplication $* & &>> logs/collector.log
-}
-
-stop() {
- log "Stopping application"
- appPids=`pidof java`
-
- if [ ! -z ${appPids} ]; then
- echo "Killing java PID(s): ${appPids}"
- kill -9 ${appPids}
- sleep 5
- if [ ! $(pidof java) ]; then
- log "Application stopped"
- else
- logWarn "Application did not stop after 5 seconds"
- fi
- else
- logWarn "Tried to stop an application, but it was not running";
- fi
-}
-
-collector_configupdate() {
- if [ -z ${CONSUL_HOST} ] || [ -z ${CONFIG_BINDING_SERVICE} ] || [ -z ${HOSTNAME} ]; then
- log "Using standard controller configuration (no dynamic configuration done)"
- else
- ${JAVA_HOME}/bin/java -cp "etc:lib/*" org.onap.dcae.controller.FetchDynamicConfig $*
-
- if [ $? -ne 0 ]; then
- logWarn "Failed to fetch dynamic configuration from consul into container /opt/app/KV-Configuration.json"
- else
- log "Dynamic config fetched and written successfully into container /opt/app/KV-Configuration.json"
- fi
-
- if [ -f /opt/app/KV-Configuration.json ]; then
- ${JAVA_HOME}/bin/java -cp "etc:lib/*" org.onap.dcae.controller.LoadDynamicConfig $*
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to update dynamic configuration into Application"
- else
- echo "INFO: Dynamic config updated successfully into VESCollector configuration!"
- fi
- paramName="collector.keystore.alias"
- localpropertyfile="etc/collector.properties"
- tmpfile="etc/collector.properties.tmp"
- keystore=`grep collector.keystore.file.location $localpropertyfile | tr -d '[:space:]' | cut -d"=" -f2`
- keypwdfile=`grep collector.keystore.passwordfile $localpropertyfile | tr -d '[:space:]' | cut -d"=" -f2`
- echo "/usr/bin/keytool -list -keystore $keystore < $keypwdfile | grep "PrivateKeyEntry" | cut -d"," -f1"
- tmpalias=`/usr/bin/keytool -list -keystore $keystore < $keypwdfile | grep "PrivateKeyEntry" | cut -d"," -f1`
- alias=`echo $tmpalias | cut -d":" -f2`
- sed "s~$paramName=.*~$paramName=$alias~g" $localpropertyfile > $tmpfile
- echo `cat $tmpfile > $localpropertyfile`
- rm $tmpfile
- log "Keystore alias updated"
- else
- logWarn "Configuration file /opt/app/KV-Configuration.json missing"
- fi
- fi
-}
-
-case $1 in
- "start") collector_configupdate; start ;;
- "stop") stop ;;
- *) echo "Bad usage. Should be: /bin/bash <this> start/stop"
-esac
-
diff --git a/src/main/scripts/appController.sh b/src/main/scripts/appController.sh
new file mode 100644
index 00000000..d141addf
--- /dev/null
+++ b/src/main/scripts/appController.sh
@@ -0,0 +1,86 @@
+#!/bin/bash
+
+###
+# ============LICENSE_START=======================================================
+# PROJECT
+# ================================================================================
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2018 Nokia Networks 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=========================================================
+###
+source bin/logger.sh
+
+updateKeystore() {
+ log "Updating keystore configuration"
+ aliasParameterName="collector.keystore.alias"
+ originalPropertyFile="etc/collector.properties"
+ temporaryPropertyFile="etc/collector.properties.tmp"
+ keystorePath=`grep collector.keystore.file.location ${originalPropertyFile} | tr -d '[:space:]' | cut -d"=" -f2`
+ keystorePasswordFile=`grep collector.keystore.passwordfile ${originalPropertyFile} | tr -d '[:space:]' | cut -d"=" -f2`
+ temporaryAlias=`/usr/bin/keytool -list -keystore $keystorePath < $keystorePasswordFile | grep "PrivateKeyEntry" | cut -d"," -f1`
+ newAlias=`echo $temporaryAlias | cut -d":" -f2`
+ sed "s~$aliasParameterName=.*~$aliasParameterName=$newAlias~g" ${originalPropertyFile} > ${temporaryPropertyFile}
+ echo `cat ${temporaryPropertyFile} > ${originalPropertyFile}`
+ rm ${temporaryPropertyFile}
+ log "Keystore configuration updated"
+}
+
+tryToPollConfiguration() {
+ log "Trying to poll configuration from CBS before application starts"
+ ${JAVA_HOME}/bin/java -cp "etc:lib/*" org.onap.dcae.controller.PreAppStartupConfigUpdater
+}
+
+start() {
+ log "Starting application"
+ appPids=`pidof java`
+
+ if [ ! -z ${appPids} ]; then
+ logWarn "Tried to start an application, but it is already running on PID(s): ${appPids}. Startup aborted."
+ exit 1
+ fi
+
+ ${JAVA_HOME}/bin/java -cp "etc:lib/*" \
+ -Xms256m -Xmx512m \
+ -XX:ErrorFile=logs/java_error%p.log \
+ -XX:+HeapDumpOnOutOfMemoryError \
+ -Dhttps.protocols=TLSv1.1,TLSv1.2 \
+ org.onap.dcae.VesApplication $* & &>> logs/collector.log
+}
+
+stop() {
+ log "Stopping application"
+ appPids=`pidof java`
+
+ if [ ! -z ${appPids} ]; then
+ echo "Killing java PID(s): ${appPids}"
+ kill -9 ${appPids}
+ sleep 5
+ if [ ! $(pidof java) ]; then
+ log "Application stopped"
+ else
+ logWarn "Application did not stop after 5 seconds"
+ fi
+ else
+ logWarn "Tried to stop an application, but it was not running";
+ fi
+}
+
+case $1 in
+ "start") tryToPollConfiguration; updateKeystore; start ;;
+ "stop") stop ;;
+ "restart") stop; start ;;
+ *) echo "Bad usage. Should be: /bin/bash <this> start/stop"
+esac
+
diff --git a/src/main/scripts/configurationPoller.sh b/src/main/scripts/configurationPoller.sh
new file mode 100644
index 00000000..59dbf840
--- /dev/null
+++ b/src/main/scripts/configurationPoller.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+###
+# ============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=========================================================
+###
+source bin/logger.sh
+
+# This scripts job is to continuously run in background and watch for changes in collector.properties
+# and in case it has changed, restart application.
+# collector.properties (and DmaapConfig.json) is being updated periodically by calling for configuration from CBS and it is
+# done inside the VESCollector application itself.
+# Configuration poller can be run regardless of deployment type.
+# It will always check for changes in collector.properties and in deployment scenario,
+# where dynamic configuration should not be used, necessary environment
+# variables that are needed (consul host, cbs name, app name) will be missing, and java app will
+# not update the configuration files so restart won't be triggered.
+
+# Start after a while, because once the application starts, it might happen that
+# it fetched new configuration. In that case, the application will already be started with newest config, there would
+# be no point in restarting it once again.
+sleep 2m
+
+while true
+do
+ sleep 1m
+ if [[ $(find etc/collector.properties -mmin -1 -print) ]]; then
+ log "Found change in collector.properties, updating keystore and restarting application"
+ bin/appController.sh restart
+ fi
+done
+
diff --git a/src/main/scripts/docker-entry.sh b/src/main/scripts/docker-entry.sh
index 0aad7584..c17dd958 100644
--- a/src/main/scripts/docker-entry.sh
+++ b/src/main/scripts/docker-entry.sh
@@ -1,66 +1,63 @@
-#!/bin/bash
-###
-# ============LICENSE_START=======================================================
-# PROJECT
-# ================================================================================
-# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
-# Copyright (C) 2018 Nokia Networks 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=========================================================
-###
-source bin/logger.sh
-
-# Redirect all stdout & stderr to a main log file, but also let it print into the console
-# At the time this script is invoked, these directories and files do not exist yet, so we need to create them
-mkdir -p logs
-touch logs/collector.log
-exec &> >(tee -a logs/collector.log)
-
-log "Enabling log rotation for collector.log"
-loggedCommand "cp etc/logrotate.conf /etc/logrotate.d"
-echo "* * * * * root logrotate /etc/logrotate.conf" >> /etc/crontab
-log "Restarting cron"
-loggedCommand "service cron reload"
-loggedCommand "service cron start"
-
-log "Main application entry-point invoked"
-
-if [ ! -z ${COLLECTOR_IP} ]; then
- log "Collector ip (${COLLECTOR_IP}) (env var 'COLLECTOR_IP') found, adding entry to /etc/hosts"
- echo ${COLLECTOR_IP} $(hostname).dcae.simpledemo.onap.org >> /etc/hosts
-fi
-
-if [ ! -z ${DMAAPHOST} ]; then
- if [ -z "$(echo ${DMAAPHOST} | sed -e 's/[0-9\.]//g')" ]; then
- log "DMaaP host (${DMAAPHOST}) (env var 'DMAAPHOST') found, adding entry to /etc/hosts"
- echo "${DMAAPHOST} onap-dmaap" >> /etc/hosts
- else
- log "DMaaP host (${DMAAPHOST}) (env var 'DMAAPHOST') found, adding entry to /etc/host.aliases"
- echo "onap-dmaap ${DMAAPHOST}" >> /etc/host.aliases
- fi
-else
- logWarn "DMaaP host (env var 'DMAAPHOST') is missing. Events will not be published to DMaaP"
-fi
-
-log "Scheduling application to be started, looping indefinitely to hold the docker process"
-bin/VESrestfulCollector.sh stop
-bin/VESrestfulCollector.sh start &
-
-# Add below if config polling should be enabled. More specific to K8 deployment in ONAP
-if [ ! -z ${CBSPOLLTIMER} ]; then
- log "Configuration poll time (${CBSPOLLTIMER}) (env var 'CBSPOLLTIMER') found, enabling configuration polling from CBS"
- bin/VESConfigPoller.sh &
-fi
-
-while true; do sleep 1000; done
+#!/bin/bash
+###
+# ============LICENSE_START=======================================================
+# PROJECT
+# ================================================================================
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2018 Nokia Networks 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=========================================================
+###
+source bin/logger.sh
+
+# Redirect all stdout & stderr to a main log file, but also let it print into the console
+# At the time this script is invoked, these directories and files do not exist yet, so we need to create them
+mkdir -p logs
+touch logs/collector.log
+exec &> >(tee -a logs/collector.log)
+
+log "Enabling log rotation for collector.log"
+loggedCommand "cp etc/logrotate.conf /etc/logrotate.d"
+echo "* * * * * root logrotate /etc/logrotate.conf" >> /etc/crontab
+log "Restarting cron"
+loggedCommand "service cron reload"
+loggedCommand "service cron start"
+
+log "Main application entry-point invoked"
+
+if [ ! -z ${COLLECTOR_IP} ]; then
+ log "Collector ip (${COLLECTOR_IP}) (env var 'COLLECTOR_IP') found, adding entry to /etc/hosts"
+ echo ${COLLECTOR_IP} $(hostname).dcae.simpledemo.onap.org >> /etc/hosts
+fi
+
+if [ ! -z ${DMAAPHOST} ]; then
+ if [ -z "$(echo ${DMAAPHOST} | sed -e 's/[0-9\.]//g')" ]; then
+ log "DMaaP host (${DMAAPHOST}) (env var 'DMAAPHOST') found, adding entry to /etc/hosts"
+ echo "${DMAAPHOST} onap-dmaap" >> /etc/hosts
+ else
+ log "DMaaP host (${DMAAPHOST}) (env var 'DMAAPHOST') found, adding entry to /etc/host.aliases"
+ echo "onap-dmaap ${DMAAPHOST}" >> /etc/host.aliases
+ fi
+else
+ logWarn "DMaaP host (env var 'DMAAPHOST') is missing. Events will not be published to DMaaP"
+fi
+
+log "Scheduling application to be started, looping indefinitely to hold the docker process"
+bin/appController.sh stop
+bin/appController.sh start &
+
+log "Enabling configuration polling from CBS"
+bin/configurationPoller.sh &
+
+while true; do sleep 1000; done