summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Dockerfile15
-rw-r--r--docker-compose.yml8
-rwxr-xr-xmvn-phase-lib.sh296
-rwxr-xr-xmvn-phase-script.sh203
-rw-r--r--pom.xml831
-rw-r--r--src/assembly/dep.xml159
-rw-r--r--src/main/java/org/onap/dcae/commonFunction/EventProcessor.java19
-rw-r--r--src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java26
-rw-r--r--src/main/scripts/VESrestfulCollector.sh16
-rw-r--r--src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java129
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestCommonStartup.java172
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestFetchConfig.java188
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java106
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestingUtilities.java84
14 files changed, 844 insertions, 1408 deletions
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 259ac980..00000000
--- a/Dockerfile
+++ /dev/null
@@ -1,15 +0,0 @@
-FROM openjdk:8-jre-slim
-
-MAINTAINER vv770d@att.com
-
-WORKDIR /opt/app/VESCollector
-
-ENV HOME /opt/app/VESCollector
-ENV JAVA_HOME /usr
-ENV HOSTALIASES /etc/host.aliases
-
-COPY opt /opt
-
-EXPOSE 8080 8443
-
-CMD [ "/opt/app/docker-entry.sh" ]
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..1d7484bb
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,8 @@
+version: '3'
+services:
+ ves:
+ container_name: ves
+ image: onap/org.onap.dcaegen2.collectors.ves.vescollector:latest
+ ports:
+ - "8080:8080"
+ - "8443:8443"
diff --git a/mvn-phase-lib.sh b/mvn-phase-lib.sh
deleted file mode 100755
index ac537223..00000000
--- a/mvn-phase-lib.sh
+++ /dev/null
@@ -1,296 +0,0 @@
-#!/bin/bash
-
-# ================================================================================
-# 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=========================================================
-#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
-
-clean_templated_files()
-{
- TEMPLATE_FILES=$(find . -name "*-template")
- for F in $TEMPLATE_FILES; do
- F2=$(echo "$F" | sed 's/-template$//')
- rm -f "$F2"
- done
-}
-clean_tox_files()
-{
- TOX_FILES=$(find . -name ".tox")
- TOX_FILES="$TOX_FILES $(find . -name 'venv-tox')"
- for F in $TOX_FILES; do
- rm -rf "$F"
- done
-}
-
-expand_templates()
-{
- # set up env variables, get ready for template resolution
- # NOTE: CCSDK artifacts do not distinguish REALESE vs SNAPSHOTs
- export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints"
-
- export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/releases"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/snapshots"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/releases"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/snapshots"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/releases"
- export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/snapshots"
-
- export ONAPTEMPLATE_PYPIURL_org_onap_dcaegen2="${MVN_NEXUSPROXY}/content/sites/pypi"
-
- export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_releases="$MVN_DOCKERREGISTRY_DAILY"
- export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_snapshots="$MVN_DOCKERREGISTRY_DAILY/snapshots"
-
-
- TEMPLATE_FILES=$(find . -name "*-template")
- for F in $TEMPLATE_FILES; do
- F2=$(echo "$F" | sed 's/-template$//')
- cp "$F" "$F2"
- MOD=$(stat --format '%a' "$F")
- chmod "$MOD" "$F2"
- done
-
-
- TEMPLATES=$(env |grep ONAPTEMPLATE)
- if [ -z "$TEMPLATES" ]; then
- return 0
- fi
-
- echo "====> Resolving the following temaplate from environment variables "
- echo "[$TEMPLATES]"
- SELFFILE=$(echo "$0" | rev | cut -f1 -d '/' | rev)
- for TEMPLATE in $TEMPLATES; do
- KEY=$(echo "$TEMPLATE" | cut -f1 -d'=')
- VALUE=$(echo "$TEMPLATE" | cut -f2 -d'=')
- VALUE2=$(echo "$TEMPLATE" | cut -f2 -d'=' |sed 's/\//\\\//g')
- set +e
- FILES=$(grep -rl "$KEY")
- set -e
-
- if [ -z "$FILES" ]; then
- continue
- fi
-
- # assuming FILES is not longer than 2M bytes, the limit for variable value max size on this VM
- for F in $FILES; do
- if [[ $F == *"$SELFFILE" ]]; then
- continue
- fi
- if [[ "$F" == *-template ]]; then
- continue
- fi
-
- echo "======> Resolving template $KEY to value $VALUE for file $F"
- sed -i "s/{{[[:space:]]*$KEY[[:space:]]*}}/$VALUE2/g" "$F"
- #cat "$F"
- done
-
- #if [ ! -z "$FILES" ]; then
- # echo "====> Resolving template $VALUE to value $VALUE"
- # #CMD="grep -rl \"$VALUE\" | tr '\n' '\0' | xargs -0 sed -i \"s/{{[[:space:]]*$VALUE[[:space:]]*}}/$VALUE/g\""
- # grep -rl "$KEY" | tr '\n' '\0' | xargs -0 sed -i 's/$KEY/$VALUE2/g'
- # #echo $CMD
- # #eval $CMD
- #fi
- done
- echo "====> Done template reolving"
-}
-
-
-run_tox_test()
-{
- set -x
- CURDIR=$(pwd)
- TOXINIS=$(find . -name "tox.ini")
- for TOXINI in "${TOXINIS[@]}"; do
- DIR=$(echo "$TOXINI" | rev | cut -f2- -d'/' | rev)
- cd "${CURDIR}/${DIR}"
- rm -rf ./venv-tox ./.tox
- virtualenv ./venv-tox
- source ./venv-tox/bin/activate
- pip install --upgrade pip
- pip install --upgrade tox argparse
- pip freeze
- tox
- deactivate
- rm -rf ./venv-tox ./.tox
- done
-}
-
-build_wagons()
-{
- rm -rf ./*.wgn venv-pkg
-
- SETUPFILES=$(find . -name "setup.py")
- for SETUPFILE in $SETUPFILES; do
- PLUGIN_DIR=$(echo "$SETUPFILE" |rev | cut -f 2- -d '/' |rev)
- PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g')
- PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g')
-
- echo "In $PLUGIN_DIR, $PLUGIN_NAME, $PLUGIN_VERSION"
-
- virtualenv ./venv-pkg
- source ./venv-pkg/bin/activate
- pip install --upgrade pip
- pip install wagon
- wagon create --format tar.gz "$PLUGIN_DIR"
- deactivate
- rm -rf venv-pkg
-
- PKG_FILE_NAMES=( "${PLUGIN_NAME}-${PLUGIN_VERSION}"*.wgn )
- echo Built package: "${PKG_FILE_NAMES[@]}"
- done
-}
-
-
-upload_raw_file()
-{
- # Extract the username and password to the nexus repo from the settings file
- USER=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/username/text()" "$SETTINGS_FILE")
- PASS=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/password/text()" "$SETTINGS_FILE")
- NETRC=$(mktemp)
- echo "machine $MVN_RAWREPO_HOST login $USER password $PASS" > "$NETRC"
-
- REPO="$MVN_RAWREPO_BASEURL_UPLOAD"
-
- OUTPUT_FILE=$1
- EXT=$(echo "$OUTPUT_FILE" | rev |cut -f1 -d '.' |rev)
- if [ "$EXT" == 'yaml' ]; then
- OUTPUT_FILE_TYPE='text/x-yaml'
- elif [ "$EXT" == 'sh' ]; then
- OUTPUT_FILE_TYPE='text/x-shellscript'
- elif [ "$EXT" == 'gz' ]; then
- OUTPUT_FILE_TYPE='application/gzip'
- elif [ "$EXT" == 'wgn' ]; then
- OUTPUT_FILE_TYPE='application/gzip'
- else
- OUTPUT_FILE_TYPE='application/octet-stream'
- fi
-
-
- if [ "$MVN_DEPLOYMENT_TYPE" == 'SNAPSHOT' ]; then
- SEND_TO="${REPO}/${FQDN}/snapshots"
- elif [ "$MVN_DEPLOYMENT_TYPE" == 'STAGING' ]; then
- SEND_TO="${REPO}/${FQDN}/releases"
- else
- echo "Unreconfnized deployment type, quit"
- exit
- fi
- if [ ! -z "$MVN_PROJECT_MODULEID" ]; then
- SEND_TO="$SEND_TO/$MVN_PROJECT_MODULEID"
- fi
-
- echo "Sending ${OUTPUT_FILE} to Nexus: ${SEND_TO}"
- curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}-${MVN_PROJECT_VERSION}-${TIMESTAMP}"
- curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}-${MVN_PROJECT_VERSION}"
- curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}"
-}
-
-
-
-upload_wagons_and_type_yamls()
-{
- WAGONS=$(ls -1 ./*.wgn)
- for WAGON in $WAGONS ; do
- WAGON_NAME=$(echo "$WAGON" | cut -f1 -d '-')
- WAGON_VERSION=$(echo "$WAGON" | cut -f2 -d '-')
- WAGON_TYPEFILE=$(grep -rl "$WAGON_NAME" | grep yaml | head -1)
-
- upload_raw_file "$WAGON"
- upload_raw_file "$WAGON_TYPEFILE"
- done
-}
-
-upload_files_of_extension()
-{
- FILES=$(ls -1 ./*."$1")
- for F in $FILES ; do
- upload_raw_file "$F"
- done
-}
-
-
-
-build_and_push_docker()
-{
- IMAGENAME="onap/${FQDN}.${MVN_PROJECT_MODULEID}"
- IMAGENAME=$(echo "$IMAGENAME" | sed -e 's/_*$//g' -e 's/\.*$//g')
- IMAGENAME=$(echo "$IMAGENAME" | tr '[:upper:]' '[:lower:]')
-
- # use the major and minor version of the MVN artifact version as docker image version
- VERSION="${MVN_PROJECT_VERSION//[^0-9.]/}"
- VERSION2=$(echo "$VERSION" | cut -f1-2 -d'.')
-
- LFQI="${IMAGENAME}:${VERSION}-${TIMESTAMP}"Z
- # build a docker image
- docker build --rm -f ./Dockerfile -t "${LFQI}" ./
-
- REPO=""
- if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then
- REPO=$MVN_DOCKERREGISTRY_DAILY
- elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then
- # there seems to be no staging docker registry? set to use SNAPSHOT also
- #REPO=$MVN_DOCKERREGISTRY_RELEASE
- REPO=$MVN_DOCKERREGISTRY_DAILY
- else
- echo "Fail to determine DEPLOYMENT_TYPE"
- REPO=$MVN_DOCKERREGISTRY_DAILY
- fi
- echo "DEPLOYMENT_TYPE is: $MVN_DEPLOYMENT_TYPE, repo is $REPO"
-
- if [ ! -z "$REPO" ]; then
- USER=$(xpath -e "//servers/server[id='$REPO']/username/text()" "$SETTINGS_FILE")
- PASS=$(xpath -e "//servers/server[id='$REPO']/password/text()" "$SETTINGS_FILE")
- if [ -z "$USER" ]; then
- echo "Error: no user provided"
- fi
- if [ -z "$PASS" ]; then
- echo "Error: no password provided"
- fi
- [ -z "$PASS" ] && PASS_PROVIDED="<empty>" || PASS_PROVIDED="<password>"
- echo docker login "$REPO" -u "$USER" -p "$PASS_PROVIDED"
- docker login "$REPO" -u "$USER" -p "$PASS"
-
- if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then
- REPO="$REPO/snapshots"
- elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then
- # there seems to be no staging docker registry? set to use SNAPSHOT also
- #REPO=$MVN_DOCKERREGISTRY_RELEASE
- REPO="$REPO"
- else
- echo "Fail to determine DEPLOYMENT_TYPE"
- REPO="$REPO/unknown"
- fi
-
- OLDTAG="${LFQI}"
- PUSHTAGS="${REPO}/${IMAGENAME}:${VERSION}-SNAPSHOT-${TIMESTAMP}Z ${REPO}/${IMAGENAME}:${VERSION} ${REPO}/${IMAGENAME}:latest"
- for NEWTAG in ${PUSHTAGS}
- do
- echo "tagging ${OLDTAG} to ${NEWTAG}"
- docker tag "${OLDTAG}" "${NEWTAG}"
- echo "pushing ${NEWTAG}"
- docker push "${NEWTAG}"
- OLDTAG="${NEWTAG}"
- done
- fi
-
-}
-
-
-
diff --git a/mvn-phase-script.sh b/mvn-phase-script.sh
deleted file mode 100755
index ea045de5..00000000
--- a/mvn-phase-script.sh
+++ /dev/null
@@ -1,203 +0,0 @@
-#!/bin/bash
-
-# ================================================================================
-# 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=========================================================
-#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
-set -ex
-
-
-echo "running script: [$0] for module [$1] at stage [$2]"
-
-MVN_PROJECT_MODULEID="$1"
-MVN_PHASE="$2"
-
-
-PROJECT_ROOT=$(dirname $0)
-if [ -z "$WORKSPACE" ]; then
- export WORKSPACE="$PROJECT_ROOT"
-fi
-
-
-FQDN="${MVN_PROJECT_GROUPID}.${MVN_PROJECT_ARTIFACTID}"
-if [ "$MVN_PROJECT_MODULEID" == "__" ]; then
- MVN_PROJECT_MODULEID=""
-fi
-
-if [[ "$MVN_PROJECT_VERSION" == *SNAPSHOT ]]; then
- echo "=> for SNAPSHOT artifact build"
- MVN_DEPLOYMENT_TYPE='SNAPSHOT'
-else
- echo "=> for STAGING/RELEASE artifact build"
- MVN_DEPLOYMENT_TYPE='STAGING'
-fi
-echo "MVN_DEPLOYMENT_TYPE is [$MVN_DEPLOYMENT_TYPE]"
-
-
-TIMESTAMP=$(date +%C%y%m%dT%H%M%S)
-
-# expected environment variables
-if [ -z "${MVN_NEXUSPROXY}" ]; then
- echo "MVN_NEXUSPROXY environment variable not set. Cannot proceed"
- exit
-fi
-MVN_NEXUSPROXY_HOST=$(echo "$MVN_NEXUSPROXY" |cut -f3 -d'/' | cut -f1 -d':')
-echo "=> Nexus Proxy at $MVN_NEXUSPROXY_HOST, $MVN_NEXUSPROXY"
-
-if [ -z "$WORKSPACE" ]; then
- WORKSPACE=$(pwd)
-fi
-
-if [ -z "$SETTINGS_FILE" ]; then
- echo "SETTINGS_FILE environment variable not set. Cannot proceed"
- exit
-fi
-
-
-
-# mvn phase in life cycle
-MVN_PHASE="$2"
-
-
-echo "MVN_PROJECT_MODULEID is [$MVN_PROJECT_MODULEID]"
-echo "MVN_PHASE is [$MVN_PHASE]"
-echo "MVN_PROJECT_GROUPID is [$MVN_PROJECT_GROUPID]"
-echo "MVN_PROJECT_ARTIFACTID is [$MVN_PROJECT_ARTIFACTID]"
-echo "MVN_PROJECT_VERSION is [$MVN_PROJECT_VERSION]"
-echo "MVN_NEXUSPROXY is [$MVN_NEXUSPROXY]"
-echo "MVN_RAWREPO_BASEURL_UPLOAD is [$MVN_RAWREPO_BASEURL_UPLOAD]"
-echo "MVN_RAWREPO_BASEURL_DOWNLOAD is [$MVN_RAWREPO_BASEURL_DOWNLOAD]"
-MVN_RAWREPO_HOST=$(echo "$MVN_RAWREPO_BASEURL_UPLOAD" | cut -f3 -d'/' |cut -f1 -d':')
-echo "MVN_RAWREPO_HOST is [$MVN_RAWREPO_HOST]"
-echo "MVN_RAWREPO_SERVERID is [$MVN_RAWREPO_SERVERID]"
-echo "MVN_DOCKERREGISTRY_DAILY is [$MVN_DOCKERREGISTRY_DAILY]"
-echo "MVN_DOCKERREGISTRY_RELEASE is [$MVN_DOCKERREGISTRY_RELEASE]"
-
-
-source "${PROJECT_ROOT}"/mvn-phase-lib.sh
-
-
-# Customize the section below for each project
-case $MVN_PHASE in
-clean)
- echo "==> clean phase script"
- clean_templated_files
- clean_tox_files
- rm -rf ./venv-* ./*.wgn ./site
- ;;
-generate-sources)
- echo "==> generate-sources phase script"
- expand_templates
- ;;
-compile)
- echo "==> compile phase script"
- ;;
-test)
- echo "==> test phase script"
- ;;
-package)
- echo "==> package phase script"
- ;;
-install)
- echo "==> install phase script"
- ;;
-deploy)
- echo "==> deploy phase script"
-
- case $MVN_DEPLOYMENT_TYPE in
- SNAPSHOT)
- phase='merge'
- ;;
- STAGING)
- phase='release'
- ;;
- *)
- exit 1
- ;;
- esac
-
- VERSION=$(xpath -e '//project/version/text()' 'pom.xml')
- VERSION=${VERSION//\"/}
- EXT=$(echo "$VERSION" | rev | cut -s -f1 -d'-' | rev)
- if [ -z "$EXT" ]; then
- EXT="STAGING"
- fi
- case $phase in
- verify|merge)
- if [ "$EXT" != 'SNAPSHOT' ]; then
- echo "$phase job only takes SNAPSHOT version, got \"$EXT\" instead"
- exit 1
- fi
- ;;
- release)
- if [ ! -z "$EXT" ] && [ "$EXT" != 'STAGING' ]; then
- echo "$phase job only takes STAGING or pure numerical version, got \"$EXT\" instead"
- exit 1
- fi
- ;;
- *)
- echo "Unknown phase \"$phase\""
- exit 1
- esac
- echo "Running \"$phase\" job for version \"$VERSION\""
-
- # unarchive the service manager
- TARGET="${WORKSPACE}/target"
- #STAGE="${TARGET}/stage"
- STAGE=.
- BASE_DIR="${STAGE}/opt/app"
-
- # unarchive the collector
- AR=${WORKSPACE}/target/VESCollector-${VERSION}-bundle.tar.gz
- APP_DIR=${STAGE}/opt/app/VESCollector
-
- [ -d "${STAGE}/opt/app/VESCollector-${VERSION}" ] && rm -rf "${STAGE}/opt/app/VESCollector-${VERSION}"
-
- [ ! -f "${APP_DIR}" ] && mkdir -p "${APP_DIR}"
-
- gunzip -c "${AR}" | tar xvf - -C "${APP_DIR}" --strip-components=1
-
-
- if [ ! -f "${APP_DIR}/bin/docker-entry.sh" ]
- then
- echo "FATAL error cannot locate ${APP_DIR}/bin/docker-entry.sh"
- exit 2
- fi
- cp -p ${APP_DIR}/bin/docker-entry.sh ${BASE_DIR}/docker-entry.sh
- chmod 755 "${BASE_DIR}/docker-entry.sh"
-
-
-
-
- #
- # generate docker file
- #
- if [ ! -f "${APP_DIR}/Dockerfile" ]
- then
- echo "FATAL error cannot locate ${APP_DIR}/Dockerfile"
- exit 2
- fi
- cp -p ${APP_DIR}/Dockerfile ${STAGE}/Dockerfile
-
- BUILD_PATH="${WORKSPACE}/target/stage"
- build_and_push_docker
- ;;
-*)
- echo "==> unprocessed phase"
- ;;
-esac
-
diff --git a/pom.xml b/pom.xml
index 9c559c68..5aae85ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,407 +1,424 @@
-<!--
-================================================================================
-Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
-Copyright (c) 2018 Nokia. 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=========================================================
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>0.1.1</version>
- <relativePath/>
- </parent>
-
- <groupId>org.onap.dcaegen2.collectors.ves</groupId>
- <artifactId>VESCollector</artifactId>
- <version>1.3.0-SNAPSHOT</version>
-
- <name>dcaegen2-collectors-ves</name>
- <description>VESCollector</description>
-
- <properties>
- <main.basedir>${project.basedir}</main.basedir>
-
- <!-- CODE COMPILATION VERSIONS -->
- <compiler.source.version>1.8</compiler.source.version>
- <compiler.target.version>1.8</compiler.target.version>
-
- <!-- PLUGINS VERSIONS -->
- <compiler.plugin.version>3.3</compiler.plugin.version>
- <jar.plugin.version>2.4</jar.plugin.version>
- <deploy.plugin.version>2.8</deploy.plugin.version>
- <source.plugin.version>2.4</source.plugin.version>
- <javadoc.plugin.version>2.10.4</javadoc.plugin.version>
- <project.info.reports.plugin.version>2.6</project.info.reports.plugin.version>
- <assembly.plugin.version>2.4.1</assembly.plugin.version>
- <exec.plugin.version>1.2.1</exec.plugin.version>
-
- <!--TEST SETTINGS -->
- <surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
-
- <!--PLUGIN SETTINGS -->
- <dependency.locations.enabled>false</dependency.locations.enabled>
-
- <!-- NEXUS RELATED SETTINGS -->
- <nexusproxy>https://nexus.onap.org</nexusproxy>
- <snapshots.path>content/repositories/snapshots/</snapshots.path>
- <releases.path>content/repositories/releases/</releases.path>
- <site.path>content/sites/site/org/onap/dcaegen2/collectors/ves/${project.artifactId}/${project.version}
- </site.path>
- </properties>
-
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>${compiler.plugin.version}</version>
- <configuration>
- <source>${compiler.target.version}</source>
- <target>${compiler.source.version}</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <version>${source.plugin.version}</version>
- <configuration>
- <excludeResources>true</excludeResources>
- </configuration>
- <executions>
- <execution>
- <id>attach-sources</id>
- <phase>verify</phase>
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>${jar.plugin.version}</version>
- <configuration>
- <archive>
- <manifest>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- </manifest>
- <manifestEntries>
- <Implementation-Build-Version>${project.version}</Implementation-Build-Version>
- </manifestEntries>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>${assembly.plugin.version}</version>
- <configuration>
- <descriptors>
- <descriptor>src/assembly/dep.xml</descriptor>
- </descriptors>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id> <!-- this is used for inheritance merges -->
- <phase>package</phase> <!-- bind to the packaging phase -->
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${javadoc.plugin.version}</version>
- <configuration>
- <!-- minimize console output messages -->
- <quiet>true</quiet>
- <verbose>false</verbose>
- <useStandardDocletOptions>false</useStandardDocletOptions>
- </configuration>
- <executions>
- <execution>
- <id>aggregate</id>
- <phase>site</phase>
- <goals>
- <goal>aggregate</goal>
- </goals>
- </execution>
- <execution>
- <id>attach-javadoc</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>${exec.plugin.version}</version>
- <configuration>
- <executable>${session.executionRootDirectory}/mvn-phase-script.sh</executable>
- <environmentVariables>
- <!-- make mvn properties as env for our script -->
- <MVN_PROJECT_GROUPID>${project.groupId}</MVN_PROJECT_GROUPID>
- <MVN_PROJECT_ARTIFACTID>${project.artifactId}</MVN_PROJECT_ARTIFACTID>
- <MVN_PROJECT_VERSION>${project.version}</MVN_PROJECT_VERSION>
- <MVN_NEXUSPROXY>${onap.nexus.url}</MVN_NEXUSPROXY>
- <MVN_RAWREPO_BASEURL_UPLOAD>${onap.nexus.rawrepo.baseurl.upload}
- </MVN_RAWREPO_BASEURL_UPLOAD>
- <MVN_RAWREPO_BASEURL_DOWNLOAD>${onap.nexus.rawrepo.baseurl.download}
- </MVN_RAWREPO_BASEURL_DOWNLOAD>
- <MVN_RAWREPO_SERVERID>${onap.nexus.rawrepo.serverid}</MVN_RAWREPO_SERVERID>
- <MVN_DOCKERREGISTRY_DAILY>${onap.nexus.dockerregistry.daily}</MVN_DOCKERREGISTRY_DAILY>
- <MVN_DOCKERREGISTRY_RELEASE>${onap.nexus.dockerregistry.release}
- </MVN_DOCKERREGISTRY_RELEASE>
- </environmentVariables>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>${exec.plugin.version}</version>
- <executions>
- <execution>
- <id>deploy script</id>
- <phase>deploy</phase>
- <goals>
- <goal>exec</goal>
- </goals>
- <configuration>
- <arguments>
- <argument>__</argument>
- <argument>deploy</argument>
- </arguments>
- </configuration>
- </execution>
- <execution>
- <id>install script</id>
- <phase>install</phase>
- <goals>
- <goal>exec</goal>
- </goals>
- <configuration>
- <arguments>
- <argument>__</argument>
- <argument>install</argument>
- </arguments>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>com.github.fge</groupId>
- <artifactId>json-schema-core</artifactId>
- <version>1.2.5</version>
- </dependency>
- <dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- <version>1.4.7</version>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.2.2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>4.5.3</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.8.11</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
- <!-- JSON RELATED -->
- <dependency>
- <groupId>com.googlecode.json-simple</groupId>
- <artifactId>json-simple</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
- <groupId>com.github.fge</groupId>
- <artifactId>json-schema-validator</artifactId>
- <version>2.2.6</version>
- </dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.3.1</version>
- </dependency>
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>20160810</version>
- </dependency>
-
- <!-- REST API EXPOSURE RELATED -->
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-core</artifactId>
- <version>8.5.23</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-catalina</artifactId>
- <version>8.5.23</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-coyote</artifactId>
- <version>8.5.23</version>
- </dependency>
- <dependency>
- <groupId>com.att.nsa</groupId>
- <artifactId>nsaServerLibrary</artifactId>
- <version>1.0.10</version>
- </dependency>
-
- <!-- LOGGING RELATED -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.21</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>apache-log4j-extras</artifactId>
- <version>1.2.17</version>
- </dependency>
-
- <!-- MISCELLANEOUS -->
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- <version>1.10</version>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>18.0</version>
- </dependency>
-
- <!-- TESTING -->
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>2.18.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <version>3.8.0</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>${project.info.reports.plugin.version}</version>
- <reportSets>
- <reportSet>
- <reports>
- <report>dependencies</report>
- <report>license</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${javadoc.plugin.version}</version>
- <configuration>
- <failOnError>false</failOnError>
- <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
- <docletArtifact>
- <groupId>org.umlgraph</groupId>
- <artifactId>umlgraph</artifactId>
- <version>5.6</version>
- </docletArtifact>
- <additionalparam>-views</additionalparam>
- <useStandardDocletOptions>true</useStandardDocletOptions>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
-
- <repositories>
- <repository>
- <id>external-repository</id>
- <url>https://oss.sonatype.org/content/repositories</url>
- </repository>
- </repositories>
-
- <pluginRepositories>
- <!-- Black Duck plugin dependencies -->
- <pluginRepository>
- <id>JCenter</id>
- <name>JCenter Repository</name>
- <url>http://jcenter.bintray.com</url>
- </pluginRepository>
- <pluginRepository>
- <id>Restlet</id>
- <name>Restlet Repository</name>
- <url>http://maven.restlet.com</url>
- </pluginRepository>
- </pluginRepositories>
-
-</project>
+<!--
+================================================================================
+Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+Copyright (c) 2018 Nokia. 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=========================================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.oparent</groupId>
+ <artifactId>oparent</artifactId>
+ <version>0.1.1</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.onap.dcaegen2.collectors.ves</groupId>
+ <artifactId>VESCollector</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+
+ <name>dcaegen2-collectors-ves</name>
+ <description>VESCollector</description>
+
+ <properties>
+ <!-- PROJECT SETTINGS -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <java.version>8</java.version>
+ <docker.image.name>onap/org.onap.dcaegen2.collectors.ves.vescollector</docker.image.name>
+
+ <!-- TEST SETTINGS -->
+ <surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
+
+ <!-- PLUGIN SETTINGS -->
+ <dependency.locations.enabled>false</dependency.locations.enabled>
+
+ <!-- NEXUS RELATED SETTINGS -->
+ <nexusproxy>https://nexus.onap.org</nexusproxy>
+ <snapshots.path>content/repositories/snapshots/</snapshots.path>
+ <releases.path>content/repositories/releases/</releases.path>
+ <site.path>
+ content/sites/site/org/onap/dcaegen2/collectors/ves/${project.artifactId}/${project.version}
+ </site.path>
+ </properties>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.7.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>3.0.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.1.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>3.1.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>3.0.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.9</version>
+ </plugin>
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>1.1.1</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ <showWarnings>true</showWarnings>
+ <showDeprecation>true</showDeprecation>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <configuration>
+ <excludeResources>true</excludeResources>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ <manifestEntries>
+ <Implementation-Build-Version>${project.version}</Implementation-Build-Version>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/dep.xml</descriptor>
+ </descriptors>
+ <attach>false</attach>
+ <appendAssemblyId>false</appendAssemblyId>
+ <updateOnly>true</updateOnly>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <!-- minimize console output messages -->
+ <quiet>true</quiet>
+ <verbose>false</verbose>
+ <useStandardDocletOptions>false</useStandardDocletOptions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>aggregate</id>
+ <phase>site</phase>
+ <goals>
+ <goal>aggregate</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>attach-javadoc</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <configuration>
+ <serverId>${onap.nexus.dockerregistry.daily}</serverId>
+ <imageName>${docker.image.name}</imageName>
+ <imageTags>
+ <tag>latest</tag>
+ </imageTags>
+
+ <baseImage>openjdk:8-jre-slim</baseImage>
+ <env>
+ <HOSTALIASES>/etc/host.aliases</HOSTALIASES>
+ </env>
+ <workdir>/opt/app/VESCollector</workdir>
+ <resources>
+ <resource>
+ <targetPath>.</targetPath>
+ <directory>${project.build.directory}/${project.artifactId}-${project.version}</directory>
+ </resource>
+ </resources>
+ <runs>
+ <run>chmod +x bin/*.sh</run> <!-- Maven is loosing file permissions during artifacts copy -->
+ </runs>
+ <exposes>
+ <expose>8080</expose>
+ <expose>8443</expose>
+ </exposes>
+ <cmd>bin/docker-entry.sh</cmd>
+ </configuration>
+
+ <executions>
+ <execution>
+ <id>build-image</id>
+ <phase>package</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-latest</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>tag</goal>
+ </goals>
+ <configuration>
+ <image>${docker.image.name}:latest</image>
+ <newName>${onap.nexus.dockerregistry.daily}/${docker.image.name}:latest</newName>
+ <pushImage>true</pushImage>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>tag</goal>
+ </goals>
+ <configuration>
+ <image>${docker.image.name}:latest</image>
+ <newName>${onap.nexus.dockerregistry.daily}/${docker.image.name}:${project.version}</newName>
+ <pushImage>true</pushImage>
+ </configuration>
+ </execution>
+ <execution>
+ <id>tag-and-push-image-with-version-and-date</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>tag</goal>
+ </goals>
+ <configuration>
+ <image>${docker.image.name}:latest</image>
+ <newName>${onap.nexus.dockerregistry.daily}/${docker.image.name}:${project.version}-${maven.build.timestamp}Z</newName>
+ <pushImage>true</pushImage>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>dependencies</report>
+ <report>license</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <failOnError>false</failOnError>
+ <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
+ <docletArtifact>
+ <groupId>org.umlgraph</groupId>
+ <artifactId>umlgraph</artifactId>
+ <version>5.6</version>
+ </docletArtifact>
+ <additionalparam>-views</additionalparam>
+ <useStandardDocletOptions>true</useStandardDocletOptions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <dependencies>
+ <!-- JSON RELATED -->
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.github.fge</groupId>
+ <artifactId>json-schema-validator</artifactId>
+ <version>2.2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>com.github.fge</groupId>
+ <artifactId>json-schema-core</artifactId>
+ <version>1.2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20160810</version>
+ </dependency>
+
+ <!-- REST API RELATED -->
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ <version>8.5.23</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-catalina</artifactId>
+ <version>8.5.23</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-coyote</artifactId>
+ <version>8.5.23</version>
+ </dependency>
+ <dependency>
+ <groupId>com.att.nsa</groupId>
+ <artifactId>nsaServerLibrary</artifactId>
+ <version>1.0.10</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.8.11</version>
+ </dependency>
+
+ <!-- LOGGING RELATED -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.21</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>apache-log4j-extras</artifactId>
+ <version>1.2.17</version>
+ </dependency>
+
+ <!-- MISCELLANEOUS -->
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>18.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.10</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4.7</version>
+ </dependency>
+
+ <!-- TESTING -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.18.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.8.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>external-repository</id>
+ <url>https://oss.sonatype.org/content/repositories</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <!-- Black Duck plugin dependencies -->
+ <pluginRepository>
+ <id>JCenter</id>
+ <name>JCenter Repository</name>
+ <url>http://jcenter.bintray.com</url>
+ </pluginRepository>
+ <pluginRepository>
+ <id>Restlet</id>
+ <name>Restlet Repository</name>
+ <url>http://maven.restlet.com</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
diff --git a/src/assembly/dep.xml b/src/assembly/dep.xml
index b322fba1..7d72f84f 100644
--- a/src/assembly/dep.xml
+++ b/src/assembly/dep.xml
@@ -1,86 +1,79 @@
<!--
- ============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=========================================================
- -->
+================================================================================
+Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+Copyright (c) 2018 Nokia. 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
-<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
- <id>bundle</id>
- <formats>
- <format>tar.gz</format>
- </formats>
- <files>
- <file>
- <source>target/${project.artifactId}-${project.version}.jar</source>
- <outputDirectory>lib</outputDirectory>
- </file>
- </files>
- <fileSets>
- <fileSet>
- <directory>src/main/scripts</directory>
- <outputDirectory>bin</outputDirectory>
- <includes>
- <include>**/*.sh</include>
- </includes>
- <fileMode>0755</fileMode>
- <lineEnding>unix</lineEnding>
- </fileSet>
- <fileSet>
- <directory>etc</directory>
- <outputDirectory>etc</outputDirectory>
- </fileSet>
- <fileSet>
- <directory>src/main/resources</directory>
- <includes>
- <include>**/*.conf</include>
- </includes>
- <outputDirectory>etc</outputDirectory>
- </fileSet>
- <fileSet>
- <directory>dpo/data-formats</directory>
- <includes>
- <include>**/*.json</include>
- </includes>
- <outputDirectory>specs</outputDirectory>
- </fileSet>
- <fileSet>
- <directory>dpo/spec</directory>
- <includes>
- <include>**/*.json</include>
- </includes>
- <outputDirectory>specs</outputDirectory>
- </fileSet>
- <fileSet>
- <directory>./</directory>
- <includes>
- <include>Dockerfile</include>
- </includes>
- <outputDirectory>./</outputDirectory>
- </fileSet>
- </fileSets>
- <dependencySets>
- <dependencySet>
- <includes>
- <include>*:jar</include>
- </includes>
- <outputDirectory>lib</outputDirectory>
- </dependencySet>
- </dependencySets>
-</assembly>
+ 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=========================================================
+-->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+
+ <id>bundle</id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>dir</format>
+ </formats>
+
+ <fileSets>
+ <fileSet>
+ <directory>src/main/scripts</directory>
+ <outputDirectory>bin</outputDirectory>
+ <includes>
+ <include>**/*.sh</include>
+ </includes>
+ <fileMode>0755</fileMode>
+ <lineEnding>unix</lineEnding>
+ </fileSet>
+ <fileSet>
+ <directory>etc</directory>
+ <outputDirectory>etc</outputDirectory>
+ </fileSet>
+
+ <fileSet>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.conf</include>
+ </includes>
+ <outputDirectory>etc</outputDirectory>
+ </fileSet>
+
+ <fileSet>
+ <directory>dpo/data-formats</directory>
+ <includes>
+ <include>**/*.json</include>
+ </includes>
+ <outputDirectory>specs</outputDirectory>
+ </fileSet>
+
+ <fileSet>
+ <directory>dpo/spec</directory>
+ <includes>
+ <include>**/*.json</include>
+ </includes>
+ <outputDirectory>specs</outputDirectory>
+ </fileSet>
+ </fileSets>
+
+ <dependencySets>
+ <dependencySet>
+ <scope>runtime</scope>
+ <useProjectArtifact>true</useProjectArtifact>
+ <unpack>false</unpack>
+ <outputDirectory>lib</outputDirectory>
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git a/src/main/java/org/onap/dcae/commonFunction/EventProcessor.java b/src/main/java/org/onap/dcae/commonFunction/EventProcessor.java
index 04687b32..6dd2f5c8 100644
--- a/src/main/java/org/onap/dcae/commonFunction/EventProcessor.java
+++ b/src/main/java/org/onap/dcae/commonFunction/EventProcessor.java
@@ -25,6 +25,7 @@ import com.att.nsa.logging.LoggingContext;
import com.att.nsa.logging.log4j.EcompFields;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
+import java.util.Map;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,7 +39,6 @@ import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
-import java.util.TimeZone;
public class EventProcessor implements Runnable {
@@ -50,23 +50,26 @@ public class EventProcessor implements Runnable {
}.getType();
private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MM dd yyyy hh:mm:ss z");
- private static HashMap<String, String[]> streamidHash = new HashMap<>();
- JSONObject event;
+ static Map<String, String[]> streamidHash = new HashMap<>();
+ public JSONObject event;
public EventProcessor() {
- dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
- String[] list = CommonStartup.streamid.split("\\|");
+ streamidHash = parseStreamIdToStreamHashMapping(CommonStartup.streamid);
+ }
+
+ private Map<String, String[]> parseStreamIdToStreamHashMapping(String streamId) {
+ Map<String, String[]> streamidHash = new HashMap<>();
+ String[] list = streamId.split("\\|");
for (String aList : list) {
String domain = aList.split("=")[0];
-
String[] streamIdList = aList.substring(aList.indexOf('=') + 1).split(",");
- log.debug(String.format("Domain: %s streamIdList:%s", domain, Arrays.toString(streamIdList)));
streamidHash.put(domain, streamIdList);
}
-
+ return streamidHash;
}
+
@Override
public void run() {
diff --git a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
index 7aa82c9f..d664b137 100644
--- a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
+++ b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
@@ -47,12 +47,11 @@ import com.att.nsa.security.NsaAuthenticator;
import com.att.nsa.security.authenticators.SimpleAuthenticator;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-
public class RestfulCollectorServlet extends CommonServlet
{
public static String authlist;
-
+
public RestfulCollectorServlet ( rrNvReadable settings ) throws loadException, missingReqdSetting
{
super ( settings, "collector", false );
@@ -76,7 +75,7 @@ public class RestfulCollectorServlet extends CommonServlet
// logging. The Restful Collector likely doesn't need API authentication, so for now,
// we init the base class services with an in-memory (and empty!) config DB.
commonServletSetup ( ConfigDbType.MEMORY );
-
+
VESLogger.setUpEcompLogging();
// setup the servlet routing and error handling
@@ -101,10 +100,10 @@ public class RestfulCollectorServlet extends CommonServlet
if (CommonStartup.authflag > 0) {
NsaAuthenticator<NsaSimpleApiKey> NsaAuth;
NsaAuth = AuthlistHandler(authlist);
-
+
this.getSecurityManager().addAuthenticator(NsaAuth);
}
-
+
log.info ( "Restful Collector Servlet is up." );
}
catch ( SecurityException e )
@@ -127,13 +126,13 @@ public class RestfulCollectorServlet extends CommonServlet
if (authlist != null)
{
String authpair[] = authlist.split("\\|");
- for (String pair: authpair) {
- String lineid[] = pair.split(",");
- String listauthid = lineid[0];
- String listauthpwd = new String(Base64.decodeBase64(lineid[1]));
- ((SimpleAuthenticator) NsaAuth).add(listauthid,listauthpwd);
- }
-
+ for (String pair: authpair) {
+ String lineid[] = pair.split(",");
+ String listauthid = lineid[0];
+ String listauthpwd = new String(Base64.decodeBase64(lineid[1]));
+ ((SimpleAuthenticator) NsaAuth).add(listauthid,listauthpwd);
+ }
+
}
else
{
@@ -143,8 +142,9 @@ public class RestfulCollectorServlet extends CommonServlet
return NsaAuth;
}
-
+
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger ( RestfulCollectorServlet.class );
}
+
diff --git a/src/main/scripts/VESrestfulCollector.sh b/src/main/scripts/VESrestfulCollector.sh
index 4e3fd83e..c883f6de 100644
--- a/src/main/scripts/VESrestfulCollector.sh
+++ b/src/main/scripts/VESrestfulCollector.sh
@@ -32,7 +32,7 @@ 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`
+ collectorPid=`pidof org.onap.dcae.commonFunction`
if [ ! -z "$collectorPid" ]; then
echo "WARNING: VES Restful Collector already running as PID $collectorPid" | tee -a ${BASEDIR}/logs/console.txt
@@ -56,13 +56,13 @@ collector_start() {
collector_stop() {
echo `date +"%Y%m%d.%H%M%S%3N"` - collector_stop
- collectorPid=`pgrep -f org.onap.dcae.commonFunction`
+ collectorPid=`pidof 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
+ if [ ! "$(pidof org.onap.dcae.commonFunction)" ]; then
echo "VES Restful Collector has been stopped!!!"
else
echo "VES Restful Collector is being stopped!!!"
@@ -107,16 +107,16 @@ collector_configupdate() {
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
@@ -126,7 +126,7 @@ collector_configupdate() {
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
diff --git a/src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java b/src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java
new file mode 100644
index 00000000..18194864
--- /dev/null
+++ b/src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java
@@ -0,0 +1,129 @@
+/*-
+ * ============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=========================================================
+ */
+package org.onap.dcae.commonFunction;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import com.att.nsa.cmdLine.NsaCommandLineUtil;
+import com.att.nsa.drumlin.service.framework.context.DrumlinRequest;
+import com.att.nsa.drumlin.till.nv.impl.nvReadableStack;
+import com.att.nsa.drumlin.till.nv.impl.nvReadableTable;
+import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
+import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
+import com.att.nsa.security.authenticators.SimpleAuthenticator;
+import com.att.nsa.security.db.simple.NsaSimpleApiKey;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Base64;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.dcae.commonFunction.CommonStartup.QueueFullException;
+import org.onap.dcae.restapi.RestfulCollectorServlet;
+
+
+public class TestCommonStartup {
+
+ @Test
+ public void testParseCLIArguments() {
+ // given
+ String args[] = {"-a", "aa"};
+ Map<String, String> argMap = NsaCommandLineUtil.processCmdLine(args, true);
+ // when
+ nvReadableStack settings = new nvReadableStack();
+ settings.push(new nvReadableTable(argMap));
+
+ // then
+ assertEquals(settings.getString("a", "default"), "aa");
+ }
+
+ @Test
+ public void shouldPutValidVESEventOnProcessingQueueWithoutExceptions() throws IOException, QueueFullException {
+ // given
+ CommonStartup.fProcessingInputQueue = new LinkedBlockingQueue<>(
+ CommonStartup.KDEFAULT_MAXQUEUEDEVENTS);
+ JsonElement vesEvent = new JsonParser().parse(new FileReader("src/test/resources/VES_valid.txt"));
+ JSONObject validVESEvent = new JSONObject(vesEvent.toString());
+ JSONArray jsonArrayMod = new JSONArray().put(validVESEvent);
+
+ // then
+ CommonStartup.handleEvents(jsonArrayMod);
+ }
+
+
+ @Test
+ public void testParseStreamIdToStreamHashMapping() {
+ // given
+ CommonStartup.streamid = "fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling";
+ EventProcessor eventProcessor = new EventProcessor();
+
+ // when
+ Map<String, String[]> streamHashMapping = EventProcessor.streamidHash;
+
+ // then
+ assertEquals(streamHashMapping.get("fault")[0], "sec_fault");
+ assertEquals(streamHashMapping.get("measurementsForVfScaling")[0], "sec_measurement");
+ }
+
+ @Test
+ public void testAuthListHandler() throws loadException, missingReqdSetting {
+ // given
+ final nvReadableStack settings = new nvReadableStack();
+
+ String user1 = "secureid";
+ String password1Hashed = "IWRjYWVSb2FkbTEyMyEt";
+ String password1UnHashed = decode("IWRjYWVSb2FkbTEyMyEt");
+ String user2 = "sample1";
+ String password2Hashed = "c2FtcGxlMQ";
+
+ String authlist = user1 + "," + password1Hashed + "|" + user2 + "," + password2Hashed;
+
+ RestfulCollectorServlet rsv = new RestfulCollectorServlet(settings);
+
+ DrumlinRequest drumlinRequestMock = Mockito.mock(DrumlinRequest.class);
+
+ String basicHeaderForUser1 = "Basic " + encode(user1, password1UnHashed);
+ when(drumlinRequestMock.getFirstHeader("Authorization")).thenReturn(basicHeaderForUser1);
+
+ // when
+ SimpleAuthenticator simpleAuthenticator = (SimpleAuthenticator) rsv.AuthlistHandler(authlist);
+ NsaSimpleApiKey authentic = simpleAuthenticator.isAuthentic(drumlinRequestMock);
+
+ // then
+ assertEquals(authentic.getSecret(), password1UnHashed);
+ }
+
+ private String decode(String hashedPassword) {
+ return new String(Base64.getDecoder().decode(hashedPassword.getBytes()));
+ }
+
+ private String encode(String user1, String password1UnHashed) {
+ return Base64.getEncoder().encodeToString((user1 + ":" + password1UnHashed).getBytes());
+ }
+
+}
+
+
diff --git a/src/test/java/org/onap/dcae/vestest/TestCommonStartup.java b/src/test/java/org/onap/dcae/vestest/TestCommonStartup.java
deleted file mode 100644
index aa56c611..00000000
--- a/src/test/java/org/onap/dcae/vestest/TestCommonStartup.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*-
- * ============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=========================================================
- */
-package org.onap.dcae.vestest;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Map;
-import java.util.concurrent.LinkedBlockingQueue;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.dcae.commonFunction.CommonStartup;
-import org.onap.dcae.commonFunction.EventProcessor;
-import org.onap.dcae.commonFunction.CommonStartup.QueueFullException;
-import org.onap.dcae.restapi.RestfulCollectorServlet;
-
-import com.att.nsa.cmdLine.NsaCommandLineUtil;
-import com.att.nsa.drumlin.service.framework.DrumlinServlet;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
-import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
-import com.att.nsa.security.NsaAuthenticator;
-import com.att.nsa.security.authenticators.SimpleAuthenticator;
-import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-import com.google.gson.JsonParser;
-import com.att.nsa.drumlin.till.nv.impl.nvPropertiesFile;
-import com.att.nsa.drumlin.till.nv.impl.nvReadableStack;
-import com.att.nsa.drumlin.till.nv.impl.nvReadableTable;
-
-
-public class TestCommonStartup {
-
- String payload = null;
- @Before
- public void setUp() throws Exception {
-
- // process command line arguments
- payload = new JsonParser().parse(new FileReader("src/test/resources/VES_valid.txt")).toString();
- CommonStartup.fProcessingInputQueue = new LinkedBlockingQueue<JSONObject> (CommonStartup.KDEFAULT_MAXQUEUEDEVENTS);
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- @Test
- public void testCommonStartupload() {
-
- String args[] = { "junittest" };
- final Map<String, String> argMap = NsaCommandLineUtil.processCmdLine(args, true);
- final String config = NsaCommandLineUtil.getSetting(argMap, "c", "collector.properties");
- final URL settingStream = DrumlinServlet.findStream(config, CommonStartup.class);
-
- final nvReadableStack settings = new nvReadableStack();
- try {
- settings.push(new nvPropertiesFile(settingStream));
- } catch (loadException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- settings.push(new nvReadableTable(argMap));
- Assert.assertEquals("true", "true");
- }
-
- @Test
- public void testhandleevent() {
- JSONArray jsonArrayMod = new JSONArray().put(new JSONObject(payload));
- try {
-
-
- CommonStartup.handleEvents (jsonArrayMod);
- } catch ( JSONException | QueueFullException | IOException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- System.out.println("junit reported:" + e.getMessage());
- }
- Assert.assertEquals("true", "true");
- }
-
-
-/*
- @Test
- public void testServlet() {
- try
- {
- RestfulCollectorServlet rsv = new RestfulCollectorServlet(null);
- }
- catch (NullPointerException|loadException| missingReqdSetting e){
- System.out.println("junit reported:" + e.getMessage());
- }
- Assert.assertEquals("true", "true");
- }
-*/
-
-
-
- @Test
- public void testEventProcessorinstantiation()
- {
- CommonStartup.streamid="fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling";
- EventProcessor ep = new EventProcessor ();
- Thread epThread=new Thread(ep);
- epThread.start();
- Assert.assertEquals("true", "true");
- epThread.interrupt();
-
- }
-
- @Test
- public void testAuthListHandler()
- {
-
- final Map<String, String> argMap = NsaCommandLineUtil.processCmdLine ( new String[0], true );
- final String config = NsaCommandLineUtil.getSetting ( argMap, "c", "collector.properties" );
- final URL settingStream = DrumlinServlet.findStream ( config, CommonStartup.class );
-
- final nvReadableStack settings = new nvReadableStack ();
- try {
- settings.push ( new nvPropertiesFile ( settingStream ) );
- settings.push ( new nvReadableTable ( argMap ) );
- } catch (loadException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
-
-
- RestfulCollectorServlet rsv = null;
- NsaAuthenticator<NsaSimpleApiKey> NsaAuth = null;
- Boolean flag = false;
- try
- {
- rsv = new RestfulCollectorServlet(settings);
- }
- catch (NullPointerException|loadException| missingReqdSetting e){
- System.out.println("junit reported:" + e.getMessage());
- }
- String authlist = "secureid,IWRjYWVSb2FkbTEyMyEt|sample1,c2FtcGxlMQ==|vdnsagg,dmRuc2FnZw==";
- NsaAuth = rsv.AuthlistHandler(authlist);
- if (NsaAuth != null)
- {
- flag = true;
- }
- Assert.assertEquals(true, flag);
-
-
- }
-}
-
-
diff --git a/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java b/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java
index 32a2299e..0b6b5027 100644
--- a/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java
+++ b/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java
@@ -7,9 +7,9 @@
* 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.
@@ -19,149 +19,63 @@
*/
package org.onap.dcae.vestest;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import static org.onap.dcae.vestest.TestingUtilities.createTemporaryFile;
-import static org.junit.Assert.assertEquals;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Map;
-import java.util.Properties;
-
-import org.json.JSONObject;
-import com.google.gson.JsonParser;
import com.google.gson.JsonObject;
-
-import org.junit.After;
+import java.nio.file.Path;
import org.junit.Before;
import org.junit.Test;
-import org.onap.dcae.commonFunction.CommonStartup;
-import org.onap.dcae.commonFunction.DmaapPropertyReader;
-import org.onap.dcae.commonFunction.EventProcessor;
-import org.onap.dcae.commonFunction.EventPublisherHash;
import org.onap.dcae.controller.FetchDynamicConfig;
+import org.onap.dcae.controller.LoadDynamicConfig;
public class TestFetchConfig {
- JSONObject jsonObject;
-
- @Before
- public void setUp() throws Exception {
-
-
- System.setProperty("CONSUL_HOST", "localhost");
- System.setProperty("CONFIG_BINDING_SERVICE", "localhost");
- System.setProperty("HOSTNAME", "localhost");
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
-
-
- @Test
- public void testwritefile() {
- Boolean flag = false;
-
- FetchDynamicConfig fc = new FetchDynamicConfig();
- //Used for writing the configuration output
- FetchDynamicConfig.configFile = "src/test/resources/controller-config_formatted_op.json";
-
-
-
- try{
- JsonParser parser = new JsonParser();
- FileReader fr = new FileReader ("src/test/resources/controller-config_singleline_ip.json" );
- final JsonObject jo = (JsonObject) parser.parse (fr);
- final String jsonText = jo.toString ();
- jsonObject = new JSONObject ( jsonText );
-
- fc.writefile(jsonObject.toString());
- }
- catch(Exception e){
- System.out.println("Exception while opening the file");
- e.printStackTrace();
- }
- if(jsonObject.has("streams_publishes"))
- {
- flag = true;
- }
-
- assertEquals(true, flag);
-
- }
-
- @Test
- public void testgetConsul() {
- Boolean flag = false;
-
-
- try{
-
- FetchDynamicConfig.getconsul();
- flag = true;
- }
- catch(Exception e){
- System.out.println("Exception while getting to consul");
- e.printStackTrace();
- }
- assertEquals(true, flag);
-
- }
-
- @Test
- public void testgetCBS() {
- Boolean flag = false;
-
- try{
-
-
- JsonParser parser = new JsonParser();
- FileReader fr = new FileReader ("src/test/resources/controller-config_singleline_ip.json" );
- final JsonObject jo = (JsonObject) parser.parse (fr);
- final String jsonText = jo.toString ();
- jsonObject = new JSONObject ( jsonText );
-
- //retstring from Consul is parsed
- FetchDynamicConfig.retString = "[{\"ID\":\"81bc2a17-8cfa-3f6f-30a9-a545a9b6ac2f\",\"Node\":\"zldcrdm5bdcc2dokr00\",\"Address\":\"135.25.108.161\",\"Datacenter\":\"zldcrdm5bdcc2\",\"TaggedAddresses\":{\"lan\":\"135.25.108.161\",\"wan\":\"135.25.108.161\"},\"NodeMeta\":{\"fqdn\":\"zldcrdm5bdcc2dokr00.2f3fb3.rdm5b.tci.att.com\"},\"ServiceID\":\"20299a144716:config_binding_service:10000\",\"ServiceName\":\"config_binding_service\",\"ServiceTags\":[],\"ServiceAddress\":\"135.25.108.161\",\"ServicePort\":10000,\"ServiceEnableTagOverride\":false,\"CreateIndex\":9153156,\"ModifyIndex\":9153156}]";
-
- //Mock the return CBS output
- FetchDynamicConfig.retCBSString = jsonObject.toString();
- FetchDynamicConfig.getCBS();
- flag = true;
- }
- catch(Exception e){
- System.out.println("Exception while fetching cbs configuration");
- e.printStackTrace();
- }
- assertEquals(true, flag);
-
- }
-
-
- @Test
- public void testverifyConfigChange() {
-
-
- Boolean ret= false;
-
- try{
- //File date to be compared
- FetchDynamicConfig.configFile = "src/test/resources/controller-config_singleline_ip.json";
- //Mock the return CBS output
- 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\"}";
- ret=FetchDynamicConfig.verifyConfigChange();
-
- }
- catch(Exception e){
- System.out.println("Exception on verifyConfigChange");
- //e.printStackTrace();
- }
- assertEquals(true, ret);
-
- }
-
+ private Path temporaryFile;
+
+ @Before
+ public void setUp() {
+ temporaryFile = createTemporaryFile();
+ }
+
+ @Test
+ public void shouldWriteFileAndAttachDMaaPStreamsPropertiesFromConfiguration() {
+ // given
+ FetchDynamicConfig loadDynamicConfig = new FetchDynamicConfig();
+ FetchDynamicConfig.configFile = temporaryFile.toString();
+ String sampleConfiguration = LoadDynamicConfig.readFile("src/test/resources/controller-config_singleline_ip.json");
+
+ // when
+ loadDynamicConfig.writefile(sampleConfiguration);
+
+ // then
+ JsonObject actuallyWrittenJSONContent = TestingUtilities.readJSONFromFile(temporaryFile);
+ assertTrue(actuallyWrittenJSONContent.has("streams_publishes"));
+ }
+
+ @Test
+ public void shouldThrowNoErrorsWhileParsingConsulResponse() {
+ // given
+ FetchDynamicConfig.retString = "[{\"ID\":\"81bc2a17-8cfa-3f6f-30a9-a545a9b6ac2f\",\"Node\":\"zldcrdm5bdcc2dokr00\",\"Address\":\"135.25.108.161\",\"Datacenter\":\"zldcrdm5bdcc2\",\"TaggedAddresses\":{\"lan\":\"135.25.108.161\",\"wan\":\"135.25.108.161\"},\"NodeMeta\":{\"fqdn\":\"zldcrdm5bdcc2dokr00.2f3fb3.rdm5b.tci.att.com\"},\"ServiceID\":\"20299a144716:config_binding_service:10000\",\"ServiceName\":\"config_binding_service\",\"ServiceTags\":[],\"ServiceAddress\":\"135.25.108.161\",\"ServicePort\":10000,\"ServiceEnableTagOverride\":false,\"CreateIndex\":9153156,\"ModifyIndex\":9153156}]";
+
+ // then
+ FetchDynamicConfig.getCBS();
+ }
+
+
+ @Test
+ public void shouldReturnTrueOnConfigurationChange() {
+ // given
+ FetchDynamicConfig.configFile = "src/test/resources/controller-config_singleline_ip.json";
+ 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\"}";
+
+ // when
+ boolean didConfigsChange = FetchDynamicConfig.verifyConfigChange();
+
+ // then
+ assertTrue(didConfigsChange);
+ }
+
}
diff --git a/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java b/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
index 765d9c61..ee0a3cba 100644
--- a/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
+++ b/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
@@ -7,9 +7,9 @@
* 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.
@@ -19,85 +19,59 @@
*/
package org.onap.dcae.vestest;
-import static org.junit.Assert.*;
-
-import java.io.FileReader;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.onap.dcae.vestest.TestingUtilities.correctQuotes;
+import static org.onap.dcae.vestest.TestingUtilities.createTemporaryFile;
+import com.github.fge.jackson.JsonLoader;
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.onap.dcae.controller.FetchDynamicConfig;
import org.onap.dcae.controller.LoadDynamicConfig;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-
public class TestLoadDynamicConfig {
- LoadDynamicConfig lc;
- String propop = "src/test/resources/test_collector_ip_op.properties";
-
-
- @Before
- public void setUp() throws Exception {
-
- lc = new LoadDynamicConfig();
-
- }
-
- @After
- public void tearDown() throws Exception {
- }
+ private Path temporaryFile;
- @Test
- public void testLoad() {
+ @Before
+ public void setUp() {
+ temporaryFile = createTemporaryFile();
+ }
-
- Boolean flag=false;
-
+ @Test
+ public void shouldReadFileContent() throws IOException {
+ // given
+ String expectedJSON = correctQuotes("{ 'field' : 1 }");
+ Files.write(temporaryFile, expectedJSON.getBytes());
- lc.propFile = "src/test/resources/test_collector_ip_op.properties";
- lc.configFile = "src/test/resources/controller-config_dmaap_ip.json";
-
- String data = LoadDynamicConfig.readFile(propop);
- assertEquals(data.isEmpty(), flag);
- }
+ // when
+ String readFileContent = LoadDynamicConfig.readFile(temporaryFile.toString());
+ // then
+ assertEquals(JsonLoader.fromString(expectedJSON), JsonLoader.fromString(readFileContent));
+ }
- @Test
- public void testwrite() {
+ @Test
+ public void shouldWriteFileAndAttachDMaaPRelatedPropertiesFromConfiguration() {
+ // given
+ LoadDynamicConfig loadDynamicConfig = new LoadDynamicConfig();
+ loadDynamicConfig.propFile = "src/test/resources/test_collector_ip_op.properties";
+ loadDynamicConfig.configFile = "src/test/resources/controller-config_dmaap_ip.json";
+ loadDynamicConfig.dmaapoutputfile = temporaryFile.toString();
+ String sampleConfiguration = LoadDynamicConfig.readFile(loadDynamicConfig.configFile);
-
- Boolean flag=false;
-
- lc.propFile = "src/test/resources/test_collector_ip_op.properties";
- lc.configFile = "src/test/resources/controller-config_dmaap_ip.json";
- lc.dmaapoutputfile = "src/test/resources/DmaapConfig-op.json";
-
- String data = LoadDynamicConfig.readFile(lc.configFile);
- JSONObject jsonObject = new JSONObject(data);
- lc.writeconfig(jsonObject);
+ // when
+ loadDynamicConfig.writeconfig(new JSONObject(sampleConfiguration));
- try{
- JsonParser parser = new JsonParser();
- FileReader fr = new FileReader ( lc.dmaapoutputfile );
- final JsonObject jo = (JsonObject) parser.parse (fr);
- final String jsonText = jo.toString ();
- jsonObject = new JSONObject ( jsonText );
- }
- catch(Exception e){
- System.out.println("Exception while opening the file");
- e.printStackTrace();
- }
- if(jsonObject.has("ves-fault-secondary"))
- {
- flag = true;
- }
-
- assertEquals(true, flag);
+ // then
+ JsonObject actuallyWrittenJSONContent = TestingUtilities.readJSONFromFile(temporaryFile);
+ assertTrue(actuallyWrittenJSONContent.has("ves-fault-secondary"));
+ }
- }
}
diff --git a/src/test/java/org/onap/dcae/vestest/TestingUtilities.java b/src/test/java/org/onap/dcae/vestest/TestingUtilities.java
new file mode 100644
index 00000000..43e7a84e
--- /dev/null
+++ b/src/test/java/org/onap/dcae/vestest/TestingUtilities.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. 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=========================================================
+ */
+package org.onap.dcae.vestest;
+
+import static java.nio.file.Files.readAllBytes;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * @author Pawel Szalapski (pawel.szalapski@nokia.com)
+ */
+final class TestingUtilities {
+
+ private TestingUtilities() {
+ // utility class, no objects allowed
+ }
+
+ static String correctQuotes(String s) {
+ return s.replace("'", "\"");
+ }
+
+ static JsonObject readJSONFromFile(Path path) {
+ return rethrow(() -> (JsonObject) new JsonParser().parse(new String(readAllBytes(path))));
+ }
+
+ static Path createTemporaryFile() {
+ return rethrow(() -> {
+ Path temporaryDirectory = Files.createTempDirectory("temporaryDirectory");
+ Path temporaryFile = TestingUtilities.createFile(temporaryDirectory + "/testFile");
+ TestingUtilities.scheduleToBeDeletedAfterTests(temporaryDirectory);
+ TestingUtilities.scheduleToBeDeletedAfterTests(temporaryFile);
+ return temporaryFile;
+ });
+ }
+
+ private static Path createFile(String path) {
+ return rethrow(() -> Files.createFile(Paths.get(path)));
+ }
+
+ private static void scheduleToBeDeletedAfterTests(Path path) {
+ path.toFile().deleteOnExit();
+ }
+
+ /**
+ * Exception in test case usually means there is something wrong, it should never be catched, but rather thrown to
+ * be handled by JUnit framework.
+ */
+ private static <T> T rethrow(CheckedSupplier<T> supplier) {
+ try {
+ return supplier.get();
+ } catch (Exception e) {
+ throw new RuntimeException();
+ }
+ }
+
+ @FunctionalInterface
+ interface CheckedSupplier<T> {
+
+ T get() throws Exception;
+ }
+
+
+}