From a19e0a6df170c02df0f1f8c36ecf97d4a8fe330b Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 15:50:17 -0500 Subject: [PATCH 01/48] enable sonar scan ALEC-247 --- .circleci/config.yml | 17 ++++- .circleci/scripts/sonar.sh | 135 +++++++++++++++++++++++++++++++++++++ pom.xml | 29 ++++++++ 3 files changed, 180 insertions(+), 1 deletion(-) create mode 100755 .circleci/scripts/sonar.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 53aa2d39..3a611f44 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -115,7 +115,13 @@ workflows: only: - develop - /release-.*/ - + - sonar: + context: "OpenNMS Build" + requires: + - build + filters: + tags: + only: /.*/ commands: smoke-test: @@ -427,3 +433,12 @@ jobs: name: Push packages to CloudSmith command: .circleci/scripts/publish-cloudsmith.sh + sonar: + executor: build-executor + steps: + - run: + name: Run SonarQube Code Analysis + when: always + command: | + export MAVEN_OPTS="-Xmx12g -XX:ReservedCodeCacheSize=1g -XX:+TieredCompilation" + .circleci/scripts/sonar.sh diff --git a/.circleci/scripts/sonar.sh b/.circleci/scripts/sonar.sh new file mode 100755 index 00000000..2a898a3f --- /dev/null +++ b/.circleci/scripts/sonar.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +set -e +set -o pipefail + +FIND_TESTS_DIR="target/find-tests" + +filter_exists() +{ + while read -r CHECK; do + [ -e "${CHECK}" ] && echo "${CHECK}" + done +} + +generate_jacoco_report_files() +{ + find . -type f '!' -path './.git/*' -name jacoco.xml +} + +generate_junit_report_folders() +{ + find . -type d '!' -path './.git/*' -a \( -name surefire-reports\* -o -name failsafe-reports\* \) +} + +generate_class_folders() +{ + generate_junit_report_folders \ + | sed -e 's,/\(surefire-reports\|failsafe-reports\).*$,,' \ + | sort -u \ + | while read -r DIR; do + find "$DIR" -maxdepth 1 -type d -name classes + done \ + | filter_exists +} + +generate_test_class_folders() +{ + generate_junit_report_folders \ + | sed -e 's,/\(surefire-reports\|failsafe-reports\).*$,,' \ + | sort -u \ + | while read -r DIR; do + find "$DIR" -maxdepth 1 -type d -name test-classes + done \ + | filter_exists +} + +generate_source_folders() +{ + find . -type d '!' -path './.git/*' -name target \ + | sed -e 's,/target,/src,' \ + | sort -u \ + | while read -r DIR; do + echo "${DIR}/main" + echo "${DIR}/assembly" + done \ + | filter_exists +} + +generate_test_folders() +{ + find . -type d '!' -path './.git/*' -name target \ + | sed -e 's,/target,/src,' \ + | sort -u \ + | while read -r DIR; do + echo "${DIR}/test" + done \ + | filter_exists +} + +find_tests() +{ + perl -pi -e "s,/(root|home/circleci)/project/,${HOME}/project/,g" target/structure-graph.json + + # Now determine the Maven modules related to the tests we need to run + cat "${FIND_TESTS_DIR}"/*_classnames | python3 .circleci/scripts/find-tests/find-tests.py generate-test-modules \ + --output=/tmp/this_node_projects \ + . +} + +# shellcheck disable=SC1091 +. ./.circleci/scripts/lib.sh + +PR_NUM="$(get_pr_num || echo 0)" +REFERENCE_BRANCH="$(get_reference_branch || echo "develop")" + +echo "#### Making sure git is up-to-date" +if [ -n "${REFERENCE_BRANCH}" ]; then + git fetch origin "${REFERENCE_BRANCH}" +fi + +echo "#### Enumerating Affected Tests and Projects" +find_tests +PROJECT_LIST="$(< /tmp/this_node_projects paste -s -d, -)" +if [ -z "${PROJECT_LIST}" ]; then + echo "WARNING: no projects found, skipping sonar run" + exit 0 +fi + +echo "#### Unpacking Sonar CLI" +unzip -o -q -d /tmp /tmp/sonar-scanner-cli.zip +SONAR_DIR="$(find /tmp/sonar* -type d -name sonar-scanner\*)" + +echo "#### Determining Arguments for Sonar CLI" +declare -a SONAR_ARGS=( + -Dsonar.login="$SONARCLOUD_LOGIN" + -Dsonar.host.url="https://sonarcloud.io" +) + +if [ "${PR_NUM}" -gt 0 ]; then + SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.pullrequest.key=${PR_NUM}" "-Dsonar.pullrequest.branch=${CIRCLE_BRANCH}" "-Dsonar.pullrequest.base=${REFERENCE_BRANCH}") + SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.pullrequest.provider=GitHub" "-Dsonar.pullrequest.github.repository=OpenNMS/opennms") +else + SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.branch.name=${CIRCLE_BRANCH}") + if [ -n "${REFERENCE_BRANCH}" ] && [ "${REFERENCE_BRANCH}" != "${CIRCLE_BRANCH}" ]; then + SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.newCode.referenceBranch=${REFERENCE_BRANCH}") + fi +fi + +mkdir -p /tmp/sonar-cache +export SONAR_USER_HOME=/tmp/sonar-cache +export SONAR_SCANNER_OPTS="${MAVEN_OPTS:--Xmx7g}" + +echo "#### Executing Sonar" +# shellcheck disable=SC2086 +"${SONAR_DIR}/bin/sonar-scanner" \ + "${SONAR_ARGS[@]}" \ + -Djava.security.egd=file:/dev/./urandom \ + -Dsonar.coverage.jacoco.xmlReportPaths="$(generate_jacoco_report_files | paste -s -d, -)" \ + -Dsonar.junit.reportPaths="$(generate_junit_report_folders | paste -s -d, -)" \ + -Dsonar.sources="$(generate_source_folders | paste -s -d, -)" \ + -Dsonar.tests="$(generate_test_folders | paste -s -d, -)" \ + -Dsonar.java.binaries="$(generate_class_folders | paste -s -d, -)" \ + -Dsonar.java.libraries="${HOME}/.m2/repository/**/*.jar,**/*.jar" \ + -Dsonar.java.test.binaries="$(generate_test_class_folders | paste -s -d, -)" \ + -Dsonar.java.test.libraries="${HOME}/.m2/repository/**/*.jar,**/*.jar" diff --git a/pom.xml b/pom.xml index cb7acc61..9def066b 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,8 @@ 1.1.1 4.5.13 4.4.15 + 3.7.0.1746 + 9.4.48.v20220622 @@ -415,6 +417,33 @@ + + org.sonarsource.scanner.maven + sonar-maven-plugin + ${sonarVersion} + + + org.eclipse.jetty + apache-jsp + ${jettyVersion} + + + org.mortbay.jasper + apache-el + + + org.mortbay.jasper + apache-jsp + + + + + javax.el + javax.el-api + 3.0.0 + + + From 287bc65a423dfc397ecbd6be045a1c067e2cd72d Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 15:53:14 -0500 Subject: [PATCH 02/48] enable sonar scan comment other jobs to test sonar faster ALEC-247 --- .circleci/config.yml | 506 +++++++++++++++++++++---------------------- 1 file changed, 253 insertions(+), 253 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3a611f44..be651833 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,193 +38,193 @@ orbs: sign-packages: opennms/sign-packages@2.3.0 workflows: - build-deploy: - jobs: - # Run build jobs for all branches and any tag - - pre-build: - context: "OpenNMS Build" - filters: - tags: - only: /.*/ - - build: - context: "OpenNMS Build" - requires: - - pre-build - filters: - tags: - only: /.*/ - - build-debian: - context: "OpenNMS Build" - requires: - - build - filters: - tags: - only: /.*/ - - build-docs: - context: "OpenNMS Build" - requires: - - pre-build - filters: - tags: - only: /.*/ - - smoke-test-commit: - context: "OpenNMS Build" - requires: - - build - filters: - branches: - ignore: - - develop - - /^release-.*/ - tags: - ignore: /^v.*/ - - smoke-test-full: - context: "OpenNMS Build" - requires: - - build - filters: - branches: - only: - - develop - - /^release-.*/ - tags: - only: /^v.*/ - - # Run deploy jobs on version tags, release branches and develop - - deploy-maven: - context: "OpenNMS Build" - requires: - - smoke-test-commit - - smoke-test-full - filters: - # Maven deploy requires GPG signing for releases - we do this manually - branches: - only: - - develop - - /release-.*/ - - deploy-packages: - context: "OpenNMS Build" - requires: - - smoke-test-commit - - smoke-test-full - - build-debian - filters: - tags: - only: /^v.*/ - branches: - only: - - develop - - /release-.*/ - - sonar: - context: "OpenNMS Build" - requires: - - build - filters: - tags: - only: /.*/ +# build-deploy: +# jobs: +# # Run build jobs for all branches and any tag +# - pre-build: +# context: "OpenNMS Build" +# filters: +# tags: +# only: /.*/ +# - build: +# context: "OpenNMS Build" +# requires: +# - pre-build +# filters: +# tags: +# only: /.*/ +# - build-debian: +# context: "OpenNMS Build" +# requires: +# - build +# filters: +# tags: +# only: /.*/ +# - build-docs: +# context: "OpenNMS Build" +# requires: +# - pre-build +# filters: +# tags: +# only: /.*/ +# - smoke-test-commit: +# context: "OpenNMS Build" +# requires: +# - build +# filters: +# branches: +# ignore: +# - develop +# - /^release-.*/ +# tags: +# ignore: /^v.*/ +# - smoke-test-full: +# context: "OpenNMS Build" +# requires: +# - build +# filters: +# branches: +# only: +# - develop +# - /^release-.*/ +# tags: +# only: /^v.*/ +# +# # Run deploy jobs on version tags, release branches and develop +# - deploy-maven: +# context: "OpenNMS Build" +# requires: +# - smoke-test-commit +# - smoke-test-full +# filters: +# # Maven deploy requires GPG signing for releases - we do this manually +# branches: +# only: +# - develop +# - /release-.*/ +# - deploy-packages: +# context: "OpenNMS Build" +# requires: +# - smoke-test-commit +# - smoke-test-full +# - build-debian +# filters: +# tags: +# only: /^v.*/ +# branches: +# only: +# - develop +# - /release-.*/ +# - sonar: +# context: "OpenNMS Build" +# requires: +# - build +# filters: +# tags: +# only: /.*/ commands: - smoke-test: - description: "Run the smoke tests" - parameters: - build_type: - type: string - steps: - - attach_workspace: - at: ~/ - - # Link root user's m2 repo from the cache with our user's m2 repo (the circleci user) - - run: - name: Link maven repo with cache - command: | - sudo chmod 777 /root - ln -s /root/.m2 ~/.m2 - - - restore_cache: - keys: - # attempt to use the cache from the last smoke-test run - - v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} - # use the cache built for the same root pom - - v5-dependencies-{{ checksum "pom.xml" }} - # fallback to using the latest cache if no exact match is found - - v5-dependencies- - - - restore_cache: - keys: - - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} - - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}- - - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}- - - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }} - - - run: - name: Refresh and import Docker cache - command: | - mkdir -p /tmp/docker - tagsFile="smoke-test/src/main/resources/docker_fixed_images" - source "${tagsFile}" - for dockerImg in $(awk -F '=' '/^[^#]/ {print $1}' "$tagsFile"); do - if [ -e /tmp/docker/"$dockerImg".tgz ]; then - echo "Importing ${!dockerImg} from ${!dockerImg}.tgz" - docker load --input /tmp/docker/"$dockerImg".tgz - else - echo "Cached image not found, pulling ${!dockerImg} from DockerHub" - docker pull "${!dockerImg}" - docker save -o /tmp/docker/"$dockerImg".tgz "${!dockerImg}" - fi - done - docker image ls - - - run: - name: Run the tests - command: | - mkdir $TEST_RECORDING_DIR - mvn install --projects org.opennms.alec:smoke-test --also-make -DskipTests=true - cd smoke-test - if [ "<< parameters.build_type >>" = "commit" ]; then - mvn surefire:test -Dtest=OnCommitSmokeTestSuite -DsmokeTest=true - elif [ "<< parameters.build_type >>" = "full" ]; then - mvn test -DsmokeTest=true - fi - - - run: - name: Remove old artifacts to keep workspace size down - command: .circleci/scripts/clean-dir.sh "/root/.m2/repository" - - - save_cache: - paths: - - /root/.m2 - key: v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} - - - save_cache: - paths: - - /tmp/docker - key: v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} - - - run: - name: Gather test artifacts - command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/target/failsafe-reports/.*xml" -exec cp {} ~/junit/ \; - find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; - mkdir -p ~/logs/ - cp -R smoke-test/target/logs/* ~/logs/ || true - when: always - - - store_test_results: - path: ~/junit - - - store_artifacts: - path: ~/logs - - # Unfortunately I can't reference the env variable containing the recording path here so I have to - # duplicate it - - store_artifacts: - path: /tmp/test-recordings - - # Future Improvements: - # - Store the logs from the sentinel and OpenNMS containers for the test run in addition to the junit logs - # - Mount the logs directories from the containers so we can copy the logs out easier - # - We might want to test full against the floating (latest) images for opennms and sentinel +# smoke-test: +# description: "Run the smoke tests" +# parameters: +# build_type: +# type: string +# steps: +# - attach_workspace: +# at: ~/ +# +# # Link root user's m2 repo from the cache with our user's m2 repo (the circleci user) +# - run: +# name: Link maven repo with cache +# command: | +# sudo chmod 777 /root +# ln -s /root/.m2 ~/.m2 +# +# - restore_cache: +# keys: +# # attempt to use the cache from the last smoke-test run +# - v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} +# # use the cache built for the same root pom +# - v5-dependencies-{{ checksum "pom.xml" }} +# # fallback to using the latest cache if no exact match is found +# - v5-dependencies- +# +# - restore_cache: +# keys: +# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} +# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}- +# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}- +# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }} +# +# - run: +# name: Refresh and import Docker cache +# command: | +# mkdir -p /tmp/docker +# tagsFile="smoke-test/src/main/resources/docker_fixed_images" +# source "${tagsFile}" +# for dockerImg in $(awk -F '=' '/^[^#]/ {print $1}' "$tagsFile"); do +# if [ -e /tmp/docker/"$dockerImg".tgz ]; then +# echo "Importing ${!dockerImg} from ${!dockerImg}.tgz" +# docker load --input /tmp/docker/"$dockerImg".tgz +# else +# echo "Cached image not found, pulling ${!dockerImg} from DockerHub" +# docker pull "${!dockerImg}" +# docker save -o /tmp/docker/"$dockerImg".tgz "${!dockerImg}" +# fi +# done +# docker image ls +# +# - run: +# name: Run the tests +# command: | +# mkdir $TEST_RECORDING_DIR +# mvn install --projects org.opennms.alec:smoke-test --also-make -DskipTests=true +# cd smoke-test +# if [ "<< parameters.build_type >>" = "commit" ]; then +# mvn surefire:test -Dtest=OnCommitSmokeTestSuite -DsmokeTest=true +# elif [ "<< parameters.build_type >>" = "full" ]; then +# mvn test -DsmokeTest=true +# fi +# +# - run: +# name: Remove old artifacts to keep workspace size down +# command: .circleci/scripts/clean-dir.sh "/root/.m2/repository" +# +# - save_cache: +# paths: +# - /root/.m2 +# key: v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} +# +# - save_cache: +# paths: +# - /tmp/docker +# key: v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} +# +# - run: +# name: Gather test artifacts +# command: | +# mkdir -p ~/junit/ +# find . -type f -regex ".*/target/failsafe-reports/.*xml" -exec cp {} ~/junit/ \; +# find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; +# mkdir -p ~/logs/ +# cp -R smoke-test/target/logs/* ~/logs/ || true +# when: always +# +# - store_test_results: +# path: ~/junit +# +# - store_artifacts: +# path: ~/logs +# +# # Unfortunately I can't reference the env variable containing the recording path here so I have to +# # duplicate it +# - store_artifacts: +# path: /tmp/test-recordings +# +# # Future Improvements: +# # - Store the logs from the sentinel and OpenNMS containers for the test run in addition to the junit logs +# # - Mount the logs directories from the containers so we can copy the logs out easier +# # - We might want to test full against the floating (latest) images for opennms and sentinel jobs: pre-build: @@ -364,74 +364,74 @@ jobs: paths: - project/assembly/ - smoke-test-commit: - executor: smoke-test-executor - - steps: - - smoke-test: - build_type: commit - - smoke-test-full: - executor: smoke-test-executor - - steps: - - smoke-test: - build_type: full - - build-docs: - executor: docs-executor - steps: - - attach_workspace: - at: ~/ - - run: - name: Validate Xrefs in docs - command: | - NODE_PATH="$(npm -g root)" antora --generator @antora/xref-validator site.yml - - run: - name: Build docs with Antora - command: | - NODE_PATH="$(npm -g root)" antora --stacktrace generate site.yml - - - store_artifacts: - path: build/site.zip - destination: site.zip - - - persist_to_workspace: - root: ~/ - paths: - - project/public - - project/build - - deploy-maven: - executor: build-executor - steps: - - attach_workspace: - at: ~/ - # Download and cache dependencies - - restore_cache: - keys: - - v5-dependencies-{{ checksum "pom.xml" }} - # fallback to using the latest cache if no exact match is found - - v5-dependencies- - - - run: - name: Deploy the artifacts - command: | - mvn -s .circleci.settings.xml -DskipTests deploy - - deploy-packages: - executor: cloudsmith/default - resource_class: small - steps: - - attach_workspace: - at: ~/ - - - cloudsmith/ensure-api-key - - cloudsmith/install-cli - - - run: - name: Push packages to CloudSmith - command: .circleci/scripts/publish-cloudsmith.sh +# smoke-test-commit: +# executor: smoke-test-executor +# +# steps: +# - smoke-test: +# build_type: commit + +# smoke-test-full: +# executor: smoke-test-executor +# +# steps: +# - smoke-test: +# build_type: full +# +# build-docs: +# executor: docs-executor +# steps: +# - attach_workspace: +# at: ~/ +# - run: +# name: Validate Xrefs in docs +# command: | +# NODE_PATH="$(npm -g root)" antora --generator @antora/xref-validator site.yml +# - run: +# name: Build docs with Antora +# command: | +# NODE_PATH="$(npm -g root)" antora --stacktrace generate site.yml +# +# - store_artifacts: +# path: build/site.zip +# destination: site.zip +# +# - persist_to_workspace: +# root: ~/ +# paths: +# - project/public +# - project/build +# +# deploy-maven: +# executor: build-executor +# steps: +# - attach_workspace: +# at: ~/ +# # Download and cache dependencies +# - restore_cache: +# keys: +# - v5-dependencies-{{ checksum "pom.xml" }} +# # fallback to using the latest cache if no exact match is found +# - v5-dependencies- +# +# - run: +# name: Deploy the artifacts +# command: | +# mvn -s .circleci.settings.xml -DskipTests deploy +# +# deploy-packages: +# executor: cloudsmith/default +# resource_class: small +# steps: +# - attach_workspace: +# at: ~/ +# +# - cloudsmith/ensure-api-key +# - cloudsmith/install-cli +# +# - run: +# name: Push packages to CloudSmith +# command: .circleci/scripts/publish-cloudsmith.sh sonar: executor: build-executor From 53bdadc4ae104af195f4b29124b28e56635c2f85 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 15:58:23 -0500 Subject: [PATCH 03/48] enable sonar scan comment other jobs to test sonar faster ALEC-247 --- .circleci/config.yml | 385 +++++++++++++++++++++---------------------- 1 file changed, 192 insertions(+), 193 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index be651833..e390f216 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,21 +38,21 @@ orbs: sign-packages: opennms/sign-packages@2.3.0 workflows: -# build-deploy: -# jobs: -# # Run build jobs for all branches and any tag -# - pre-build: -# context: "OpenNMS Build" -# filters: -# tags: -# only: /.*/ -# - build: -# context: "OpenNMS Build" -# requires: -# - pre-build -# filters: -# tags: -# only: /.*/ + build-deploy: + jobs: + # Run build jobs for all branches and any tag + - pre-build: + context: "OpenNMS Build" + filters: + tags: + only: /.*/ + - build: + context: "OpenNMS Build" + requires: + - pre-build + filters: + tags: + only: /.*/ # - build-debian: # context: "OpenNMS Build" # requires: @@ -89,8 +89,7 @@ workflows: # - /^release-.*/ # tags: # only: /^v.*/ -# -# # Run deploy jobs on version tags, release branches and develop + # Run deploy jobs on version tags, release branches and develop # - deploy-maven: # context: "OpenNMS Build" # requires: @@ -115,116 +114,116 @@ workflows: # only: # - develop # - /release-.*/ -# - sonar: -# context: "OpenNMS Build" -# requires: -# - build -# filters: -# tags: -# only: /.*/ + - sonar: + context: "OpenNMS Build" + requires: + - build + filters: + tags: + only: /.*/ commands: -# smoke-test: -# description: "Run the smoke tests" -# parameters: -# build_type: -# type: string -# steps: -# - attach_workspace: -# at: ~/ -# -# # Link root user's m2 repo from the cache with our user's m2 repo (the circleci user) -# - run: -# name: Link maven repo with cache -# command: | -# sudo chmod 777 /root -# ln -s /root/.m2 ~/.m2 -# -# - restore_cache: -# keys: -# # attempt to use the cache from the last smoke-test run -# - v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} -# # use the cache built for the same root pom -# - v5-dependencies-{{ checksum "pom.xml" }} -# # fallback to using the latest cache if no exact match is found -# - v5-dependencies- -# -# - restore_cache: -# keys: -# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} -# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}- -# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}- -# - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }} -# -# - run: -# name: Refresh and import Docker cache -# command: | -# mkdir -p /tmp/docker -# tagsFile="smoke-test/src/main/resources/docker_fixed_images" -# source "${tagsFile}" -# for dockerImg in $(awk -F '=' '/^[^#]/ {print $1}' "$tagsFile"); do -# if [ -e /tmp/docker/"$dockerImg".tgz ]; then -# echo "Importing ${!dockerImg} from ${!dockerImg}.tgz" -# docker load --input /tmp/docker/"$dockerImg".tgz -# else -# echo "Cached image not found, pulling ${!dockerImg} from DockerHub" -# docker pull "${!dockerImg}" -# docker save -o /tmp/docker/"$dockerImg".tgz "${!dockerImg}" -# fi -# done -# docker image ls -# -# - run: -# name: Run the tests -# command: | -# mkdir $TEST_RECORDING_DIR -# mvn install --projects org.opennms.alec:smoke-test --also-make -DskipTests=true -# cd smoke-test -# if [ "<< parameters.build_type >>" = "commit" ]; then -# mvn surefire:test -Dtest=OnCommitSmokeTestSuite -DsmokeTest=true -# elif [ "<< parameters.build_type >>" = "full" ]; then -# mvn test -DsmokeTest=true -# fi -# -# - run: -# name: Remove old artifacts to keep workspace size down -# command: .circleci/scripts/clean-dir.sh "/root/.m2/repository" -# -# - save_cache: -# paths: -# - /root/.m2 -# key: v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} -# -# - save_cache: -# paths: -# - /tmp/docker -# key: v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} -# -# - run: -# name: Gather test artifacts -# command: | -# mkdir -p ~/junit/ -# find . -type f -regex ".*/target/failsafe-reports/.*xml" -exec cp {} ~/junit/ \; -# find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; -# mkdir -p ~/logs/ -# cp -R smoke-test/target/logs/* ~/logs/ || true -# when: always -# -# - store_test_results: -# path: ~/junit -# -# - store_artifacts: -# path: ~/logs -# -# # Unfortunately I can't reference the env variable containing the recording path here so I have to -# # duplicate it -# - store_artifacts: -# path: /tmp/test-recordings -# -# # Future Improvements: -# # - Store the logs from the sentinel and OpenNMS containers for the test run in addition to the junit logs -# # - Mount the logs directories from the containers so we can copy the logs out easier -# # - We might want to test full against the floating (latest) images for opennms and sentinel + smoke-test: + description: "Run the smoke tests" + parameters: + build_type: + type: string + steps: + - attach_workspace: + at: ~/ + + # Link root user's m2 repo from the cache with our user's m2 repo (the circleci user) + - run: + name: Link maven repo with cache + command: | + sudo chmod 777 /root + ln -s /root/.m2 ~/.m2 + + - restore_cache: + keys: + # attempt to use the cache from the last smoke-test run + - v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} + # use the cache built for the same root pom + - v5-dependencies-{{ checksum "pom.xml" }} + # fallback to using the latest cache if no exact match is found + - v5-dependencies- + + - restore_cache: + keys: + - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} + - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}- + - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}- + - v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }} + + - run: + name: Refresh and import Docker cache + command: | + mkdir -p /tmp/docker + tagsFile="smoke-test/src/main/resources/docker_fixed_images" + source "${tagsFile}" + for dockerImg in $(awk -F '=' '/^[^#]/ {print $1}' "$tagsFile"); do + if [ -e /tmp/docker/"$dockerImg".tgz ]; then + echo "Importing ${!dockerImg} from ${!dockerImg}.tgz" + docker load --input /tmp/docker/"$dockerImg".tgz + else + echo "Cached image not found, pulling ${!dockerImg} from DockerHub" + docker pull "${!dockerImg}" + docker save -o /tmp/docker/"$dockerImg".tgz "${!dockerImg}" + fi + done + docker image ls + + - run: + name: Run the tests + command: | + mkdir $TEST_RECORDING_DIR + mvn install --projects org.opennms.alec:smoke-test --also-make -DskipTests=true + cd smoke-test + if [ "<< parameters.build_type >>" = "commit" ]; then + mvn surefire:test -Dtest=OnCommitSmokeTestSuite -DsmokeTest=true + elif [ "<< parameters.build_type >>" = "full" ]; then + mvn test -DsmokeTest=true + fi + + - run: + name: Remove old artifacts to keep workspace size down + command: .circleci/scripts/clean-dir.sh "/root/.m2/repository" + + - save_cache: + paths: + - /root/.m2 + key: v2-smoke-dependencies-{{ checksum "smoke-test/pom.xml" }}-{{ checksum "pom.xml" }} + + - save_cache: + paths: + - /tmp/docker + key: v2-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}-{{ .Branch }}-{{ .Revision }} + + - run: + name: Gather test artifacts + command: | + mkdir -p ~/junit/ + find . -type f -regex ".*/target/failsafe-reports/.*xml" -exec cp {} ~/junit/ \; + find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; + mkdir -p ~/logs/ + cp -R smoke-test/target/logs/* ~/logs/ || true + when: always + + - store_test_results: + path: ~/junit + + - store_artifacts: + path: ~/logs + + # Unfortunately I can't reference the env variable containing the recording path here so I have to + # duplicate it + - store_artifacts: + path: /tmp/test-recordings + + # Future Improvements: + # - Store the logs from the sentinel and OpenNMS containers for the test run in addition to the junit logs + # - Mount the logs directories from the containers so we can copy the logs out easier + # - We might want to test full against the floating (latest) images for opennms and sentinel jobs: pre-build: @@ -364,74 +363,74 @@ jobs: paths: - project/assembly/ -# smoke-test-commit: -# executor: smoke-test-executor -# -# steps: -# - smoke-test: -# build_type: commit - -# smoke-test-full: -# executor: smoke-test-executor -# -# steps: -# - smoke-test: -# build_type: full -# -# build-docs: -# executor: docs-executor -# steps: -# - attach_workspace: -# at: ~/ -# - run: -# name: Validate Xrefs in docs -# command: | -# NODE_PATH="$(npm -g root)" antora --generator @antora/xref-validator site.yml -# - run: -# name: Build docs with Antora -# command: | -# NODE_PATH="$(npm -g root)" antora --stacktrace generate site.yml -# -# - store_artifacts: -# path: build/site.zip -# destination: site.zip -# -# - persist_to_workspace: -# root: ~/ -# paths: -# - project/public -# - project/build -# -# deploy-maven: -# executor: build-executor -# steps: -# - attach_workspace: -# at: ~/ -# # Download and cache dependencies -# - restore_cache: -# keys: -# - v5-dependencies-{{ checksum "pom.xml" }} -# # fallback to using the latest cache if no exact match is found -# - v5-dependencies- -# -# - run: -# name: Deploy the artifacts -# command: | -# mvn -s .circleci.settings.xml -DskipTests deploy -# -# deploy-packages: -# executor: cloudsmith/default -# resource_class: small -# steps: -# - attach_workspace: -# at: ~/ -# -# - cloudsmith/ensure-api-key -# - cloudsmith/install-cli -# -# - run: -# name: Push packages to CloudSmith -# command: .circleci/scripts/publish-cloudsmith.sh + smoke-test-commit: + executor: smoke-test-executor + + steps: + - smoke-test: + build_type: commit + + smoke-test-full: + executor: smoke-test-executor + + steps: + - smoke-test: + build_type: full + + build-docs: + executor: docs-executor + steps: + - attach_workspace: + at: ~/ + - run: + name: Validate Xrefs in docs + command: | + NODE_PATH="$(npm -g root)" antora --generator @antora/xref-validator site.yml + - run: + name: Build docs with Antora + command: | + NODE_PATH="$(npm -g root)" antora --stacktrace generate site.yml + + - store_artifacts: + path: build/site.zip + destination: site.zip + + - persist_to_workspace: + root: ~/ + paths: + - project/public + - project/build + + deploy-maven: + executor: build-executor + steps: + - attach_workspace: + at: ~/ + # Download and cache dependencies + - restore_cache: + keys: + - v5-dependencies-{{ checksum "pom.xml" }} + # fallback to using the latest cache if no exact match is found + - v5-dependencies- + + - run: + name: Deploy the artifacts + command: | + mvn -s .circleci.settings.xml -DskipTests deploy + + deploy-packages: + executor: cloudsmith/default + resource_class: small + steps: + - attach_workspace: + at: ~/ + + - cloudsmith/ensure-api-key + - cloudsmith/install-cli + + - run: + name: Push packages to CloudSmith + command: .circleci/scripts/publish-cloudsmith.sh sonar: executor: build-executor From 1e3ec2496edefcf81fe6e21b4673de212fac0361 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 16:14:28 -0500 Subject: [PATCH 04/48] enable sonar scan comment other jobs to test sonar faster ALEC-247 --- .circleci/config.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e390f216..d6e05360 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,13 +46,13 @@ workflows: filters: tags: only: /.*/ - - build: - context: "OpenNMS Build" - requires: - - pre-build - filters: - tags: - only: /.*/ +# - build: +# context: "OpenNMS Build" +# requires: +# - pre-build +# filters: +# tags: +# only: /.*/ # - build-debian: # context: "OpenNMS Build" # requires: From dc2e126273f21daa932a069b155ff94c836523db Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 16:15:35 -0500 Subject: [PATCH 05/48] enable sonar scan comment other jobs to test sonar faster ALEC-247 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d6e05360..96ca2f29 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: - sonar: context: "OpenNMS Build" requires: - - build + - pre-build filters: tags: only: /.*/ From 3fabbbb52b6fe67da7d6696be27848da7d1dc75a Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 16:21:19 -0500 Subject: [PATCH 06/48] enable sonar scan comment other jobs to test sonar faster ALEC-247 --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 96ca2f29..bc0738b9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -439,5 +439,4 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - export MAVEN_OPTS="-Xmx12g -XX:ReservedCodeCacheSize=1g -XX:+TieredCompilation" - .circleci/scripts/sonar.sh + mvn sonar:sonar From 2fde86ec1b5638542e07c857a575323c67ee8705 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 17:05:48 -0500 Subject: [PATCH 07/48] enable sonar scan comment other jobs to test sonar faster ALEC-247 --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index bc0738b9..218c1318 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -435,6 +435,8 @@ jobs: sonar: executor: build-executor steps: + - attach_workspace: + at: ~/ - run: name: Run SonarQube Code Analysis when: always From 162cf13b768ba3e772aefbf30adde7254014ae35 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Thu, 24 Nov 2022 18:39:04 -0500 Subject: [PATCH 08/48] enable sonar scan add profile sonar ALEC-247 --- .circleci/config.yml | 2 +- pom.xml | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 218c1318..fe38bb39 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -441,4 +441,4 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn sonar:sonar + mvn sonar:sonar -P sonar diff --git a/pom.xml b/pom.xml index 9def066b..def8ce37 100644 --- a/pom.xml +++ b/pom.xml @@ -623,5 +623,17 @@ -Xdoclint:none + + sonar + + false + + + https://sonarcloud.io + 403e578d6e712376ec4f03c50303b209be3f2814 + opennms + OpenNMS_alec + + From 08049748aeefa8501869d5720060833b92fd65bc Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 14:02:20 -0500 Subject: [PATCH 09/48] set sonar.module to allow multi module scan --- .circleci/config.yml | 2 +- pom.xml | 24 +----------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fe38bb39..70646a9e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -441,4 +441,4 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn sonar:sonar -P sonar + mvn sonar:sonar -P sonar -Dsonar.projectKey=opennms diff --git a/pom.xml b/pom.xml index def8ce37..a0cd1764 100644 --- a/pom.xml +++ b/pom.xml @@ -421,28 +421,6 @@ org.sonarsource.scanner.maven sonar-maven-plugin ${sonarVersion} - - - org.eclipse.jetty - apache-jsp - ${jettyVersion} - - - org.mortbay.jasper - apache-el - - - org.mortbay.jasper - apache-jsp - - - - - javax.el - javax.el-api - 3.0.0 - - @@ -632,7 +610,7 @@ https://sonarcloud.io 403e578d6e712376ec4f03c50303b209be3f2814 opennms - OpenNMS_alec + ${artifactId} From 4475aa35f8cdb130496064c524de2a7367af2a64 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 14:35:06 -0500 Subject: [PATCH 10/48] Revert "comment other jobs to test sonar faster" This reverts commit 287bc65a --- .circleci/config.yml | 137 ++++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 70646a9e..22c370b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,78 +46,79 @@ workflows: filters: tags: only: /.*/ -# - build: -# context: "OpenNMS Build" -# requires: -# - pre-build -# filters: -# tags: -# only: /.*/ -# - build-debian: -# context: "OpenNMS Build" -# requires: -# - build -# filters: -# tags: -# only: /.*/ -# - build-docs: -# context: "OpenNMS Build" -# requires: -# - pre-build -# filters: -# tags: -# only: /.*/ -# - smoke-test-commit: -# context: "OpenNMS Build" -# requires: -# - build -# filters: -# branches: -# ignore: -# - develop -# - /^release-.*/ -# tags: -# ignore: /^v.*/ -# - smoke-test-full: -# context: "OpenNMS Build" -# requires: -# - build -# filters: -# branches: -# only: -# - develop -# - /^release-.*/ -# tags: -# only: /^v.*/ + - build: + context: "OpenNMS Build" + requires: + - pre-build + filters: + tags: + only: /.*/ + - build-debian: + context: "OpenNMS Build" + requires: + - build + filters: + tags: + only: /.*/ + - build-docs: + context: "OpenNMS Build" + requires: + - pre-build + filters: + tags: + only: /.*/ + - smoke-test-commit: + context: "OpenNMS Build" + requires: + - build + filters: + branches: + ignore: + - develop + - /^release-.*/ + tags: + ignore: /^v.*/ + - smoke-test-full: + context: "OpenNMS Build" + requires: + - build + filters: + branches: + only: + - develop + - /^release-.*/ + tags: + only: /^v.*/ + # Run deploy jobs on version tags, release branches and develop -# - deploy-maven: -# context: "OpenNMS Build" -# requires: -# - smoke-test-commit -# - smoke-test-full -# filters: -# # Maven deploy requires GPG signing for releases - we do this manually -# branches: -# only: -# - develop -# - /release-.*/ -# - deploy-packages: -# context: "OpenNMS Build" -# requires: -# - smoke-test-commit -# - smoke-test-full -# - build-debian -# filters: -# tags: -# only: /^v.*/ -# branches: -# only: -# - develop -# - /release-.*/ + - deploy-maven: + context: "OpenNMS Build" + requires: + - smoke-test-commit + - smoke-test-full + filters: + # Maven deploy requires GPG signing for releases - we do this manually + branches: + only: + - develop + - /release-.*/ + - deploy-packages: + context: "OpenNMS Build" + requires: + - smoke-test-commit + - smoke-test-full + - build-debian + filters: + tags: + only: /^v.*/ + branches: + only: + - develop + - /release-.*/ - sonar: context: "OpenNMS Build" requires: - - pre-build + - build filters: tags: only: /.*/ From 980168e243df9dc34646f8160ea7f506abe612e1 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 15:06:54 -0500 Subject: [PATCH 11/48] compile and sonar scan same command line add projectKey into the parent pom --- .circleci/config.yml | 19 +++++++++++-------- pom.xml | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 22c370b5..34470295 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,6 +53,7 @@ workflows: filters: tags: only: /.*/ + - build-debian: context: "OpenNMS Build" requires: @@ -60,6 +61,13 @@ workflows: filters: tags: only: /.*/ + - sonar: + context: "OpenNMS Build" + requires: + - build + filters: + tags: + only: /.*/ - build-docs: context: "OpenNMS Build" requires: @@ -115,13 +123,7 @@ workflows: only: - develop - /release-.*/ - - sonar: - context: "OpenNMS Build" - requires: - - build - filters: - tags: - only: /.*/ + commands: smoke-test: @@ -442,4 +444,5 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn sonar:sonar -P sonar -Dsonar.projectKey=opennms + mvn -Psonar verify \ + org.sonarsource.scanner.maven:sonar-maven-plugin:sonar diff --git a/pom.xml b/pom.xml index a0cd1764..c0cfaa54 100644 --- a/pom.xml +++ b/pom.xml @@ -611,6 +611,7 @@ 403e578d6e712376ec4f03c50303b209be3f2814 opennms ${artifactId} + opennms From 62767bd8f6720561f5cb4e92da8d0a83c51e3916 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 15:14:11 -0500 Subject: [PATCH 12/48] comment --- .circleci/config.yml | 136 +++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 34470295..08902296 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,83 +46,83 @@ workflows: filters: tags: only: /.*/ - - build: - context: "OpenNMS Build" - requires: - - pre-build - filters: - tags: - only: /.*/ - - - build-debian: - context: "OpenNMS Build" - requires: - - build - filters: - tags: - only: /.*/ +# - build: +# context: "OpenNMS Build" +# requires: +# - pre-build +# filters: +# tags: +# only: /.*/ + +# - build-debian: +# context: "OpenNMS Build" +# requires: +# - build +# filters: +# tags: +# only: /.*/ - sonar: - context: "OpenNMS Build" - requires: - - build - filters: - tags: - only: /.*/ - - build-docs: context: "OpenNMS Build" requires: - pre-build filters: tags: only: /.*/ - - smoke-test-commit: - context: "OpenNMS Build" - requires: - - build - filters: - branches: - ignore: - - develop - - /^release-.*/ - tags: - ignore: /^v.*/ - - smoke-test-full: - context: "OpenNMS Build" - requires: - - build - filters: - branches: - only: - - develop - - /^release-.*/ - tags: - only: /^v.*/ +# - build-docs: +# context: "OpenNMS Build" +# requires: +# - pre-build +# filters: +# tags: +# only: /.*/ +# - smoke-test-commit: +# context: "OpenNMS Build" +# requires: +# - build +# filters: +# branches: +# ignore: +# - develop +# - /^release-.*/ +# tags: +# ignore: /^v.*/ +# - smoke-test-full: +# context: "OpenNMS Build" +# requires: +# - build +# filters: +# branches: +# only: +# - develop +# - /^release-.*/ +# tags: +# only: /^v.*/ # Run deploy jobs on version tags, release branches and develop - - deploy-maven: - context: "OpenNMS Build" - requires: - - smoke-test-commit - - smoke-test-full - filters: - # Maven deploy requires GPG signing for releases - we do this manually - branches: - only: - - develop - - /release-.*/ - - deploy-packages: - context: "OpenNMS Build" - requires: - - smoke-test-commit - - smoke-test-full - - build-debian - filters: - tags: - only: /^v.*/ - branches: - only: - - develop - - /release-.*/ +# - deploy-maven: +# context: "OpenNMS Build" +# requires: +# - smoke-test-commit +# - smoke-test-full +# filters: +# # Maven deploy requires GPG signing for releases - we do this manually +# branches: +# only: +# - develop +# - /release-.*/ +# - deploy-packages: +# context: "OpenNMS Build" +# requires: +# - smoke-test-commit +# - smoke-test-full +# - build-debian +# filters: +# tags: +# only: /^v.*/ +# branches: +# only: +# - develop +# - /release-.*/ commands: From aa846160d4023d413ef90cb8bd64b5d88fe57b8c Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 15:19:41 -0500 Subject: [PATCH 13/48] fix yaml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 08902296..835fb62c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -444,5 +444,5 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn -Psonar verify \ + mvn -Psonar verify \ org.sonarsource.scanner.maven:sonar-maven-plugin:sonar From 33a7a5e32ac83771393d695324cc7f8ca9d4d627 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 15:24:51 -0500 Subject: [PATCH 14/48] remove sonar token login --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index c0cfaa54..2570a672 100644 --- a/pom.xml +++ b/pom.xml @@ -608,7 +608,6 @@ https://sonarcloud.io - 403e578d6e712376ec4f03c50303b209be3f2814 opennms ${artifactId} opennms From 08f7353a4dd2bc60bad355d5f24fc37855db2331 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 16:06:21 -0500 Subject: [PATCH 15/48] re enable build step --- .circleci/config.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 835fb62c..22be94d8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,13 +46,13 @@ workflows: filters: tags: only: /.*/ -# - build: -# context: "OpenNMS Build" -# requires: -# - pre-build -# filters: -# tags: -# only: /.*/ + - build: + context: "OpenNMS Build" + requires: + - pre-build + filters: + tags: + only: /.*/ # - build-debian: # context: "OpenNMS Build" @@ -64,7 +64,7 @@ workflows: - sonar: context: "OpenNMS Build" requires: - - pre-build + - build filters: tags: only: /.*/ From 673830e62a5b39e25565847c5eab03931c5706a8 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 16:08:29 -0500 Subject: [PATCH 16/48] add dependencu with sonar mvn command --- .circleci/config.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 22be94d8..cc986302 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,13 +46,13 @@ workflows: filters: tags: only: /.*/ - - build: - context: "OpenNMS Build" - requires: - - pre-build - filters: - tags: - only: /.*/ +# - build: +# context: "OpenNMS Build" +# requires: +# - pre-build +# filters: +# tags: +# only: /.*/ # - build-debian: # context: "OpenNMS Build" @@ -444,5 +444,5 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn -Psonar verify \ + mvn -Psonar -Dbuild.packages clean install dependency:resolve-plugins dependency:go-offline \ org.sonarsource.scanner.maven:sonar-maven-plugin:sonar From 87554c4455fb653795a12117d8e8cc58cc43f73b Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 16:08:58 -0500 Subject: [PATCH 17/48] add dependencu with sonar mvn command --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cc986302..40776577 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ workflows: - sonar: context: "OpenNMS Build" requires: - - build + - pre-build filters: tags: only: /.*/ From ee9e02c2187e4783859b97e5772aa7de63ab707f Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 16:12:30 -0500 Subject: [PATCH 18/48] skip test for sonar --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 40776577..16432aaa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -444,5 +444,5 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn -Psonar -Dbuild.packages clean install dependency:resolve-plugins dependency:go-offline \ + mvn -Psonar -DskipTests -Dbuild.packages clean install dependency:resolve-plugins dependency:go-offline \ org.sonarsource.scanner.maven:sonar-maven-plugin:sonar From 9e0576f72b6d1109dc9b40cd31a73c15be750aaf Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 16:22:51 -0500 Subject: [PATCH 19/48] update projectkey --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2570a672..704a321e 100644 --- a/pom.xml +++ b/pom.xml @@ -609,8 +609,8 @@ https://sonarcloud.io opennms - ${artifactId} - opennms + ${project.artifactId} + OpenNMS_alec From 77ba56a07ec0b56a72902accaac1ae47dc8fa2c6 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 17:40:31 -0500 Subject: [PATCH 20/48] use sonar.login --- .circleci/config.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 16432aaa..3b4c2f66 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -445,4 +445,4 @@ jobs: when: always command: | mvn -Psonar -DskipTests -Dbuild.packages clean install dependency:resolve-plugins dependency:go-offline \ - org.sonarsource.scanner.maven:sonar-maven-plugin:sonar + org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.login="SONAR_TOKEN" diff --git a/pom.xml b/pom.xml index 704a321e..5afa54af 100644 --- a/pom.xml +++ b/pom.xml @@ -609,8 +609,8 @@ https://sonarcloud.io opennms - ${project.artifactId} OpenNMS_alec + ${project.artifactId} From b72ea465fcea951776a4bbcf631a174b4c13bc7c Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 18:04:46 -0500 Subject: [PATCH 21/48] use sonar.login --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b4c2f66..1e72ba00 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -445,4 +445,4 @@ jobs: when: always command: | mvn -Psonar -DskipTests -Dbuild.packages clean install dependency:resolve-plugins dependency:go-offline \ - org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.login="SONAR_TOKEN" + org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.login="$SONAR_TOKEN" From 55f5469d8640089537d4054607e05e1687db534d Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 18:27:06 -0500 Subject: [PATCH 22/48] test sonar.sh from opennms project --- .circleci/config.yml | 4 ++-- sonar-project.properties | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 sonar-project.properties diff --git a/.circleci/config.yml b/.circleci/config.yml index 1e72ba00..2e94d5c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -444,5 +444,5 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn -Psonar -DskipTests -Dbuild.packages clean install dependency:resolve-plugins dependency:go-offline \ - org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.login="$SONAR_TOKEN" + export MAVEN_OPTS="-Xmx12g -XX:ReservedCodeCacheSize=1g -XX:+TieredCompilation" + .circleci/scripts/sonar.sh diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..629282f5 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.organization=opennms +sonar.projectKey=OpenNMS_alec +sonar.java.source=11 +sonar.sourceEncoding=UTF-8 + +# skip c/++/objc, they don't process properly ATM +sonar.c.file.suffixes=- +sonar.cpp.file.suffixes=- +sonar.objc.file.suffixes=- + +# skip 3rd-party javascript +#sonar.exclusions=core/web-assets/src/main/assets/static/legacy/**/* From e6d71630477a8b895ce7e03cf2fd204381a2c82c Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 18:29:58 -0500 Subject: [PATCH 23/48] test sonar.sh from opennms project --- .circleci/scripts/sonar.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/scripts/sonar.sh b/.circleci/scripts/sonar.sh index 2a898a3f..5aa7243e 100755 --- a/.circleci/scripts/sonar.sh +++ b/.circleci/scripts/sonar.sh @@ -78,7 +78,7 @@ find_tests() } # shellcheck disable=SC1091 -. ./.circleci/scripts/lib.sh +#. ./.circleci/scripts/lib.sh PR_NUM="$(get_pr_num || echo 0)" REFERENCE_BRANCH="$(get_reference_branch || echo "develop")" From 4a393f87c0781c61f875f635a33e07d29e7227e3 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 18:33:11 -0500 Subject: [PATCH 24/48] test sonar.sh from opennms project --- .circleci/scripts/lib.sh | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .circleci/scripts/lib.sh diff --git a/.circleci/scripts/lib.sh b/.circleci/scripts/lib.sh new file mode 100644 index 00000000..f0161c8b --- /dev/null +++ b/.circleci/scripts/lib.sh @@ -0,0 +1,49 @@ +# get the PR number from CircleCI environment; caches on success +__cache_pr_num="" +get_pr_num() { + if [ -z "${__cache_pr_num}" ]; then + local _pr_num=0 + if [ -n "${CIRCLE_PULL_REQUEST}" ]; then + _pr_num="$(echo "${CIRCLE_PULL_REQUEST}" | sed -e 's,.*/,,')" + if [ -n "${_pr_num}" ] && [ "${_pr_num}" -gt 0 ]; then + __cache_pr_num="${_pr_num}" + fi + fi + __cache_pr_num=0 + fi + if [ ! "${__cache_pr_num}" -gt 0 ]; then + return 1 + fi + echo "${__cache_pr_num}" +} + +# get the "reference" (merge/pr-parent) branch for this branch; caches on success +__cache_reference_branch="" +get_reference_branch() { + if [ -z "${__cache_reference_branch}" ]; then + local _parent_branch="" + + local _pr_num="$(get_pr_num || echo 0)" + + if [ "${_pr_num}" -gt 0 ] && [ -n "${GITHUB_API_TOKEN}" ]; then + local _github_base="$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_API_TOKEN}" "https://api.github.com/repos/OpenNMS/opennms/pulls/${_pr_num}" | jq -r '.base.ref')" + if [ -n "${_github_base}" ]; then + __cache_reference_branch="${_github_base}" + fi + fi + + if [ -z "${__cache_reference_branch}" ] && [ -e .nightly ]; then + _parent_branch="$(cat .nightly | grep -E '^parent_branch:' | sed -e 's,parent_branch: *,,')" + if [ -n "${_parent_branch}" ]; then + __cache_reference_branch="${_parent_branch}" + fi + fi + fi + + if [ -n "${__cache_reference_branch}" ]; then + echo "${__cache_reference_branch}" + return 0 + fi + + return 1 +} \ No newline at end of file From 5e581a68a24925829a2799a835a31be800f05620 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Mon, 28 Nov 2022 18:37:19 -0500 Subject: [PATCH 25/48] test sonar.sh from opennms project --- .circleci/scripts/sonar.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/scripts/sonar.sh b/.circleci/scripts/sonar.sh index 5aa7243e..2a898a3f 100755 --- a/.circleci/scripts/sonar.sh +++ b/.circleci/scripts/sonar.sh @@ -78,7 +78,7 @@ find_tests() } # shellcheck disable=SC1091 -#. ./.circleci/scripts/lib.sh +. ./.circleci/scripts/lib.sh PR_NUM="$(get_pr_num || echo 0)" REFERENCE_BRANCH="$(get_reference_branch || echo "develop")" From 1aa4f60bfea598011e774050ae02c02271ee02bd Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 09:17:24 -0500 Subject: [PATCH 26/48] test sonar without profile --- .circleci/config.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2e94d5c2..72613a6f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -444,5 +444,8 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - export MAVEN_OPTS="-Xmx12g -XX:ReservedCodeCacheSize=1g -XX:+TieredCompilation" - .circleci/scripts/sonar.sh + mvn -DskipTests -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ + sonar:sonar -Dsonar.login="$SONAR_TOKEN" \ + -Dsonar.host.url=https://sonarcloud.io \ + -Dsonar.organization=opennms \ + -Dsonar.projectKey=OpenNMS_alec From 4c538a02af30d7a6066e12c2659c5051704aed74 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 09:40:00 -0500 Subject: [PATCH 27/48] test sonar with SONARCLOUD_LOGIN --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 72613a6f..1cba3032 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -445,7 +445,7 @@ jobs: when: always command: | mvn -DskipTests -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ - sonar:sonar -Dsonar.login="$SONAR_TOKEN" \ + sonar:sonar -Dsonar.login="$SONARCLOUD_LOGIN" \ -Dsonar.host.url=https://sonarcloud.io \ -Dsonar.organization=opennms \ -Dsonar.projectKey=OpenNMS_alec From d5cebbfbf928f8cc408d9152511f687dec8c2bbf Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 09:52:11 -0500 Subject: [PATCH 28/48] test sonar with SONARCLOUD_LOGIN --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1cba3032..0de724a4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -444,8 +444,7 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn -DskipTests -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ - sonar:sonar -Dsonar.login="$SONARCLOUD_LOGIN" \ + mvn sonar:sonar -Dsonar.login=$SONARCLOUD_LOGIN \ -Dsonar.host.url=https://sonarcloud.io \ -Dsonar.organization=opennms \ -Dsonar.projectKey=OpenNMS_alec From 39e4400f1ed37ce2f36d7fd047ec3601aac64c43 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 09:55:59 -0500 Subject: [PATCH 29/48] test sonar with SONARCLOUD_LOGIN --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0de724a4..a2c9be0f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -444,7 +444,8 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn sonar:sonar -Dsonar.login=$SONARCLOUD_LOGIN \ + mvn -DskipTests -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ + sonar:sonar -Dsonar.login=$SONARCLOUD_LOGIN \ -Dsonar.host.url=https://sonarcloud.io \ -Dsonar.organization=opennms \ -Dsonar.projectKey=OpenNMS_alec From b268a5b057050717dca5828574871f01eff14c87 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 11:06:20 -0500 Subject: [PATCH 30/48] add coverage --- .circleci/config.yml | 7 ++----- pom.xml | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a2c9be0f..8fcd7ddc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -444,8 +444,5 @@ jobs: name: Run SonarQube Code Analysis when: always command: | - mvn -DskipTests -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ - sonar:sonar -Dsonar.login=$SONARCLOUD_LOGIN \ - -Dsonar.host.url=https://sonarcloud.io \ - -Dsonar.organization=opennms \ - -Dsonar.projectKey=OpenNMS_alec + mvn -Psonar,coverage -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ + sonar:sonar -Dsonar.login=$SONARCLOUD_LOGIN diff --git a/pom.xml b/pom.xml index 5afa54af..f2b8d811 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,7 @@ 4.4.15 3.7.0.1746 9.4.48.v20220622 + 0.8.8 @@ -422,6 +423,11 @@ sonar-maven-plugin ${sonarVersion} + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + @@ -613,5 +619,35 @@ ${project.artifactId} + + coverage + + + + org.jacoco + jacoco-maven-plugin + + + prepare-agent + + prepare-agent + + + + report + + report + + + + XML + + + + + + + + From 6749e602df9bfa41aa29ed5779fc6a17f1d871b9 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 25 Nov 2022 07:14:17 -0500 Subject: [PATCH 31/48] Fix getSituationStatusList (#88) o make getSituationStatusList return longId to match id from the UI ALEC-252 --- .../main/java/org/opennms/alec/rest/SituationRestImpl.java | 2 +- .../java/org/opennms/alec/rest/SituationRestImplTest.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java index 508ef796..e43de849 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java @@ -130,7 +130,7 @@ public Response getSituationStatusList() { try { List situationStatusList = new ArrayList<>(); situationDatasource.getSituations().forEach(o -> situationStatusList.add(SituationStatusImpl.newBuilder() - .id(o.getId()) + .id(String.valueOf(o.getLongId())) .status(o.getStatus()) .build())); List sorted = situationStatusList.stream().sorted(Comparator.comparing(SituationStatus::getStatus)).collect(Collectors.toList()); diff --git a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java index 720c9a44..ece1a594 100644 --- a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java +++ b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java @@ -210,6 +210,8 @@ public void getSituationStatusList() throws InterruptedException { assertThat(actual.getStatus(), equalTo(200)); List situationList = (List) actual.getEntity(); assertThat(situationList.size(), equalTo(2)); + assertThat(situationList.get(0).getId(), equalTo("10")); + assertThat(situationList.get(1).getId(), equalTo("11")); verify(situationDatasource, times(1)).getSituations(); } } @@ -221,11 +223,13 @@ private void getAlarmsAndSituations() { situations.add(ImmutableSituation.newBuilderNow() .setId("10") + .setLongId(10) .addAlarm(alarms.get(0)) .addAlarm(alarms.get(1)) .build()); situations.add(ImmutableSituation.newBuilderNow() .setId("11") + .setLongId(11) .addAlarm(alarms.get(2)) .addAlarm(alarms.get(3)) .addAlarm(alarms.get(4)) From 3640d55bdb54e545bad92dbe1ec0c4ed75cab74e Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 25 Nov 2022 08:49:43 -0500 Subject: [PATCH 32/48] increase timeout from 30 seconds to 60 seconds (#89) --- .../smoke/correlation/DistributedStandaloneCorrelationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java index a9f1d462..81542ed5 100644 --- a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java +++ b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java @@ -76,7 +76,7 @@ private void verifyCorrectEngineIsRunning() { LOG.debug("Checking for engine {}", engine); await() - .atMost(30, TimeUnit. + .atMost(60, TimeUnit. SECONDS) .pollInterval(5, TimeUnit.SECONDS) .ignoreExceptions() From ff36901a621df726119a4a631f34671b050f9982 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 28 Nov 2022 08:49:11 -0500 Subject: [PATCH 33/48] Feature/fix smoke test (#91) * Fix smoke test by updating ranking for cluster engine cluster should not be the highest ranking when multiple engine are available. --- .../cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml | 2 +- .../smoke/correlation/DistributedStandaloneCorrelationTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 5b93769a..09aaf7de 100644 --- a/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -2,7 +2,7 @@ > - + diff --git a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java index 81542ed5..a9f1d462 100644 --- a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java +++ b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java @@ -76,7 +76,7 @@ private void verifyCorrectEngineIsRunning() { LOG.debug("Checking for engine {}", engine); await() - .atMost(60, TimeUnit. + .atMost(30, TimeUnit. SECONDS) .pollInterval(5, TimeUnit.SECONDS) .ignoreExceptions() From ae01d9306c37131dfbd75ebca25f4bc815b6034d Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 11:15:21 -0500 Subject: [PATCH 34/48] add security issue on purpose Array is Stored Directly ( PMD ) and Method returns internal array ( PMD ) --- .../java/org/opennms/alec/rest/SituationRestImpl.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java index e43de849..fa22448d 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java @@ -227,6 +227,14 @@ public Response createSituation(CreateSituationPayload createSituationPayload) { } } + private String[] months; + public String[] getMonths() { + return months; + } + public void setMonths(String[] months) { + this.months = months; + } + private Set getAlarmSetToAdd(List alarmIdList) throws InterruptedException { Set alarms = new HashSet<>(); for (String id : alarmIdList) { From ac8f6ad81ea0048f2e99871971301cb92b69f37c Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 11:43:16 -0500 Subject: [PATCH 35/48] add security issue on purpose Array is Stored Directly ( PMD ) and Method returns internal array ( PMD ) --- .../src/main/java/org/opennms/alec/rest/SituationRestImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java index fa22448d..3e1ec729 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java @@ -41,6 +41,7 @@ import java.util.stream.Collectors; import javax.ws.rs.core.Response; +import javax.xml.transform.TransformerFactory; import org.opennms.alec.data.AlarmSet; import org.opennms.alec.data.CreateSituationPayload; @@ -77,6 +78,8 @@ public SituationRestImpl(KeyValueStore kvStore, this.situationDatasource = Objects.requireNonNull(situationDatasource); this.alarmDatasource = Objects.requireNonNull(alarmDatasource); objectMapper = new ObjectMapper(); + TransformerFactory transFactory = TransformerFactory.newInstance(); + } @Override From 899a06f9ad8a6883467a49b4d4983556ab50ddcc Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 12:16:23 -0500 Subject: [PATCH 36/48] Fix jacoco fixed jacoco: https://stackoverflow.com/questions/18107375/getting-skipping-jacoco-execution-due-to-missing-execution-data-file-upon-exec remove unused scripts try sonar.login into profile --- .circleci/config.yml | 2 +- .circleci/scripts/lib.sh | 49 -------------- .circleci/scripts/sonar.sh | 135 ------------------------------------- pom.xml | 3 +- sonar-project.properties | 12 ---- 5 files changed, 3 insertions(+), 198 deletions(-) delete mode 100644 .circleci/scripts/lib.sh delete mode 100755 .circleci/scripts/sonar.sh delete mode 100644 sonar-project.properties diff --git a/.circleci/config.yml b/.circleci/config.yml index 8fcd7ddc..05d083d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -445,4 +445,4 @@ jobs: when: always command: | mvn -Psonar,coverage -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ - sonar:sonar -Dsonar.login=$SONARCLOUD_LOGIN + sonar:sonar diff --git a/.circleci/scripts/lib.sh b/.circleci/scripts/lib.sh deleted file mode 100644 index f0161c8b..00000000 --- a/.circleci/scripts/lib.sh +++ /dev/null @@ -1,49 +0,0 @@ -# get the PR number from CircleCI environment; caches on success -__cache_pr_num="" -get_pr_num() { - if [ -z "${__cache_pr_num}" ]; then - local _pr_num=0 - if [ -n "${CIRCLE_PULL_REQUEST}" ]; then - _pr_num="$(echo "${CIRCLE_PULL_REQUEST}" | sed -e 's,.*/,,')" - if [ -n "${_pr_num}" ] && [ "${_pr_num}" -gt 0 ]; then - __cache_pr_num="${_pr_num}" - fi - fi - __cache_pr_num=0 - fi - if [ ! "${__cache_pr_num}" -gt 0 ]; then - return 1 - fi - echo "${__cache_pr_num}" -} - -# get the "reference" (merge/pr-parent) branch for this branch; caches on success -__cache_reference_branch="" -get_reference_branch() { - if [ -z "${__cache_reference_branch}" ]; then - local _parent_branch="" - - local _pr_num="$(get_pr_num || echo 0)" - - if [ "${_pr_num}" -gt 0 ] && [ -n "${GITHUB_API_TOKEN}" ]; then - local _github_base="$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_API_TOKEN}" "https://api.github.com/repos/OpenNMS/opennms/pulls/${_pr_num}" | jq -r '.base.ref')" - if [ -n "${_github_base}" ]; then - __cache_reference_branch="${_github_base}" - fi - fi - - if [ -z "${__cache_reference_branch}" ] && [ -e .nightly ]; then - _parent_branch="$(cat .nightly | grep -E '^parent_branch:' | sed -e 's,parent_branch: *,,')" - if [ -n "${_parent_branch}" ]; then - __cache_reference_branch="${_parent_branch}" - fi - fi - fi - - if [ -n "${__cache_reference_branch}" ]; then - echo "${__cache_reference_branch}" - return 0 - fi - - return 1 -} \ No newline at end of file diff --git a/.circleci/scripts/sonar.sh b/.circleci/scripts/sonar.sh deleted file mode 100755 index 2a898a3f..00000000 --- a/.circleci/scripts/sonar.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash - -set -e -set -o pipefail - -FIND_TESTS_DIR="target/find-tests" - -filter_exists() -{ - while read -r CHECK; do - [ -e "${CHECK}" ] && echo "${CHECK}" - done -} - -generate_jacoco_report_files() -{ - find . -type f '!' -path './.git/*' -name jacoco.xml -} - -generate_junit_report_folders() -{ - find . -type d '!' -path './.git/*' -a \( -name surefire-reports\* -o -name failsafe-reports\* \) -} - -generate_class_folders() -{ - generate_junit_report_folders \ - | sed -e 's,/\(surefire-reports\|failsafe-reports\).*$,,' \ - | sort -u \ - | while read -r DIR; do - find "$DIR" -maxdepth 1 -type d -name classes - done \ - | filter_exists -} - -generate_test_class_folders() -{ - generate_junit_report_folders \ - | sed -e 's,/\(surefire-reports\|failsafe-reports\).*$,,' \ - | sort -u \ - | while read -r DIR; do - find "$DIR" -maxdepth 1 -type d -name test-classes - done \ - | filter_exists -} - -generate_source_folders() -{ - find . -type d '!' -path './.git/*' -name target \ - | sed -e 's,/target,/src,' \ - | sort -u \ - | while read -r DIR; do - echo "${DIR}/main" - echo "${DIR}/assembly" - done \ - | filter_exists -} - -generate_test_folders() -{ - find . -type d '!' -path './.git/*' -name target \ - | sed -e 's,/target,/src,' \ - | sort -u \ - | while read -r DIR; do - echo "${DIR}/test" - done \ - | filter_exists -} - -find_tests() -{ - perl -pi -e "s,/(root|home/circleci)/project/,${HOME}/project/,g" target/structure-graph.json - - # Now determine the Maven modules related to the tests we need to run - cat "${FIND_TESTS_DIR}"/*_classnames | python3 .circleci/scripts/find-tests/find-tests.py generate-test-modules \ - --output=/tmp/this_node_projects \ - . -} - -# shellcheck disable=SC1091 -. ./.circleci/scripts/lib.sh - -PR_NUM="$(get_pr_num || echo 0)" -REFERENCE_BRANCH="$(get_reference_branch || echo "develop")" - -echo "#### Making sure git is up-to-date" -if [ -n "${REFERENCE_BRANCH}" ]; then - git fetch origin "${REFERENCE_BRANCH}" -fi - -echo "#### Enumerating Affected Tests and Projects" -find_tests -PROJECT_LIST="$(< /tmp/this_node_projects paste -s -d, -)" -if [ -z "${PROJECT_LIST}" ]; then - echo "WARNING: no projects found, skipping sonar run" - exit 0 -fi - -echo "#### Unpacking Sonar CLI" -unzip -o -q -d /tmp /tmp/sonar-scanner-cli.zip -SONAR_DIR="$(find /tmp/sonar* -type d -name sonar-scanner\*)" - -echo "#### Determining Arguments for Sonar CLI" -declare -a SONAR_ARGS=( - -Dsonar.login="$SONARCLOUD_LOGIN" - -Dsonar.host.url="https://sonarcloud.io" -) - -if [ "${PR_NUM}" -gt 0 ]; then - SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.pullrequest.key=${PR_NUM}" "-Dsonar.pullrequest.branch=${CIRCLE_BRANCH}" "-Dsonar.pullrequest.base=${REFERENCE_BRANCH}") - SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.pullrequest.provider=GitHub" "-Dsonar.pullrequest.github.repository=OpenNMS/opennms") -else - SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.branch.name=${CIRCLE_BRANCH}") - if [ -n "${REFERENCE_BRANCH}" ] && [ "${REFERENCE_BRANCH}" != "${CIRCLE_BRANCH}" ]; then - SONAR_ARGS=("${SONAR_ARGS[@]}" "-Dsonar.newCode.referenceBranch=${REFERENCE_BRANCH}") - fi -fi - -mkdir -p /tmp/sonar-cache -export SONAR_USER_HOME=/tmp/sonar-cache -export SONAR_SCANNER_OPTS="${MAVEN_OPTS:--Xmx7g}" - -echo "#### Executing Sonar" -# shellcheck disable=SC2086 -"${SONAR_DIR}/bin/sonar-scanner" \ - "${SONAR_ARGS[@]}" \ - -Djava.security.egd=file:/dev/./urandom \ - -Dsonar.coverage.jacoco.xmlReportPaths="$(generate_jacoco_report_files | paste -s -d, -)" \ - -Dsonar.junit.reportPaths="$(generate_junit_report_folders | paste -s -d, -)" \ - -Dsonar.sources="$(generate_source_folders | paste -s -d, -)" \ - -Dsonar.tests="$(generate_test_folders | paste -s -d, -)" \ - -Dsonar.java.binaries="$(generate_class_folders | paste -s -d, -)" \ - -Dsonar.java.libraries="${HOME}/.m2/repository/**/*.jar,**/*.jar" \ - -Dsonar.java.test.binaries="$(generate_test_class_folders | paste -s -d, -)" \ - -Dsonar.java.test.libraries="${HOME}/.m2/repository/**/*.jar,**/*.jar" diff --git a/pom.xml b/pom.xml index f2b8d811..6398e68b 100644 --- a/pom.xml +++ b/pom.xml @@ -532,7 +532,7 @@ 2.22.1 - -Xmx1024m -Xms1024m -XX:MaxPermSize=512m -Djdk.net.URLClassPath.disableClassPathURLCheck=true + ${argLine} -Xmx1024m -Xms1024m -XX:MaxPermSize=512m -Djdk.net.URLClassPath.disableClassPathURLCheck=true @@ -617,6 +617,7 @@ opennms OpenNMS_alec ${project.artifactId} + $SONARCLOUD_LOGIN diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 629282f5..00000000 --- a/sonar-project.properties +++ /dev/null @@ -1,12 +0,0 @@ -sonar.organization=opennms -sonar.projectKey=OpenNMS_alec -sonar.java.source=11 -sonar.sourceEncoding=UTF-8 - -# skip c/++/objc, they don't process properly ATM -sonar.c.file.suffixes=- -sonar.cpp.file.suffixes=- -sonar.objc.file.suffixes=- - -# skip 3rd-party javascript -#sonar.exclusions=core/web-assets/src/main/assets/static/legacy/**/* From d38f7b8fde575e211a2b051ab918e38b27e003e0 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 12:29:57 -0500 Subject: [PATCH 37/48] revert sonar.login to circleci --- .circleci/config.yml | 2 +- pom.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 05d083d1..42edbe53 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -445,4 +445,4 @@ jobs: when: always command: | mvn -Psonar,coverage -Dbuild.packages clean verify dependency:resolve-plugins dependency:go-offline \ - sonar:sonar + sonar:sonar -Dsonar.login=$SONARCLOUD_LOGIN diff --git a/pom.xml b/pom.xml index 6398e68b..2d60bca2 100644 --- a/pom.xml +++ b/pom.xml @@ -617,7 +617,6 @@ opennms OpenNMS_alec ${project.artifactId} - $SONARCLOUD_LOGIN From b788618faedc81c5dcfd95374f559c4f59edd899 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 14:33:26 -0500 Subject: [PATCH 38/48] remove intentional vulnerabilities to test sonar --- .../java/org/opennms/alec/rest/SituationRestImpl.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java index 3e1ec729..e43de849 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java @@ -41,7 +41,6 @@ import java.util.stream.Collectors; import javax.ws.rs.core.Response; -import javax.xml.transform.TransformerFactory; import org.opennms.alec.data.AlarmSet; import org.opennms.alec.data.CreateSituationPayload; @@ -78,8 +77,6 @@ public SituationRestImpl(KeyValueStore kvStore, this.situationDatasource = Objects.requireNonNull(situationDatasource); this.alarmDatasource = Objects.requireNonNull(alarmDatasource); objectMapper = new ObjectMapper(); - TransformerFactory transFactory = TransformerFactory.newInstance(); - } @Override @@ -230,14 +227,6 @@ public Response createSituation(CreateSituationPayload createSituationPayload) { } } - private String[] months; - public String[] getMonths() { - return months; - } - public void setMonths(String[] months) { - this.months = months; - } - private Set getAlarmSetToAdd(List alarmIdList) throws InterruptedException { Set alarms = new HashSet<>(); for (String id : alarmIdList) { From b02fd73257f0850b9ed4fea7738f48c4f81d6f5e Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 14:39:02 -0500 Subject: [PATCH 39/48] cleanup --- .circleci/config.yml | 135 +++++++++++++++++++++---------------------- pom.xml | 1 - 2 files changed, 67 insertions(+), 69 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 42edbe53..42b23504 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,21 +46,20 @@ workflows: filters: tags: only: /.*/ -# - build: -# context: "OpenNMS Build" -# requires: -# - pre-build -# filters: -# tags: -# only: /.*/ - -# - build-debian: -# context: "OpenNMS Build" -# requires: -# - build -# filters: -# tags: -# only: /.*/ + - build: + context: "OpenNMS Build" + requires: + - pre-build + filters: + tags: + only: /.*/ + - build-debian: + context: "OpenNMS Build" + requires: + - build + filters: + tags: + only: /.*/ - sonar: context: "OpenNMS Build" requires: @@ -68,61 +67,61 @@ workflows: filters: tags: only: /.*/ -# - build-docs: -# context: "OpenNMS Build" -# requires: -# - pre-build -# filters: -# tags: -# only: /.*/ -# - smoke-test-commit: -# context: "OpenNMS Build" -# requires: -# - build -# filters: -# branches: -# ignore: -# - develop -# - /^release-.*/ -# tags: -# ignore: /^v.*/ -# - smoke-test-full: -# context: "OpenNMS Build" -# requires: -# - build -# filters: -# branches: -# only: -# - develop -# - /^release-.*/ -# tags: -# only: /^v.*/ + - build-docs: + context: "OpenNMS Build" + requires: + - pre-build + filters: + tags: + only: /.*/ + - smoke-test-commit: + context: "OpenNMS Build" + requires: + - build + filters: + branches: + ignore: + - develop + - /^release-.*/ + tags: + ignore: /^v.*/ + - smoke-test-full: + context: "OpenNMS Build" + requires: + - build + filters: + branches: + only: + - develop + - /^release-.*/ + tags: + only: /^v.*/ # Run deploy jobs on version tags, release branches and develop -# - deploy-maven: -# context: "OpenNMS Build" -# requires: -# - smoke-test-commit -# - smoke-test-full -# filters: -# # Maven deploy requires GPG signing for releases - we do this manually -# branches: -# only: -# - develop -# - /release-.*/ -# - deploy-packages: -# context: "OpenNMS Build" -# requires: -# - smoke-test-commit -# - smoke-test-full -# - build-debian -# filters: -# tags: -# only: /^v.*/ -# branches: -# only: -# - develop -# - /release-.*/ + - deploy-maven: + context: "OpenNMS Build" + requires: + - smoke-test-commit + - smoke-test-full + filters: + # Maven deploy requires GPG signing for releases - we do this manually + branches: + only: + - develop + - /release-.*/ + - deploy-packages: + context: "OpenNMS Build" + requires: + - smoke-test-commit + - smoke-test-full + - build-debian + filters: + tags: + only: /^v.*/ + branches: + only: + - develop + - /release-.*/ commands: diff --git a/pom.xml b/pom.xml index 2d60bca2..c8e53107 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,6 @@ 4.5.13 4.4.15 3.7.0.1746 - 9.4.48.v20220622 0.8.8 From 6edcf298bb62aeaaa7d0951f2f336bf193de474b Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 15:08:55 -0500 Subject: [PATCH 40/48] cleanup --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 42b23504..394491b0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,7 @@ workflows: - build: context: "OpenNMS Build" requires: - - pre-build + - sonar filters: tags: only: /.*/ From a4ef1f50b5fbd7002958bbba362a4120a66fd4e3 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 15:28:03 -0500 Subject: [PATCH 41/48] cleanup --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 394491b0..3046017e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,7 @@ workflows: - build: context: "OpenNMS Build" requires: - - sonar + - pre-build filters: tags: only: /.*/ @@ -63,7 +63,7 @@ workflows: - sonar: context: "OpenNMS Build" requires: - - pre-build + - build filters: tags: only: /.*/ From 03301ea1accb91bef6884e7eb4a8a515233c083f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 28 Nov 2022 11:08:31 -0500 Subject: [PATCH 42/48] Add feedback and engine parameter to alec situations (#87) o fix sonar issue ALEC-251 --- .../alec/datasource/api/Situation.java | 4 ++ .../datasource/common/ImmutableSituation.java | 64 +++++++++++++------ .../org/opennms/alec/driver/main/Driver.java | 2 +- .../opennms/alec/driver/test/TestDriver.java | 2 + .../alec/engine/api/EngineFactory.java | 2 + .../engine/cluster/AbstractClusterEngine.java | 53 +++++++-------- .../engine/cluster/ClusterEngineFactory.java | 4 ++ .../cluster/ClusterEngineSituationTest.java | 4 +- .../engine/cluster/ClusterEngineTest.java | 4 ++ .../engine/dbscan/DBScanEngineFactory.java | 6 ++ .../DeepLearningEngineFactory.java | 5 ++ .../itest/Level1EngineComplianceTest.java | 1 + .../itest/Level2EngineComplianceTest.java | 2 + .../deeplearning/shell/Vectorize.java | 6 ++ .../java/org/opennms/alec/data/AlarmSet.java | 2 + .../org/opennms/alec/data/AlarmSetImpl.java | 19 +++++- .../alec/data/CreateSituationPayload.java | 2 + .../alec/data/CreateSituationPayloadImpl.java | 21 +++++- .../org/opennms/alec/rest/SituationRest.java | 2 +- .../opennms/alec/rest/SituationRestImpl.java | 14 ++-- .../alec/rest/SituationRestImplTest.java | 17 ++++- 21 files changed, 180 insertions(+), 56 deletions(-) diff --git a/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java b/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java index 533d9d95..6f27a0d9 100644 --- a/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java +++ b/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java @@ -67,4 +67,8 @@ public interface Situation { String getUei(); String getDescription(); + + List getFeedback(); + + String getEngineParameter(); } diff --git a/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java b/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java index 351efeda..21adcebe 100644 --- a/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java +++ b/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java @@ -64,6 +64,8 @@ public final class ImmutableSituation implements Situation { private final Long lastTime; private final String uei; private final String description; + private final List feedbacks; + private final String engineParameter; private ImmutableSituation(Builder builder) { this.id = builder.id; @@ -81,6 +83,9 @@ private ImmutableSituation(Builder builder) { this.lastTime = builder.lastTime; this.uei = builder.uei; this.description = builder.description; + this.feedbacks = builder.feedbacks == null ? Collections.emptyList() : + Collections.unmodifiableList(new ArrayList<>(builder.feedbacks)); + this.engineParameter = builder.engineParameter; } public static final class Builder { @@ -96,6 +101,8 @@ public static final class Builder { private Long lastTime; private String uei; private String description; + private List feedbacks; + private String engineParameter; private Builder() { } @@ -117,6 +124,8 @@ private Builder(Situation situation) { this.lastTime = situation.getLastTime(); this.uei = situation.getUei(); this.description = situation.getDescription(); + this.feedbacks = new ArrayList<>(situation.getFeedback()); + this.engineParameter = situation.getEngineParameter(); } public Builder setId(String id) { @@ -212,6 +221,24 @@ public Builder setDescription(String description) { return this; } + public Builder setFeedbacks(List feedbacks) { + this.feedbacks = feedbacks; + return this; + } + + public Builder addFeedback(String feedback) { + if (feedbacks == null) { + feedbacks = new ArrayList<>(); + } + feedbacks.add(feedback); + return this; + } + + public Builder setEngineParameter(String engineParameter) { + this.engineParameter = engineParameter; + return this; + } + public ImmutableSituation build() { Objects.requireNonNull(id, "Id cannot be null"); Objects.requireNonNull(creationTime, "creation time cannot be null"); @@ -317,27 +344,13 @@ public String getDescription() { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ImmutableSituation that = (ImmutableSituation) o; - return creationTime == that.creationTime && - severity == that.severity && - Objects.equals(resourceKeys, that.resourceKeys) && - Objects.equals(alarms, that.alarms) && - Objects.equals(diagnosticText, that.diagnosticText) && - Objects.equals(status, that.status) && - Objects.equals(reductionKey, that.reductionKey) && - Objects.equals(lastTime, that.lastTime) && - Objects.equals(uei, that.uei) && - Objects.equals(id, that.id) && - Objects.equals(longId, that.longId) && - Objects.equals(description, that.description); + public List getFeedback() { + return feedbacks; } @Override - public int hashCode() { - return Objects.hash(id, longId, creationTime, resourceKeys, alarms, severity, diagnosticText, status, reductionKey, lastTime, uei, description); + public String getEngineParameter() { + return engineParameter; } @Override @@ -356,6 +369,21 @@ public String toString() { .add("lastTime=" + lastTime) .add("uei='" + uei + "'") .add("description='" + description + "'") + .add("feedbacks=" + feedbacks) + .add("engineParameter='" + engineParameter + "'") .toString(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ImmutableSituation that = (ImmutableSituation) o; + return longId == that.longId && creationTime == that.creationTime && Objects.equals(id, that.id) && severity == that.severity && Objects.equals(resourceKeys, that.resourceKeys) && Objects.equals(alarms, that.alarms) && Objects.equals(alarmsFromMap, that.alarmsFromMap) && Objects.equals(diagnosticText, that.diagnosticText) && status == that.status && Objects.equals(reductionKey, that.reductionKey) && Objects.equals(lastTime, that.lastTime) && Objects.equals(uei, that.uei) && Objects.equals(description, that.description) && Objects.equals(feedbacks, that.feedbacks) && Objects.equals(engineParameter, that.engineParameter); + } + + @Override + public int hashCode() { + return Objects.hash(id, longId, creationTime, severity, resourceKeys, alarms, alarmsFromMap, diagnosticText, status, reductionKey, lastTime, uei, description, feedbacks, engineParameter); + } } diff --git a/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java b/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java index a4147cc3..c2af15cf 100644 --- a/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java +++ b/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java @@ -200,7 +200,7 @@ public void onSituation(Situation situation) { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { - Thread.currentThread().setName("ALEC Driver Tick"); + Thread.currentThread().setName("ALEC Driver Tick -- " + engineFactory.getParameters()); try (com.codahale.metrics.Timer.Context context = ticks.time()) { engine.tick(System.currentTimeMillis()); } catch (Exception e) { diff --git a/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java b/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java index ca3443f8..33cd71c0 100644 --- a/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java +++ b/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java @@ -152,6 +152,8 @@ private List run(List alarms, List inventory, engine.registerSituationHandler(session); engine.init(previousAlarms, previousAlarmFeedback, previousSituations, inventory); + Thread.currentThread().setName("ALEC Driver Tick -- engine"); + final GraphProvider graphProvider = getGraphProvider(engine); final boolean shouldExportGraph = isShouldExportGraph(graphProvider); long lastGraphGeneratedAt = 0; diff --git a/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java b/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java index 2e7f2f53..8b103a59 100644 --- a/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java +++ b/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java @@ -40,4 +40,6 @@ public interface EngineFactory { EngineFactory getEngineFactory(); + String getParameters(); + } diff --git a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java index f90ea041..6314a9d3 100644 --- a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java +++ b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java @@ -56,6 +56,7 @@ import org.apache.commons.math3.ml.clustering.Cluster; import org.opennms.alec.datasource.api.Alarm; import org.opennms.alec.datasource.api.AlarmFeedback; +import org.opennms.alec.datasource.api.FeedbackType; import org.opennms.alec.datasource.api.InventoryObject; import org.opennms.alec.datasource.api.Situation; import org.opennms.alec.datasource.api.SituationHandler; @@ -83,6 +84,7 @@ /** * Group alarms into situations by leveraging some clustering algorithm (i.e. DBSCAN) */ +@SuppressWarnings("java:S3776") public abstract class AbstractClusterEngine implements Engine, GraphProvider, SpatialDistanceCalculator { private static final Logger LOG = LoggerFactory.getLogger(AbstractClusterEngine.class); @@ -131,7 +133,7 @@ public abstract class AbstractClusterEngine implements Engine, GraphProvider, Sp private final AtomicInteger numEdgesFromLastTick = new AtomicInteger(-1); private final AtomicInteger numAlarmsFromLastTick = new AtomicInteger(-1); - public AbstractClusterEngine(MetricRegistry metrics) { + protected AbstractClusterEngine(MetricRegistry metrics) { metrics.gauge(name("vertices"), () -> numVerticesFromLastTick::get); metrics.gauge(name("edges"), () -> numEdgesFromLastTick::get); metrics.gauge(name("alarms"), () -> numAlarmsFromLastTick::get); @@ -190,7 +192,7 @@ public synchronized void init(List alarms, List alarmFeedb // Process all the alarm feedback provided on init alarmFeedback.forEach(this::handleAlarmFeedback); - if (alarms.size() > 0) { + if (!alarms.isEmpty()) { alarmsChangedSinceLastTick = true; } @@ -271,7 +273,7 @@ ImmutableSituation.Builder getBuilderForExistingSituationWithId(String situation throw new IllegalArgumentException("Situation with id: " + situationId + " does not exist."); } return newOrUpdatedSituationsById.computeIfAbsent(situationId, - (sid) -> ImmutableSituation.newBuilderFrom(existingSituation)); + sid -> ImmutableSituation.newBuilderFrom(existingSituation)); } ImmutableSituation.Builder getBuilderForNewSituationWithId(String situationId) { @@ -420,7 +422,7 @@ void mapClusterToSituations(Cluster clusterOfAlarms, TickConte final Alarm alarm = alarmInSpaceTime.getAlarm(); final Situation situation = alarmIdToSituationMap.get(alarm.getId()); if (situation != null) { - alarmsBySituationId.computeIfAbsent(situation.getId(), (sid) -> new ArrayList<>()).add(alarm); + alarmsBySituationId.computeIfAbsent(situation.getId(), sid -> new ArrayList<>()).add(alarm); } else { alarmsWithoutSituations.add(alarm); } @@ -428,10 +430,8 @@ void mapClusterToSituations(Cluster clusterOfAlarms, TickConte if (LOG.isDebugEnabled()) { final Map> alarmIdsBySituationIds = new LinkedHashMap<>(); - alarmsBySituationId.forEach((situationId, alarms) -> { - alarmIdsBySituationIds.put(situationId, alarms.stream() - .map(Alarm::getId).collect(Collectors.toList())); - }); + alarmsBySituationId.forEach((situationId, alarms) -> alarmIdsBySituationIds.put(situationId, alarms.stream() + .map(Alarm::getId).collect(Collectors.toList()))); LOG.debug("{}: Alarms IDs by Situations IDs in the cluster: {}", context.getTimestampInMillis(), alarmIdsBySituationIds); final List alarmIdsWithoutSituations = alarmsWithoutSituations.stream() @@ -511,8 +511,10 @@ void mapClusterToSituations(Cluster clusterOfAlarms, TickConte Collection situationBuilders = context.getBuildersForNewOrUpdatedSituations(); LOG.debug("{}: Generating diagnostic texts for {} situations...", context.getTimestampInMillis(), situationBuilders.size()); - situationBuilders.forEach(situationBuilder -> - situationBuilder.setDiagnosticText(getDiagnosticTextForSituation(situationBuilder.build()))); + situationBuilders.forEach(situationBuilder -> { + situationBuilder.setDiagnosticText(getDiagnosticTextForSituation(situationBuilder.build())); + situationBuilder.setEngineParameter(Thread.currentThread().getName().substring(20)); + }); LOG.debug("{}: Done generating diagnostic texts.", context.getTimestampInMillis()); } @@ -654,29 +656,25 @@ public void onInventoryRemoved(Collection inventory) { } @Override + @SuppressWarnings("java:S131") public void handleAlarmFeedback(AlarmFeedback alarmFeedback) { synchronized (situationsWithFeedback) { feedbackChangedSinceLastTick = true; - switch (alarmFeedback.getFeedbackType()) { - case FALSE_POSITIVE: - situationAlarmBlacklist.compute(alarmFeedback.getSituationId(), (key, value) -> { - Set alarmIds = value == null ? new HashSet<>() : value; - alarmIds.add(alarmFeedback.getAlarmKey()); + FeedbackType feedbackType = alarmFeedback.getFeedbackType(); + if (feedbackType == FeedbackType.FALSE_POSITIVE) { + situationAlarmBlacklist.compute(alarmFeedback.getSituationId(), (key, value) -> { + Set alarmIds = value == null ? new HashSet<>() : value; + alarmIds.add(alarmFeedback.getAlarmKey()); - return alarmIds; - }); + return alarmIds; + }); - situationsWithFeedback.add(alarmFeedback.getSituationId()); - - break; - case FALSE_NEGATIVE: - if (situationAlarmBlacklist.containsKey(alarmFeedback.getSituationId())) { - situationAlarmBlacklist.get(alarmFeedback.getSituationId()) - .remove(alarmFeedback.getAlarmKey()); - } - break; + situationsWithFeedback.add(alarmFeedback.getSituationId()); + } else if (feedbackType == FeedbackType.FALSE_NEGATIVE && situationAlarmBlacklist.containsKey(alarmFeedback.getSituationId())) { + situationAlarmBlacklist.get(alarmFeedback.getSituationId()) + .remove(alarmFeedback.getAlarmKey()); } } } @@ -766,6 +764,7 @@ private long getVertexIdForAlarm(Alarm alarm) { * @param distance spatial distance between alarm1 and alarm2 * @return effective distance between alarm1 and alarm2 */ + @SuppressWarnings("java:S1172") public double getDistanceBetween(double t1, double t2, double firstTimeA, double firstTimeB, double distance) { return Math.abs(t2 - t1) + distance; } @@ -791,6 +790,7 @@ private Alarm getClosestNeighborInSituation(Alarm alarm, List candidates) } @Override + @SuppressWarnings("java:S112") public double getSpatialDistanceBetween(long vertexIdA, long vertexIdB) { final EdgeKey key = new EdgeKey(vertexIdA, vertexIdB); try { @@ -800,6 +800,7 @@ public double getSpatialDistanceBetween(long vertexIdA, long vertexIdB) { } } + @SuppressWarnings("java:S2153") private final LoadingCache spatialDistances = CacheBuilder.newBuilder() .maximumSize(10000) .build(new CacheLoader() { diff --git a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java index 35be7897..ec51f180 100644 --- a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java +++ b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java @@ -55,4 +55,8 @@ public EngineFactory getEngineFactory() { return this; } + @Override + public String getParameters() { + return String.format("engine: %s", getName()); + } } diff --git a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java index 43beb2c8..82dac162 100644 --- a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java +++ b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java @@ -82,6 +82,7 @@ public void canHandleExistingSituations() { // No situations should have been triggered yet assertThat(triggeredSituations, hasSize(0)); + Thread.currentThread().setName("ALEC Driver Tick -- engine"); ClusterEngine clusterEngine = new ClusterEngine(new MetricRegistry()); clusterEngine.init(alarms, Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); clusterEngine.registerSituationHandler(this); @@ -155,7 +156,7 @@ public void canHandleSituationThatIncludesADeadVertex() { // No situations should have been triggered yet assertThat(triggeredSituations, hasSize(0)); - + Thread.currentThread().setName("ALEC Driver Tick -- engine"); Engine oneClusterEngine = new OneClusterEngine(new MetricRegistry()); oneClusterEngine.init(alarms, Collections.emptyList(), Collections.emptyList(), MockInventory.SAMPLE_NETWORK); oneClusterEngine.registerSituationHandler(this); @@ -224,6 +225,7 @@ public void canHandleSituationWithNonEligbleVertex() { // No situations should have been triggered yet assertThat(triggeredSituations, hasSize(0)); + Thread.currentThread().setName("ALEC Driver Tick -- engine"); Engine oneClusterEngine = new OneClusterEngine(new MetricRegistry()); oneClusterEngine.init(alarms, Collections.emptyList(), Collections.emptyList(), MockInventory.SAMPLE_NETWORK); oneClusterEngine.registerSituationHandler(this); diff --git a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java index 3a9808e8..8b764cf2 100644 --- a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java +++ b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java @@ -152,6 +152,7 @@ public void canClusterAlarmsAndDeleteSituations() { assertThat(situationsById.keySet(), hasSize(0)); // Tick + Thread.currentThread().setName("ALEC Driver Tick -- engine"); engine.tick(now+2); // We should now have a single situation with both alarms @@ -245,6 +246,7 @@ public void canBlacklistAlarms() { assertThat(situationsById.keySet(), hasSize(0)); // Tick + Thread.currentThread().setName("ALEC Driver Tick -- engine"); engine.tick(now+2); // We should now have a single situation with both alarms @@ -297,6 +299,7 @@ public void canHandleAlarmsInClusters() { // A cluster with a single alarm that was not previously mapped to a situation should be in a new situation Cluster cluster = new Cluster<>(); cluster.addPoint(alarm1InSpaceTime); + Thread.currentThread().setName("ALEC Driver Tick -- engine"); context = engine.getTickContextFor(0L); engine.mapClusterToSituations(cluster, context); situations = context.getNewOrUpdatedSituations(); @@ -376,6 +379,7 @@ public void canUpdateExistingSituationsWithManyAlarmsInCluster() { cluster.addPoint(alarm4InSpaceTime); // Process the cluster + Thread.currentThread().setName("ALEC Driver Tick -- engine"); engine.solveEntireGraphForTesting(); engine.setSituations(Arrays.asList(situation1, situation2)); AbstractClusterEngine.TickContext context = engine.getTickContextFor(0L); diff --git a/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java b/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java index 10860950..4ed4d3a1 100644 --- a/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java +++ b/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java @@ -94,6 +94,12 @@ public EngineFactory getEngineFactory() { return this; } + @Override + public String getParameters() { + return String.format("engine: %s, alpha: %s, beta: %s, epsilon: %s, distanceMeasure: %s", + getName(), getAlpha(), getBeta(), getEpsilon(), getDistanceMeasureFactoryName()); + } + public double getEpsilon() { return epsilon; } diff --git a/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java b/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java index f498b2ae..0e153a6f 100644 --- a/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java +++ b/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java @@ -83,6 +83,11 @@ public EngineFactory getEngineFactory() { return this; } + @Override + public String getParameters() { + return String.format("engine: %s", getName()); + } + public void setToken(String token) { this.token = token; } diff --git a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java index 7b4dfd54..d9214367 100644 --- a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java +++ b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java @@ -101,6 +101,7 @@ public void setUp() { driver = TestDriver.builder() .withEngineFactory(factory) .build(); + Thread.currentThread().setName("ALEC Driver Tick -- engine"); } @Test diff --git a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java index f3e88777..d70e1be5 100644 --- a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java +++ b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java @@ -87,6 +87,8 @@ public void setUp() { driver = TestDriver.builder() .withEngineFactory(factory) .build(); + + Thread.currentThread().setName("ALEC Driver Tick -- engine"); } @Test diff --git a/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java b/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java index 362763c3..7e14e804 100644 --- a/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java +++ b/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java @@ -87,6 +87,7 @@ public class Vectorize implements Action { private String csvOut; @Override + @SuppressWarnings({"java:S106","java:S112"}) public Object execute() throws Exception { final List alarms = JaxbUtils.getAlarms(Paths.get(alarmsIn)); final List inventory = JaxbUtils.getInventory(Paths.get(inventoryIn)); @@ -200,6 +201,11 @@ public Engine createEngine(MetricRegistry metrics) { public EngineFactory getEngineFactory() { return this; } + + @Override + public String getParameters() { + return String.format("engine: %s", getName()); + } } private void streamVectors(List inventory, List alarms, Set situations, Consumer consumer) { diff --git a/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java b/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java index a9382c29..eeb96d80 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java +++ b/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java @@ -38,4 +38,6 @@ public interface AlarmSet { String getSituationId(); List getAlarmIdList(); + + String getFeedback(); } diff --git a/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java b/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java index 97253c12..5c9f6cfa 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java @@ -35,20 +35,24 @@ public class AlarmSetImpl implements AlarmSet { private final String situationId; private final List alarmIdList; + private final String feedback; + private AlarmSetImpl(Builder builder) { situationId = builder.situationId; alarmIdList = builder.alarmIdList; + feedback = builder.feedback; } - public static AlarmSetImpl.Builder newBuilder() { - return new AlarmSetImpl.Builder(); + public static Builder newBuilder() { + return new Builder(); } public static Builder newBuilder(AlarmSet copy) { Builder builder = new Builder(); builder.situationId = copy.getSituationId(); builder.alarmIdList = copy.getAlarmIdList(); + builder.feedback = copy.getFeedback(); return builder; } @@ -56,6 +60,7 @@ public static Builder newBuilder(AlarmSet copy) { public static final class Builder { private String situationId; private List alarmIdList; + private String feedback; private Builder() { } @@ -74,6 +79,11 @@ public Builder alarmIdList(List val) { return this; } + public Builder feedback(String val) { + feedback = val; + return this; + } + public AlarmSetImpl build() { return new AlarmSetImpl(this); } @@ -88,4 +98,9 @@ public String getSituationId() { public List getAlarmIdList() { return alarmIdList; } + + @Override + public String getFeedback() { + return feedback; + } } diff --git a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java index 3da0f9a0..16356add 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java +++ b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java @@ -39,4 +39,6 @@ public interface CreateSituationPayload { String getDiagnosticText(); String getDescription(); + + String getFeedback(); } diff --git a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java index 2351979c..c80f9bcf 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java @@ -37,22 +37,26 @@ public class CreateSituationPayloadImpl implements CreateSituationPayload { private final List alarmIdList; private final String diagnosticText; private final String description; + private final String feedback; + private CreateSituationPayloadImpl(Builder builder) { alarmIdList = builder.alarmIdList; diagnosticText = builder.diagnosticText; description = builder.description; + feedback = builder.feedback; } public static Builder newBuilder() { return new Builder(); } - public static Builder newBuilder(CreateSituationPayloadImpl copy) { + public static Builder newBuilder(CreateSituationPayload copy) { Builder builder = new Builder(); builder.alarmIdList = copy.getAlarmIdList(); builder.diagnosticText = copy.getDiagnosticText(); builder.description = copy.getDescription(); + builder.feedback = copy.getFeedback(); return builder; } @@ -61,10 +65,15 @@ public static final class Builder { private List alarmIdList; private String diagnosticText; private String description; + private String feedback; private Builder() { } + public static Builder newBuilder() { + return new Builder(); + } + public Builder alarmIdList(List val) { alarmIdList = val; return this; @@ -80,6 +89,11 @@ public Builder description(String val) { return this; } + public Builder feedback(String val) { + feedback = val; + return this; + } + public CreateSituationPayloadImpl build() { return new CreateSituationPayloadImpl(this); } @@ -99,4 +113,9 @@ public String getDiagnosticText() { public String getDescription() { return description; } + + @Override + public String getFeedback() { + return feedback; + } } diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java index af283203..b4f81193 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java @@ -48,7 +48,7 @@ public interface SituationRest { @POST @Path("rejected/{id}") - Response rejected(@PathParam("id") String id); + Response rejected(@PathParam("id") String id, String feedback); @POST @Path("accepted/{id}") diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java index e43de849..e7dfb554 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java @@ -80,20 +80,22 @@ public SituationRestImpl(KeyValueStore kvStore, } @Override - public Response rejected(String situationId) { + public Response rejected(String situationId, String feedback) { try { Optional situationOptional = situationDatasource.getSituation(Integer.parseInt(situationId)); if (situationOptional.isPresent()) { - Situation situation = situationOptional.get(); + final Situation situation = situationOptional.get(); //check status if (Status.REJECTED.equals(situation.getStatus())) { LOG.debug("Situation {} already rejected", situationId); return Response.accepted(MessageFormat.format("Situation {0} already rejected", situationId)).build(); } + feedback = String.format("reject situation [%s] -- user feedback :[%s]", situationId, feedback); Situation situationRejected = ImmutableSituation.newBuilderFrom(situation) .setStatus(Status.REJECTED) .setAlarms(Collections.emptySet()) .setSeverity(Severity.CLEARED) + .addFeedback(feedback) .build(); return forwardAndStoreSituation(situationRejected, situationRejected.getAlarms()); } @@ -163,7 +165,8 @@ public Response addAlarm(AlarmSet alarm) { if (oldSituation.getAlarms().equals(alarmSet)) { return ALECRestUtils.noContent(); } - return forwardAndStoreSituation(oldSituation, alarmSet); + String feedback = String.format("add alarm [%s] to situation [%s] -- user feedback :[%s]", alarm.getAlarmIdList(), alarm.getSituationId(), alarm.getFeedback()); + return forwardAndStoreSituation(ImmutableSituation.newBuilderFrom(oldSituation).addFeedback(feedback).build(), alarmSet); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -186,7 +189,8 @@ public Response removeAlarm(AlarmSet alarm) { if (oldSituation.getAlarms().equals(alarmSet)) { return ALECRestUtils.noContent(); } else { - return forwardAndStoreSituation(oldSituation, alarmSet); + String feedback = String.format("remove alarms [%s] to situation [%s] -- user feedback :[%s]", alarm.getAlarmIdList(), situationId, alarm.getFeedback()); + return forwardAndStoreSituation(ImmutableSituation.newBuilderFrom(oldSituation).addFeedback(feedback).build(), alarmSet); } } } catch (InterruptedException e) { @@ -218,6 +222,8 @@ public Response createSituation(CreateSituationPayload createSituationPayload) { .setDiagnosticText(createSituationPayload.getDiagnosticText()) .setDescription(createSituationPayload.getDescription()) .setSeverity(maxSeverity) + .setEngineParameter("user created") + .addFeedback(createSituationPayload.getFeedback()) .build(); if (situation.getAlarms().size() >= 2) { situationDatasource.forwardSituation(situation); diff --git a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java index ece1a594..32a196c5 100644 --- a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java +++ b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java @@ -28,6 +28,7 @@ import org.opennms.alec.data.CreateSituationPayloadImpl; import org.opennms.alec.data.SituationStatus; import org.opennms.alec.datasource.api.Alarm; +import org.opennms.alec.datasource.api.Severity; import org.opennms.alec.datasource.api.Situation; import org.opennms.alec.datasource.api.SituationDatasource; import org.opennms.alec.datasource.api.Status; @@ -65,10 +66,12 @@ public void tearDown() { @Test public void rejected() throws InterruptedException { ArgumentCaptor situationCaptor = ArgumentCaptor.forClass(Situation.class); - try (Response actual = underTest.rejected("11")) { + try (Response actual = underTest.rejected("11", "rejected")) { assertThat(actual.getStatus(), equalTo(200)); verify(situationDatasource, times(1)).forwardSituation(situationCaptor.capture()); assertThat(situationCaptor.getValue().getStatus(), equalTo(Status.REJECTED)); + assertThat(situationCaptor.getValue().getFeedback().size(), equalTo(1)); + assertThat(situationCaptor.getValue().getFeedback().get(0), equalTo("reject situation [11] -- user feedback :[rejected]")); assertThat(situationCaptor.getValue().getAlarms().size(), equalTo(0)); verify(situationDatasource, times(1)).getSituation(11); verify(situationDatasource, times(2)).getSituations(); @@ -143,7 +146,7 @@ public void addAlarmsAlreadyInSituation() throws InterruptedException { @Test public void addAlarms() throws InterruptedException { ArgumentCaptor situationCaptor = ArgumentCaptor.forClass(Situation.class); - try (Response actual = underTest.addAlarm(AlarmSetImpl.newBuilder().situationId("11").alarmIdList(Arrays.asList("7", "8")).build())) { + try (Response actual = underTest.addAlarm(AlarmSetImpl.newBuilder().situationId("11").alarmIdList(Arrays.asList("7", "8")).feedback("feedback").build())) { assertThat(actual.getStatus(), equalTo(200)); verify(situationDatasource, times(1)).forwardSituation(situationCaptor.capture()); assertThat(situationCaptor.getValue().getAlarms().size(), equalTo(6)); @@ -151,6 +154,8 @@ public void addAlarms() throws InterruptedException { .map(Alarm::getId) .collect(Collectors .toList()).containsAll(Arrays.asList("2", "3", "4", "5", "7", "8")), equalTo(true)); + assertThat(situationCaptor.getValue().getFeedback().size(), equalTo(1)); + assertThat(situationCaptor.getValue().getFeedback().get(0), equalTo("add alarm [[7, 8]] to situation [11] -- user feedback :[feedback]")); verify(situationDatasource, times(1)).getSituation(11); verify(situationDatasource, times(4)).getSituations(); } @@ -226,6 +231,10 @@ private void getAlarmsAndSituations() { .setLongId(10) .addAlarm(alarms.get(0)) .addAlarm(alarms.get(1)) + .setSeverity(Severity.MAJOR) + .setLastTime(System.currentTimeMillis()) + .setEngineParameter("engine test") + .setStatus(Status.CREATED) .build()); situations.add(ImmutableSituation.newBuilderNow() .setId("11") @@ -234,6 +243,10 @@ private void getAlarmsAndSituations() { .addAlarm(alarms.get(3)) .addAlarm(alarms.get(4)) .addAlarm(alarms.get(5)) + .setSeverity(Severity.MAJOR) + .setLastTime(System.currentTimeMillis()) + .setEngineParameter("engine test") + .setStatus(Status.CREATED) .build()); } } \ No newline at end of file From 90354e98315057ffbc779f17d3a9a49b3ba1a99e Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Tue, 29 Nov 2022 15:41:51 -0500 Subject: [PATCH 43/48] comment configuration for maven-surefire-plugin without ${argLine} jacoco won't work, but it breaks the build --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index c8e53107..e80c6e1e 100644 --- a/pom.xml +++ b/pom.xml @@ -529,10 +529,10 @@ org.apache.maven.plugins maven-surefire-plugin 2.22.1 - - - ${argLine} -Xmx1024m -Xms1024m -XX:MaxPermSize=512m -Djdk.net.URLClassPath.disableClassPathURLCheck=true - + + + + org.apache.maven.plugins From 443efcd4dba298cb0ae6851218bda6f0d3dfeb84 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Wed, 30 Nov 2022 09:41:04 -0500 Subject: [PATCH 44/48] comment configuration for maven-surefire-plugin this cause the sonar scan to fail --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e80c6e1e..146f74c1 100644 --- a/pom.xml +++ b/pom.xml @@ -529,9 +529,10 @@ org.apache.maven.plugins maven-surefire-plugin 2.22.1 + - + From 4a21599883bb8fcdc01dbd08a741c0acf96f2bac Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Wed, 30 Nov 2022 10:18:46 -0500 Subject: [PATCH 45/48] Revert "Add feedback and engine parameter to alec situations (#87)" This reverts commit 03301ea1accb91bef6884e7eb4a8a515233c083f. --- .../alec/datasource/api/Situation.java | 4 -- .../datasource/common/ImmutableSituation.java | 64 ++++++------------- .../org/opennms/alec/driver/main/Driver.java | 2 +- .../opennms/alec/driver/test/TestDriver.java | 2 - .../alec/engine/api/EngineFactory.java | 2 - .../engine/cluster/AbstractClusterEngine.java | 53 ++++++++------- .../engine/cluster/ClusterEngineFactory.java | 4 -- .../cluster/ClusterEngineSituationTest.java | 4 +- .../engine/cluster/ClusterEngineTest.java | 4 -- .../engine/dbscan/DBScanEngineFactory.java | 6 -- .../DeepLearningEngineFactory.java | 5 -- .../itest/Level1EngineComplianceTest.java | 1 - .../itest/Level2EngineComplianceTest.java | 2 - .../deeplearning/shell/Vectorize.java | 6 -- .../java/org/opennms/alec/data/AlarmSet.java | 2 - .../org/opennms/alec/data/AlarmSetImpl.java | 19 +----- .../alec/data/CreateSituationPayload.java | 2 - .../alec/data/CreateSituationPayloadImpl.java | 21 +----- .../org/opennms/alec/rest/SituationRest.java | 2 +- .../opennms/alec/rest/SituationRestImpl.java | 14 ++-- .../alec/rest/SituationRestImplTest.java | 17 +---- 21 files changed, 56 insertions(+), 180 deletions(-) diff --git a/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java b/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java index 6f27a0d9..533d9d95 100644 --- a/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java +++ b/datasource/api/src/main/java/org/opennms/alec/datasource/api/Situation.java @@ -67,8 +67,4 @@ public interface Situation { String getUei(); String getDescription(); - - List getFeedback(); - - String getEngineParameter(); } diff --git a/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java b/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java index 21adcebe..351efeda 100644 --- a/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java +++ b/datasource/common/src/main/java/org/opennms/alec/datasource/common/ImmutableSituation.java @@ -64,8 +64,6 @@ public final class ImmutableSituation implements Situation { private final Long lastTime; private final String uei; private final String description; - private final List feedbacks; - private final String engineParameter; private ImmutableSituation(Builder builder) { this.id = builder.id; @@ -83,9 +81,6 @@ private ImmutableSituation(Builder builder) { this.lastTime = builder.lastTime; this.uei = builder.uei; this.description = builder.description; - this.feedbacks = builder.feedbacks == null ? Collections.emptyList() : - Collections.unmodifiableList(new ArrayList<>(builder.feedbacks)); - this.engineParameter = builder.engineParameter; } public static final class Builder { @@ -101,8 +96,6 @@ public static final class Builder { private Long lastTime; private String uei; private String description; - private List feedbacks; - private String engineParameter; private Builder() { } @@ -124,8 +117,6 @@ private Builder(Situation situation) { this.lastTime = situation.getLastTime(); this.uei = situation.getUei(); this.description = situation.getDescription(); - this.feedbacks = new ArrayList<>(situation.getFeedback()); - this.engineParameter = situation.getEngineParameter(); } public Builder setId(String id) { @@ -221,24 +212,6 @@ public Builder setDescription(String description) { return this; } - public Builder setFeedbacks(List feedbacks) { - this.feedbacks = feedbacks; - return this; - } - - public Builder addFeedback(String feedback) { - if (feedbacks == null) { - feedbacks = new ArrayList<>(); - } - feedbacks.add(feedback); - return this; - } - - public Builder setEngineParameter(String engineParameter) { - this.engineParameter = engineParameter; - return this; - } - public ImmutableSituation build() { Objects.requireNonNull(id, "Id cannot be null"); Objects.requireNonNull(creationTime, "creation time cannot be null"); @@ -344,13 +317,27 @@ public String getDescription() { } @Override - public List getFeedback() { - return feedbacks; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ImmutableSituation that = (ImmutableSituation) o; + return creationTime == that.creationTime && + severity == that.severity && + Objects.equals(resourceKeys, that.resourceKeys) && + Objects.equals(alarms, that.alarms) && + Objects.equals(diagnosticText, that.diagnosticText) && + Objects.equals(status, that.status) && + Objects.equals(reductionKey, that.reductionKey) && + Objects.equals(lastTime, that.lastTime) && + Objects.equals(uei, that.uei) && + Objects.equals(id, that.id) && + Objects.equals(longId, that.longId) && + Objects.equals(description, that.description); } @Override - public String getEngineParameter() { - return engineParameter; + public int hashCode() { + return Objects.hash(id, longId, creationTime, resourceKeys, alarms, severity, diagnosticText, status, reductionKey, lastTime, uei, description); } @Override @@ -369,21 +356,6 @@ public String toString() { .add("lastTime=" + lastTime) .add("uei='" + uei + "'") .add("description='" + description + "'") - .add("feedbacks=" + feedbacks) - .add("engineParameter='" + engineParameter + "'") .toString(); } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ImmutableSituation that = (ImmutableSituation) o; - return longId == that.longId && creationTime == that.creationTime && Objects.equals(id, that.id) && severity == that.severity && Objects.equals(resourceKeys, that.resourceKeys) && Objects.equals(alarms, that.alarms) && Objects.equals(alarmsFromMap, that.alarmsFromMap) && Objects.equals(diagnosticText, that.diagnosticText) && status == that.status && Objects.equals(reductionKey, that.reductionKey) && Objects.equals(lastTime, that.lastTime) && Objects.equals(uei, that.uei) && Objects.equals(description, that.description) && Objects.equals(feedbacks, that.feedbacks) && Objects.equals(engineParameter, that.engineParameter); - } - - @Override - public int hashCode() { - return Objects.hash(id, longId, creationTime, severity, resourceKeys, alarms, alarmsFromMap, diagnosticText, status, reductionKey, lastTime, uei, description, feedbacks, engineParameter); - } } diff --git a/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java b/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java index c2af15cf..a4147cc3 100644 --- a/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java +++ b/driver/main/src/main/java/org/opennms/alec/driver/main/Driver.java @@ -200,7 +200,7 @@ public void onSituation(Situation situation) { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { - Thread.currentThread().setName("ALEC Driver Tick -- " + engineFactory.getParameters()); + Thread.currentThread().setName("ALEC Driver Tick"); try (com.codahale.metrics.Timer.Context context = ticks.time()) { engine.tick(System.currentTimeMillis()); } catch (Exception e) { diff --git a/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java b/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java index 33cd71c0..ca3443f8 100644 --- a/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java +++ b/driver/test/src/main/java/org/opennms/alec/driver/test/TestDriver.java @@ -152,8 +152,6 @@ private List run(List alarms, List inventory, engine.registerSituationHandler(session); engine.init(previousAlarms, previousAlarmFeedback, previousSituations, inventory); - Thread.currentThread().setName("ALEC Driver Tick -- engine"); - final GraphProvider graphProvider = getGraphProvider(engine); final boolean shouldExportGraph = isShouldExportGraph(graphProvider); long lastGraphGeneratedAt = 0; diff --git a/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java b/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java index 8b103a59..2e7f2f53 100644 --- a/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java +++ b/engine/api/src/main/java/org/opennms/alec/engine/api/EngineFactory.java @@ -40,6 +40,4 @@ public interface EngineFactory { EngineFactory getEngineFactory(); - String getParameters(); - } diff --git a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java index 6314a9d3..f90ea041 100644 --- a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java +++ b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/AbstractClusterEngine.java @@ -56,7 +56,6 @@ import org.apache.commons.math3.ml.clustering.Cluster; import org.opennms.alec.datasource.api.Alarm; import org.opennms.alec.datasource.api.AlarmFeedback; -import org.opennms.alec.datasource.api.FeedbackType; import org.opennms.alec.datasource.api.InventoryObject; import org.opennms.alec.datasource.api.Situation; import org.opennms.alec.datasource.api.SituationHandler; @@ -84,7 +83,6 @@ /** * Group alarms into situations by leveraging some clustering algorithm (i.e. DBSCAN) */ -@SuppressWarnings("java:S3776") public abstract class AbstractClusterEngine implements Engine, GraphProvider, SpatialDistanceCalculator { private static final Logger LOG = LoggerFactory.getLogger(AbstractClusterEngine.class); @@ -133,7 +131,7 @@ public abstract class AbstractClusterEngine implements Engine, GraphProvider, Sp private final AtomicInteger numEdgesFromLastTick = new AtomicInteger(-1); private final AtomicInteger numAlarmsFromLastTick = new AtomicInteger(-1); - protected AbstractClusterEngine(MetricRegistry metrics) { + public AbstractClusterEngine(MetricRegistry metrics) { metrics.gauge(name("vertices"), () -> numVerticesFromLastTick::get); metrics.gauge(name("edges"), () -> numEdgesFromLastTick::get); metrics.gauge(name("alarms"), () -> numAlarmsFromLastTick::get); @@ -192,7 +190,7 @@ public synchronized void init(List alarms, List alarmFeedb // Process all the alarm feedback provided on init alarmFeedback.forEach(this::handleAlarmFeedback); - if (!alarms.isEmpty()) { + if (alarms.size() > 0) { alarmsChangedSinceLastTick = true; } @@ -273,7 +271,7 @@ ImmutableSituation.Builder getBuilderForExistingSituationWithId(String situation throw new IllegalArgumentException("Situation with id: " + situationId + " does not exist."); } return newOrUpdatedSituationsById.computeIfAbsent(situationId, - sid -> ImmutableSituation.newBuilderFrom(existingSituation)); + (sid) -> ImmutableSituation.newBuilderFrom(existingSituation)); } ImmutableSituation.Builder getBuilderForNewSituationWithId(String situationId) { @@ -422,7 +420,7 @@ void mapClusterToSituations(Cluster clusterOfAlarms, TickConte final Alarm alarm = alarmInSpaceTime.getAlarm(); final Situation situation = alarmIdToSituationMap.get(alarm.getId()); if (situation != null) { - alarmsBySituationId.computeIfAbsent(situation.getId(), sid -> new ArrayList<>()).add(alarm); + alarmsBySituationId.computeIfAbsent(situation.getId(), (sid) -> new ArrayList<>()).add(alarm); } else { alarmsWithoutSituations.add(alarm); } @@ -430,8 +428,10 @@ void mapClusterToSituations(Cluster clusterOfAlarms, TickConte if (LOG.isDebugEnabled()) { final Map> alarmIdsBySituationIds = new LinkedHashMap<>(); - alarmsBySituationId.forEach((situationId, alarms) -> alarmIdsBySituationIds.put(situationId, alarms.stream() - .map(Alarm::getId).collect(Collectors.toList()))); + alarmsBySituationId.forEach((situationId, alarms) -> { + alarmIdsBySituationIds.put(situationId, alarms.stream() + .map(Alarm::getId).collect(Collectors.toList())); + }); LOG.debug("{}: Alarms IDs by Situations IDs in the cluster: {}", context.getTimestampInMillis(), alarmIdsBySituationIds); final List alarmIdsWithoutSituations = alarmsWithoutSituations.stream() @@ -511,10 +511,8 @@ void mapClusterToSituations(Cluster clusterOfAlarms, TickConte Collection situationBuilders = context.getBuildersForNewOrUpdatedSituations(); LOG.debug("{}: Generating diagnostic texts for {} situations...", context.getTimestampInMillis(), situationBuilders.size()); - situationBuilders.forEach(situationBuilder -> { - situationBuilder.setDiagnosticText(getDiagnosticTextForSituation(situationBuilder.build())); - situationBuilder.setEngineParameter(Thread.currentThread().getName().substring(20)); - }); + situationBuilders.forEach(situationBuilder -> + situationBuilder.setDiagnosticText(getDiagnosticTextForSituation(situationBuilder.build()))); LOG.debug("{}: Done generating diagnostic texts.", context.getTimestampInMillis()); } @@ -656,25 +654,29 @@ public void onInventoryRemoved(Collection inventory) { } @Override - @SuppressWarnings("java:S131") public void handleAlarmFeedback(AlarmFeedback alarmFeedback) { synchronized (situationsWithFeedback) { feedbackChangedSinceLastTick = true; - FeedbackType feedbackType = alarmFeedback.getFeedbackType(); - if (feedbackType == FeedbackType.FALSE_POSITIVE) { - situationAlarmBlacklist.compute(alarmFeedback.getSituationId(), (key, value) -> { - Set alarmIds = value == null ? new HashSet<>() : value; - alarmIds.add(alarmFeedback.getAlarmKey()); + switch (alarmFeedback.getFeedbackType()) { + case FALSE_POSITIVE: + situationAlarmBlacklist.compute(alarmFeedback.getSituationId(), (key, value) -> { + Set alarmIds = value == null ? new HashSet<>() : value; + alarmIds.add(alarmFeedback.getAlarmKey()); - return alarmIds; - }); + return alarmIds; + }); - situationsWithFeedback.add(alarmFeedback.getSituationId()); - } else if (feedbackType == FeedbackType.FALSE_NEGATIVE && situationAlarmBlacklist.containsKey(alarmFeedback.getSituationId())) { - situationAlarmBlacklist.get(alarmFeedback.getSituationId()) - .remove(alarmFeedback.getAlarmKey()); + situationsWithFeedback.add(alarmFeedback.getSituationId()); + + break; + case FALSE_NEGATIVE: + if (situationAlarmBlacklist.containsKey(alarmFeedback.getSituationId())) { + situationAlarmBlacklist.get(alarmFeedback.getSituationId()) + .remove(alarmFeedback.getAlarmKey()); + } + break; } } } @@ -764,7 +766,6 @@ private long getVertexIdForAlarm(Alarm alarm) { * @param distance spatial distance between alarm1 and alarm2 * @return effective distance between alarm1 and alarm2 */ - @SuppressWarnings("java:S1172") public double getDistanceBetween(double t1, double t2, double firstTimeA, double firstTimeB, double distance) { return Math.abs(t2 - t1) + distance; } @@ -790,7 +791,6 @@ private Alarm getClosestNeighborInSituation(Alarm alarm, List candidates) } @Override - @SuppressWarnings("java:S112") public double getSpatialDistanceBetween(long vertexIdA, long vertexIdB) { final EdgeKey key = new EdgeKey(vertexIdA, vertexIdB); try { @@ -800,7 +800,6 @@ public double getSpatialDistanceBetween(long vertexIdA, long vertexIdB) { } } - @SuppressWarnings("java:S2153") private final LoadingCache spatialDistances = CacheBuilder.newBuilder() .maximumSize(10000) .build(new CacheLoader() { diff --git a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java index ec51f180..35be7897 100644 --- a/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java +++ b/engine/cluster/src/main/java/org/opennms/alec/engine/cluster/ClusterEngineFactory.java @@ -55,8 +55,4 @@ public EngineFactory getEngineFactory() { return this; } - @Override - public String getParameters() { - return String.format("engine: %s", getName()); - } } diff --git a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java index 82dac162..43beb2c8 100644 --- a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java +++ b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineSituationTest.java @@ -82,7 +82,6 @@ public void canHandleExistingSituations() { // No situations should have been triggered yet assertThat(triggeredSituations, hasSize(0)); - Thread.currentThread().setName("ALEC Driver Tick -- engine"); ClusterEngine clusterEngine = new ClusterEngine(new MetricRegistry()); clusterEngine.init(alarms, Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); clusterEngine.registerSituationHandler(this); @@ -156,7 +155,7 @@ public void canHandleSituationThatIncludesADeadVertex() { // No situations should have been triggered yet assertThat(triggeredSituations, hasSize(0)); - Thread.currentThread().setName("ALEC Driver Tick -- engine"); + Engine oneClusterEngine = new OneClusterEngine(new MetricRegistry()); oneClusterEngine.init(alarms, Collections.emptyList(), Collections.emptyList(), MockInventory.SAMPLE_NETWORK); oneClusterEngine.registerSituationHandler(this); @@ -225,7 +224,6 @@ public void canHandleSituationWithNonEligbleVertex() { // No situations should have been triggered yet assertThat(triggeredSituations, hasSize(0)); - Thread.currentThread().setName("ALEC Driver Tick -- engine"); Engine oneClusterEngine = new OneClusterEngine(new MetricRegistry()); oneClusterEngine.init(alarms, Collections.emptyList(), Collections.emptyList(), MockInventory.SAMPLE_NETWORK); oneClusterEngine.registerSituationHandler(this); diff --git a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java index 8b764cf2..3a9808e8 100644 --- a/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java +++ b/engine/cluster/src/test/java/org/opennms/alec/engine/cluster/ClusterEngineTest.java @@ -152,7 +152,6 @@ public void canClusterAlarmsAndDeleteSituations() { assertThat(situationsById.keySet(), hasSize(0)); // Tick - Thread.currentThread().setName("ALEC Driver Tick -- engine"); engine.tick(now+2); // We should now have a single situation with both alarms @@ -246,7 +245,6 @@ public void canBlacklistAlarms() { assertThat(situationsById.keySet(), hasSize(0)); // Tick - Thread.currentThread().setName("ALEC Driver Tick -- engine"); engine.tick(now+2); // We should now have a single situation with both alarms @@ -299,7 +297,6 @@ public void canHandleAlarmsInClusters() { // A cluster with a single alarm that was not previously mapped to a situation should be in a new situation Cluster cluster = new Cluster<>(); cluster.addPoint(alarm1InSpaceTime); - Thread.currentThread().setName("ALEC Driver Tick -- engine"); context = engine.getTickContextFor(0L); engine.mapClusterToSituations(cluster, context); situations = context.getNewOrUpdatedSituations(); @@ -379,7 +376,6 @@ public void canUpdateExistingSituationsWithManyAlarmsInCluster() { cluster.addPoint(alarm4InSpaceTime); // Process the cluster - Thread.currentThread().setName("ALEC Driver Tick -- engine"); engine.solveEntireGraphForTesting(); engine.setSituations(Arrays.asList(situation1, situation2)); AbstractClusterEngine.TickContext context = engine.getTickContextFor(0L); diff --git a/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java b/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java index 4ed4d3a1..10860950 100644 --- a/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java +++ b/engine/dbscan/src/main/java/org/opennms/alec/engine/dbscan/DBScanEngineFactory.java @@ -94,12 +94,6 @@ public EngineFactory getEngineFactory() { return this; } - @Override - public String getParameters() { - return String.format("engine: %s, alpha: %s, beta: %s, epsilon: %s, distanceMeasure: %s", - getName(), getAlpha(), getBeta(), getEpsilon(), getDistanceMeasureFactoryName()); - } - public double getEpsilon() { return epsilon; } diff --git a/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java b/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java index 0e153a6f..f498b2ae 100644 --- a/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java +++ b/engine/deeplearning/src/main/java/org/opennms/alec/engine/deeplearning/DeepLearningEngineFactory.java @@ -83,11 +83,6 @@ public EngineFactory getEngineFactory() { return this; } - @Override - public String getParameters() { - return String.format("engine: %s", getName()); - } - public void setToken(String token) { this.token = token; } diff --git a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java index d9214367..7b4dfd54 100644 --- a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java +++ b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level1EngineComplianceTest.java @@ -101,7 +101,6 @@ public void setUp() { driver = TestDriver.builder() .withEngineFactory(factory) .build(); - Thread.currentThread().setName("ALEC Driver Tick -- engine"); } @Test diff --git a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java index d70e1be5..f3e88777 100644 --- a/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java +++ b/engine/itest/src/test/java/org/opennms/alec/engine/itest/Level2EngineComplianceTest.java @@ -87,8 +87,6 @@ public void setUp() { driver = TestDriver.builder() .withEngineFactory(factory) .build(); - - Thread.currentThread().setName("ALEC Driver Tick -- engine"); } @Test diff --git a/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java b/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java index 7e14e804..362763c3 100644 --- a/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java +++ b/features/deeplearning/src/main/java/org/opennms/features/deeplearning/shell/Vectorize.java @@ -87,7 +87,6 @@ public class Vectorize implements Action { private String csvOut; @Override - @SuppressWarnings({"java:S106","java:S112"}) public Object execute() throws Exception { final List alarms = JaxbUtils.getAlarms(Paths.get(alarmsIn)); final List inventory = JaxbUtils.getInventory(Paths.get(inventoryIn)); @@ -201,11 +200,6 @@ public Engine createEngine(MetricRegistry metrics) { public EngineFactory getEngineFactory() { return this; } - - @Override - public String getParameters() { - return String.format("engine: %s", getName()); - } } private void streamVectors(List inventory, List alarms, Set situations, Consumer consumer) { diff --git a/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java b/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java index eeb96d80..a9382c29 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java +++ b/features/ui/src/main/java/org/opennms/alec/data/AlarmSet.java @@ -38,6 +38,4 @@ public interface AlarmSet { String getSituationId(); List getAlarmIdList(); - - String getFeedback(); } diff --git a/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java b/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java index 5c9f6cfa..97253c12 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/data/AlarmSetImpl.java @@ -35,24 +35,20 @@ public class AlarmSetImpl implements AlarmSet { private final String situationId; private final List alarmIdList; - private final String feedback; - private AlarmSetImpl(Builder builder) { situationId = builder.situationId; alarmIdList = builder.alarmIdList; - feedback = builder.feedback; } - public static Builder newBuilder() { - return new Builder(); + public static AlarmSetImpl.Builder newBuilder() { + return new AlarmSetImpl.Builder(); } public static Builder newBuilder(AlarmSet copy) { Builder builder = new Builder(); builder.situationId = copy.getSituationId(); builder.alarmIdList = copy.getAlarmIdList(); - builder.feedback = copy.getFeedback(); return builder; } @@ -60,7 +56,6 @@ public static Builder newBuilder(AlarmSet copy) { public static final class Builder { private String situationId; private List alarmIdList; - private String feedback; private Builder() { } @@ -79,11 +74,6 @@ public Builder alarmIdList(List val) { return this; } - public Builder feedback(String val) { - feedback = val; - return this; - } - public AlarmSetImpl build() { return new AlarmSetImpl(this); } @@ -98,9 +88,4 @@ public String getSituationId() { public List getAlarmIdList() { return alarmIdList; } - - @Override - public String getFeedback() { - return feedback; - } } diff --git a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java index 16356add..3da0f9a0 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java +++ b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayload.java @@ -39,6 +39,4 @@ public interface CreateSituationPayload { String getDiagnosticText(); String getDescription(); - - String getFeedback(); } diff --git a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java index c80f9bcf..2351979c 100644 --- a/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/data/CreateSituationPayloadImpl.java @@ -37,26 +37,22 @@ public class CreateSituationPayloadImpl implements CreateSituationPayload { private final List alarmIdList; private final String diagnosticText; private final String description; - private final String feedback; - private CreateSituationPayloadImpl(Builder builder) { alarmIdList = builder.alarmIdList; diagnosticText = builder.diagnosticText; description = builder.description; - feedback = builder.feedback; } public static Builder newBuilder() { return new Builder(); } - public static Builder newBuilder(CreateSituationPayload copy) { + public static Builder newBuilder(CreateSituationPayloadImpl copy) { Builder builder = new Builder(); builder.alarmIdList = copy.getAlarmIdList(); builder.diagnosticText = copy.getDiagnosticText(); builder.description = copy.getDescription(); - builder.feedback = copy.getFeedback(); return builder; } @@ -65,15 +61,10 @@ public static final class Builder { private List alarmIdList; private String diagnosticText; private String description; - private String feedback; private Builder() { } - public static Builder newBuilder() { - return new Builder(); - } - public Builder alarmIdList(List val) { alarmIdList = val; return this; @@ -89,11 +80,6 @@ public Builder description(String val) { return this; } - public Builder feedback(String val) { - feedback = val; - return this; - } - public CreateSituationPayloadImpl build() { return new CreateSituationPayloadImpl(this); } @@ -113,9 +99,4 @@ public String getDiagnosticText() { public String getDescription() { return description; } - - @Override - public String getFeedback() { - return feedback; - } } diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java index b4f81193..af283203 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRest.java @@ -48,7 +48,7 @@ public interface SituationRest { @POST @Path("rejected/{id}") - Response rejected(@PathParam("id") String id, String feedback); + Response rejected(@PathParam("id") String id); @POST @Path("accepted/{id}") diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java index e7dfb554..e43de849 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java @@ -80,22 +80,20 @@ public SituationRestImpl(KeyValueStore kvStore, } @Override - public Response rejected(String situationId, String feedback) { + public Response rejected(String situationId) { try { Optional situationOptional = situationDatasource.getSituation(Integer.parseInt(situationId)); if (situationOptional.isPresent()) { - final Situation situation = situationOptional.get(); + Situation situation = situationOptional.get(); //check status if (Status.REJECTED.equals(situation.getStatus())) { LOG.debug("Situation {} already rejected", situationId); return Response.accepted(MessageFormat.format("Situation {0} already rejected", situationId)).build(); } - feedback = String.format("reject situation [%s] -- user feedback :[%s]", situationId, feedback); Situation situationRejected = ImmutableSituation.newBuilderFrom(situation) .setStatus(Status.REJECTED) .setAlarms(Collections.emptySet()) .setSeverity(Severity.CLEARED) - .addFeedback(feedback) .build(); return forwardAndStoreSituation(situationRejected, situationRejected.getAlarms()); } @@ -165,8 +163,7 @@ public Response addAlarm(AlarmSet alarm) { if (oldSituation.getAlarms().equals(alarmSet)) { return ALECRestUtils.noContent(); } - String feedback = String.format("add alarm [%s] to situation [%s] -- user feedback :[%s]", alarm.getAlarmIdList(), alarm.getSituationId(), alarm.getFeedback()); - return forwardAndStoreSituation(ImmutableSituation.newBuilderFrom(oldSituation).addFeedback(feedback).build(), alarmSet); + return forwardAndStoreSituation(oldSituation, alarmSet); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -189,8 +186,7 @@ public Response removeAlarm(AlarmSet alarm) { if (oldSituation.getAlarms().equals(alarmSet)) { return ALECRestUtils.noContent(); } else { - String feedback = String.format("remove alarms [%s] to situation [%s] -- user feedback :[%s]", alarm.getAlarmIdList(), situationId, alarm.getFeedback()); - return forwardAndStoreSituation(ImmutableSituation.newBuilderFrom(oldSituation).addFeedback(feedback).build(), alarmSet); + return forwardAndStoreSituation(oldSituation, alarmSet); } } } catch (InterruptedException e) { @@ -222,8 +218,6 @@ public Response createSituation(CreateSituationPayload createSituationPayload) { .setDiagnosticText(createSituationPayload.getDiagnosticText()) .setDescription(createSituationPayload.getDescription()) .setSeverity(maxSeverity) - .setEngineParameter("user created") - .addFeedback(createSituationPayload.getFeedback()) .build(); if (situation.getAlarms().size() >= 2) { situationDatasource.forwardSituation(situation); diff --git a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java index 32a196c5..ece1a594 100644 --- a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java +++ b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java @@ -28,7 +28,6 @@ import org.opennms.alec.data.CreateSituationPayloadImpl; import org.opennms.alec.data.SituationStatus; import org.opennms.alec.datasource.api.Alarm; -import org.opennms.alec.datasource.api.Severity; import org.opennms.alec.datasource.api.Situation; import org.opennms.alec.datasource.api.SituationDatasource; import org.opennms.alec.datasource.api.Status; @@ -66,12 +65,10 @@ public void tearDown() { @Test public void rejected() throws InterruptedException { ArgumentCaptor situationCaptor = ArgumentCaptor.forClass(Situation.class); - try (Response actual = underTest.rejected("11", "rejected")) { + try (Response actual = underTest.rejected("11")) { assertThat(actual.getStatus(), equalTo(200)); verify(situationDatasource, times(1)).forwardSituation(situationCaptor.capture()); assertThat(situationCaptor.getValue().getStatus(), equalTo(Status.REJECTED)); - assertThat(situationCaptor.getValue().getFeedback().size(), equalTo(1)); - assertThat(situationCaptor.getValue().getFeedback().get(0), equalTo("reject situation [11] -- user feedback :[rejected]")); assertThat(situationCaptor.getValue().getAlarms().size(), equalTo(0)); verify(situationDatasource, times(1)).getSituation(11); verify(situationDatasource, times(2)).getSituations(); @@ -146,7 +143,7 @@ public void addAlarmsAlreadyInSituation() throws InterruptedException { @Test public void addAlarms() throws InterruptedException { ArgumentCaptor situationCaptor = ArgumentCaptor.forClass(Situation.class); - try (Response actual = underTest.addAlarm(AlarmSetImpl.newBuilder().situationId("11").alarmIdList(Arrays.asList("7", "8")).feedback("feedback").build())) { + try (Response actual = underTest.addAlarm(AlarmSetImpl.newBuilder().situationId("11").alarmIdList(Arrays.asList("7", "8")).build())) { assertThat(actual.getStatus(), equalTo(200)); verify(situationDatasource, times(1)).forwardSituation(situationCaptor.capture()); assertThat(situationCaptor.getValue().getAlarms().size(), equalTo(6)); @@ -154,8 +151,6 @@ public void addAlarms() throws InterruptedException { .map(Alarm::getId) .collect(Collectors .toList()).containsAll(Arrays.asList("2", "3", "4", "5", "7", "8")), equalTo(true)); - assertThat(situationCaptor.getValue().getFeedback().size(), equalTo(1)); - assertThat(situationCaptor.getValue().getFeedback().get(0), equalTo("add alarm [[7, 8]] to situation [11] -- user feedback :[feedback]")); verify(situationDatasource, times(1)).getSituation(11); verify(situationDatasource, times(4)).getSituations(); } @@ -231,10 +226,6 @@ private void getAlarmsAndSituations() { .setLongId(10) .addAlarm(alarms.get(0)) .addAlarm(alarms.get(1)) - .setSeverity(Severity.MAJOR) - .setLastTime(System.currentTimeMillis()) - .setEngineParameter("engine test") - .setStatus(Status.CREATED) .build()); situations.add(ImmutableSituation.newBuilderNow() .setId("11") @@ -243,10 +234,6 @@ private void getAlarmsAndSituations() { .addAlarm(alarms.get(3)) .addAlarm(alarms.get(4)) .addAlarm(alarms.get(5)) - .setSeverity(Severity.MAJOR) - .setLastTime(System.currentTimeMillis()) - .setEngineParameter("engine test") - .setStatus(Status.CREATED) .build()); } } \ No newline at end of file From 4954f4061866ced6108f9076c6e96f50944c226a Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Wed, 30 Nov 2022 10:19:34 -0500 Subject: [PATCH 46/48] Revert "Feature/fix smoke test (#91)" This reverts commit ff36901a621df726119a4a631f34671b050f9982. --- .../cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml | 2 +- .../smoke/correlation/DistributedStandaloneCorrelationTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 09aaf7de..5b93769a 100644 --- a/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/engine/cluster/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -2,7 +2,7 @@ > - + diff --git a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java index a9f1d462..81542ed5 100644 --- a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java +++ b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java @@ -76,7 +76,7 @@ private void verifyCorrectEngineIsRunning() { LOG.debug("Checking for engine {}", engine); await() - .atMost(30, TimeUnit. + .atMost(60, TimeUnit. SECONDS) .pollInterval(5, TimeUnit.SECONDS) .ignoreExceptions() From df5c12794bf5da58f87eb9d05e5b7ac604083cdc Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Wed, 30 Nov 2022 10:19:34 -0500 Subject: [PATCH 47/48] Revert "increase timeout from 30 seconds to 60 seconds (#89)" This reverts commit 3640d55bdb54e545bad92dbe1ec0c4ed75cab74e. --- .../smoke/correlation/DistributedStandaloneCorrelationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java index 81542ed5..a9f1d462 100644 --- a/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java +++ b/smoke-test/src/test/java/org/opennms/alec/smoke/correlation/DistributedStandaloneCorrelationTest.java @@ -76,7 +76,7 @@ private void verifyCorrectEngineIsRunning() { LOG.debug("Checking for engine {}", engine); await() - .atMost(60, TimeUnit. + .atMost(30, TimeUnit. SECONDS) .pollInterval(5, TimeUnit.SECONDS) .ignoreExceptions() From 9d0d71121a54101b7cffc0da89d83a90b7849546 Mon Sep 17 00:00:00 2001 From: Benjamin Janssens Date: Wed, 30 Nov 2022 10:19:34 -0500 Subject: [PATCH 48/48] Revert "Fix getSituationStatusList (#88)" This reverts commit 6749e602df9bfa41aa29ed5779fc6a17f1d871b9. --- .../main/java/org/opennms/alec/rest/SituationRestImpl.java | 2 +- .../java/org/opennms/alec/rest/SituationRestImplTest.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java index e43de849..508ef796 100644 --- a/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java +++ b/features/ui/src/main/java/org/opennms/alec/rest/SituationRestImpl.java @@ -130,7 +130,7 @@ public Response getSituationStatusList() { try { List situationStatusList = new ArrayList<>(); situationDatasource.getSituations().forEach(o -> situationStatusList.add(SituationStatusImpl.newBuilder() - .id(String.valueOf(o.getLongId())) + .id(o.getId()) .status(o.getStatus()) .build())); List sorted = situationStatusList.stream().sorted(Comparator.comparing(SituationStatus::getStatus)).collect(Collectors.toList()); diff --git a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java index ece1a594..720c9a44 100644 --- a/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java +++ b/features/ui/src/test/java/org/opennms/alec/rest/SituationRestImplTest.java @@ -210,8 +210,6 @@ public void getSituationStatusList() throws InterruptedException { assertThat(actual.getStatus(), equalTo(200)); List situationList = (List) actual.getEntity(); assertThat(situationList.size(), equalTo(2)); - assertThat(situationList.get(0).getId(), equalTo("10")); - assertThat(situationList.get(1).getId(), equalTo("11")); verify(situationDatasource, times(1)).getSituations(); } } @@ -223,13 +221,11 @@ private void getAlarmsAndSituations() { situations.add(ImmutableSituation.newBuilderNow() .setId("10") - .setLongId(10) .addAlarm(alarms.get(0)) .addAlarm(alarms.get(1)) .build()); situations.add(ImmutableSituation.newBuilderNow() .setId("11") - .setLongId(11) .addAlarm(alarms.get(2)) .addAlarm(alarms.get(3)) .addAlarm(alarms.get(4))