## The secure port is required if header.authflag is set to 1 (true)\r
## Authentication is only supported via secure port\r
## When enabled - require valid keystore defined\r
-#ccollector.service.secure.port=8443\r
+#collector.service.secure.port=8443\r
\r
## The keystore must be setup per installation when secure port is configured\r
collector.keystore.file.location=../etc/keystore\r
import org.json.JSONArray;\r
import org.json.JSONObject;\r
import org.json.JSONTokener;\r
+import org.onap.dcae.commonFunction.CommonStartup;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.google.gson.JsonElement;\r
+import com.google.gson.JsonObject;\r
+import com.google.gson.JsonParser;\r
+\r
import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileReader;\r
import java.io.FileWriter;\r
import java.io.IOException;\r
import java.io.InputStreamReader;\r
public static String configFile = "/opt/app/KV-Configuration.json";\r
static String url;\r
public static String retString;\r
- public static String retCBSString; \r
+ public static String retCBSString;\r
public static Map<String, String> env;\r
- \r
+\r
public FetchDynamicConfig() {\r
}\r
\r
public static void main(String[] args) {\r
- \r
- //Call consul api and identify the CBS Service address and port\r
+ Boolean areEqual = false;\r
+ // Call consul api and identify the CBS Service address and port\r
getconsul();\r
- //Construct and invoke CBS API to get application Configuration\r
+ // Construct and invoke CBS API to get application Configuration\r
getCBS();\r
- //Write data returned into configFile for LoadDynamicConfig process to pickup\r
- FetchDynamicConfig fc= new FetchDynamicConfig();\r
- fc.writefile(retCBSString);\r
+ // Verify if data has changed\r
+ areEqual = verifyConfigChange();\r
+ // If new config then write data returned into configFile for\r
+ // LoadDynamicConfig process\r
+ if (! areEqual) {\r
+ FetchDynamicConfig fc = new FetchDynamicConfig();\r
+ fc.writefile(retCBSString);\r
+ } else {\r
+ log.info("New config pull results identical - " + configFile + " NOT refreshed");\r
+ }\r
}\r
- \r
- public static void getconsul()\r
- {\r
- \r
+\r
+ public static void getconsul() {\r
+\r
env = System.getenv();\r
for (Map.Entry<String, String> entry : env.entrySet()) {\r
- log.info( entry.getKey() + ":"+ entry.getValue());\r
+ log.info(entry.getKey() + ":" + entry.getValue());\r
}\r
\r
if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE")) {\r
-// && env.containsKey("HOSTNAME")) {\r
+ // && env.containsKey("HOSTNAME")) {\r
log.info(">>>Dynamic configuration to be fetched from ConfigBindingService");\r
url = env.get("CONSUL_HOST") + ":8500/v1/catalog/service/" + env.get("CONFIG_BINDING_SERVICE");\r
\r
retString = executecurl(url);\r
- \r
- \r
+\r
} else {\r
log.info(">>>Static configuration to be used");\r
}\r
\r
- \r
}\r
\r
- public static void getCBS()\r
- {\r
+ public static boolean verifyConfigChange() {\r
+\r
+ boolean areEqual = false;\r
+ // Read current data\r
+ try {\r
+ File f = new File(configFile);\r
+ if (f.exists() && !f.isDirectory()) {\r
+\r
+ String jsonData = LoadDynamicConfig.readFile(configFile);\r
+ JSONObject jsonObject = new JSONObject(jsonData);\r
+\r
+ ObjectMapper mapper = new ObjectMapper();\r
+\r
+ JsonNode tree1 = mapper.readTree(jsonObject.toString());\r
+ JsonNode tree2 = mapper.readTree(retCBSString.toString());\r
+ areEqual = tree1.equals(tree2);\r
+ log.info("Comparison value:" + areEqual);\r
+ } else {\r
+ log.info("First time config file read: " + configFile);\r
+ // To allow first time file creation\r
+ areEqual = false;\r
+ }\r
+\r
+ } catch (IOException e) {\r
+ log.error("Comparison with new fetched data failed" + e.getMessage());\r
+\r
+ }\r
+\r
+ return areEqual;\r
+\r
+ }\r
+\r
+ public static void getCBS() {\r
\r
env = System.getenv();\r
// consul return as array\r
}\r
\r
log.info("CONFIG_BINDING_SERVICE DNS RESOLVED:" + urlPart1);\r
- \r
- if (env.containsKey("HOSTNAME"))\r
- {\r
+\r
+ if (env.containsKey("HOSTNAME")) {\r
url = urlPart1 + "/service_component/" + env.get("HOSTNAME");\r
retCBSString = executecurl(url);\r
- }\r
- else if (env.containsKey("SERVICE_NAME"))\r
- {\r
+ } else if (env.containsKey("SERVICE_NAME")) {\r
url = urlPart1 + "/service_component/" + env.get("SERVICE_NAME");\r
retCBSString = executecurl(url);\r
- }\r
- else\r
- {\r
+ } else {\r
log.error("Service name environment variable - HOSTNAME/SERVICE_NAME not found within container ");\r
}\r
- \r
+\r
}\r
- \r
- public void writefile (String retCBSString)\r
- {\r
- log.info("URL to fetch configuration:" + url + " Return String:" + retCBSString);\r
-\r
- \r
- String indentedretstring=(new JSONObject(retCBSString)).toString(4);\r
- \r
+\r
+ public void writefile(String retCBSString) {\r
+ log.info("URL to fetch configuration:" + url + " Return String:" + retCBSString);\r
+\r
+ String indentedretstring = (new JSONObject(retCBSString)).toString(4);\r
+\r
try (FileWriter file = new FileWriter(FetchDynamicConfig.configFile)) {\r
file.write(indentedretstring);\r
\r
log.info("Successfully Copied JSON Object to file " + configFile);\r
} catch (IOException e) {\r
- log.error("Error in writing configuration into file " + configFile + retString + e.getMessage());\r
+ log.error("Error in writing configuration into file " + configFile + retString + e.getMessage());\r
e.printStackTrace();\r
}\r
- \r
+\r
}\r
\r
public static String executecurl(String url) {\r
import java.io.FileReader;\r
import java.io.IOException;\r
import java.io.InputStream;\r
+import java.nio.charset.Charset;\r
+import java.util.Base64;\r
import java.util.UUID;\r
import java.util.regex.Matcher;\r
import java.util.regex.Pattern;\r
InputStream istr = null;\r
int arrayFlag = 0;\r
String vesVersion = null;\r
+ String userId=null;\r
\r
try {\r
\r
\r
- log.debug("Request recieved :" + ctx.request().getRemoteAddress());\r
istr = ctx.request().getBodyStream();\r
jsonObject = new JSONObject(new JSONTokener(istr));\r
\r
\r
try {\r
if (CommonStartup.authflag == 1) {\r
+ userId = getUser (ctx);\r
retkey = NsaBaseEndpoint.getAuthenticatedUser(ctx);\r
}\r
} catch (NullPointerException x) {\r
- log.info("Invalid user request " + ctx.request().getContentType() + MESSAGE + jsonObject);\r
- CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Unauthorized user" + x);\r
+ log.info("Invalid user request " + userId + ctx.request().getContentType() + MESSAGE + jsonObject);\r
+ CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Unauthorized user" + userId + x);\r
respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized, "Invalid user");\r
return;\r
}\r
\r
- schemaCheck( retkey, arrayFlag, jsonObject, vesVersion, ctx, uuid);\r
+ Boolean ErrorStatus = false;\r
+ ErrorStatus = schemaCheck( retkey, arrayFlag, jsonObject, vesVersion, ctx, uuid);\r
+ if (ErrorStatus)\r
+ {\r
+ return;\r
+ }\r
\r
} catch (JSONException | NullPointerException | IOException x) {\r
log.error(String.format("Couldn't parse JSON Array - HttpStatusCodes.k400_badRequest%d%s%s",\r
ctx.response().sendErrorAndBody(HttpStatusCodes.k200_ok, "Message Accepted", MimeTypes.kAppJson);\r
}\r
\r
- public static void schemaCheck(NsaSimpleApiKey retkey, int arrayFlag,JSONObject jsonObject, String vesVersion, DrumlinRequestContext ctx, UUID uuid) throws JSONException, QueueFullException, IOException\r
+ \r
+ public static String getUser( DrumlinRequestContext ctx){\r
+ String authorization = null;\r
+ authorization = ctx.request().getFirstHeader("Authorization");\r
+ if (authorization != null && authorization.startsWith("Basic")) {\r
+ // Authorization: Basic base64credentials\r
+ String base64Credentials = authorization.substring("Basic".length()).trim();\r
+ String credentials = new String(Base64.getDecoder().decode(base64Credentials),\r
+ Charset.forName("UTF-8"));\r
+ // credentials = username:password\r
+ final String[] values = credentials.split(":",2);\r
+ log.debug("User:" + values[0].toString() + " Pwd:" + values[1].toString());\r
+ return values[0].toString();\r
+ }\r
+ return null;\r
+ \r
+ }\r
+ public static Boolean schemaCheck(NsaSimpleApiKey retkey, int arrayFlag,JSONObject jsonObject, String vesVersion, DrumlinRequestContext ctx, UUID uuid) throws JSONException, QueueFullException, IOException\r
{\r
JSONArray jsonArray;\r
JSONArray jsonArrayMod = new JSONArray();\r
JSONObject event;\r
+ Boolean ErrorStatus=false;\r
FileReader fr;\r
if (retkey != null || CommonStartup.authflag == 0) {\r
if (CommonStartup.schemaValidatorflag > 0) {\r
log.info("Validation failed");\r
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,\r
"Schema validation failed");\r
- return;\r
+ ErrorStatus=true;\r
+ return ErrorStatus;\r
} else {\r
log.error("Validation errored" + valresult);\r
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,\r
"Couldn't parse JSON object");\r
- return;\r
+ ErrorStatus=true;\r
+ return ErrorStatus;\r
}\r
} else {\r
log.info("Validation failed");\r
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest, "Schema validation failed");\r
- return;\r
+ ErrorStatus=true;\r
+ return ErrorStatus;\r
}\r
if (arrayFlag == 1) {\r
jsonArray = jsonObject.getJSONArray("eventList");\r
ctx.request().getContentType(), jsonObject));\r
respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,\r
"Incorrect message content-type; only accepts application/json messages");\r
- return;\r
+ ErrorStatus=true;\r
+ return ErrorStatus;\r
}\r
\r
CommonStartup.handleEvents(jsonArrayMod);\r
} else {\r
- log.info(String.format("Unauthorized request %s%s%s", ctx.request().getContentType(), MESSAGE,\r
+ log.info(String.format("Unauthorized request %s%s%s%s", getUser(ctx), ctx.request().getContentType(), MESSAGE,\r
jsonObject));\r
respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized, "Unauthorized user");\r
- return;\r
+ ErrorStatus=true;\r
+ return ErrorStatus;\r
}\r
+ return ErrorStatus;\r
}\r
\r
public static void respondWithCustomMsginJson(DrumlinRequestContext ctx, int sc, String msg) {\r
--- /dev/null
+#!/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
+
-#!/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\r
+\r
+###\r
+# ============LICENSE_START=======================================================\r
+# PROJECT\r
+# ================================================================================\r
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.\r
+# ================================================================================\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+# ============LICENSE_END=========================================================\r
+###\r
+\r
+# redirect stdout/stderr to a file\r
+#exec &> /opt/app/VESCollector/logs/console.txt\r
+\r
+usage() {\r
+ echo "VESrestfulCollector.sh <start/stop>"\r
+}\r
+\r
+\r
+BASEDIR=/opt/app/VESCollector/\r
+\r
+collector_start() {\r
+ echo `date +"%Y%m%d.%H%M%S%3N"` - collector_start | tee -a ${BASEDIR}/logs/console.txt\r
+ collectorPid=`pgrep -f org.onap.dcae.commonFunction`\r
+\r
+ if [ ! -z "$collectorPid" ]; then\r
+ echo "WARNING: VES Restful Collector already running as PID $collectorPid" | tee -a ${BASEDIR}/logs/console.txt\r
+ echo "Startup Aborted!!!" | tee -a ${BASEDIR}/logs/console.txt\r
+ exit 1\r
+ fi\r
+\r
+\r
+ # run java. The classpath is the etc dir for config files, and the lib dir\r
+ # for all the jars.\r
+ #cd /opt/app/VESCollector/\r
+ cd ${BASEDIR}\r
+ #nohup $JAVA -cp "etc${PATHSEP}lib/*" $JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2 $MAINCLASS $* &\r
+ 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 $* &\r
+ if [ $? -ne 0 ]; then\r
+ echo "VES Restful Collector has been started!!!" | tee -a ${BASEDIR}/logs/console.txt\r
+ fi\r
+\r
+\r
+}\r
+\r
+collector_stop() {\r
+ echo `date +"%Y%m%d.%H%M%S%3N"` - collector_stop\r
+ collectorPid=`pgrep -f org.onap.dcae.commonFunction`\r
+ if [ ! -z "$collectorPid" ]; then\r
+ echo "Stopping PID $collectorPid"\r
+\r
+ kill -9 $collectorPid\r
+ sleep 5\r
+ if [ ! "$(pgrep -f org.onap.dcae.commonFunction)" ]; then\r
+ echo "VES Restful Collector has been stopped!!!"\r
+ else\r
+ echo "VES Restful Collector is being stopped!!!"\r
+ fi\r
+ else\r
+ echo "WARNING: No VES Collector instance is currently running";\r
+ exit 1\r
+ fi\r
+\r
+\r
+}\r
+\r
+collector_configupdate() {\r
+\r
+ echo `date +"%Y%m%d.%H%M%S%3N"` - collector_configupdate\r
+ if [ -z "$CONSUL_HOST" ] || [ -z "$CONFIG_BINDING_SERVICE" ] || [ -z "$HOSTNAME" ]; then\r
+ echo "INFO: USING STANDARD CONTROLLER CONFIGURATION"\r
+ else\r
+\r
+ echo "INFO: DYNAMIC CONFIG INTERFACE SUPPORTED"\r
+ # move into base directory\r
+\r
+ #BASEDIR=`dirname $0`\r
+ #cd $BASEDIR/..\r
+ cd /opt/app/VESCollector\r
+\r
+ CONFIG_FETCH=org.onap.dcae.controller.FetchDynamicConfig\r
+ $JAVA -cp "etc${PATHSEP}lib/*" $CONFIG_FETCH $*\r
+ if [ $? -ne 0 ]; then\r
+ echo "ERROR: Failed to fetch dynamic configuration from consul into container /opt/app/KV-Configuration.json"\r
+ else\r
+ echo "INFO: Dynamic config fetched and written successfully into container /opt/app/KV-Configuration.json"\r
+ fi\r
+\r
+\r
+ if [ -f /opt/app/KV-Configuration.json ]; then\r
+\r
+ CONFIG_UPDATER=org.onap.dcae.controller.LoadDynamicConfig\r
+ $JAVA -cp "etc${PATHSEP}lib/*" $CONFIG_UPDATER $*\r
+ if [ $? -ne 0 ]; then\r
+ echo "ERROR: Failed to update dynamic configuration into Application"\r
+ else\r
+ echo "INFO: Dynamic config updated successfully into VESCollector configuration!"\r
+ fi\r
+ \r
+ # Identify alias names from keystore and password provided\r
+ \r
+ paramName="collector.keystore.alias"\r
+ localpropertyfile="/opt/app/VESCollector/etc/collector.properties"\r
+ tmpfile="/opt/app/VESCollector/etc/collector.properties.tmp"\r
+ \r
+ keystore=`grep collector.keystore.file.location $localpropertyfile | tr -d '[:space:]' | cut -d"=" -f2`\r
+ keypwdfile=`grep collector.keystore.passwordfile $localpropertyfile | tr -d '[:space:]' | cut -d"=" -f2`\r
+ \r
+ echo "/usr/bin/keytool -list -keystore $keystore < $keypwdfile | grep "PrivateKeyEntry" | cut -d"," -f1"\r
+ tmpalias=`/usr/bin/keytool -list -keystore $keystore < $keypwdfile | grep "PrivateKeyEntry" | cut -d"," -f1`\r
+ echo "tmpalias:" $tmpalias\r
+ alias=`echo $tmpalias | cut -d":" -f2`\r
+ echo "alias:" $alias\r
+ sed "s~$paramName=.*~$paramName=$alias~g" $localpropertyfile > $tmpfile\r
+ echo `cat $tmpfile > $localpropertyfile`\r
+ rm $tmpfile\r
+ echo "INFO: Keystore alias updated into configuration"\r
+ \r
+ else\r
+ echo "ERROR: Configuration file /opt/app/KV-Configuration.json missing"\r
+ fi\r
+\r
+ fi\r
+}\r
+\r
+\r
+## Check usage\r
+if [ $# -ne 1 ]; then\r
+ usage\r
+ exit\r
+fi\r
+\r
+\r
+## Pre-setting\r
+\r
+# use JAVA_HOME if provided\r
+if [ -z "$JAVA_HOME" ]; then\r
+ echo "ERROR: JAVA_HOME not setup"\r
+ echo "Startup Aborted!!"\r
+ exit 1\r
+ #JAVA=java\r
+else\r
+ JAVA=$JAVA_HOME/bin/java\r
+fi\r
+\r
+\r
+MAINCLASS=org.onap.dcae.commonFunction.CommonStartup\r
+\r
+# determine a path separator that works for this platform\r
+PATHSEP=":"\r
+case "$(uname -s)" in\r
+\r
+ Darwin)\r
+ ;;\r
+\r
+ Linux)\r
+ ;;\r
+\r
+ CYGWIN*|MINGW32*|MSYS*)\r
+ PATHSEP=";"\r
+ ;;\r
+\r
+ *)\r
+ ;;\r
+esac\r
+\r
+\r
+\r
+\r
+case $1 in\r
+ "start")\r
+ collector_configupdate | tee -a ${BASEDIR}/logs/console.txt\r
+ collector_start\r
+ ;;\r
+ "stop")\r
+ collector_stop | tee -a ${BASEDIR}/logs/console.txt\r
+ ;;\r
+ *)\r
+ usage\r
+ ;;\r
+esac\r
+\r
-#!/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\r
+###\r
+# ============LICENSE_START=======================================================\r
+# PROJECT\r
+# ================================================================================\r
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.\r
+# ================================================================================\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+# ============LICENSE_END=========================================================\r
+###\r
+\r
+if [ ! -z "$COLLECTOR_IP" ]; then\r
+ echo $COLLECTOR_IP $(hostname).dcae.simpledemo.onap.org >> /etc/hosts\r
+fi\r
+\r
+if [ ! -z "$DMAAPHOST" ]; then\r
+ if [ -z "$(echo $DMAAPHOST | sed -e 's/[0-9\.]//g')" ]; then \r
+ echo "$DMAAPHOST onap-dmaap" >> /etc/hosts\r
+ else\r
+ echo "onap-dmaap $DMAAPHOST" >> /etc/host.aliases\r
+ fi\r
+else\r
+ echo "DMAAPHOST ENV NOT SET!! PUBLISH WILL NOT BE SUPPORTED"\r
+fi\r
+\r
+if [ -z "$CONSUL_HOST" ] || [ -z "$CONFIG_BINDING_SERVICE" ] || [ -z "$HOSTNAME" ]; then\r
+ echo "INFO: USING STANDARD ALONE CONFIGURATION SETUP"\r
+ ## For Container supporting both classic and GEN2 controller - below line should be uncommented, provided service manager package is included\r
+ #/opt/app/manager/start-manager.sh\r
+else\r
+ echo "INFO: USING DCAEGEN2 CONTROLLER"\r
+fi\r
+\r
+/opt/app/VESCollector/bin/VESrestfulCollector.sh stop\r
+/opt/app/VESCollector/bin/VESrestfulCollector.sh start &\r
+\r
+# Add below if config polling should be enabled\r
+# More specific to K8 deployment in ONAP\r
+if [ ! -z "$CBSPOLLTIMER" ]; then\r
+ /opt/app/VESCollector/bin/VESConfigPoller.sh &\r
+fi\r
+\r
+while true; do sleep 1000; done\r
// schemaCheck(NsaSimpleApiKey retkey, int arrayFlag,JSONObject\r
// jsonObject, String vesVersion, FileReader fr, DrumlinRequestContext\r
// ctx, UUID uuid) throws JSONException, QueueFullException, IOException\r
+ Boolean flag = true;\r
NsaSimpleApiKey retkey = null;\r
int arrayFlag = 0;\r
\r
UUID uuid = UUID.randomUUID();\r
\r
try {\r
- EventReceipt.schemaCheck(retkey, arrayFlag, jsonObject, vesVersion, ctx, uuid);\r
+ flag = EventReceipt.schemaCheck(retkey, arrayFlag, jsonObject, vesVersion, ctx, uuid);\r
} catch (NullPointerException |JSONException | QueueFullException | IOException e) {\r
\r
Log.debug("Response object creation failure");\r
}\r
- assertEquals(true, true);\r
+ assertEquals(true, flag);\r
+ }\r
+\r
+ @Test\r
+ public void testgetUser() {\r
+\r
+ \r
+ Boolean flag = true;\r
+ String user;\r
+ \r
+ CommonStartup.authflag = 1;\r
+ CommonStartup.schemaValidatorflag = 1;\r
+\r
+ jsonObject = new org.json.JSONObject(ev);\r
+\r
+ DrumlinRequestContext ctx = null;\r
+\r
+ try {\r
+ user = EventReceipt.getUser(ctx);\r
+ } catch (NullPointerException |JSONException e) {\r
+ \r
+ Log.debug("Response object creation failure");\r
+ }\r
+ assertEquals(true, flag);\r
}\r
\r
@Test\r
\r
}\r
\r
+\r
+ @Test\r
+ public void testverifyConfigChange() {\r
+ \r
+ \r
+ Boolean ret= false;\r
+ \r
+ try{\r
+ //File date to be compared\r
+ FetchDynamicConfig.configFile = "src/test/resources/controller-config_singleline_ip.json";\r
+ //Mock the return CBS output\r
+ FetchDynamicConfig.retCBSString = "{\"header.authflag\": \"1\", \"collector.schema.file\": \"{\\\"v1\\\": \\\"./etc/CommonEventFormat_27.2.json\\\", \\\"v2\\\": \\\"./etc/CommonEventFormat_27.2.json\\\", \\\"v3\\\": \\\"./etc/CommonEventFormat_27.2.json\\\", \\\"v4\\\": \\\"./etc/CommonEventFormat_27.2.json\\\", \\\"v5\\\": \\\"./etc/CommonEventFormat_28.4.json\\\"}\", \"collector.keystore.passwordfile\": \"/opt/app/dcae-certificate/.password\", \"tomcat.maxthreads\": \"200\", \"collector.dmaap.streamid\": \"fault=ves-fault|syslog=ves-syslog|heartbeat=ves-heartbeat|measurementsForVfScaling=ves-measurement|mobileFlow=ves-mobileflow|other=ves-other|stateChange=ves-statechange|thresholdCrossingAlert=ves-thresholdCrossingAlert|voiceQuality=ves-voicequality|sipSignaling=ves-sipsignaling\", \"streams_subscribes\": {}, \"collector.inputQueue.maxPending\": \"8096\", \"collector.keystore.alias\": \"dynamically generated\", \"streams_publishes\": {\"ves-mobileflow\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590629043\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-SEC-MOBILEFLOW-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-measurement\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590433916\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-ENC-MEASUREMENT-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-voicequality\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590778397\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-VES-VOICEQUALITY-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-thresholdCrossingAlert\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590728150\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-SEC-TCA-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-fault\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590384670\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-SEC-FAULT-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-heartbeat\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590530041\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-SEC-HEARTBEAT-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-sipsignaling\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590828736\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-VES-SIPSIGNALING-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-syslog\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590482019\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-SEC-SYSLOG-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-other\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590581045\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-SEC-OTHER-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}, \"ves-statechange\": {\"type\": \"message_router\", \"dmaap_info\": {\"client_id\": \"1517590677649\", \"client_role\": \"com.att.secCollector.member\", \"location\": \"rdm5bdcc2\", \"topic_url\": \"https://DMAAPHOST:3905/events/com.att.dcae.dmaap.FTL.24256-SEC-STATECHANGE-OUTPUT-v1\"}, \"aaf_username\": \"userid@namespace\", \"aaf_password\": \"authpwd\"}}, \"collector.schema.checkflag\": \"1\", \"services_calls\": {}, \"event.transform.flag\": \"1\", \"collector.keystore.file.location\": \"/opt/app/dcae-certificate/keystore.jks\", \"header.authlist\": \"sample1,c2FtcGxlMQ==|userid1,base64encodepwd1|userid2,base64encodepwd2\", \"collector.service.secure.port\": \"8443\", \"collector.service.port\": \"-1\"}";\r
+ ret=FetchDynamicConfig.verifyConfigChange();\r
+ \r
+ }\r
+ catch(Exception e){\r
+ System.out.println("Exception on verifyConfigChange");\r
+ //e.printStackTrace();\r
+ }\r
+ assertEquals(true, ret);\r
+ \r
+ }\r
+ \r
}\r
\r