diff options
author | Vijay VK <vv770d@att.com> | 2018-02-27 18:12:41 +0000 |
---|---|---|
committer | VENKATESH KUMAR <vv770d@att.com> | 2018-02-27 13:13:40 -0500 |
commit | e6cb4531f2dfd8c5e4e3b90c69891cca686142ee (patch) | |
tree | 1ece3a2d8124bc0d9df31f9a1c78a5b9ee651034 /src/main | |
parent | 8ead72e4a6b7b92e370d89fa2590ea21c2764428 (diff) |
Misc updates to collector
Change-Id: I7a3b52c454442d6a9f93331142b78bf671ffcd0a
Signed-off-by: VENKATESH KUMAR <vv770d@att.com>
Issue-ID: DCAEGEN2-373
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java | 116 | ||||
-rw-r--r-- | src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java | 54 | ||||
-rw-r--r-- | src/main/scripts/VESConfigPoller.sh | 125 | ||||
-rw-r--r-- | src/main/scripts/VESrestfulCollector.sh | 386 | ||||
-rw-r--r-- | src/main/scripts/docker-entry.sh | 100 |
5 files changed, 491 insertions, 290 deletions
diff --git a/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java b/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java index 7b2e0b3b..db4a5ad7 100644 --- a/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java +++ b/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java @@ -23,10 +23,20 @@ package org.onap.dcae.controller; import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
+import org.onap.dcae.commonFunction.CommonStartup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -39,48 +49,83 @@ public class FetchDynamicConfig { public static String configFile = "/opt/app/KV-Configuration.json";
static String url;
public static String retString;
- public static String retCBSString;
+ public static String retCBSString;
public static Map<String, String> env;
-
+
public FetchDynamicConfig() {
}
public static void main(String[] args) {
-
- //Call consul api and identify the CBS Service address and port
+ Boolean areEqual = false;
+ // Call consul api and identify the CBS Service address and port
getconsul();
- //Construct and invoke CBS API to get application Configuration
+ // Construct and invoke CBS API to get application Configuration
getCBS();
- //Write data returned into configFile for LoadDynamicConfig process to pickup
- FetchDynamicConfig fc= new FetchDynamicConfig();
- fc.writefile(retCBSString);
+ // Verify if data has changed
+ areEqual = verifyConfigChange();
+ // If new config then write data returned into configFile for
+ // LoadDynamicConfig process
+ if (! areEqual) {
+ FetchDynamicConfig fc = new FetchDynamicConfig();
+ fc.writefile(retCBSString);
+ } else {
+ log.info("New config pull results identical - " + configFile + " NOT refreshed");
+ }
}
-
- public static void getconsul()
- {
-
+
+ public static void getconsul() {
+
env = System.getenv();
for (Map.Entry<String, String> entry : env.entrySet()) {
- log.info( entry.getKey() + ":"+ entry.getValue());
+ log.info(entry.getKey() + ":" + entry.getValue());
}
if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE")) {
-// && env.containsKey("HOSTNAME")) {
+ // && env.containsKey("HOSTNAME")) {
log.info(">>>Dynamic configuration to be fetched from ConfigBindingService");
url = env.get("CONSUL_HOST") + ":8500/v1/catalog/service/" + env.get("CONFIG_BINDING_SERVICE");
retString = executecurl(url);
-
-
+
} else {
log.info(">>>Static configuration to be used");
}
-
}
- public static void getCBS()
- {
+ public static boolean verifyConfigChange() {
+
+ boolean areEqual = false;
+ // Read current data
+ try {
+ File f = new File(configFile);
+ if (f.exists() && !f.isDirectory()) {
+
+ String jsonData = LoadDynamicConfig.readFile(configFile);
+ JSONObject jsonObject = new JSONObject(jsonData);
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ JsonNode tree1 = mapper.readTree(jsonObject.toString());
+ JsonNode tree2 = mapper.readTree(retCBSString.toString());
+ areEqual = tree1.equals(tree2);
+ log.info("Comparison value:" + areEqual);
+ } else {
+ log.info("First time config file read: " + configFile);
+ // To allow first time file creation
+ areEqual = false;
+ }
+
+ } catch (IOException e) {
+ log.error("Comparison with new fetched data failed" + e.getMessage());
+
+ }
+
+ return areEqual;
+
+ }
+
+ public static void getCBS() {
env = System.getenv();
// consul return as array
@@ -93,40 +138,33 @@ public class FetchDynamicConfig { }
log.info("CONFIG_BINDING_SERVICE DNS RESOLVED:" + urlPart1);
-
- if (env.containsKey("HOSTNAME"))
- {
+
+ if (env.containsKey("HOSTNAME")) {
url = urlPart1 + "/service_component/" + env.get("HOSTNAME");
retCBSString = executecurl(url);
- }
- else if (env.containsKey("SERVICE_NAME"))
- {
+ } else if (env.containsKey("SERVICE_NAME")) {
url = urlPart1 + "/service_component/" + env.get("SERVICE_NAME");
retCBSString = executecurl(url);
- }
- else
- {
+ } else {
log.error("Service name environment variable - HOSTNAME/SERVICE_NAME not found within container ");
}
-
+
}
-
- public void writefile (String retCBSString)
- {
- log.info("URL to fetch configuration:" + url + " Return String:" + retCBSString);
-
-
- String indentedretstring=(new JSONObject(retCBSString)).toString(4);
-
+
+ public void writefile(String retCBSString) {
+ log.info("URL to fetch configuration:" + url + " Return String:" + retCBSString);
+
+ String indentedretstring = (new JSONObject(retCBSString)).toString(4);
+
try (FileWriter file = new FileWriter(FetchDynamicConfig.configFile)) {
file.write(indentedretstring);
log.info("Successfully Copied JSON Object to file " + configFile);
} catch (IOException e) {
- log.error("Error in writing configuration into file " + configFile + retString + e.getMessage());
+ log.error("Error in writing configuration into file " + configFile + retString + e.getMessage());
e.printStackTrace();
}
-
+
}
public static String executecurl(String url) {
diff --git a/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java b/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java index f45f60c3..204e5058 100644 --- a/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java +++ b/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java @@ -44,6 +44,8 @@ import org.slf4j.LoggerFactory; import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.Base64;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -68,11 +70,11 @@ public class EventReceipt extends NsaBaseEndpoint { InputStream istr = null;
int arrayFlag = 0;
String vesVersion = null;
+ String userId=null;
try {
- log.debug("Request recieved :" + ctx.request().getRemoteAddress());
istr = ctx.request().getBodyStream();
jsonObject = new JSONObject(new JSONTokener(istr));
@@ -107,16 +109,22 @@ public class EventReceipt extends NsaBaseEndpoint { try {
if (CommonStartup.authflag == 1) {
+ userId = getUser (ctx);
retkey = NsaBaseEndpoint.getAuthenticatedUser(ctx);
}
} catch (NullPointerException x) {
- log.info("Invalid user request " + ctx.request().getContentType() + MESSAGE + jsonObject);
- CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Unauthorized user" + x);
+ log.info("Invalid user request " + userId + ctx.request().getContentType() + MESSAGE + jsonObject);
+ CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Unauthorized user" + userId + x);
respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized, "Invalid user");
return;
}
- schemaCheck( retkey, arrayFlag, jsonObject, vesVersion, ctx, uuid);
+ Boolean ErrorStatus = false;
+ ErrorStatus = schemaCheck( retkey, arrayFlag, jsonObject, vesVersion, ctx, uuid);
+ if (ErrorStatus)
+ {
+ return;
+ }
} catch (JSONException | NullPointerException | IOException x) {
log.error(String.format("Couldn't parse JSON Array - HttpStatusCodes.k400_badRequest%d%s%s",
@@ -142,11 +150,29 @@ public class EventReceipt extends NsaBaseEndpoint { ctx.response().sendErrorAndBody(HttpStatusCodes.k200_ok, "Message Accepted", MimeTypes.kAppJson);
}
- public static void schemaCheck(NsaSimpleApiKey retkey, int arrayFlag,JSONObject jsonObject, String vesVersion, DrumlinRequestContext ctx, UUID uuid) throws JSONException, QueueFullException, IOException
+
+ public static String getUser( DrumlinRequestContext ctx){
+ String authorization = null;
+ authorization = ctx.request().getFirstHeader("Authorization");
+ if (authorization != null && authorization.startsWith("Basic")) {
+ // Authorization: Basic base64credentials
+ String base64Credentials = authorization.substring("Basic".length()).trim();
+ String credentials = new String(Base64.getDecoder().decode(base64Credentials),
+ Charset.forName("UTF-8"));
+ // credentials = username:password
+ final String[] values = credentials.split(":",2);
+ log.debug("User:" + values[0].toString() + " Pwd:" + values[1].toString());
+ return values[0].toString();
+ }
+ return null;
+
+ }
+ public static Boolean schemaCheck(NsaSimpleApiKey retkey, int arrayFlag,JSONObject jsonObject, String vesVersion, DrumlinRequestContext ctx, UUID uuid) throws JSONException, QueueFullException, IOException
{
JSONArray jsonArray;
JSONArray jsonArrayMod = new JSONArray();
JSONObject event;
+ Boolean ErrorStatus=false;
FileReader fr;
if (retkey != null || CommonStartup.authflag == 0) {
if (CommonStartup.schemaValidatorflag > 0) {
@@ -162,17 +188,20 @@ public class EventReceipt extends NsaBaseEndpoint { log.info("Validation failed");
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
"Schema validation failed");
- return;
+ ErrorStatus=true;
+ return ErrorStatus;
} else {
log.error("Validation errored" + valresult);
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
"Couldn't parse JSON object");
- return;
+ ErrorStatus=true;
+ return ErrorStatus;
}
} else {
log.info("Validation failed");
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest, "Schema validation failed");
- return;
+ ErrorStatus=true;
+ return ErrorStatus;
}
if (arrayFlag == 1) {
jsonArray = jsonObject.getJSONArray("eventList");
@@ -197,16 +226,19 @@ public class EventReceipt extends NsaBaseEndpoint { ctx.request().getContentType(), jsonObject));
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
"Incorrect message content-type; only accepts application/json messages");
- return;
+ ErrorStatus=true;
+ return ErrorStatus;
}
CommonStartup.handleEvents(jsonArrayMod);
} else {
- log.info(String.format("Unauthorized request %s%s%s", ctx.request().getContentType(), MESSAGE,
+ log.info(String.format("Unauthorized request %s%s%s%s", getUser(ctx), ctx.request().getContentType(), MESSAGE,
jsonObject));
respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized, "Unauthorized user");
- return;
+ ErrorStatus=true;
+ return ErrorStatus;
}
+ return ErrorStatus;
}
public static void respondWithCustomMsginJson(DrumlinRequestContext ctx, int sc, String msg) {
diff --git a/src/main/scripts/VESConfigPoller.sh b/src/main/scripts/VESConfigPoller.sh new file mode 100644 index 00000000..75c2b585 --- /dev/null +++ b/src/main/scripts/VESConfigPoller.sh @@ -0,0 +1,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 + diff --git a/src/main/scripts/VESrestfulCollector.sh b/src/main/scripts/VESrestfulCollector.sh index 14e90cc9..4e3fd83e 100644 --- a/src/main/scripts/VESrestfulCollector.sh +++ b/src/main/scripts/VESrestfulCollector.sh @@ -1,193 +1,193 @@ -#!/bin/sh - -### -# ============LICENSE_START======================================================= -# PROJECT -# ================================================================================ -# Copyright (C) 2017-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 "VESrestfulCollector.sh <start/stop>" -} - - -BASEDIR=/opt/app/VESCollector/ - -collector_start() { - echo `date +"%Y%m%d.%H%M%S%3N"` - collector_start | tee -a ${BASEDIR}/logs/console.txt - collectorPid=`pgrep -f org.onap.dcae.commonFunction` - - if [ ! -z "$collectorPid" ]; then - echo "WARNING: VES Restful Collector already running as PID $collectorPid" | tee -a ${BASEDIR}/logs/console.txt - echo "Startup Aborted!!!" | tee -a ${BASEDIR}/logs/console.txt - exit 1 - fi - - - # run java. The classpath is the etc dir for config files, and the lib dir - # for all the jars. - #cd /opt/app/VESCollector/ - cd ${BASEDIR} - #nohup $JAVA -cp "etc${PATHSEP}lib/*" $JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2 $MAINCLASS $* & - nohup $JAVA -cp "etc${PATHSEP}lib/*" -Xms256m -Xmx512m -XX:ErrorFile=/opt/app/VESCollector/logs/java_error%p.log -XX:+HeapDumpOnOutOfMemoryError -Dhttps.protocols=TLSv1.1,TLSv1.2 $MAINCLASS $* & - if [ $? -ne 0 ]; then - echo "VES Restful Collector has been started!!!" | tee -a ${BASEDIR}/logs/console.txt - fi - - -} - -collector_stop() { - echo `date +"%Y%m%d.%H%M%S%3N"` - collector_stop - collectorPid=`pgrep -f org.onap.dcae.commonFunction` - if [ ! -z "$collectorPid" ]; then - echo "Stopping PID $collectorPid" - - kill -9 $collectorPid - sleep 5 - if [ ! "$(pgrep -f org.onap.dcae.commonFunction)" ]; then - echo "VES Restful Collector has been stopped!!!" - else - echo "VES Restful Collector is being stopped!!!" - fi - else - echo "WARNING: No VES Collector instance is currently running"; - exit 1 - fi - - -} - -collector_configupdate() { - - echo `date +"%Y%m%d.%H%M%S%3N"` - collector_configupdate - if [ -z "$CONSUL_HOST" ] || [ -z "$CONFIG_BINDING_SERVICE" ] || [ -z "$HOSTNAME" ]; then - echo "INFO: USING STANDARD CONTROLLER CONFIGURATION" - else - - echo "INFO: DYNAMIC CONFIG INTERFACE SUPPORTED" - # move into base directory - - #BASEDIR=`dirname $0` - #cd $BASEDIR/.. - cd /opt/app/VESCollector - - 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 /opt/app/KV-Configuration.json" - else - echo "INFO: Dynamic config fetched and written successfully into container /opt/app/KV-Configuration.json" - fi - - - if [ -f /opt/app/KV-Configuration.json ]; then - - CONFIG_UPDATER=org.onap.dcae.controller.LoadDynamicConfig - $JAVA -cp "etc${PATHSEP}lib/*" $CONFIG_UPDATER $* - if [ $? -ne 0 ]; then - echo "ERROR: Failed to update dynamic configuration into Application" - else - echo "INFO: Dynamic config updated successfully into VESCollector configuration!" - fi - - # Identify alias names from keystore and password provided - - paramName="collector.keystore.alias" - localpropertyfile="/opt/app/VESCollector/etc/collector.properties" - tmpfile="/opt/app/VESCollector/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` - echo "tmpalias:" $tmpalias - alias=`echo $tmpalias | cut -d":" -f2` - echo "alias:" $alias - sed "s~$paramName=.*~$paramName=$alias~g" $localpropertyfile > $tmpfile - echo `cat $tmpfile > $localpropertyfile` - rm $tmpfile - echo "INFO: Keystore alias updated into configuration" - - else - echo "ERROR: Configuration file /opt/app/KV-Configuration.json missing" - fi - - fi -} - - -## Check usage -if [ $# -ne 1 ]; then - usage - exit -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 - - -MAINCLASS=org.onap.dcae.commonFunction.CommonStartup - -# determine a path separator that works for this platform -PATHSEP=":" -case "$(uname -s)" in - - Darwin) - ;; - - Linux) - ;; - - CYGWIN*|MINGW32*|MSYS*) - PATHSEP=";" - ;; - - *) - ;; -esac - - - - -case $1 in - "start") - collector_configupdate | tee -a ${BASEDIR}/logs/console.txt - collector_start - ;; - "stop") - collector_stop | tee -a ${BASEDIR}/logs/console.txt - ;; - *) - usage - ;; -esac - +#!/bin/sh
+
+###
+# ============LICENSE_START=======================================================
+# PROJECT
+# ================================================================================
+# Copyright (C) 2017-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 "VESrestfulCollector.sh <start/stop>"
+}
+
+
+BASEDIR=/opt/app/VESCollector/
+
+collector_start() {
+ echo `date +"%Y%m%d.%H%M%S%3N"` - collector_start | tee -a ${BASEDIR}/logs/console.txt
+ collectorPid=`pgrep -f org.onap.dcae.commonFunction`
+
+ if [ ! -z "$collectorPid" ]; then
+ echo "WARNING: VES Restful Collector already running as PID $collectorPid" | tee -a ${BASEDIR}/logs/console.txt
+ echo "Startup Aborted!!!" | tee -a ${BASEDIR}/logs/console.txt
+ exit 1
+ fi
+
+
+ # run java. The classpath is the etc dir for config files, and the lib dir
+ # for all the jars.
+ #cd /opt/app/VESCollector/
+ cd ${BASEDIR}
+ #nohup $JAVA -cp "etc${PATHSEP}lib/*" $JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2 $MAINCLASS $* &
+ nohup $JAVA -cp "etc${PATHSEP}lib/*" -Xms256m -Xmx512m -XX:ErrorFile=/opt/app/VESCollector/logs/java_error%p.log -XX:+HeapDumpOnOutOfMemoryError -Dhttps.protocols=TLSv1.1,TLSv1.2 $MAINCLASS $* &
+ if [ $? -ne 0 ]; then
+ echo "VES Restful Collector has been started!!!" | tee -a ${BASEDIR}/logs/console.txt
+ fi
+
+
+}
+
+collector_stop() {
+ echo `date +"%Y%m%d.%H%M%S%3N"` - collector_stop
+ collectorPid=`pgrep -f org.onap.dcae.commonFunction`
+ if [ ! -z "$collectorPid" ]; then
+ echo "Stopping PID $collectorPid"
+
+ kill -9 $collectorPid
+ sleep 5
+ if [ ! "$(pgrep -f org.onap.dcae.commonFunction)" ]; then
+ echo "VES Restful Collector has been stopped!!!"
+ else
+ echo "VES Restful Collector is being stopped!!!"
+ fi
+ else
+ echo "WARNING: No VES Collector instance is currently running";
+ exit 1
+ fi
+
+
+}
+
+collector_configupdate() {
+
+ echo `date +"%Y%m%d.%H%M%S%3N"` - collector_configupdate
+ if [ -z "$CONSUL_HOST" ] || [ -z "$CONFIG_BINDING_SERVICE" ] || [ -z "$HOSTNAME" ]; then
+ echo "INFO: USING STANDARD CONTROLLER CONFIGURATION"
+ else
+
+ echo "INFO: DYNAMIC CONFIG INTERFACE SUPPORTED"
+ # move into base directory
+
+ #BASEDIR=`dirname $0`
+ #cd $BASEDIR/..
+ cd /opt/app/VESCollector
+
+ 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 /opt/app/KV-Configuration.json"
+ else
+ echo "INFO: Dynamic config fetched and written successfully into container /opt/app/KV-Configuration.json"
+ fi
+
+
+ if [ -f /opt/app/KV-Configuration.json ]; then
+
+ CONFIG_UPDATER=org.onap.dcae.controller.LoadDynamicConfig
+ $JAVA -cp "etc${PATHSEP}lib/*" $CONFIG_UPDATER $*
+ if [ $? -ne 0 ]; then
+ echo "ERROR: Failed to update dynamic configuration into Application"
+ else
+ echo "INFO: Dynamic config updated successfully into VESCollector configuration!"
+ fi
+
+ # Identify alias names from keystore and password provided
+
+ paramName="collector.keystore.alias"
+ localpropertyfile="/opt/app/VESCollector/etc/collector.properties"
+ tmpfile="/opt/app/VESCollector/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`
+ echo "tmpalias:" $tmpalias
+ alias=`echo $tmpalias | cut -d":" -f2`
+ echo "alias:" $alias
+ sed "s~$paramName=.*~$paramName=$alias~g" $localpropertyfile > $tmpfile
+ echo `cat $tmpfile > $localpropertyfile`
+ rm $tmpfile
+ echo "INFO: Keystore alias updated into configuration"
+
+ else
+ echo "ERROR: Configuration file /opt/app/KV-Configuration.json missing"
+ fi
+
+ fi
+}
+
+
+## Check usage
+if [ $# -ne 1 ]; then
+ usage
+ exit
+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
+
+
+MAINCLASS=org.onap.dcae.commonFunction.CommonStartup
+
+# determine a path separator that works for this platform
+PATHSEP=":"
+case "$(uname -s)" in
+
+ Darwin)
+ ;;
+
+ Linux)
+ ;;
+
+ CYGWIN*|MINGW32*|MSYS*)
+ PATHSEP=";"
+ ;;
+
+ *)
+ ;;
+esac
+
+
+
+
+case $1 in
+ "start")
+ collector_configupdate | tee -a ${BASEDIR}/logs/console.txt
+ collector_start
+ ;;
+ "stop")
+ collector_stop | tee -a ${BASEDIR}/logs/console.txt
+ ;;
+ *)
+ usage
+ ;;
+esac
+
diff --git a/src/main/scripts/docker-entry.sh b/src/main/scripts/docker-entry.sh index 3b73005f..96cb088c 100644 --- a/src/main/scripts/docker-entry.sh +++ b/src/main/scripts/docker-entry.sh @@ -1,47 +1,53 @@ -#!/bin/sh -### -# ============LICENSE_START======================================================= -# PROJECT -# ================================================================================ -# Copyright (C) 2017 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========================================================= -### - -if [ ! -z "$COLLECTOR_IP" ]; then - 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 - echo "$DMAAPHOST onap-dmaap" >> /etc/hosts - else - echo "onap-dmaap $DMAAPHOST" >> /etc/host.aliases - fi -else - echo "DMAAPHOST ENV NOT SET!! PUBLISH WILL NOT BE SUPPORTED" -fi - -if [ -z "$CONSUL_HOST" ] || [ -z "$CONFIG_BINDING_SERVICE" ] || [ -z "$HOSTNAME" ]; then - echo "INFO: USING STANDARD ALONE CONFIGURATION SETUP" - ## For Container supporting both classic and GEN2 controller - below line should be uncommented, provided service manager package is included - #/opt/app/manager/start-manager.sh -else - echo "INFO: USING DCAEGEN2 CONTROLLER" -fi - -/opt/app/VESCollector/bin/VESrestfulCollector.sh stop -/opt/app/VESCollector/bin/VESrestfulCollector.sh start & - -while true; do sleep 1000; done +#!/bin/sh
+###
+# ============LICENSE_START=======================================================
+# PROJECT
+# ================================================================================
+# Copyright (C) 2017-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=========================================================
+###
+
+if [ ! -z "$COLLECTOR_IP" ]; then
+ 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
+ echo "$DMAAPHOST onap-dmaap" >> /etc/hosts
+ else
+ echo "onap-dmaap $DMAAPHOST" >> /etc/host.aliases
+ fi
+else
+ echo "DMAAPHOST ENV NOT SET!! PUBLISH WILL NOT BE SUPPORTED"
+fi
+
+if [ -z "$CONSUL_HOST" ] || [ -z "$CONFIG_BINDING_SERVICE" ] || [ -z "$HOSTNAME" ]; then
+ echo "INFO: USING STANDARD ALONE CONFIGURATION SETUP"
+ ## For Container supporting both classic and GEN2 controller - below line should be uncommented, provided service manager package is included
+ #/opt/app/manager/start-manager.sh
+else
+ echo "INFO: USING DCAEGEN2 CONTROLLER"
+fi
+
+/opt/app/VESCollector/bin/VESrestfulCollector.sh stop
+/opt/app/VESCollector/bin/VESrestfulCollector.sh start &
+
+# Add below if config polling should be enabled
+# More specific to K8 deployment in ONAP
+if [ ! -z "$CBSPOLLTIMER" ]; then
+ /opt/app/VESCollector/bin/VESConfigPoller.sh &
+fi
+
+while true; do sleep 1000; done
|