From 6c919ed76d6a31cdd73256f37462d9cdd12043c6 Mon Sep 17 00:00:00 2001 From: "DIR\\luca.ciccarelli" Date: Wed, 13 Sep 2023 18:12:26 +0200 Subject: [PATCH 01/62] start project structure --- .gitignore | 33 ++ Dockerfile | 9 + config/application.properties | 8 + lombok.config | 3 + mvnw | 316 ++++++++++++++++++ mvnw.cmd | 188 +++++++++++ pom.xml | 197 +++++++++++ .../SignalHubSignalsPersisterApplication.java | 20 ++ src/main/resources/application.properties | 14 + 9 files changed, 788 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 config/application.properties create mode 100644 lombok.config create mode 100644 mvnw create mode 100644 mvnw.cmd create mode 100644 pom.xml create mode 100644 src/main/java/it/pagopa/interop/signalhub/signals/persister/SignalHubSignalsPersisterApplication.java create mode 100644 src/main/resources/application.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3aa2b86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM maven:3.8.3-openjdk-17 AS MAVEN_BUILD +WORKDIR /interop-be-signal/ +COPY . . +RUN mvn -q clean package -Dmaven.test.skip=true + +FROM eclipse-temurin:17-jre-alpine +WORKDIR /app +COPY --from=MAVEN_BUILD /interop-be-signal/target/*.jar /app/app.jar +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/config/application.properties b/config/application.properties new file mode 100644 index 0000000..440a8f2 --- /dev/null +++ b/config/application.properties @@ -0,0 +1,8 @@ +aws.profile-name=default +aws.region-code=us-east-1 +aws.bucket-name= +aws.dynamodb-endpoint=http://localhost:4566 + +aws.name-pod_ms=signal-hub-pod + +aws.internal-queue-name=internal-queue diff --git a/lombok.config b/lombok.config new file mode 100644 index 0000000..5ca90ea --- /dev/null +++ b/lombok.config @@ -0,0 +1,3 @@ +lombok.addLombokGeneratedAnnotation = true + +lombok.log.custom.declaration = it.pagopa.sh.shperformancetest.abstractions.log.PnLogger.getLogger(NAME) \ No newline at end of file diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..8a8fb22 --- /dev/null +++ b/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..1d8ab01 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..17708bf --- /dev/null +++ b/pom.xml @@ -0,0 +1,197 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.2 + + + it.pagopa.interop + signalhub-signal-persister + 0.0.1-SNAPSHOT + signalhub signals persister + Signals persister microservice + + 17 + UTF-8 + 5.6.15.Final + 2.11.0 + 2.8.0 + 0.2.1 + 2.3.1 + 1.18.24 + 0.2.0 + + 1.5.1.Final + 2.13.4 + + + + + io.awspring.cloud + spring-cloud-aws-dependencies + 3.0.1 + pom + import + + + + + + com.amazonaws + aws-xray-recorder-sdk-apache-http + ${com.amazonaws.version} + + + + + com.amazonaws + aws-xray-recorder-sdk-spring + ${com.amazonaws.version} + + + javax.xml.bind + jaxb-api + ${javax.xml.bind.version} + + + org.openapitools + jackson-databind-nullable + ${org.openapitools.version} + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-data-r2dbc + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-reactor-netty + + + io.springfox + springfox-swagger2 + ${io.springfox.version} + + + io.springfox + springfox-swagger-ui + ${io.springfox.version} + + + org.projectlombok + lombok + ${org.projectlombok.version} + + + org.projectlombok + lombok-mapstruct-binding + ${org.projectlombok.mapstruct.version} + + + org.apache.commons + commons-lang3 + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-core + + + ch.qos.logback + logback-classic + + + + io.projectreactor + reactor-test + test + + + + io.awspring.cloud + spring-cloud-aws-starter-sqs + + + + software.amazon.awssdk + sts + + + org.liquibase + liquibase-core + 4.23.0 + + + com.auth0 + java-jwt + 4.3.0 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 3.1.2 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + 17 + + + org.projectlombok + lombok + 1.18.24 + + + org.mapstruct + mapstruct-processor + 1.5.1.Final + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/SignalHubSignalsPersisterApplication.java b/src/main/java/it/pagopa/interop/signalhub/signals/persister/SignalHubSignalsPersisterApplication.java new file mode 100644 index 0000000..2170e4c --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/signals/persister/SignalHubSignalsPersisterApplication.java @@ -0,0 +1,20 @@ +package it.pagopa.interop.signalhub.signals.persister; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.r2dbc.config.EnableR2dbcAuditing; + +@Slf4j +@SpringBootApplication +@EnableR2dbcAuditing +public class SignalHubSignalsPersisterApplication { + + public static void main(String[] args) { + + log.error("AVAILABLE PROCESSOR: {}", Runtime.getRuntime().availableProcessors() ); + + SpringApplication.run(SignalHubSignalsPersisterApplication.class, args); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..2d67783 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,14 @@ +logging.level.root=INFO +spring.main.web-appplication-type=reactive + +cloud.aws.region.auto=true + +# Load instance profile credentials +cloud.aws.credentials.instanceProfile=true + +# Disable auto cloud formation +cloud.aws.stack.auto=false + +aws.sqs-endpoint=http://localhost:4566/000000000000/ +aws.internal-queue-name=internal-queue +aws.pull-limit=100 From c995ee02daaddc4ef03c6998ce93f84acbf36118 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Mon, 18 Sep 2023 13:06:41 +0200 Subject: [PATCH 02/62] added config --- pom.xml | 2 +- .../persister/config/AwsBeanBuilder.java | 81 +++++++++++++++++++ .../persister/config/AwsPropertiesConfig.java | 17 ++++ .../config/SignalHubPersisterConfig.java | 17 ++++ .../queue/consumer/SqsInternalListener.java | 23 ++++++ .../persister/queue/model/SignalEvent.java | 4 + 6 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsBeanBuilder.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsPropertiesConfig.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/signals/persister/config/SignalHubPersisterConfig.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/consumer/SqsInternalListener.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java diff --git a/pom.xml b/pom.xml index 17708bf..48b1a74 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 2.5.2 - it.pagopa.interop + it.pagopa.interop.signalhub.signals.persister signalhub-signal-persister 0.0.1-SNAPSHOT signalhub signals persister diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsBeanBuilder.java new file mode 100644 index 0000000..89e0c3d --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsBeanBuilder.java @@ -0,0 +1,81 @@ +package it.pagopa.interop.signalhub.signals.persister.config; + +import io.awspring.cloud.sqs.config.SqsBootstrapConfiguration; +import io.awspring.cloud.sqs.config.SqsMessageListenerContainerFactory; +import io.awspring.cloud.sqs.operations.SqsTemplate; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; +import software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider; +import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.sqs.SqsAsyncClient; + +import java.net.URI; + +@Import(SqsBootstrapConfiguration.class) +@Configuration +@Slf4j +public class AwsBeanBuilder { + + private final AwsPropertiesConfig props; + private final SignalHubPersisterConfig signalHubPersisterConfig; + + public AwsBeanBuilder(AwsPropertiesConfig props, SignalHubPersisterConfig signalHubPersisterConfig) { + this.props = props; + this.signalHubPersisterConfig = signalHubPersisterConfig; + } + + @Bean + public SqsAsyncClient sqsAsyncClient() { + return configureBuilder(SqsAsyncClient.builder(), props.getEndpointUrlSqs()); + } + + @Bean + public SqsTemplate sqsTemplate() { + return SqsTemplate.builder().sqsAsyncClient(sqsAsyncClient()) + .configure(options -> options.defaultQueue(signalHubPersisterConfig.getInternalQueueName())) + .build(); + } + + @Bean + public SqsMessageListenerContainerFactory defaultSqsListenerContainerFactory() { + return SqsMessageListenerContainerFactory + .builder() + .configure(options -> options + .maxConcurrentMessages(10) + .maxMessagesPerPoll(10)) + .sqsAsyncClient(sqsAsyncClient()) + .build(); + } + + private C configureBuilder(AwsClientBuilder builder, String endpoint) { + if( props != null ) { + + String profileName = props.getProfile(); + if( StringUtils.isNotBlank( profileName ) ) { + builder.credentialsProvider( ProfileCredentialsProvider.create( profileName ) ); + } else { + log.debug("Using WebIdentityTokenFileCredentialsProvider"); + builder.credentialsProvider( WebIdentityTokenFileCredentialsProvider.create() ); + } + + String regionCode = props.getRegion(); + if( StringUtils.isNotBlank( regionCode )) { + log.debug("Setting region to: {}", regionCode); + builder.region( Region.of( regionCode )); + } + + if( StringUtils.isNotBlank( endpoint )) { + builder.endpointOverride(URI.create(endpoint)); + } + + } + + return builder.build(); + } + +} \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsPropertiesConfig.java b/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsPropertiesConfig.java new file mode 100644 index 0000000..9fc6b30 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsPropertiesConfig.java @@ -0,0 +1,17 @@ +package it.pagopa.interop.signalhub.signals.persister.config; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Getter +@Setter +@Configuration +@ConfigurationProperties(prefix = "aws") +public class AwsPropertiesConfig { + private String profile; + private String region; + private String endpointUrl; + private String endpointUrlSqs; +} diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/SignalHubPersisterConfig.java b/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/SignalHubPersisterConfig.java new file mode 100644 index 0000000..8edd31e --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/SignalHubPersisterConfig.java @@ -0,0 +1,17 @@ +package it.pagopa.interop.signalhub.signals.persister.config; + + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Getter +@Setter +@Configuration +@ConfigurationProperties(prefix = "poc.signal-hub") +public class SignalHubPersisterConfig { + + private String internalQueueName; + +} diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/consumer/SqsInternalListener.java new file mode 100644 index 0000000..08ddd61 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/consumer/SqsInternalListener.java @@ -0,0 +1,23 @@ +package it.pagopa.interop.signalhub.signals.persister.queue.consumer; + + +import io.awspring.cloud.sqs.annotation.SqsListener; +import lombok.extern.slf4j.Slf4j; +import org.springframework.messaging.handler.annotation.Headers; +import org.springframework.stereotype.Component; + +import java.util.Map; +import java.util.concurrent.CompletableFuture; + + +@Slf4j +@Component +public class SqsInternalListener { + + + @SqsListener + public CompletableFuture listen(String node, @Headers Map headers) { + return CompletableFuture.completedFuture(null); + } + +} diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java b/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java new file mode 100644 index 0000000..dfd33ca --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java @@ -0,0 +1,4 @@ +package it.pagopa.interop.signalhub.signals.persister.queue.model; + +public class SignalEvent { +} From d799135fe76849b199713dc2e4122a9a8ed185fb Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Tue, 19 Sep 2023 10:50:32 +0200 Subject: [PATCH 03/62] refactor package name, added test config --- pom.xml | 21 ++++++- .../SignalHubSignalsPersisterApplication.java | 2 +- .../persister/config/AwsBeanBuilder.java | 14 +---- .../persister/config/AwsPropertiesConfig.java | 2 +- .../config/SignalHubPersisterConfig.java | 2 +- .../queue/consumer/SqsInternalListener.java | 6 +- .../persister/queue/model/SignalEvent.java | 4 ++ .../persister/queue/model/SignalEvent.java | 4 -- .../signalhub/persister/ApplicationTest.java | 23 +++++++ .../resources/application-test.properties | 20 ++++++ src/test/resources/data-h2.sql | 0 src/test/resources/schema-h2.sql | 62 +++++++++++++++++++ src/test/resources/testcontainers/credentials | 4 ++ src/test/resources/testcontainers/init.sh | 15 +++++ 14 files changed, 155 insertions(+), 24 deletions(-) rename src/main/java/it/pagopa/interop/signalhub/{signals => }/persister/SignalHubSignalsPersisterApplication.java (90%) rename src/main/java/it/pagopa/interop/signalhub/{signals => }/persister/config/AwsBeanBuilder.java (79%) rename src/main/java/it/pagopa/interop/signalhub/{signals => }/persister/config/AwsPropertiesConfig.java (86%) rename src/main/java/it/pagopa/interop/signalhub/{signals => }/persister/config/SignalHubPersisterConfig.java (84%) rename src/main/java/it/pagopa/interop/signalhub/{signals => }/persister/queue/consumer/SqsInternalListener.java (80%) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java delete mode 100644 src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java create mode 100644 src/test/resources/application-test.properties create mode 100644 src/test/resources/data-h2.sql create mode 100644 src/test/resources/schema-h2.sql create mode 100644 src/test/resources/testcontainers/credentials create mode 100644 src/test/resources/testcontainers/init.sh diff --git a/pom.xml b/pom.xml index 48b1a74..0fe2590 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 2.5.2 - it.pagopa.interop.signalhub.signals.persister + it.pagopa.interop.signalhub.persister signalhub-signal-persister 0.0.1-SNAPSHOT signalhub signals persister @@ -138,6 +138,18 @@ test + + com.h2database + h2 + runtime + + + + io.r2dbc + r2dbc-h2 + runtime + + io.awspring.cloud spring-cloud-aws-starter-sqs @@ -157,6 +169,13 @@ java-jwt 4.3.0 + + + org.testcontainers + localstack + 1.17.6 + test + diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/SignalHubSignalsPersisterApplication.java b/src/main/java/it/pagopa/interop/signalhub/persister/SignalHubSignalsPersisterApplication.java similarity index 90% rename from src/main/java/it/pagopa/interop/signalhub/signals/persister/SignalHubSignalsPersisterApplication.java rename to src/main/java/it/pagopa/interop/signalhub/persister/SignalHubSignalsPersisterApplication.java index 2170e4c..193daf6 100644 --- a/src/main/java/it/pagopa/interop/signalhub/signals/persister/SignalHubSignalsPersisterApplication.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/SignalHubSignalsPersisterApplication.java @@ -1,4 +1,4 @@ -package it.pagopa.interop.signalhub.signals.persister; +package it.pagopa.interop.signalhub.persister; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java similarity index 79% rename from src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsBeanBuilder.java rename to src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java index 89e0c3d..078c919 100644 --- a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsBeanBuilder.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java @@ -1,8 +1,7 @@ -package it.pagopa.interop.signalhub.signals.persister.config; +package it.pagopa.interop.signalhub.persister.config; import io.awspring.cloud.sqs.config.SqsBootstrapConfiguration; import io.awspring.cloud.sqs.config.SqsMessageListenerContainerFactory; -import io.awspring.cloud.sqs.operations.SqsTemplate; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Bean; @@ -22,11 +21,9 @@ public class AwsBeanBuilder { private final AwsPropertiesConfig props; - private final SignalHubPersisterConfig signalHubPersisterConfig; - public AwsBeanBuilder(AwsPropertiesConfig props, SignalHubPersisterConfig signalHubPersisterConfig) { + public AwsBeanBuilder(AwsPropertiesConfig props) { this.props = props; - this.signalHubPersisterConfig = signalHubPersisterConfig; } @Bean @@ -34,13 +31,6 @@ public SqsAsyncClient sqsAsyncClient() { return configureBuilder(SqsAsyncClient.builder(), props.getEndpointUrlSqs()); } - @Bean - public SqsTemplate sqsTemplate() { - return SqsTemplate.builder().sqsAsyncClient(sqsAsyncClient()) - .configure(options -> options.defaultQueue(signalHubPersisterConfig.getInternalQueueName())) - .build(); - } - @Bean public SqsMessageListenerContainerFactory defaultSqsListenerContainerFactory() { return SqsMessageListenerContainerFactory diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsPropertiesConfig.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsPropertiesConfig.java similarity index 86% rename from src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsPropertiesConfig.java rename to src/main/java/it/pagopa/interop/signalhub/persister/config/AwsPropertiesConfig.java index 9fc6b30..57bbaaf 100644 --- a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/AwsPropertiesConfig.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsPropertiesConfig.java @@ -1,4 +1,4 @@ -package it.pagopa.interop.signalhub.signals.persister.config; +package it.pagopa.interop.signalhub.persister.config; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/SignalHubPersisterConfig.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java similarity index 84% rename from src/main/java/it/pagopa/interop/signalhub/signals/persister/config/SignalHubPersisterConfig.java rename to src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java index 8edd31e..8286cd2 100644 --- a/src/main/java/it/pagopa/interop/signalhub/signals/persister/config/SignalHubPersisterConfig.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java @@ -1,4 +1,4 @@ -package it.pagopa.interop.signalhub.signals.persister.config; +package it.pagopa.interop.signalhub.persister.config; import lombok.Getter; diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java similarity index 80% rename from src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/consumer/SqsInternalListener.java rename to src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 08ddd61..313a4ae 100644 --- a/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -1,8 +1,9 @@ -package it.pagopa.interop.signalhub.signals.persister.queue.consumer; +package it.pagopa.interop.signalhub.persister.queue.consumer; import io.awspring.cloud.sqs.annotation.SqsListener; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Profile; import org.springframework.messaging.handler.annotation.Headers; import org.springframework.stereotype.Component; @@ -11,11 +12,8 @@ @Slf4j -@Component public class SqsInternalListener { - - @SqsListener public CompletableFuture listen(String node, @Headers Map headers) { return CompletableFuture.completedFuture(null); } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java new file mode 100644 index 0000000..407cd23 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java @@ -0,0 +1,4 @@ +package it.pagopa.interop.signalhub.persister.queue.model; + +public class SignalEvent { +} diff --git a/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java b/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java deleted file mode 100644 index dfd33ca..0000000 --- a/src/main/java/it/pagopa/interop/signalhub/signals/persister/queue/model/SignalEvent.java +++ /dev/null @@ -1,4 +0,0 @@ -package it.pagopa.interop.signalhub.signals.persister.queue.model; - -public class SignalEvent { -} diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java new file mode 100644 index 0000000..56619e2 --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java @@ -0,0 +1,23 @@ +package it.pagopa.interop.signalhub.persister; + + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Import(LocalStackTestConfig.class) +@SpringBootTest(classes = SignalHubSignalsPersisterApplication.class) + +@ActiveProfiles("test") +class ApplicationTest { + + + @Test + void testApp(){ + assertTrue(true); + } + +} diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties new file mode 100644 index 0000000..d1c6204 --- /dev/null +++ b/src/test/resources/application-test.properties @@ -0,0 +1,20 @@ +cloud.aws.region.auto=true + +# Load instance profile credentials +cloud.aws.credentials.instanceProfile=true + +aws.endpoint-url=http://localhost:4566 +aws.endpoint-url-sqs=http://localhost:4566/000000000000/ +aws.internal-queue-name=internal-queue +aws.region=us-east-1 +aws.profile=default + +spring.r2dbc.url=r2dbc:h2:mem:///db;MODE=PostgreSQL +spring.r2dbc.username=signal-hub-test +spring.r2dbc.password=signal-hub-test +spring.r2dbc.pool.max-size=20 +spring.r2dbc.pool.initial-size=5 +spring.r2dbc.pool.enabled=true +spring.data.r2dbc.repositories.enabled=true + +spring.sql.init.platform=h2 \ No newline at end of file diff --git a/src/test/resources/data-h2.sql b/src/test/resources/data-h2.sql new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql new file mode 100644 index 0000000..9b23a27 --- /dev/null +++ b/src/test/resources/schema-h2.sql @@ -0,0 +1,62 @@ + +CREATE TABLE IF NOT EXISTS ORGANIZATION_ESERVICE ( + eservice_id VARCHAR (50) UNIQUE NOT NULL, + organization_id VARCHAR (50) NOT NULL, + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, organization_id) +); + + +CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( + eservice_id VARCHAR (50) NOT NULL, + consumer_id VARCHAR (50) NOT NULL, + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, consumer_id) +); + +CREATE TABLE IF NOT EXISTS SIGNAL ( + id SERIAL PRIMARY KEY, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + UNIQUE (signal_id, eservice_id) +); + +/* H2 not support USING constructor +CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); +CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); +*/ + +CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL (signal_id); +CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL (eservice_id); + +CREATE TABLE IF NOT EXISTS EVENT_TEMP ( + event_temp_id SERIAL PRIMARY KEY, + event_id BIGINT UNIQUE NOT NULL, + event_type VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + object_id VARCHAR (50) NOT NULL, + state VARCHAR (50) NOT NULL, + state_processing VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + tmst_processing TIMESTAMP +); + + +CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( + id SERIAL PRIMARY KEY, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + error VARCHAR(255) NOT NULL +); \ No newline at end of file diff --git a/src/test/resources/testcontainers/credentials b/src/test/resources/testcontainers/credentials new file mode 100644 index 0000000..4ab1290 --- /dev/null +++ b/src/test/resources/testcontainers/credentials @@ -0,0 +1,4 @@ +[default] +aws_access_key_id=TEST +aws_secret_access_key=TEST +region=us-east-1 diff --git a/src/test/resources/testcontainers/init.sh b/src/test/resources/testcontainers/init.sh new file mode 100644 index 0000000..85e6051 --- /dev/null +++ b/src/test/resources/testcontainers/init.sh @@ -0,0 +1,15 @@ +echo "### CREATE PN-SERVICE-DESK QUEUES ###" + +queues="internal-queue" + +for qn in $( echo $queues | tr " " "\n" ) ; do + + echo creating queue $qn ... + + aws --profile default --region us-east-1 --endpoint-url http://localstack:4566 \ + sqs create-queue \ + --attributes '{"DelaySeconds":"2"}' \ + --queue-name $qn +done + +echo "Initialization terminated" From 4fac1bc142babea5d48e03bfdbad5544040a3134 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Tue, 19 Sep 2023 11:02:43 +0200 Subject: [PATCH 04/62] added LocalStackTestConfig --- .../persister/LocalStackTestConfig.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java b/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java new file mode 100644 index 0000000..474487e --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java @@ -0,0 +1,50 @@ +package it.pagopa.interop.signalhub.persister; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.core.io.ClassPathResource; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.localstack.LocalStackContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; + +import java.io.IOException; +import java.time.Duration; + +import static org.testcontainers.containers.localstack.LocalStackContainer.Service.DYNAMODB; +import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SQS; + +/** + * Classe che permette di creare un container Docker di LocalStack. + * Il container (e quindi la classe) può essere condivisa tra più classi di test. + * Per utilizzare questa classe, le classi di test dovranno essere annotate con + * @Import(LocalStackTestConfig.class) + */ +@TestConfiguration +public class LocalStackTestConfig { + + static LocalStackContainer localStack = + new LocalStackContainer(DockerImageName.parse("localstack/localstack:1.0.4").asCompatibleSubstituteFor("localstack/localstack")) + .withServices(DYNAMODB, SQS) + .withClasspathResourceMapping("testcontainers/init.sh", + "/docker-entrypoint-initaws.d/make-storages.sh", BindMode.READ_ONLY) + .withClasspathResourceMapping("testcontainers/credentials", + "/root/.aws/credentials", BindMode.READ_ONLY) + .withNetworkAliases("localstack") + .withNetwork(Network.builder().build()) + .waitingFor(Wait.forLogMessage(".*Initialization terminated.*", 1) + .withStartupTimeout(Duration.ofSeconds(180))); + + static { + localStack.start(); + System.setProperty("aws.endpoint-url", localStack.getEndpointOverride(DYNAMODB).toString()); + try { + System.setProperty("aws.sharedCredentialsFile", new ClassPathResource("testcontainers/credentials").getFile().getAbsolutePath()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + + +} From 2983cbfdf537ab819301fef23af3a7556d7bbfa1 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Tue, 19 Sep 2023 17:14:54 +0200 Subject: [PATCH 05/62] Updated spring boot configuration for liquibase --- pom.xml | 11 +++++++++++ src/main/resources/application.properties | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pom.xml b/pom.xml index 0fe2590..c96d258 100644 --- a/pom.xml +++ b/pom.xml @@ -150,6 +150,12 @@ runtime + + io.r2dbc + r2dbc-postgresql + runtime + + io.awspring.cloud spring-cloud-aws-starter-sqs @@ -176,6 +182,11 @@ 1.17.6 test + + org.postgresql + postgresql + runtime + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2d67783..3636d0c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -12,3 +12,20 @@ cloud.aws.stack.auto=false aws.sqs-endpoint=http://localhost:4566/000000000000/ aws.internal-queue-name=internal-queue aws.pull-limit=100 + +#Liquibase +spring.liquibase.url=jdbc:postgresql://localhost:5432/signal-hub +spring.liquibase.user=postgres +spring.liquibase.password=postgres +spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml +spring.liquibase.enabled=true +logging.level.liquibase=INFO + +#Postgres +spring.r2dbc.url=r2dbc:postgresql://localhost:5432/signal-hub +spring.r2dbc.username=postgres +spring.r2dbc.password=postgres +spring.r2dbc.pool.max-size=20 +spring.r2dbc.pool.initial-size=5 +spring.r2dbc.pool.enabled=true +spring.data.r2dbc.repositories.enabled=true \ No newline at end of file From 0007c392578ad56946704e84c6d5ad58cf44a366 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Tue, 19 Sep 2023 17:15:58 +0200 Subject: [PATCH 06/62] Added liquibase changelog and sql scripts --- .../db/changelog/changelog-master.xml | 10 +++ .../changes/init_table/changelog.xml | 18 ++++++ .../changes/init_table/init_table.sql | 61 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 src/main/resources/db/changelog/changelog-master.xml create mode 100644 src/main/resources/db/changelog/changes/init_table/changelog.xml create mode 100644 src/main/resources/db/changelog/changes/init_table/init_table.sql diff --git a/src/main/resources/db/changelog/changelog-master.xml b/src/main/resources/db/changelog/changelog-master.xml new file mode 100644 index 0000000..3c8cf85 --- /dev/null +++ b/src/main/resources/db/changelog/changelog-master.xml @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog/changes/init_table/changelog.xml b/src/main/resources/db/changelog/changes/init_table/changelog.xml new file mode 100644 index 0000000..430055c --- /dev/null +++ b/src/main/resources/db/changelog/changes/init_table/changelog.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql new file mode 100644 index 0000000..65e4f43 --- /dev/null +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -0,0 +1,61 @@ +CREATE TABLE IF NOT EXISTS ORGANIZATION_ESERVICE ( + eservice_id VARCHAR (50) UNIQUE NOT NULL, + organization_id VARCHAR (50) NOT NULL, + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, organization_id) +); + + +CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( + eservice_id VARCHAR (50) NOT NULL, + consumer_id VARCHAR (50) NOT NULL, + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, consumer_id) +); + + +CREATE TABLE IF NOT EXISTS SIGNAL ( + id SERIAL PRIMARY KEY, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + UNIQUE (signal_id, eservice_id) +); + + +CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); + + +CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); + + +CREATE TABLE IF NOT EXISTS EVENT_TEMP ( + event_temp_id SERIAL PRIMARY KEY, + event_id BIGINT UNIQUE NOT NULL, + event_type VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + object_id VARCHAR (50) NOT NULL, + state VARCHAR (50) NOT NULL, + state_processing VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + tmst_processing TIMESTAMP +); + + +CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( + id SERIAL PRIMARY KEY, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + error VARCHAR(255) NOT NULL +); \ No newline at end of file From 436afbf5feedb3d327850d697b5ecbbdbbb1bec2 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Wed, 20 Sep 2023 15:54:37 +0200 Subject: [PATCH 07/62] fixed properties --- src/main/resources/application.properties | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3636d0c..2dc89e1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,30 +1,34 @@ logging.level.root=INFO spring.main.web-appplication-type=reactive -cloud.aws.region.auto=true - -# Load instance profile credentials -cloud.aws.credentials.instanceProfile=true # Disable auto cloud formation cloud.aws.stack.auto=false - -aws.sqs-endpoint=http://localhost:4566/000000000000/ +aws.profile=default +aws.region=${AWS_REGION:us-east-1} +aws.endpoint-url=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} +aws.endpoint-url-sqs=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} aws.internal-queue-name=internal-queue aws.pull-limit=100 +database.name=${DB_NAME:signal_hub} +database.host=${DB_HOST:localhost} +database.port=${DB_PORT:5432} +database.username=${DB_USER:postgres} +database.password=${DB_PASSWORD:postgres} + #Liquibase -spring.liquibase.url=jdbc:postgresql://localhost:5432/signal-hub -spring.liquibase.user=postgres -spring.liquibase.password=postgres +spring.liquibase.url=jdbc:postgresql://${database.host}:${DB_PORT}/${database.name} +spring.liquibase.user=${database.username} +spring.liquibase.password=${database.password} spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml spring.liquibase.enabled=true logging.level.liquibase=INFO #Postgres -spring.r2dbc.url=r2dbc:postgresql://localhost:5432/signal-hub -spring.r2dbc.username=postgres -spring.r2dbc.password=postgres +spring.r2dbc.url=r2dbc:postgresql://${database.host}:${DB_PORT}/${database.name} +spring.r2dbc.username=${database.username} +spring.r2dbc.password=${database.password} spring.r2dbc.pool.max-size=20 spring.r2dbc.pool.initial-size=5 spring.r2dbc.pool.enabled=true From 812aa6234ba2297e778ec240dea109359908d765 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 20 Sep 2023 19:26:51 +0200 Subject: [PATCH 08/62] Updated dependencies and properties --- pom.xml | 5 +++++ src/main/resources/application.properties | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index c96d258..51bfab5 100644 --- a/pom.xml +++ b/pom.xml @@ -175,6 +175,11 @@ java-jwt 4.3.0 + + org.modelmapper + modelmapper + 3.1.0 + org.testcontainers diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2dc89e1..86c2bfb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,17 +8,17 @@ aws.profile=default aws.region=${AWS_REGION:us-east-1} aws.endpoint-url=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} aws.endpoint-url-sqs=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} -aws.internal-queue-name=internal-queue -aws.pull-limit=100 +aws.internal-queue-name=local-internal-signal-hub -database.name=${DB_NAME:signal_hub} +database.name=${DB_NAME:signal-hub} database.host=${DB_HOST:localhost} database.port=${DB_PORT:5432} database.username=${DB_USER:postgres} database.password=${DB_PASSWORD:postgres} + #Liquibase -spring.liquibase.url=jdbc:postgresql://${database.host}:${DB_PORT}/${database.name} +spring.liquibase.url=jdbc:postgresql://${database.host}:${database.port}/${database.name} spring.liquibase.user=${database.username} spring.liquibase.password=${database.password} spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml @@ -26,7 +26,7 @@ spring.liquibase.enabled=true logging.level.liquibase=INFO #Postgres -spring.r2dbc.url=r2dbc:postgresql://${database.host}:${DB_PORT}/${database.name} +spring.r2dbc.url=r2dbc:postgresql://${database.host}:${database.port}/${database.name} spring.r2dbc.username=${database.username} spring.r2dbc.password=${database.password} spring.r2dbc.pool.max-size=20 From 256426dc2ad5283d7a15579cff8b6a1d77e48cfd Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 20 Sep 2023 19:31:49 +0200 Subject: [PATCH 09/62] Added SignalEvent dto, Signal and DeadSignal entities and respective mapper --- .../persister/entity/DeadSignal.java | 33 +++++++++++++++++ .../signalhub/persister/entity/Signal.java | 32 +++++++++++++++++ .../persister/mapper/SignalMapper.java | 15 ++++++++ .../persister/queue/model/SignalEvent.java | 15 ++++++++ .../persister/queue/model/SignalType.java | 36 +++++++++++++++++++ .../repository/DeadSignalRepository.java | 9 +++++ .../repository/SignalRepository.java | 9 +++++ .../signalhub/persister/utils/Utility.java | 23 ++++++++++++ 8 files changed, 172 insertions(+) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalType.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/repository/DeadSignalRepository.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java b/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java new file mode 100644 index 0000000..97666f7 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java @@ -0,0 +1,33 @@ +package it.pagopa.interop.signalhub.persister.entity; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Table; +import java.time.Instant; + +@Getter +@Setter +@Table +public class DeadSignal { + @Id + @Column("id") + private Long id; + @Column("signal_id") + private Long signalId; + @Column("object_id") + private String objectId; + @Column("eservice_id") + private String eserviceId; + @Column("object_type") + private String objectType; + @Column("signal_type") + private String signalType; + @CreatedDate + @Column("tmst_insert") + private Instant tmstInsert; + @Column("error") + private String error; +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java new file mode 100644 index 0000000..f6d7704 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java @@ -0,0 +1,32 @@ +package it.pagopa.interop.signalhub.persister.entity; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Table; +import java.time.Instant; + + +@Getter +@Setter +@Table +public class Signal { + @Id + @Column("id") + private Long id; + @Column("signal_id") + private Long signalId; + @Column("object_id") + private String objectId; + @Column("eservice_id") + private String eserviceId; + @Column("object_type") + private String objectType; + @Column("signal_type") + private String signalType; + @CreatedDate + @Column("tmst_insert") + private Instant tmstInsert; +} \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java new file mode 100644 index 0000000..e35b666 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java @@ -0,0 +1,15 @@ +package it.pagopa.interop.signalhub.persister.mapper; + +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + + +@Mapper(componentModel = "spring") +public interface SignalMapper { + @Mapping(target = "indexSignal", source = "signal.signalId") + SignalEvent signalToSignalEvent(Signal signal); + @Mapping(target = "signalId", source = "signalEvent.indexSignal") + Signal signalEventToSignal(SignalEvent signalEvent); +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java index 407cd23..1cac181 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java @@ -1,4 +1,19 @@ package it.pagopa.interop.signalhub.persister.queue.model; +import lombok.Getter; +import lombok.Setter; + + +@Getter +@Setter public class SignalEvent { + private SignalType signalType; + + private String objectId; + + private String objectType; + + private String eserviceId; + + private Long indexSignal; } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalType.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalType.java new file mode 100644 index 0000000..8e13201 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalType.java @@ -0,0 +1,36 @@ +package it.pagopa.interop.signalhub.persister.queue.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public enum SignalType { + + CREATE("CREATE"), + + UPDATE("UPDATE"), + + DELETE("DELETE"), + + SEEDUPDATE("SEEDUPDATE"); + + private String code; + + SignalType(String code) { + this.code = code; + } + + @JsonValue() + private String getCode() { + return this.code; + } + + @JsonCreator() + private SignalType fromCode(String code) { + for(SignalType signalType: SignalType.values()) { + if(signalType.code.equals(code)) { + return signalType; + } + } + throw new IllegalArgumentException("Unexpected error on enum creation"); + } +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/repository/DeadSignalRepository.java b/src/main/java/it/pagopa/interop/signalhub/persister/repository/DeadSignalRepository.java new file mode 100644 index 0000000..6fd4ec8 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/repository/DeadSignalRepository.java @@ -0,0 +1,9 @@ +package it.pagopa.interop.signalhub.persister.repository; + +import it.pagopa.interop.signalhub.persister.entity.DeadSignal; +import org.springframework.data.repository.reactive.ReactiveCrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DeadSignalRepository extends ReactiveCrudRepository { +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java b/src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java new file mode 100644 index 0000000..c8c3dcf --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java @@ -0,0 +1,9 @@ +package it.pagopa.interop.signalhub.persister.repository; + +import it.pagopa.interop.signalhub.persister.entity.Signal; +import org.springframework.data.repository.reactive.ReactiveCrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SignalRepository extends ReactiveCrudRepository { +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java new file mode 100644 index 0000000..01cdb46 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java @@ -0,0 +1,23 @@ +package it.pagopa.interop.signalhub.persister.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class Utility { + + private Utility() { + throw new IllegalCallerException(); + } + + public static T jsonToObject(ObjectMapper objectMapper, String json, Class tClass){ + try { + return objectMapper.readValue(json, tClass); + } catch (JsonProcessingException exception) { + log.error("exception = {}, errorReason = {}, Error during mapping an object", exception, exception.getMessage()); + return null; + } + } + +} From bc73a94e2565ab61b210815ae283b2a2212e81f6 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 20 Sep 2023 19:33:31 +0200 Subject: [PATCH 10/62] Added exception management --- .../persister/exception/ExceptionTypeEnum.java | 18 ++++++++++++++++++ .../exception/PdndGenericException.java | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericException.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java b/src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java new file mode 100644 index 0000000..dc4db18 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java @@ -0,0 +1,18 @@ +package it.pagopa.interop.signalhub.persister.exception; + +import lombok.Getter; + + +@Getter +public enum ExceptionTypeEnum{ + MAPPER_ERROR("MAPPER_ERROR", "The requested object could not be mapped"); + + private final String title; + private final String message; + + + ExceptionTypeEnum(String title, String message) { + this.title = title; + this.message = message; + } +} \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericException.java b/src/main/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericException.java new file mode 100644 index 0000000..7cc634a --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericException.java @@ -0,0 +1,17 @@ +package it.pagopa.interop.signalhub.persister.exception; + +import lombok.Getter; + + +@Getter +public class PdndGenericException extends RuntimeException { + private final ExceptionTypeEnum exceptionType; + private final String message; + + + public PdndGenericException(ExceptionTypeEnum exceptionType, String message){ + super(message); + this.exceptionType = exceptionType; + this.message = message; + } +} \ No newline at end of file From 8ebde0996915d7b49160f5a9d12bafc5e98e8c3c Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 20 Sep 2023 19:36:10 +0200 Subject: [PATCH 11/62] Added listener on internal queue --- .../queue/consumer/SqsInternalListener.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 313a4ae..26174b9 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -1,21 +1,54 @@ package it.pagopa.interop.signalhub.persister.queue.consumer; +import com.fasterxml.jackson.databind.ObjectMapper; import io.awspring.cloud.sqs.annotation.SqsListener; +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; +import it.pagopa.interop.signalhub.persister.mapper.SignalMapper; +import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import it.pagopa.interop.signalhub.persister.service.SignalService; +import it.pagopa.interop.signalhub.persister.utils.Utility; import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Profile; +//import io.awspring.cloud.messaging.listener.SqsMessageDeletionPolicy; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.handler.annotation.Headers; +import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Component; import java.util.Map; import java.util.concurrent.CompletableFuture; +import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; + @Slf4j +@Component public class SqsInternalListener { + @Autowired + private SignalService signalService; + @Autowired + private ObjectMapper objectMapper; + @Autowired + private SignalMapper signalMapper; + + @SqsListener(value = "${aws.internal-queue-name}") + public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { + log.info("node: {}, headers: {}, PullFromInternalQueue received input", node, headers); + SignalEvent signalEvent = convertToObject(node, SignalEvent.class); + Signal signal = signalMapper.signalEventToSignal(signalEvent); + signalService + .pushIntoAwsDbMaster(signal) + .block(); - public CompletableFuture listen(String node, @Headers Map headers) { return CompletableFuture.completedFuture(null); } + private T convertToObject(String body, Class tClass){ + T entity = Utility.jsonToObject(this.objectMapper, body, tClass); + if (entity == null) { + throw new PdndGenericException(MAPPER_ERROR, MAPPER_ERROR.getMessage()); + } + return entity; + } } From c9dfe87b5e314ddc1aa8a0e766f2aafee34b9ef2 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 20 Sep 2023 19:36:53 +0200 Subject: [PATCH 12/62] Added signal service --- .../persister/service/SignalService.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java new file mode 100644 index 0000000..9ccec51 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java @@ -0,0 +1,33 @@ +package it.pagopa.interop.signalhub.persister.service; + +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import it.pagopa.interop.signalhub.persister.repository.SignalRepository; +import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.concurrent.CompletableFuture; + + +@Service +public class SignalService { + @Autowired + private SignalRepository signalRepository; + @Autowired + private DeadSignalRepository deadSignalRepository; + + private Mono getSignalById(Long signalId) { + return this.signalRepository.findById(signalId); + } + + private Mono createSignal(final Signal signal) { + return this.signalRepository.save(signal); + } + + public Mono pushIntoAwsDbMaster(Signal signal) { + return signalRepository. + save(signal); + } +} \ No newline at end of file From d45f5c997f829294b2598f14f536ec5834b5d740 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Thu, 21 Sep 2023 16:16:32 +0200 Subject: [PATCH 13/62] Updated signal service --- .../persister/entity/DeadSignal.java | 2 ++ .../signalhub/persister/entity/Signal.java | 2 ++ .../persister/mapper/DeadSignalMapper.java | 11 +++++++ .../queue/consumer/SqsInternalListener.java | 12 ++++---- .../persister/queue/model/SignalEvent.java | 2 ++ .../persister/service/SignalService.java | 30 +++++++++++++++++-- 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapper.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java b/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java index 97666f7..a6d8215 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java @@ -2,6 +2,7 @@ import lombok.Getter; import lombok.Setter; +import lombok.ToString; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.relational.core.mapping.Column; @@ -11,6 +12,7 @@ @Getter @Setter @Table +@ToString public class DeadSignal { @Id @Column("id") diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java index f6d7704..b39b5d3 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java @@ -2,6 +2,7 @@ import lombok.Getter; import lombok.Setter; +import lombok.ToString; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.relational.core.mapping.Column; @@ -12,6 +13,7 @@ @Getter @Setter @Table +@ToString public class Signal { @Id @Column("id") diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapper.java b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapper.java new file mode 100644 index 0000000..d9ec9be --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapper.java @@ -0,0 +1,11 @@ +package it.pagopa.interop.signalhub.persister.mapper; + +import it.pagopa.interop.signalhub.persister.entity.DeadSignal; +import it.pagopa.interop.signalhub.persister.entity.Signal; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface DeadSignalMapper { + DeadSignal signalToDeadSignal(Signal signal); + Signal deadSignalToSignal(DeadSignal deadSignal); +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 26174b9..7879b3c 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -10,7 +10,6 @@ import it.pagopa.interop.signalhub.persister.service.SignalService; import it.pagopa.interop.signalhub.persister.utils.Utility; import lombok.extern.slf4j.Slf4j; -//import io.awspring.cloud.messaging.listener.SqsMessageDeletionPolicy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.handler.annotation.Headers; import org.springframework.messaging.handler.annotation.Payload; @@ -34,19 +33,20 @@ public class SqsInternalListener { @SqsListener(value = "${aws.internal-queue-name}") public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { - log.info("node: {}, headers: {}, PullFromInternalQueue received input", node, headers); + log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers); SignalEvent signalEvent = convertToObject(node, SignalEvent.class); Signal signal = signalMapper.signalEventToSignal(signalEvent); - signalService - .pushIntoAwsDbMaster(signal) - .block(); - return CompletableFuture.completedFuture(null); + return signalService + .pushIntoAwsDbMaster(signal) + .then() + .toFuture(); } private T convertToObject(String body, Class tClass){ T entity = Utility.jsonToObject(this.objectMapper, body, tClass); if (entity == null) { + log.error("errorReason = {}, An error occurred during object conversion", MAPPER_ERROR.getMessage()); throw new PdndGenericException(MAPPER_ERROR, MAPPER_ERROR.getMessage()); } return entity; diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java index 1cac181..33458e5 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java @@ -2,10 +2,12 @@ import lombok.Getter; import lombok.Setter; +import lombok.ToString; @Getter @Setter +@ToString public class SignalEvent { private SignalType signalType; diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java index 9ccec51..ac3e9f7 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java @@ -1,22 +1,30 @@ package it.pagopa.interop.signalhub.persister.service; +import it.pagopa.interop.signalhub.persister.entity.DeadSignal; import it.pagopa.interop.signalhub.persister.entity.Signal; -import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; +import it.pagopa.interop.signalhub.persister.mapper.DeadSignalMapper; import it.pagopa.interop.signalhub.persister.repository.SignalRepository; import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; import java.util.concurrent.CompletableFuture; +import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR; + @Service +@Slf4j public class SignalService { @Autowired private SignalRepository signalRepository; @Autowired private DeadSignalRepository deadSignalRepository; + @Autowired + private DeadSignalMapper deadSignalMapper; private Mono getSignalById(Long signalId) { return this.signalRepository.findById(signalId); @@ -27,7 +35,23 @@ private Mono createSignal(final Signal signal) { } public Mono pushIntoAwsDbMaster(Signal signal) { - return signalRepository. - save(signal); + return signalRepository + .findByIndexSignalAndEserviceId(signal.getSignalId(), signal.getEserviceId()) + .switchIfEmpty(Mono.just(signal)) + .flatMap(entity -> { + if(entity.getId() == null) { + return signalRepository.save(signal) + .doOnNext(entitySaved -> log.info("signalEntity = {}, Signal entity created", entitySaved)); + } + log.info("signal = {}, The searched entity is not present in the Database", signal); + return Mono.error(new PdndGenericException(DUPLICATE_SIGNAL_ERROR, DUPLICATE_SIGNAL_ERROR.getMessage())); + }) + .onErrorResume(exception -> { + DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); + deadSignal.setError(DUPLICATE_SIGNAL_ERROR.toString()); + return deadSignalRepository.save(deadSignal) + .doOnNext(entitySaved -> log.info("signal = {}, The searched entity is already present into Signal's table, it has been saved into DeadSignal's table", entitySaved)) + .thenReturn(signal); + }); } } \ No newline at end of file From b899f8328cdc49672ca17fbc8f1ea67ad1f47dd8 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Thu, 21 Sep 2023 16:18:40 +0200 Subject: [PATCH 14/62] Updated signal repository and enum --- .../signalhub/persister/exception/ExceptionTypeEnum.java | 3 ++- .../signalhub/persister/repository/SignalRepository.java | 5 +++++ src/main/resources/application.properties | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java b/src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java index dc4db18..bebff9a 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/exception/ExceptionTypeEnum.java @@ -5,7 +5,8 @@ @Getter public enum ExceptionTypeEnum{ - MAPPER_ERROR("MAPPER_ERROR", "The requested object could not be mapped"); + MAPPER_ERROR("MAPPER_ERROR", "The requested object could not be mapped."), + DUPLICATE_SIGNAL_ERROR("DUPLICATE_SIGNAL_ERROR", "The signal is already saved on database."); private final String title; private final String message; diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java b/src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java index c8c3dcf..c5743fe 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/repository/SignalRepository.java @@ -1,9 +1,14 @@ package it.pagopa.interop.signalhub.persister.repository; import it.pagopa.interop.signalhub.persister.entity.Signal; +import org.springframework.data.r2dbc.repository.Query; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.stereotype.Repository; +import reactor.core.publisher.Mono; @Repository public interface SignalRepository extends ReactiveCrudRepository { + + @Query("SELECT * FROM SIGNAL WHERE signal_id = :signalId AND eservice_id = :eserviceId") + Mono findByIndexSignalAndEserviceId(Long signalId, String eserviceId); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 86c2bfb..8c017bf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -25,7 +25,7 @@ spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml spring.liquibase.enabled=true logging.level.liquibase=INFO -#Postgres +#R2DBC - Postgres spring.r2dbc.url=r2dbc:postgresql://${database.host}:${database.port}/${database.name} spring.r2dbc.username=${database.username} spring.r2dbc.password=${database.password} From 3ef6c82c967434f93a072b05b66e95ba8d97e9e9 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Fri, 22 Sep 2023 09:00:44 +0200 Subject: [PATCH 15/62] some fixes --- config/application.properties | 7 ------- .../persister/queue/consumer/SqsInternalListener.java | 2 +- src/main/resources/application.properties | 3 ++- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/config/application.properties b/config/application.properties index 440a8f2..8b13789 100644 --- a/config/application.properties +++ b/config/application.properties @@ -1,8 +1 @@ -aws.profile-name=default -aws.region-code=us-east-1 -aws.bucket-name= -aws.dynamodb-endpoint=http://localhost:4566 -aws.name-pod_ms=signal-hub-pod - -aws.internal-queue-name=internal-queue diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 7879b3c..9208585 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -31,7 +31,7 @@ public class SqsInternalListener { @Autowired private SignalMapper signalMapper; - @SqsListener(value = "${aws.internal-queue-name}") + @SqsListener(value = "${poc.signal-hub.internal-queue-name}") public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers); SignalEvent signalEvent = convertToObject(node, SignalEvent.class); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8c017bf..2ac7414 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,7 +8,8 @@ aws.profile=default aws.region=${AWS_REGION:us-east-1} aws.endpoint-url=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} aws.endpoint-url-sqs=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} -aws.internal-queue-name=local-internal-signal-hub + +poc.signal-hub.internal-queue-name=local-internal-signal-hub database.name=${DB_NAME:signal-hub} database.host=${DB_HOST:localhost} From 85a947426e5f4551d55bdbe878cfca3b699846f4 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Fri, 22 Sep 2023 11:10:30 +0200 Subject: [PATCH 16/62] added dlq --- .../persister/config/AwsBeanBuilder.java | 12 +++++++++- .../config/SignalHubPersisterConfig.java | 2 +- .../queue/producer/InternalSqsProducer.java | 24 +++++++++++++++++++ .../persister/queue/producer/SqsProducer.java | 9 +++++++ src/main/resources/application.properties | 1 + 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java index 078c919..ab15d27 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java @@ -2,6 +2,7 @@ import io.awspring.cloud.sqs.config.SqsBootstrapConfiguration; import io.awspring.cloud.sqs.config.SqsMessageListenerContainerFactory; +import io.awspring.cloud.sqs.operations.SqsTemplate; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Bean; @@ -21,9 +22,11 @@ public class AwsBeanBuilder { private final AwsPropertiesConfig props; + private final SignalHubPersisterConfig cfn; - public AwsBeanBuilder(AwsPropertiesConfig props) { + public AwsBeanBuilder(AwsPropertiesConfig props, SignalHubPersisterConfig cfn) { this.props = props; + this.cfn = cfn; } @Bean @@ -31,6 +34,13 @@ public SqsAsyncClient sqsAsyncClient() { return configureBuilder(SqsAsyncClient.builder(), props.getEndpointUrlSqs()); } + @Bean + public SqsTemplate sqsTemplate(SqsAsyncClient sqsAsyncClient) { + return SqsTemplate.builder().sqsAsyncClient(sqsAsyncClient) + .configure(options -> options.defaultQueue(cfn.getInternalQueueNameDlq())) + .build(); + } + @Bean public SqsMessageListenerContainerFactory defaultSqsListenerContainerFactory() { return SqsMessageListenerContainerFactory diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java index 8286cd2..5631305 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java @@ -13,5 +13,5 @@ public class SignalHubPersisterConfig { private String internalQueueName; - + private String internalQueueNameDlq; } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java new file mode 100644 index 0000000..75118fe --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java @@ -0,0 +1,24 @@ +package it.pagopa.interop.signalhub.persister.queue.producer; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.awspring.cloud.sqs.operations.SqsTemplate; +import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +@Component +@AllArgsConstructor +public class InternalSqsProducer implements SqsProducer { + private SqsTemplate sqsTemplate; + private final ObjectMapper objectMapper; + + + @Override + public Mono push(SignalEvent event) { + return Mono.fromFuture(this.sqsTemplate.sendAsync( + //MessageBuilder.withPayload(convertToJson(event)) + )).thenReturn(event); + } + +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java new file mode 100644 index 0000000..65bd20d --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java @@ -0,0 +1,9 @@ +package it.pagopa.interop.signalhub.persister.queue.producer; + +import reactor.core.publisher.Mono; + +public interface SqsProducer { + + Mono push(T event); + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2ac7414..b170f64 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,6 +10,7 @@ aws.endpoint-url=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} aws.endpoint-url-sqs=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} poc.signal-hub.internal-queue-name=local-internal-signal-hub +poc.signal-hub.internal-queue-name-dlq=local-internal-signal-hub-dlq database.name=${DB_NAME:signal-hub} database.host=${DB_HOST:localhost} From fef18bc090fc1bf12b7936f8c9eab2214382e520 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Fri, 22 Sep 2023 18:53:55 +0200 Subject: [PATCH 17/62] Added push dead signal on dlq queue --- .../queue/producer/InternalSqsProducer.java | 17 ++++--- .../persister/service/SignalService.java | 44 +++++++++++++------ .../signalhub/persister/utils/Utility.java | 19 +++++++- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java index 75118fe..69edbbd 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java @@ -1,24 +1,31 @@ package it.pagopa.interop.signalhub.persister.queue.producer; -import com.fasterxml.jackson.databind.ObjectMapper; import io.awspring.cloud.sqs.operations.SqsTemplate; import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import it.pagopa.interop.signalhub.persister.utils.Utility; import lombok.AllArgsConstructor; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; + @Component @AllArgsConstructor public class InternalSqsProducer implements SqsProducer { private SqsTemplate sqsTemplate; - private final ObjectMapper objectMapper; @Override public Mono push(SignalEvent event) { - return Mono.fromFuture(this.sqsTemplate.sendAsync( - //MessageBuilder.withPayload(convertToJson(event)) - )).thenReturn(event); + String json = Utility.objectToJson(event); + if(json == null) { + return null; + } else { + Message message = MessageBuilder.withPayload(json).build(); + return Mono.fromFuture(this.sqsTemplate.sendAsync(message)) + .thenReturn(event); + } } } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java index ac3e9f7..c5bcb1d 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java @@ -4,14 +4,16 @@ import it.pagopa.interop.signalhub.persister.entity.Signal; import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; import it.pagopa.interop.signalhub.persister.mapper.DeadSignalMapper; -import it.pagopa.interop.signalhub.persister.repository.SignalRepository; +import it.pagopa.interop.signalhub.persister.mapper.SignalMapper; +import it.pagopa.interop.signalhub.persister.queue.producer.InternalSqsProducer; import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; +import it.pagopa.interop.signalhub.persister.repository.SignalRepository; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Mono; - -import java.util.concurrent.CompletableFuture; +import reactor.core.scheduler.Schedulers; import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR; @@ -24,34 +26,48 @@ public class SignalService { @Autowired private DeadSignalRepository deadSignalRepository; @Autowired + private SignalMapper signalMapper; + @Autowired private DeadSignalMapper deadSignalMapper; + @Autowired + private InternalSqsProducer internalSqsProducer; - private Mono getSignalById(Long signalId) { - return this.signalRepository.findById(signalId); - } + + private Mono getSignalById(Long signalId, String eserviceId) { return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId); } private Mono createSignal(final Signal signal) { return this.signalRepository.save(signal); } + @Transactional public Mono pushIntoAwsDbMaster(Signal signal) { - return signalRepository - .findByIndexSignalAndEserviceId(signal.getSignalId(), signal.getEserviceId()) + return getSignalById(signal.getSignalId(), signal.getEserviceId()) .switchIfEmpty(Mono.just(signal)) .flatMap(entity -> { if(entity.getId() == null) { - return signalRepository.save(signal) + return createSignal(signal) .doOnNext(entitySaved -> log.info("signalEntity = {}, Signal entity created", entitySaved)); } log.info("signal = {}, The searched entity is not present in the Database", signal); return Mono.error(new PdndGenericException(DUPLICATE_SIGNAL_ERROR, DUPLICATE_SIGNAL_ERROR.getMessage())); }) .onErrorResume(exception -> { - DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); - deadSignal.setError(DUPLICATE_SIGNAL_ERROR.toString()); - return deadSignalRepository.save(deadSignal) - .doOnNext(entitySaved -> log.info("signal = {}, The searched entity is already present into Signal's table, it has been saved into DeadSignal's table", entitySaved)) - .thenReturn(signal); + pushDeadSignalDlsQueue(signal); + return Mono.empty(); }); } + + private void pushDeadSignalDlsQueue(Signal signal) { + DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); + deadSignal.setError(DUPLICATE_SIGNAL_ERROR.toString()); + deadSignalRepository.save(deadSignal) + .publishOn(Schedulers.boundedElastic()) + .doOnNext(entitySaved -> log.info("signal = {}, The searched entity is already present into Signal's table, it has been saved into DeadSignal's table", entitySaved)) + .flatMap(entitySaved -> { + log.info("signal = {}, The signal has been pushed on dlq queue", signal); + return internalSqsProducer.push(signalMapper.signalToSignalEvent(signal)); + }) + .subscribeOn(Schedulers.boundedElastic()) + .subscribe(); + } } \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java index 01cdb46..e6c0578 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java @@ -2,8 +2,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import lombok.extern.slf4j.Slf4j; + @Slf4j public class Utility { @@ -20,4 +24,17 @@ public static T jsonToObject(ObjectMapper objectMapper, String json, Class String objectToJson(T data){ + try{ + ObjectMapper objectMapper = new ObjectMapper() + .registerModule(new Jdk8Module()) + .registerModule(new JavaTimeModule()); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + return objectMapper.writeValueAsString(data); + } + catch (JsonProcessingException exception){ + log.error("exception = {}, errorReason = {}, Error during mapping an object", exception, exception.getMessage()); + return null; + } + } +} \ No newline at end of file From 152a550754e00903c256d8ea69f51a9ba89d159b Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Wed, 27 Sep 2023 18:28:28 +0200 Subject: [PATCH 18/62] minor change --- .../queue/consumer/SqsInternalListener.java | 18 ++----- .../queue/producer/InternalSqsProducer.java | 31 ------------ .../persister/queue/producer/SqsProducer.java | 9 ---- .../persister/service/SignalService.java | 48 +++++++------------ .../signalhub/persister/utils/Utility.java | 5 +- 5 files changed, 26 insertions(+), 85 deletions(-) delete mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java delete mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 9208585..f8cf114 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -14,6 +14,7 @@ import org.springframework.messaging.handler.annotation.Headers; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -34,21 +35,12 @@ public class SqsInternalListener { @SqsListener(value = "${poc.signal-hub.internal-queue-name}") public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers); - SignalEvent signalEvent = convertToObject(node, SignalEvent.class); - Signal signal = signalMapper.signalEventToSignal(signalEvent); - return signalService - .pushIntoAwsDbMaster(signal) + return Mono.just(node) + .map(json -> Utility.jsonToObject(objectMapper, node, SignalEvent.class)) + .map(signalMapper::signalEventToSignal) + .flatMap(signalService::pushIntoAwsDbMaster) .then() .toFuture(); } - - private T convertToObject(String body, Class tClass){ - T entity = Utility.jsonToObject(this.objectMapper, body, tClass); - if (entity == null) { - log.error("errorReason = {}, An error occurred during object conversion", MAPPER_ERROR.getMessage()); - throw new PdndGenericException(MAPPER_ERROR, MAPPER_ERROR.getMessage()); - } - return entity; - } } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java deleted file mode 100644 index 69edbbd..0000000 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/InternalSqsProducer.java +++ /dev/null @@ -1,31 +0,0 @@ -package it.pagopa.interop.signalhub.persister.queue.producer; - -import io.awspring.cloud.sqs.operations.SqsTemplate; -import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; -import it.pagopa.interop.signalhub.persister.utils.Utility; -import lombok.AllArgsConstructor; -import org.springframework.messaging.Message; -import org.springframework.messaging.support.MessageBuilder; -import org.springframework.stereotype.Component; -import reactor.core.publisher.Mono; - - -@Component -@AllArgsConstructor -public class InternalSqsProducer implements SqsProducer { - private SqsTemplate sqsTemplate; - - - @Override - public Mono push(SignalEvent event) { - String json = Utility.objectToJson(event); - if(json == null) { - return null; - } else { - Message message = MessageBuilder.withPayload(json).build(); - return Mono.fromFuture(this.sqsTemplate.sendAsync(message)) - .thenReturn(event); - } - } - -} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java deleted file mode 100644 index 65bd20d..0000000 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/producer/SqsProducer.java +++ /dev/null @@ -1,9 +0,0 @@ -package it.pagopa.interop.signalhub.persister.queue.producer; - -import reactor.core.publisher.Mono; - -public interface SqsProducer { - - Mono push(T event); - -} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java index c5bcb1d..7d53837 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java @@ -2,10 +2,7 @@ import it.pagopa.interop.signalhub.persister.entity.DeadSignal; import it.pagopa.interop.signalhub.persister.entity.Signal; -import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; import it.pagopa.interop.signalhub.persister.mapper.DeadSignalMapper; -import it.pagopa.interop.signalhub.persister.mapper.SignalMapper; -import it.pagopa.interop.signalhub.persister.queue.producer.InternalSqsProducer; import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; import it.pagopa.interop.signalhub.persister.repository.SignalRepository; import lombok.extern.slf4j.Slf4j; @@ -13,7 +10,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR; @@ -26,48 +22,38 @@ public class SignalService { @Autowired private DeadSignalRepository deadSignalRepository; @Autowired - private SignalMapper signalMapper; - @Autowired private DeadSignalMapper deadSignalMapper; - @Autowired - private InternalSqsProducer internalSqsProducer; + private Mono getSignalById(Long signalId, String eserviceId) { return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId); } - private Mono createSignal(final Signal signal) { + private Mono createSignal(Signal signal) { return this.signalRepository.save(signal); } + @Transactional public Mono pushIntoAwsDbMaster(Signal signal) { + return getSignalById(signal.getSignalId(), signal.getEserviceId()) .switchIfEmpty(Mono.just(signal)) - .flatMap(entity -> { - if(entity.getId() == null) { - return createSignal(signal) - .doOnNext(entitySaved -> log.info("signalEntity = {}, Signal entity created", entitySaved)); - } - log.info("signal = {}, The searched entity is not present in the Database", signal); - return Mono.error(new PdndGenericException(DUPLICATE_SIGNAL_ERROR, DUPLICATE_SIGNAL_ERROR.getMessage())); - }) - .onErrorResume(exception -> { - pushDeadSignalDlsQueue(signal); - return Mono.empty(); - }); + .filter(entity -> entity.getId() == null) + .flatMap(this::createSignal) + .switchIfEmpty(Mono.defer(() -> saveToDeadSignal(signal))); } - private void pushDeadSignalDlsQueue(Signal signal) { + + private Mono getDeadSignal(Signal signal) { DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); deadSignal.setError(DUPLICATE_SIGNAL_ERROR.toString()); - deadSignalRepository.save(deadSignal) - .publishOn(Schedulers.boundedElastic()) - .doOnNext(entitySaved -> log.info("signal = {}, The searched entity is already present into Signal's table, it has been saved into DeadSignal's table", entitySaved)) - .flatMap(entitySaved -> { - log.info("signal = {}, The signal has been pushed on dlq queue", signal); - return internalSqsProducer.push(signalMapper.signalToSignalEvent(signal)); - }) - .subscribeOn(Schedulers.boundedElastic()) - .subscribe(); + return Mono.just(deadSignal); + } + + private Mono saveToDeadSignal(Signal signal) { + return getDeadSignal(signal) + .flatMap(this.deadSignalRepository::save) + .then(Mono.just(signal)); + } } \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java index e6c0578..34b8eca 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java @@ -5,8 +5,11 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; import lombok.extern.slf4j.Slf4j; +import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; + @Slf4j public class Utility { @@ -20,7 +23,7 @@ public static T jsonToObject(ObjectMapper objectMapper, String json, Class Date: Thu, 28 Sep 2023 12:45:53 +0200 Subject: [PATCH 19/62] Updated some configuration --- .../persister/config/AwsBeanBuilder.java | 12 +----------- .../config/SignalHubPersisterConfig.java | 2 -- .../queue/consumer/SqsInternalListener.java | 12 +++--------- .../persister/service/SignalService.java | 17 +++++------------ .../signalhub/persister/utils/Utility.java | 4 +++- src/main/resources/application.properties | 1 - 6 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java index ab15d27..cf5c0e9 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java @@ -2,7 +2,6 @@ import io.awspring.cloud.sqs.config.SqsBootstrapConfiguration; import io.awspring.cloud.sqs.config.SqsMessageListenerContainerFactory; -import io.awspring.cloud.sqs.operations.SqsTemplate; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Bean; @@ -13,14 +12,13 @@ import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.sqs.SqsAsyncClient; - import java.net.URI; + @Import(SqsBootstrapConfiguration.class) @Configuration @Slf4j public class AwsBeanBuilder { - private final AwsPropertiesConfig props; private final SignalHubPersisterConfig cfn; @@ -34,13 +32,6 @@ public SqsAsyncClient sqsAsyncClient() { return configureBuilder(SqsAsyncClient.builder(), props.getEndpointUrlSqs()); } - @Bean - public SqsTemplate sqsTemplate(SqsAsyncClient sqsAsyncClient) { - return SqsTemplate.builder().sqsAsyncClient(sqsAsyncClient) - .configure(options -> options.defaultQueue(cfn.getInternalQueueNameDlq())) - .build(); - } - @Bean public SqsMessageListenerContainerFactory defaultSqsListenerContainerFactory() { return SqsMessageListenerContainerFactory @@ -77,5 +68,4 @@ private C configureBuilder(AwsClientBuilder builder, String endpoint) return builder.build(); } - } \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java index 5631305..ebe5939 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java @@ -11,7 +11,5 @@ @Configuration @ConfigurationProperties(prefix = "poc.signal-hub") public class SignalHubPersisterConfig { - private String internalQueueName; - private String internalQueueNameDlq; } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index f8cf114..65ec3ad 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -1,10 +1,7 @@ package it.pagopa.interop.signalhub.persister.queue.consumer; -import com.fasterxml.jackson.databind.ObjectMapper; import io.awspring.cloud.sqs.annotation.SqsListener; -import it.pagopa.interop.signalhub.persister.entity.Signal; -import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; import it.pagopa.interop.signalhub.persister.mapper.SignalMapper; import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; import it.pagopa.interop.signalhub.persister.service.SignalService; @@ -19,8 +16,6 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; -import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; - @Slf4j @Component @@ -28,18 +23,17 @@ public class SqsInternalListener { @Autowired private SignalService signalService; @Autowired - private ObjectMapper objectMapper; - @Autowired private SignalMapper signalMapper; + @SqsListener(value = "${poc.signal-hub.internal-queue-name}") public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers); return Mono.just(node) - .map(json -> Utility.jsonToObject(objectMapper, node, SignalEvent.class)) + .map(json -> Utility.jsonToObject(node, SignalEvent.class)) .map(signalMapper::signalEventToSignal) - .flatMap(signalService::pushIntoAwsDbMaster) + .flatMap(signalService::signalServiceFlow) .then() .toFuture(); } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java index 7d53837..28f4c33 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Mono; - import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR; @@ -25,16 +24,8 @@ public class SignalService { private DeadSignalMapper deadSignalMapper; - - private Mono getSignalById(Long signalId, String eserviceId) { return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId); } - - private Mono createSignal(Signal signal) { - return this.signalRepository.save(signal); - } - - @Transactional - public Mono pushIntoAwsDbMaster(Signal signal) { + public Mono signalServiceFlow(Signal signal) { return getSignalById(signal.getSignalId(), signal.getEserviceId()) .switchIfEmpty(Mono.just(signal)) @@ -43,6 +34,9 @@ public Mono pushIntoAwsDbMaster(Signal signal) { .switchIfEmpty(Mono.defer(() -> saveToDeadSignal(signal))); } + private Mono getSignalById(Long signalId, String eserviceId) { return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId); } + private Mono createSignal(Signal signal) { return this.signalRepository.save(signal); } + private Mono createDeadSignal(DeadSignal signal) { return this.deadSignalRepository.save(signal); } private Mono getDeadSignal(Signal signal) { DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); @@ -52,8 +46,7 @@ private Mono getDeadSignal(Signal signal) { private Mono saveToDeadSignal(Signal signal) { return getDeadSignal(signal) - .flatMap(this.deadSignalRepository::save) + .flatMap(this::createDeadSignal) .then(Mono.just(signal)); - } } \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java index 34b8eca..ab03951 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; import lombok.extern.slf4j.Slf4j; +import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; @@ -18,8 +19,9 @@ private Utility() { throw new IllegalCallerException(); } - public static T jsonToObject(ObjectMapper objectMapper, String json, Class tClass){ + public static T jsonToObject(String json, Class tClass){ try { + ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.readValue(json, tClass); } catch (JsonProcessingException exception) { log.error("exception = {}, errorReason = {}, Error during mapping an object", exception, exception.getMessage()); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b170f64..2ac7414 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,7 +10,6 @@ aws.endpoint-url=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} aws.endpoint-url-sqs=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} poc.signal-hub.internal-queue-name=local-internal-signal-hub -poc.signal-hub.internal-queue-name-dlq=local-internal-signal-hub-dlq database.name=${DB_NAME:signal-hub} database.host=${DB_HOST:localhost} From a222c4905024a507a2f82734eee06b2241978cb7 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Mon, 2 Oct 2023 11:42:53 +0200 Subject: [PATCH 20/62] Updated init table sql script --- .../it/pagopa/interop/signalhub/persister/utils/Utility.java | 3 --- .../resources/db/changelog/changes/init_table/init_table.sql | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java index ab03951..b7d9e75 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java @@ -9,12 +9,9 @@ import lombok.extern.slf4j.Slf4j; import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; -import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; - @Slf4j public class Utility { - private Utility() { throw new IllegalCallerException(); } diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 65e4f43..5fa0315 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -1,10 +1,10 @@ CREATE TABLE IF NOT EXISTS ORGANIZATION_ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, - organization_id VARCHAR (50) NOT NULL, + producer_id VARCHAR (50) NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, organization_id) + UNIQUE (eservice_id, producer_id) ); From e3f24aca3500f9f7472720e50f6cbefc50c5b872 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Mon, 2 Oct 2023 11:59:20 +0200 Subject: [PATCH 21/62] Updated pom with jacoco configuration --- pom.xml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pom.xml b/pom.xml index 51bfab5..f6433d9 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ 1.5.1.Final 2.13.4 + 0.00 @@ -227,6 +228,32 @@ + + org.jacoco + jacoco-maven-plugin + + + it/pagopa/interop/signalhub/push/service/rest/v1/dto/* + it/pagopa/interop/signalhub/push/service/rest/v1/dto/** + it/pagopa/interop/signalhub/push/service/generated/* + it/pagopa/interop/signalhub/push/service/generated/** + + + + + + prepare-agent + + + + report + prepare-package + + report + + + + From 5d0b9a69aa434d247dd34d643334fb001edd9959 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Wed, 11 Oct 2023 09:35:38 +0200 Subject: [PATCH 22/62] refactoring name of column and added new table for tracing batch --- .../changes/init_table/init_table.sql | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 5fa0315..6ce9371 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -1,6 +1,6 @@ -CREATE TABLE IF NOT EXISTS ORGANIZATION_ESERVICE ( +CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, - producer_id VARCHAR (50) NOT NULL, + producer_id VARCHAR (50) NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, @@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( CREATE TABLE IF NOT EXISTS SIGNAL ( id SERIAL PRIMARY KEY, + correlation_id VARCHAR(50) NOT NULL, signal_id BIGINT NOT NULL, object_id VARCHAR (50) NOT NULL, eservice_id VARCHAR (50) NOT NULL, @@ -35,17 +36,18 @@ CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); +CREATE INDEX ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); +CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); -CREATE TABLE IF NOT EXISTS EVENT_TEMP ( - event_temp_id SERIAL PRIMARY KEY, - event_id BIGINT UNIQUE NOT NULL, - event_type VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - object_id VARCHAR (50) NOT NULL, +CREATE INDEX CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); +CREATE INDEX ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); + +CREATE TABLE IF NOT EXISTS TRACING_BATCH ( + batch_id SERIAL PRIMARY KEY, state VARCHAR (50) NOT NULL, - state_processing VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - tmst_processing TIMESTAMP + last_event_id BIGINT, + tmst_started TIMESTAMP NOT NULL, + tmst_ended TIMESTAMP ); From bcbb989f2bf668dc09658bb5a0598feef4fb076d Mon Sep 17 00:00:00 2001 From: ariannazafarana <112564573+ariannazafarana@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:22:24 +0200 Subject: [PATCH 23/62] adds gitflow --- .github/workflows/build.yaml | 38 +++++++++++++++++++++++++++ .github/workflows/build_prod-uat.yaml | 36 +++++++++++++++++++++++++ Dockerfile | 19 +++++++++----- 3 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/build_prod-uat.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..8826150 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,38 @@ +name: "CI Develop" + +on: + push: + branches: + - '**' + - '!main' + - '!master' + paths: + - '**' + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: normalize branch name for tagging + run: | + NORM_TAG=$(echo "$GITHUB_REF_NAME" | tr -s "/" "-") + echo "NORM_TAG=$NORM_TAG" >> $GITHUB_ENV + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push on GitHub packages + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository }}:${{ env.NORM_TAG }} \ No newline at end of file diff --git a/.github/workflows/build_prod-uat.yaml b/.github/workflows/build_prod-uat.yaml new file mode 100644 index 0000000..e35d325 --- /dev/null +++ b/.github/workflows/build_prod-uat.yaml @@ -0,0 +1,36 @@ +name: "CI RCs - PROD" + +on: + push: + tags: + - 'v*' + - '*-rc' + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: normalize branch name for tagging + run: | + NORM_TAG=$(echo "$GITHUB_REF_NAME" | tr -s "/" "-") + echo "NORM_TAG=$NORM_TAG" >> $GITHUB_ENV + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push on GitHub packages + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository }}:${{ env.NORM_TAG }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3aa2b86..073c893 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,16 @@ -FROM maven:3.8.3-openjdk-17 AS MAVEN_BUILD -WORKDIR /interop-be-signal/ +## BUILD ## +FROM maven:3.8.3-openjdk-17 AS build + +WORKDIR /app + COPY . . + RUN mvn -q clean package -Dmaven.test.skip=true -FROM eclipse-temurin:17-jre-alpine -WORKDIR /app -COPY --from=MAVEN_BUILD /interop-be-signal/target/*.jar /app/app.jar -ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file + +## RUN ## +FROM openjdk:17-alpine + +COPY --from=build /app/target/*.jar /app/app.jar + +ENTRYPOINT ["java", "-jar", "/app/app.jar"] \ No newline at end of file From cea935e3e52acd3a568e1caf05911356581ff7c4 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 11 Oct 2023 16:58:00 +0200 Subject: [PATCH 24/62] Updated init_table's script and h2's schema --- .../changes/init_table/init_table.sql | 56 ++++++++--------- src/test/resources/schema-h2.sql | 61 ++++++++++--------- 2 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 6ce9371..ed41b34 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -6,6 +6,8 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, producer_id) ); +CREATE INDEX ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); +CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( @@ -16,48 +18,42 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, consumer_id) ); +CREATE INDEX CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); +CREATE INDEX ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); CREATE TABLE IF NOT EXISTS SIGNAL ( id SERIAL PRIMARY KEY, correlation_id VARCHAR(50) NOT NULL, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, UNIQUE (signal_id, eservice_id) ); - - CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); - - CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); -CREATE INDEX ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); -CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); -CREATE INDEX CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); -CREATE INDEX ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); - -CREATE TABLE IF NOT EXISTS TRACING_BATCH ( - batch_id SERIAL PRIMARY KEY, - state VARCHAR (50) NOT NULL, - last_event_id BIGINT, - tmst_started TIMESTAMP NOT NULL, - tmst_ended TIMESTAMP +CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( + id SERIAL PRIMARY KEY, + correlation_id VARCHAR(50) NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + error_reason VARCHAR(255) NOT NULL ); -CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( - id SERIAL PRIMARY KEY, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - error VARCHAR(255) NOT NULL +CREATE TABLE IF NOT EXISTS TRACING_BATCH ( + batch_id SERIAL PRIMARY KEY, + state VARCHAR (50) NOT NULL, + last_event_id BIGINT, + tmst_started TIMESTAMP NOT NULL, + tmst_ended TIMESTAMP ); \ No newline at end of file diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index 9b23a27..3077371 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -1,12 +1,13 @@ - -CREATE TABLE IF NOT EXISTS ORGANIZATION_ESERVICE ( +CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, - organization_id VARCHAR (50) NOT NULL, + producer_id VARCHAR (50) NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, organization_id) + UNIQUE (eservice_id, producer_id) ); +CREATE INDEX ESERVICE_INDEX_ID ON ESERVICE (eservice_id); +CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE (producer_id); CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( @@ -17,15 +18,19 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, consumer_id) ); +CREATE INDEX CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE (eservice_id); +CREATE INDEX ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE (consumer_id); + CREATE TABLE IF NOT EXISTS SIGNAL ( id SERIAL PRIMARY KEY, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + correlation_id VARCHAR(50) NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, UNIQUE (signal_id, eservice_id) ); @@ -37,26 +42,24 @@ CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL (signal_id); CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL (eservice_id); -CREATE TABLE IF NOT EXISTS EVENT_TEMP ( - event_temp_id SERIAL PRIMARY KEY, - event_id BIGINT UNIQUE NOT NULL, - event_type VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - object_id VARCHAR (50) NOT NULL, - state VARCHAR (50) NOT NULL, - state_processing VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - tmst_processing TIMESTAMP -); - CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( id SERIAL PRIMARY KEY, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - error VARCHAR(255) NOT NULL + correlation_id VARCHAR(50) NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + error_reason VARCHAR(255) NOT NULL +); + + +CREATE TABLE IF NOT EXISTS TRACING_BATCH ( + batch_id SERIAL PRIMARY KEY, + state VARCHAR (50) NOT NULL, + last_event_id BIGINT, + tmst_started TIMESTAMP NOT NULL, + tmst_ended TIMESTAMP ); \ No newline at end of file From 35c60e1a59a1a887c141e0d6a6dcf0cc2b7119a2 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 11 Oct 2023 17:26:07 +0200 Subject: [PATCH 25/62] Updated entities for handle correlation_id --- .../interop/signalhub/persister/entity/DeadSignal.java | 8 +++++--- .../pagopa/interop/signalhub/persister/entity/Signal.java | 2 ++ .../interop/signalhub/persister/mapper/SignalMapper.java | 5 ++++- .../persister/queue/consumer/SqsInternalListener.java | 3 ++- .../signalhub/persister/service/SignalService.java | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java b/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java index a6d8215..ba61682 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/entity/DeadSignal.java @@ -17,6 +17,8 @@ public class DeadSignal { @Id @Column("id") private Long id; + @Column("correlation_id") + private String correlationId; @Column("signal_id") private Long signalId; @Column("object_id") @@ -30,6 +32,6 @@ public class DeadSignal { @CreatedDate @Column("tmst_insert") private Instant tmstInsert; - @Column("error") - private String error; -} + @Column("error_reason") + private String errorReason; +} \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java index b39b5d3..253f9e9 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java @@ -18,6 +18,8 @@ public class Signal { @Id @Column("id") private Long id; + @Column("correlation_id") + private String correlationId; @Column("signal_id") private Long signalId; @Column("object_id") diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java index e35b666..758c720 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java @@ -8,8 +8,11 @@ @Mapper(componentModel = "spring") public interface SignalMapper { + String CORRELATION_ID_HEADER_KEY = "correlationId"; + @Mapping(target = "indexSignal", source = "signal.signalId") SignalEvent signalToSignalEvent(Signal signal); @Mapping(target = "signalId", source = "signalEvent.indexSignal") - Signal signalEventToSignal(SignalEvent signalEvent); + @Mapping(target = "correlationId", source = "correlationId") + Signal signalEventToSignal(SignalEvent signalEvent, String correlationId); } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 65ec3ad..2244bf0 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -29,10 +29,11 @@ public class SqsInternalListener { @SqsListener(value = "${poc.signal-hub.internal-queue-name}") public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers); + String correlationId = (String) headers.get(SignalMapper.CORRELATION_ID_HEADER_KEY); return Mono.just(node) .map(json -> Utility.jsonToObject(node, SignalEvent.class)) - .map(signalMapper::signalEventToSignal) + .map((signalEvent) -> signalMapper.signalEventToSignal(signalEvent, correlationId)) .flatMap(signalService::signalServiceFlow) .then() .toFuture(); diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java index 28f4c33..5fe0fca 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java @@ -40,7 +40,7 @@ public Mono signalServiceFlow(Signal signal) { private Mono getDeadSignal(Signal signal) { DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); - deadSignal.setError(DUPLICATE_SIGNAL_ERROR.toString()); + deadSignal.setErrorReason(DUPLICATE_SIGNAL_ERROR.toString()); return Mono.just(deadSignal); } From 644734bac48c1788174efea6e6af57139f7a287b Mon Sep 17 00:00:00 2001 From: ariannazafarana <112564573+ariannazafarana@users.noreply.github.com> Date: Fri, 13 Oct 2023 17:09:35 +0200 Subject: [PATCH 26/62] adds actuator configuration --- src/main/resources/application.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2ac7414..5b5c63c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ logging.level.root=INFO spring.main.web-appplication-type=reactive - +management.endpoint.health.show-details=always # Disable auto cloud formation cloud.aws.stack.auto=false @@ -17,7 +17,6 @@ database.port=${DB_PORT:5432} database.username=${DB_USER:postgres} database.password=${DB_PASSWORD:postgres} - #Liquibase spring.liquibase.url=jdbc:postgresql://${database.host}:${database.port}/${database.name} spring.liquibase.user=${database.username} From fec77dfc5e9112ccf6f9ed885336ef2e07847fb7 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Mon, 16 Oct 2023 11:03:40 +0200 Subject: [PATCH 27/62] Updated sql init_table script --- .../changes/init_table/init_table.sql | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index ed41b34..25d5be5 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -1,10 +1,12 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, producer_id VARCHAR (50) NOT NULL, + event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id) + UNIQUE (eservice_id, producer_id), + PRIMARY KEY (eservice_id, producer_id) ); CREATE INDEX ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); @@ -13,10 +15,12 @@ CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( eservice_id VARCHAR (50) NOT NULL, consumer_id VARCHAR (50) NOT NULL, + event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, consumer_id) + UNIQUE (eservice_id, consumer_id), + PRIMARY KEY (eservice_id, consumer_id) ); CREATE INDEX CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); CREATE INDEX ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); @@ -53,7 +57,21 @@ CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( CREATE TABLE IF NOT EXISTS TRACING_BATCH ( batch_id SERIAL PRIMARY KEY, state VARCHAR (50) NOT NULL, - last_event_id BIGINT, + last_event_id BIGINT, + event_type VARCHAR (50) NOT NULL, tmst_started TIMESTAMP NOT NULL, tmst_ended TIMESTAMP +); + + +CREATE TABLE IF NOT EXISTS EVENT_TEMP ( + event_temp_id SERIAL PRIMARY KEY, + event_id BIGINT UNIQUE NOT NULL, + event_type VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + object_id VARCHAR (50) NOT NULL, + state VARCHAR (50) NOT NULL, + state_processing VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + tmst_processing TIMESTAMP ); \ No newline at end of file From efbb1ed74cb8245ec173b7dc9d6b150012f88ed1 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Mon, 16 Oct 2023 11:09:52 +0200 Subject: [PATCH 28/62] Added some unit test --- .../exception/PdndGenericExceptionTest.java | 14 +++ .../mapper/DeadSignalMapperTest.java | 102 +++++++++++++++++ .../persister/mapper/SignalMapperTest.java | 108 ++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericExceptionTest.java create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericExceptionTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericExceptionTest.java new file mode 100644 index 0000000..6223cc6 --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericExceptionTest.java @@ -0,0 +1,14 @@ +package it.pagopa.interop.signalhub.persister.exception; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +class PdndGenericExceptionTest { + + @Test + void exceptionTest() { + assertDoesNotThrow(() -> new PdndGenericException(ExceptionTypeEnum.MAPPER_ERROR, ExceptionTypeEnum.MAPPER_ERROR.getMessage())); + assertDoesNotThrow(() -> new PdndGenericException(ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR, ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR.getMessage())); + } +} diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java new file mode 100644 index 0000000..fc2c90f --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java @@ -0,0 +1,102 @@ +package it.pagopa.interop.signalhub.persister.mapper; + +import it.pagopa.interop.signalhub.persister.entity.DeadSignal; +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.queue.model.SignalType; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; +import static org.junit.jupiter.api.Assertions.*; + + +class DeadSignalMapperTest { + private final DeadSignalMapper deadSignalMapper = Mappers.getMapper(DeadSignalMapper.class); + private final Long signalId = 0L; + private final String objectId = "OBJ1"; + private final String correlationId = "0A"; + private final String eserviceId = "OBJ1"; + private final String objectType = "0E"; + private final Long indexSignal = 0L; + private final String errorReason = "404 Not Found"; + private final String signalType = SignalType.CREATE.toString(); + + + + @Test + void signalToDeadSignalTest() { + Signal signal = getSignal(); + DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); + assertNotNull(deadSignal); + assertEquals(deadSignal.getSignalId(), this.indexSignal); + assertEquals(deadSignal.getObjectId(), this.objectId); + assertEquals(deadSignal.getEserviceId(), this.eserviceId); + assertEquals(deadSignal.getCorrelationId(), this.correlationId); + assertEquals(deadSignal.getSignalType(), this.signalType); + assertEquals(deadSignal.getObjectType(), this.objectType); + } + + @Test + void signalToDeadSignalNullCaseTest() { + DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(null); + assertNull(deadSignal); + } + + @Test + void signalToDeadSignalWithSignalTypeNullTest() { + Signal signal = getSignal(); + signal.setSignalType(null); + DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); + assertNotNull(deadSignal); + assertNull(deadSignal.getSignalType()); + } + + @Test + void deadSignalToSignalTest() { + DeadSignal deadSignal = getDeadSignal(); + Signal signal = deadSignalMapper.deadSignalToSignal(deadSignal); + assertNotNull(signal); + assertEquals(signal.getSignalId(), this.indexSignal); + assertEquals(signal.getObjectId(), this.objectId); + assertEquals(signal.getEserviceId(), this.eserviceId); + assertEquals(signal.getCorrelationId(), this.correlationId); + assertEquals(signal.getSignalType(), this.signalType); + assertEquals(signal.getObjectType(), this.objectType); + } + + @Test + void deadSignalToSignalNullCaseTest() { + Signal signal = deadSignalMapper.deadSignalToSignal(null); + assertNull(signal); + } + + @Test + void deadSignalToSignalWithSignalTypeNullTest() { + DeadSignal deadSignal = getDeadSignal(); + deadSignal.setSignalType(null); + Signal signal = deadSignalMapper.deadSignalToSignal(deadSignal); + assertNotNull(signal); + assertNull(signal.getSignalType()); + } + + private Signal getSignal() { + Signal signal = new Signal(); + signal.setSignalId(this.signalId); + signal.setSignalType(this.signalType); + signal.setObjectType(this.objectType); + signal.setCorrelationId(this.correlationId); + signal.setEserviceId(this.eserviceId); + signal.setObjectId(this.objectId); + return signal; + } + + private DeadSignal getDeadSignal() { + DeadSignal deadSignal = new DeadSignal(); + deadSignal.setSignalType(this.signalType); + deadSignal.setObjectType(this.objectType); + deadSignal.setEserviceId(this.eserviceId); + deadSignal.setObjectId(this.objectId); + deadSignal.setCorrelationId(this.correlationId); + deadSignal.setSignalId(this.signalId); + deadSignal.setErrorReason(this.errorReason); + return deadSignal; + } +} \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java new file mode 100644 index 0000000..0294dcf --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java @@ -0,0 +1,108 @@ +package it.pagopa.interop.signalhub.persister.mapper; + +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import it.pagopa.interop.signalhub.persister.queue.model.SignalType; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; +import static org.junit.jupiter.api.Assertions.*; + + +class SignalMapperTest { + private final SignalMapper signalMapper = Mappers.getMapper(SignalMapper.class); + private final Long signalId = 0L; + private final String objectId = "OBJ1"; + private final String correlationId = "0A"; + private final String eserviceId = "OBJ1"; + private final String objectType = "0E"; + private final Long indexSignal = 0L; + private final String signalType = SignalType.CREATE.toString(); + + + @Test + void signalToSignalEventTest() { + Signal signal = getSignal(); + SignalEvent signalEvent = signalMapper.signalToSignalEvent(signal); + assertNotNull(signalEvent); + assertEquals(signalEvent.getObjectId(), this.objectId); + assertEquals(signalEvent.getEserviceId(), this.eserviceId); + assertEquals(signalEvent.getSignalType(), SignalType.CREATE); + assertEquals(signalEvent.getObjectType(), this.objectType); + assertEquals(signalEvent.getIndexSignal(), this.indexSignal); + } + + @Test + void signalToSignalEventNullCaseTest() { + SignalEvent signalEvent = signalMapper.signalToSignalEvent(null); + assertNull(signalEvent); + } + + @Test + void signalToSignalEventWithSignalTypeNullTest() { + Signal signal = getSignal(); + signal.setSignalType(null); + SignalEvent signalEvent = signalMapper.signalToSignalEvent(signal); + assertNotNull(signalEvent); + assertNull(signalEvent.getSignalType()); + } + + @Test + void signalEventToSignalTest() { + SignalEvent signalEvent = getSignalEvent(); + Signal signal = signalMapper.signalEventToSignal(signalEvent, this.correlationId); + assertNotNull(signal); + assertEquals(signal.getSignalId(), this.indexSignal); + assertEquals(signal.getObjectId(), this.objectId); + assertEquals(signal.getEserviceId(), this.eserviceId); + assertEquals(signal.getCorrelationId(), this.correlationId); + assertEquals(signal.getSignalType(), this.signalType); + assertEquals(signal.getObjectType(), this.objectType); + } + + @Test + void signalEventToSignalNullCaseTest() { + Signal signal = signalMapper.signalEventToSignal(null, null); + assertNull(signal); + + signal = signalMapper.signalEventToSignal(null, this.correlationId); + assertNotNull(signal); + + SignalEvent signalEvent = getSignalEvent(); + signal = signalMapper.signalEventToSignal(signalEvent, null); + assertNotNull(signal); + assertEquals(signal.getSignalId(), this.indexSignal); + assertEquals(signal.getObjectId(), this.objectId); + assertEquals(signal.getEserviceId(), this.eserviceId); + assertEquals(signal.getObjectType(), this.objectType); + } + + @Test + void signalEventToSignalWithSignalTypeNullTest() { + SignalEvent signalEvent = getSignalEvent(); + signalEvent.setSignalType(null); + Signal signal = signalMapper.signalEventToSignal(signalEvent, this.correlationId); + assertNotNull(signal); + assertNull(signal.getSignalType()); + } + + private Signal getSignal() { + Signal signal = new Signal(); + signal.setSignalId(this.signalId); + signal.setSignalType(this.signalType); + signal.setObjectType(this.objectType); + signal.setCorrelationId(this.correlationId); + signal.setEserviceId(this.eserviceId); + signal.setObjectId(this.objectId); + return signal; + } + + private SignalEvent getSignalEvent() { + SignalEvent signalEvent = new SignalEvent(); + signalEvent.setSignalType(SignalType.CREATE); + signalEvent.setObjectType(this.objectType); + signalEvent.setEserviceId(this.eserviceId); + signalEvent.setObjectId(this.objectId); + signalEvent.setIndexSignal(this.indexSignal); + return signalEvent; + } +} \ No newline at end of file From 23a07c3d98b0bdf0dd2e3f0109e96288900da899 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Mon, 16 Oct 2023 11:11:02 +0200 Subject: [PATCH 29/62] Added mockito test configuration --- pom.xml | 7 +++++++ .../mockito-extensions/org.mockito.plugins.MockMaker | 1 + 2 files changed, 8 insertions(+) create mode 100644 src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/pom.xml b/pom.xml index f6433d9..8db8325 100644 --- a/pom.xml +++ b/pom.xml @@ -193,6 +193,13 @@ postgresql runtime + + + org.mockito + mockito-inline + 5.2.0 + test + diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000..ca6ee9c --- /dev/null +++ b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file From 7a402f5c6f6eae35a32f4675ddeea9ae9e246b88 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Mon, 16 Oct 2023 16:35:11 +0200 Subject: [PATCH 30/62] some fixes --- .../signalhub/persister/config/AwsBeanBuilder.java | 6 ++---- .../persister/config/AwsPropertiesConfig.java | 3 +-- .../persister/config/SignalHubPersisterConfig.java | 3 +-- .../queue/consumer/SqsInternalListener.java | 2 +- src/main/resources/application.properties | 6 ++---- .../db/changelog/changes/init_table/init_table.sql | 13 ------------- 6 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java index cf5c0e9..46a7e92 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java @@ -20,16 +20,14 @@ @Slf4j public class AwsBeanBuilder { private final AwsPropertiesConfig props; - private final SignalHubPersisterConfig cfn; - public AwsBeanBuilder(AwsPropertiesConfig props, SignalHubPersisterConfig cfn) { + public AwsBeanBuilder(AwsPropertiesConfig props) { this.props = props; - this.cfn = cfn; } @Bean public SqsAsyncClient sqsAsyncClient() { - return configureBuilder(SqsAsyncClient.builder(), props.getEndpointUrlSqs()); + return configureBuilder(SqsAsyncClient.builder(), props.getSqsEndpoint()); } @Bean diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsPropertiesConfig.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsPropertiesConfig.java index 57bbaaf..d06d333 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsPropertiesConfig.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsPropertiesConfig.java @@ -12,6 +12,5 @@ public class AwsPropertiesConfig { private String profile; private String region; - private String endpointUrl; - private String endpointUrlSqs; + private String sqsEndpoint; } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java index ebe5939..54b1bf9 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/SignalHubPersisterConfig.java @@ -9,7 +9,6 @@ @Getter @Setter @Configuration -@ConfigurationProperties(prefix = "poc.signal-hub") +@ConfigurationProperties(prefix = "pdnd.signal-hub") public class SignalHubPersisterConfig { - private String internalQueueName; } diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 2244bf0..54880e7 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -26,7 +26,7 @@ public class SqsInternalListener { private SignalMapper signalMapper; - @SqsListener(value = "${poc.signal-hub.internal-queue-name}") + @SqsListener(value = "${aws.internal-queue-name}") public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers); String correlationId = (String) headers.get(SignalMapper.CORRELATION_ID_HEADER_KEY); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5b5c63c..62d84c4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,10 +6,8 @@ management.endpoint.health.show-details=always cloud.aws.stack.auto=false aws.profile=default aws.region=${AWS_REGION:us-east-1} -aws.endpoint-url=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} -aws.endpoint-url-sqs=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} - -poc.signal-hub.internal-queue-name=local-internal-signal-hub +aws.sqs-endpoint=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} +aws.internal-queue-name=local-internal-signal-hub database.name=${DB_NAME:signal-hub} database.host=${DB_HOST:localhost} diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 25d5be5..bbebc3c 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -62,16 +62,3 @@ CREATE TABLE IF NOT EXISTS TRACING_BATCH ( tmst_started TIMESTAMP NOT NULL, tmst_ended TIMESTAMP ); - - -CREATE TABLE IF NOT EXISTS EVENT_TEMP ( - event_temp_id SERIAL PRIMARY KEY, - event_id BIGINT UNIQUE NOT NULL, - event_type VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - object_id VARCHAR (50) NOT NULL, - state VARCHAR (50) NOT NULL, - state_processing VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - tmst_processing TIMESTAMP -); \ No newline at end of file From 056bafd28532c465cc298da09d8f7d93d60c730d Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Tue, 17 Oct 2023 11:09:43 +0200 Subject: [PATCH 31/62] added dead event table --- .../db/changelog/changes/init_table/changelog.xml | 2 +- .../db/changelog/changes/init_table/init_table.sql | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/changelog.xml b/src/main/resources/db/changelog/changes/init_table/changelog.xml index 430055c..6dadf9e 100644 --- a/src/main/resources/db/changelog/changes/init_table/changelog.xml +++ b/src/main/resources/db/changelog/changes/init_table/changelog.xml @@ -7,7 +7,7 @@ http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd"> - + Date: Tue, 17 Oct 2023 14:18:05 +0200 Subject: [PATCH 32/62] moved aws profile to dev config --- config/application.properties | 1 + src/main/resources/application.properties | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.properties b/config/application.properties index 8b13789..4bc1109 100644 --- a/config/application.properties +++ b/config/application.properties @@ -1 +1,2 @@ +aws.profile=default diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 62d84c4..9b14208 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,7 +4,6 @@ management.endpoint.health.show-details=always # Disable auto cloud formation cloud.aws.stack.auto=false -aws.profile=default aws.region=${AWS_REGION:us-east-1} aws.sqs-endpoint=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} aws.internal-queue-name=local-internal-signal-hub From 5b469d6792f7760fc4e93fffcb9caf92f45fbf5f Mon Sep 17 00:00:00 2001 From: Francesco Carlucci Date: Tue, 17 Oct 2023 14:41:42 +0200 Subject: [PATCH 33/62] add conditional creation on indexes --- .../db/changelog/changes/init_table/init_table.sql | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 5ee5d32..3f5359a 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -8,8 +8,9 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( UNIQUE (eservice_id, producer_id), PRIMARY KEY (eservice_id, producer_id) ); -CREATE INDEX ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); -CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); + +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( @@ -22,8 +23,8 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( UNIQUE (eservice_id, consumer_id), PRIMARY KEY (eservice_id, consumer_id) ); -CREATE INDEX CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); -CREATE INDEX ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); CREATE TABLE IF NOT EXISTS SIGNAL ( @@ -37,8 +38,8 @@ CREATE TABLE IF NOT EXISTS SIGNAL ( tmst_insert TIMESTAMP NOT NULL, UNIQUE (signal_id, eservice_id) ); -CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); -CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); +CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); +CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( From a4b2f53eae459786bc0af52b2a6bece3789176c2 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Wed, 18 Oct 2023 17:14:48 +0200 Subject: [PATCH 34/62] Added Signal Service unit Test --- .../persister/service/SignalServiceTest.java | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceTest.java diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceTest.java new file mode 100644 index 0000000..77783c8 --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceTest.java @@ -0,0 +1,163 @@ +package it.pagopa.interop.signalhub.persister.service; + +import it.pagopa.interop.signalhub.persister.entity.DeadSignal; +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.mapper.DeadSignalMapper; +import it.pagopa.interop.signalhub.persister.queue.model.SignalType; +import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; +import it.pagopa.interop.signalhub.persister.repository.SignalRepository; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mapstruct.factory.Mappers; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import reactor.core.publisher.Mono; + +import java.util.Objects; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + + +@ExtendWith(MockitoExtension.class) +class SignalServiceTest { + @InjectMocks + SignalService signalService; + @Mock + private SignalRepository signalRepository; + @Mock + private DeadSignalRepository deadSignalRepository; + @Mock + private DeadSignalMapper deadSignalMapper; + + private final Long id = 0L; + private final Long signalId = 100L; + private final String objectId = "OBJ1"; + private final String correlationId = "0A"; + private final String eserviceId = "OBJ1"; + private final String objectType = "0E"; + private final String signalType = SignalType.CREATE.toString(); + + + @Test + void signalServiceFlowTest() { + Signal signalToSave = getSignal(); + signalToSave.setId(null); + Mockito + .when(signalRepository.findByIndexSignalAndEserviceId(signalToSave.getSignalId(), signalToSave.getEserviceId())) + .thenReturn(Mono.empty()); + + Mockito + .when(signalRepository.save(signalToSave)) + .thenReturn(Mono.just(signalToSave)); + + + signalService.signalServiceFlow(signalToSave) + .flatMap(sig -> { + Assertions.assertNotNull(sig); + Assertions.assertEquals(signalToSave, sig); + return Mono.empty(); + } + ).block(); + + + ArgumentCaptor captorString = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captorLong = ArgumentCaptor.forClass(Long.class); + Mockito.verify(signalRepository, Mockito.timeout(1000).times(1)) + .findByIndexSignalAndEserviceId(captorLong.capture(), captorString.capture()); + + assertNotNull(captorLong.getValue()); + assertNotNull(captorString.getValue()); + + assertEquals(signalToSave.getSignalId(), + Objects.requireNonNull(captorLong.getValue())); + + assertEquals(signalToSave.getEserviceId(), + Objects.requireNonNull(captorString.getValue())); + + + ArgumentCaptor signalArgumentCaptor = ArgumentCaptor.forClass(Signal.class); + Mockito.verify(signalRepository, Mockito.timeout(1000).times(1)) + .save(signalArgumentCaptor.capture()); + + assertNotNull(signalArgumentCaptor.getValue()); + assertEquals(signalToSave, + Objects.requireNonNull(signalArgumentCaptor.getValue())); + } + + + @Test + void signalServiceFlowDuplicateSignalTest() { + Signal signalToUpdate = getSignal(); + Mockito + .when(signalRepository.findByIndexSignalAndEserviceId(signalToUpdate.getSignalId(), signalToUpdate.getEserviceId())) + .thenReturn(Mono.just(signalToUpdate)); + + DeadSignalMapper dsm = Mappers.getMapper(DeadSignalMapper.class); + DeadSignal deadSignal = dsm.signalToDeadSignal(signalToUpdate); + Mockito + .when(deadSignalMapper.signalToDeadSignal(signalToUpdate)) + .thenReturn(deadSignal); + + Mockito + .when(deadSignalRepository.save(deadSignal)) + .thenReturn(Mono.empty()); + + signalService.signalServiceFlow(signalToUpdate) + .flatMap(sig -> { + Assertions.assertNotNull(sig); + Assertions.assertEquals(signalToUpdate, sig); + return Mono.empty(); + } + ).block(); + + + ArgumentCaptor captorString = ArgumentCaptor.forClass(String.class); + ArgumentCaptor captorLong = ArgumentCaptor.forClass(Long.class); + Mockito.verify(signalRepository, Mockito.timeout(1000).times(1)) + .findByIndexSignalAndEserviceId(captorLong.capture(), captorString.capture()); + + assertNotNull(captorLong.getValue()); + assertNotNull(captorString.getValue()); + + assertEquals(signalToUpdate.getSignalId(), + Objects.requireNonNull(captorLong.getValue())); + + assertEquals(signalToUpdate.getEserviceId(), + Objects.requireNonNull(captorString.getValue())); + + + ArgumentCaptor signalArgumentCaptor = ArgumentCaptor.forClass(Signal.class); + Mockito.verify(deadSignalMapper, Mockito.timeout(1000).times(1)) + .signalToDeadSignal(signalArgumentCaptor.capture()); + + assertNotNull(signalArgumentCaptor.getValue()); + assertEquals(signalToUpdate, + Objects.requireNonNull(signalArgumentCaptor.getValue())); + + + ArgumentCaptor deadSignalArgumentCaptor = ArgumentCaptor.forClass(DeadSignal.class); + Mockito.verify(deadSignalRepository, Mockito.timeout(1000).times(1)) + .save(deadSignalArgumentCaptor.capture()); + + assertNotNull(deadSignalArgumentCaptor.getValue()); + assertEquals(deadSignal, + Objects.requireNonNull(deadSignalArgumentCaptor.getValue())); + } + + private Signal getSignal() { + Signal signal = new Signal(); + signal.setId(this.id); + signal.setSignalId(this.signalId); + signal.setSignalType(this.signalType); + signal.setObjectType(this.objectType); + signal.setCorrelationId(this.correlationId); + signal.setEserviceId(this.eserviceId); + signal.setObjectId(this.objectId); + return signal; + } +} \ No newline at end of file From c8cc11f631e9fdc21d2898dfc836fe847826fea7 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Fri, 20 Oct 2023 11:17:18 +0200 Subject: [PATCH 35/62] Added SignalListener unit test and updated configurations --- .../signalhub/persister/entity/Signal.java | 2 + ...ception.java => PDNDGenericException.java} | 4 +- .../queue/consumer/SqsInternalListener.java | 8 +- .../persister/queue/model/SignalEvent.java | 4 +- .../signalhub/persister/utils/Utility.java | 18 +- .../persister/LocalStackTestConfig.java | 2 +- ...est.java => PDNDGenericExceptionTest.java} | 6 +- .../consumer/SqsInternalListenerTest.java | 165 ++++++++++++++++++ .../persister/utility/UtilityTest.java | 31 ++++ .../resources/application-test.properties | 12 +- src/test/resources/schema-h2.sql | 60 ++++--- 11 files changed, 258 insertions(+), 54 deletions(-) rename src/main/java/it/pagopa/interop/signalhub/persister/exception/{PdndGenericException.java => PDNDGenericException.java} (68%) rename src/test/java/it/pagopa/interop/signalhub/persister/exception/{PdndGenericExceptionTest.java => PDNDGenericExceptionTest.java} (68%) create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java create mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java index 253f9e9..7e7af0d 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/entity/Signal.java @@ -1,5 +1,6 @@ package it.pagopa.interop.signalhub.persister.entity; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -14,6 +15,7 @@ @Setter @Table @ToString +@EqualsAndHashCode public class Signal { @Id @Column("id") diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericException.java b/src/main/java/it/pagopa/interop/signalhub/persister/exception/PDNDGenericException.java similarity index 68% rename from src/main/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericException.java rename to src/main/java/it/pagopa/interop/signalhub/persister/exception/PDNDGenericException.java index 7cc634a..9afe841 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericException.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/exception/PDNDGenericException.java @@ -4,12 +4,12 @@ @Getter -public class PdndGenericException extends RuntimeException { +public class PDNDGenericException extends RuntimeException { private final ExceptionTypeEnum exceptionType; private final String message; - public PdndGenericException(ExceptionTypeEnum exceptionType, String message){ + public PDNDGenericException(ExceptionTypeEnum exceptionType, String message){ super(message); this.exceptionType = exceptionType; this.message = message; diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 54880e7..0562bcd 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -6,23 +6,21 @@ import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; import it.pagopa.interop.signalhub.persister.service.SignalService; import it.pagopa.interop.signalhub.persister.utils.Utility; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.handler.annotation.Headers; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; - import java.util.Map; import java.util.concurrent.CompletableFuture; @Slf4j @Component +@AllArgsConstructor public class SqsInternalListener { - @Autowired private SignalService signalService; - @Autowired private SignalMapper signalMapper; @@ -38,4 +36,4 @@ public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @H .then() .toFuture(); } -} +} \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java index 33458e5..57886ed 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java @@ -1,5 +1,6 @@ package it.pagopa.interop.signalhub.persister.queue.model; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -8,6 +9,7 @@ @Getter @Setter @ToString +@EqualsAndHashCode public class SignalEvent { private SignalType signalType; @@ -18,4 +20,4 @@ public class SignalEvent { private String eserviceId; private Long indexSignal; -} +} \ No newline at end of file diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java index b7d9e75..1f0f552 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import it.pagopa.interop.signalhub.persister.exception.PdndGenericException; +import it.pagopa.interop.signalhub.persister.exception.PDNDGenericException; import lombok.extern.slf4j.Slf4j; import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; @@ -22,21 +22,7 @@ public static T jsonToObject(String json, Class tClass){ return objectMapper.readValue(json, tClass); } catch (JsonProcessingException exception) { log.error("exception = {}, errorReason = {}, Error during mapping an object", exception, exception.getMessage()); - throw new PdndGenericException(MAPPER_ERROR, MAPPER_ERROR.getMessage()); - } - } - - public static String objectToJson(T data){ - try{ - ObjectMapper objectMapper = new ObjectMapper() - .registerModule(new Jdk8Module()) - .registerModule(new JavaTimeModule()); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - return objectMapper.writeValueAsString(data); - } - catch (JsonProcessingException exception){ - log.error("exception = {}, errorReason = {}, Error during mapping an object", exception, exception.getMessage()); - return null; + throw new PDNDGenericException(MAPPER_ERROR, MAPPER_ERROR.getMessage()); } } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java b/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java index 474487e..5ee3524 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java @@ -37,7 +37,7 @@ public class LocalStackTestConfig { static { localStack.start(); - System.setProperty("aws.endpoint-url", localStack.getEndpointOverride(DYNAMODB).toString()); + System.setProperty("aws.sqs-endpoint", localStack.getEndpointOverride(DYNAMODB).toString()); try { System.setProperty("aws.sharedCredentialsFile", new ClassPathResource("testcontainers/credentials").getFile().getAbsolutePath()); } catch (IOException e) { diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericExceptionTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/exception/PDNDGenericExceptionTest.java similarity index 68% rename from src/test/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericExceptionTest.java rename to src/test/java/it/pagopa/interop/signalhub/persister/exception/PDNDGenericExceptionTest.java index 6223cc6..a7c411b 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/exception/PdndGenericExceptionTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/exception/PDNDGenericExceptionTest.java @@ -4,11 +4,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -class PdndGenericExceptionTest { +class PDNDGenericExceptionTest { @Test void exceptionTest() { - assertDoesNotThrow(() -> new PdndGenericException(ExceptionTypeEnum.MAPPER_ERROR, ExceptionTypeEnum.MAPPER_ERROR.getMessage())); - assertDoesNotThrow(() -> new PdndGenericException(ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR, ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR.getMessage())); + assertDoesNotThrow(() -> new PDNDGenericException(ExceptionTypeEnum.MAPPER_ERROR, ExceptionTypeEnum.MAPPER_ERROR.getMessage())); + assertDoesNotThrow(() -> new PDNDGenericException(ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR, ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR.getMessage())); } } diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java new file mode 100644 index 0000000..bc1e2f8 --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java @@ -0,0 +1,165 @@ +package it.pagopa.interop.signalhub.persister.queue.consumer; + +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.exception.PDNDGenericException; +import it.pagopa.interop.signalhub.persister.mapper.SignalMapper; +import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import it.pagopa.interop.signalhub.persister.queue.model.SignalType; +import it.pagopa.interop.signalhub.persister.service.SignalService; +import it.pagopa.interop.signalhub.persister.utils.Utility; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mapstruct.factory.Mappers; +import org.mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; +import reactor.core.publisher.Mono; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ExecutionException; +import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; +import static org.junit.jupiter.api.Assertions.*; + + +@ExtendWith(MockitoExtension.class) +class SqsInternalListenerTest { + @InjectMocks + private SqsInternalListener sqsInternalListener; + @Mock + private SignalService signalService; + @Mock + private SignalMapper signalMapper; + private MockedStatic utility; + private final String objectId = "OBJ1"; + private final String correlationId = "0A"; + private final String eserviceId = "OBJ1"; + private final String objectType = "0E"; + private final Long indexSignal = 0L; + + + @BeforeEach + void preTest() { + utility = Mockito.mockStatic(Utility.class); + } + + @AfterEach + void postTest() { + if(utility != null) { + utility.close(); + } + } + + @Test + void pullFromAwsInternalQueueTest() throws ExecutionException, InterruptedException { + String jsoNode = """ + { + "signalType": "CREATE", + "objectId": "OBJ1", + "objectType": "T1", + "eserviceId": "E1", + "indexSignal": "000001" + } + """; + SignalEvent signalEvent = getSignalEvent(); + + utility.when(() -> Utility.jsonToObject(jsoNode, SignalEvent.class)) + .thenReturn(signalEvent); + + Map headers = new HashMap<>(); + headers.put(SignalMapper.CORRELATION_ID_HEADER_KEY, correlationId); + + SignalMapper sm = Mappers.getMapper(SignalMapper.class); + Signal signal = sm.signalEventToSignal(signalEvent, correlationId); + + Mockito + .when(signalMapper.signalEventToSignal(signalEvent, correlationId)) + .thenReturn(signal); + + Mockito + .when(signalService.signalServiceFlow(signal)) + .thenReturn(Mono.just(signal)); + + sqsInternalListener.pullFromAwsInternalQueue(jsoNode, headers).get(); + + + Mockito + .verify(signalMapper, Mockito.timeout(1000).times(1)) + .signalEventToSignal(signalEvent, correlationId); + + + ArgumentCaptor signalEventArgumentCaptor = ArgumentCaptor.forClass(SignalEvent.class); + ArgumentCaptor captorString = ArgumentCaptor.forClass(String.class); + + Mockito + .verify(signalMapper, Mockito.timeout(1000).times(1)) + .signalEventToSignal(signalEventArgumentCaptor.capture(), captorString.capture()); + + assertNotNull(signalEventArgumentCaptor.getValue()); + assertNotNull(captorString.getValue()); + + assertEquals(signalEvent, + Objects.requireNonNull(signalEventArgumentCaptor.getValue())); + assertEquals(correlationId, + Objects.requireNonNull(captorString.getValue())); + + + Mockito + .verify(signalService, Mockito.timeout(1000).times(1)) + .signalServiceFlow(signal); + } + + @Test + void pullFromAwsInternalQueueJsonNullTest() { + String jsoNode = null; + Map headers = new HashMap<>(); + headers.put(SignalMapper.CORRELATION_ID_HEADER_KEY, correlationId); + Assertions.assertThrows(NullPointerException.class, () -> + sqsInternalListener.pullFromAwsInternalQueue(jsoNode, headers) + .get()); + } + + @Test + void pullFromAwsInternalQueueExceptionToObjectTest() { + String jsoNode = """ + { + "signalType": "CREATE", + "objectId": "OBJ1", + "objectType": "T1", + "eserviceId": "E1", + "indexSignal": "000001" + } + """; + SignalEvent signalEvent = getSignalEvent(); + + utility.when(() -> Utility.jsonToObject(jsoNode, SignalEvent.class)) + .thenThrow(new PDNDGenericException(MAPPER_ERROR, MAPPER_ERROR.getMessage())); + + Map headers = new HashMap<>(); + headers.put(SignalMapper.CORRELATION_ID_HEADER_KEY, correlationId); + + ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> + sqsInternalListener.pullFromAwsInternalQueue(jsoNode, headers) + .get()); + + Mockito.verify(signalMapper, Mockito.timeout(1000).times(0)) + .signalEventToSignal(signalEvent, correlationId); + + Mockito.verify(signalService, Mockito.timeout(1000).times(0)) + .signalServiceFlow(Mockito.any()); + + Assertions.assertEquals(MAPPER_ERROR.getMessage(), exception.getCause().getMessage()); + } + + private SignalEvent getSignalEvent() { + SignalEvent signalEvent = new SignalEvent(); + signalEvent.setSignalType(SignalType.CREATE); + signalEvent.setObjectType(this.objectType); + signalEvent.setEserviceId(this.eserviceId); + signalEvent.setObjectId(this.objectId); + signalEvent.setIndexSignal(this.indexSignal); + return signalEvent; + } +} \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java new file mode 100644 index 0000000..b8ad0a3 --- /dev/null +++ b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java @@ -0,0 +1,31 @@ +package it.pagopa.interop.signalhub.persister.utility; + +import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; +import it.pagopa.interop.signalhub.persister.queue.model.SignalType; +import it.pagopa.interop.signalhub.persister.utils.Utility; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + + +class UtilityTest { + @Test + void jsonToObjectTest() { + String jsonNode = """ + { + "signalType": "CREATE", + "objectId": "OBJ1", + "objectType": "T1", + "eserviceId": "E1", + "indexSignal": "000001" + } + """; + SignalEvent signalEvent = Utility.jsonToObject(jsonNode, SignalEvent.class); + assertNotNull(signalEvent); + assertEquals(SignalType.CREATE, signalEvent.getSignalType()); + assertEquals("OBJ1", signalEvent.getObjectId()); + assertEquals("T1", signalEvent.getObjectType()); + assertEquals("E1", signalEvent.getEserviceId()); + assertEquals("1", signalEvent.getIndexSignal().toString()); + } +} \ No newline at end of file diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index d1c6204..8326c0e 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -3,9 +3,8 @@ cloud.aws.region.auto=true # Load instance profile credentials cloud.aws.credentials.instanceProfile=true -aws.endpoint-url=http://localhost:4566 -aws.endpoint-url-sqs=http://localhost:4566/000000000000/ -aws.internal-queue-name=internal-queue +aws.sqs-endpoint=http://localhost:4566/000000000000/ +aws.internal-queue-name=local-internal-signal-hub aws.region=us-east-1 aws.profile=default @@ -16,5 +15,10 @@ spring.r2dbc.pool.max-size=20 spring.r2dbc.pool.initial-size=5 spring.r2dbc.pool.enabled=true spring.data.r2dbc.repositories.enabled=true +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect +spring.sql.init.platform=h2 +spring.sql.init.mode=always -spring.sql.init.platform=h2 \ No newline at end of file +spring.liquibase.enabled=false \ No newline at end of file diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index 3077371..c210a25 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -1,25 +1,33 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, producer_id VARCHAR (50) NOT NULL, + event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id) + UNIQUE (eservice_id, producer_id), + PRIMARY KEY (eservice_id, producer_id) ); -CREATE INDEX ESERVICE_INDEX_ID ON ESERVICE (eservice_id); -CREATE INDEX ESERVICE_INDEX_PRODUCER_ID ON ESERVICE (producer_id); +/* +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE (eservice_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE (producer_id); +*/ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( eservice_id VARCHAR (50) NOT NULL, consumer_id VARCHAR (50) NOT NULL, + event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, consumer_id) + UNIQUE (eservice_id, consumer_id), + PRIMARY KEY (eservice_id, consumer_id) ); -CREATE INDEX CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE (eservice_id); -CREATE INDEX ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE (consumer_id); +/* +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE (eservice_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE (consumer_id); +*/ CREATE TABLE IF NOT EXISTS SIGNAL ( @@ -33,33 +41,41 @@ CREATE TABLE IF NOT EXISTS SIGNAL ( tmst_insert TIMESTAMP NOT NULL, UNIQUE (signal_id, eservice_id) ); - /* H2 not support USING constructor -CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); -CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); +CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); +CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); */ -CREATE INDEX SIGNAL_INDEX_SIGNAL_ID ON SIGNAL (signal_id); -CREATE INDEX SIGNAL_INDEX_ESERVICE_ID ON SIGNAL (eservice_id); - CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( - id SERIAL PRIMARY KEY, - correlation_id VARCHAR(50) NOT NULL, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - error_reason VARCHAR(255) NOT NULL + id SERIAL PRIMARY KEY, + correlation_id VARCHAR(50) NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + error_reason VARCHAR(255) NOT NULL ); CREATE TABLE IF NOT EXISTS TRACING_BATCH ( batch_id SERIAL PRIMARY KEY, state VARCHAR (50) NOT NULL, - last_event_id BIGINT, + last_event_id BIGINT, tmst_started TIMESTAMP NOT NULL, tmst_ended TIMESTAMP +); + + +CREATE TABLE IF NOT EXISTS DEAD_EVENT ( + event_tmp_id SERIAL PRIMARY KEY, + tmst_insert TIMESTAMP, + error_reason VARCHAR(255) NOT NULL, + event_id BIGINT NOT NULL, + event_type VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50), + agreement_id VARCHAR (50) ); \ No newline at end of file From 3cf70e8543c93fdb79dc2f60a1043de2db278882 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Fri, 20 Oct 2023 11:48:00 +0200 Subject: [PATCH 36/62] Splitted signal service impl with its interface --- .../persister/service/SignalService.java | 50 ++--------------- .../service/impl/SignalServiceImpl.java | 53 +++++++++++++++++++ .../signalhub/persister/ApplicationTest.java | 23 -------- ...ceTest.java => SignalServiceImplTest.java} | 9 ++-- 4 files changed, 61 insertions(+), 74 deletions(-) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java delete mode 100644 src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java rename src/test/java/it/pagopa/interop/signalhub/persister/service/{SignalServiceTest.java => SignalServiceImplTest.java} (93%) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java index 5fe0fca..9e642e7 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/SignalService.java @@ -1,52 +1,8 @@ package it.pagopa.interop.signalhub.persister.service; -import it.pagopa.interop.signalhub.persister.entity.DeadSignal; import it.pagopa.interop.signalhub.persister.entity.Signal; -import it.pagopa.interop.signalhub.persister.mapper.DeadSignalMapper; -import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; -import it.pagopa.interop.signalhub.persister.repository.SignalRepository; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Mono; -import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR; - -@Service -@Slf4j -public class SignalService { - @Autowired - private SignalRepository signalRepository; - @Autowired - private DeadSignalRepository deadSignalRepository; - @Autowired - private DeadSignalMapper deadSignalMapper; - - - @Transactional - public Mono signalServiceFlow(Signal signal) { - - return getSignalById(signal.getSignalId(), signal.getEserviceId()) - .switchIfEmpty(Mono.just(signal)) - .filter(entity -> entity.getId() == null) - .flatMap(this::createSignal) - .switchIfEmpty(Mono.defer(() -> saveToDeadSignal(signal))); - } - - private Mono getSignalById(Long signalId, String eserviceId) { return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId); } - private Mono createSignal(Signal signal) { return this.signalRepository.save(signal); } - private Mono createDeadSignal(DeadSignal signal) { return this.deadSignalRepository.save(signal); } - - private Mono getDeadSignal(Signal signal) { - DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); - deadSignal.setErrorReason(DUPLICATE_SIGNAL_ERROR.toString()); - return Mono.just(deadSignal); - } - - private Mono saveToDeadSignal(Signal signal) { - return getDeadSignal(signal) - .flatMap(this::createDeadSignal) - .then(Mono.just(signal)); - } -} \ No newline at end of file +public interface SignalService { + Mono signalServiceFlow(Signal signal); +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java new file mode 100644 index 0000000..756fa7a --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java @@ -0,0 +1,53 @@ +package it.pagopa.interop.signalhub.persister.service.impl; + +import it.pagopa.interop.signalhub.persister.entity.DeadSignal; +import it.pagopa.interop.signalhub.persister.entity.Signal; +import it.pagopa.interop.signalhub.persister.mapper.DeadSignalMapper; +import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; +import it.pagopa.interop.signalhub.persister.repository.SignalRepository; +import it.pagopa.interop.signalhub.persister.service.SignalService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import reactor.core.publisher.Mono; +import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR; + + +@Service +@Slf4j +public class SignalServiceImpl implements SignalService { + @Autowired + private SignalRepository signalRepository; + @Autowired + private DeadSignalRepository deadSignalRepository; + @Autowired + private DeadSignalMapper deadSignalMapper; + + + @Transactional + public Mono signalServiceFlow(Signal signal) { + + return getSignalById(signal.getSignalId(), signal.getEserviceId()) + .switchIfEmpty(Mono.just(signal)) + .filter(entity -> entity.getId() == null) + .flatMap(this::createSignal) + .switchIfEmpty(Mono.defer(() -> saveToDeadSignal(signal))); + } + + private Mono getSignalById(Long signalId, String eserviceId) { return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId); } + private Mono createSignal(Signal signal) { return this.signalRepository.save(signal); } + private Mono createDeadSignal(DeadSignal signal) { return this.deadSignalRepository.save(signal); } + + private Mono getDeadSignal(Signal signal) { + DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); + deadSignal.setErrorReason(DUPLICATE_SIGNAL_ERROR.toString()); + return Mono.just(deadSignal); + } + + private Mono saveToDeadSignal(Signal signal) { + return getDeadSignal(signal) + .flatMap(this::createDeadSignal) + .then(Mono.just(signal)); + } +} \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java deleted file mode 100644 index 56619e2..0000000 --- a/src/test/java/it/pagopa/interop/signalhub/persister/ApplicationTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package it.pagopa.interop.signalhub.persister; - - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.ActiveProfiles; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -@Import(LocalStackTestConfig.class) -@SpringBootTest(classes = SignalHubSignalsPersisterApplication.class) - -@ActiveProfiles("test") -class ApplicationTest { - - - @Test - void testApp(){ - assertTrue(true); - } - -} diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java similarity index 93% rename from src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceTest.java rename to src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java index 77783c8..e47738c 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java @@ -6,6 +6,7 @@ import it.pagopa.interop.signalhub.persister.queue.model.SignalType; import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; import it.pagopa.interop.signalhub.persister.repository.SignalRepository; +import it.pagopa.interop.signalhub.persister.service.impl.SignalServiceImpl; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -24,9 +25,9 @@ @ExtendWith(MockitoExtension.class) -class SignalServiceTest { +class SignalServiceImplTest { @InjectMocks - SignalService signalService; + SignalServiceImpl signalServiceImpl; @Mock private SignalRepository signalRepository; @Mock @@ -56,7 +57,7 @@ void signalServiceFlowTest() { .thenReturn(Mono.just(signalToSave)); - signalService.signalServiceFlow(signalToSave) + signalServiceImpl.signalServiceFlow(signalToSave) .flatMap(sig -> { Assertions.assertNotNull(sig); Assertions.assertEquals(signalToSave, sig); @@ -107,7 +108,7 @@ void signalServiceFlowDuplicateSignalTest() { .when(deadSignalRepository.save(deadSignal)) .thenReturn(Mono.empty()); - signalService.signalServiceFlow(signalToUpdate) + signalServiceImpl.signalServiceFlow(signalToUpdate) .flatMap(sig -> { Assertions.assertNotNull(sig); Assertions.assertEquals(signalToUpdate, sig); From 38272b217adcb627f96eb68b460d611f35fc3d3d Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Fri, 20 Oct 2023 13:19:55 +0200 Subject: [PATCH 37/62] Updated jacoco configuration --- pom.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 8db8325..6a28dec 100644 --- a/pom.xml +++ b/pom.xml @@ -240,10 +240,8 @@ jacoco-maven-plugin - it/pagopa/interop/signalhub/push/service/rest/v1/dto/* - it/pagopa/interop/signalhub/push/service/rest/v1/dto/** - it/pagopa/interop/signalhub/push/service/generated/* - it/pagopa/interop/signalhub/push/service/generated/** + it/pagopa/interop/signalhub/persister/config/* + **/SignalHubSignalsPersisterApplication.class From d677773e8f8c8e7b270a72a19132045a748865c0 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Fri, 20 Oct 2023 15:12:51 +0200 Subject: [PATCH 38/62] Updated SignalServiceImplTest with entity save exception test --- .../service/SignalServiceImplTest.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java index e47738c..abf82c1 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java @@ -20,8 +20,7 @@ import java.util.Objects; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; @ExtendWith(MockitoExtension.class) @@ -48,6 +47,7 @@ class SignalServiceImplTest { void signalServiceFlowTest() { Signal signalToSave = getSignal(); signalToSave.setId(null); + Mockito .when(signalRepository.findByIndexSignalAndEserviceId(signalToSave.getSignalId(), signalToSave.getEserviceId())) .thenReturn(Mono.empty()); @@ -150,6 +150,29 @@ void signalServiceFlowDuplicateSignalTest() { Objects.requireNonNull(deadSignalArgumentCaptor.getValue())); } + @Test + void signalServiceFlowExceptionSaveTest() { + Signal signalToSave = getSignal(); + signalToSave.setId(null); + + Mockito + .when(signalRepository.findByIndexSignalAndEserviceId(signalToSave.getSignalId(), signalToSave.getEserviceId())) + .thenReturn(Mono.just(signalToSave)); + + Mockito + .when(signalRepository.save(signalToSave)) + .thenThrow(new IllegalArgumentException()); + + signalServiceImpl.signalServiceFlow(signalToSave) + .onErrorResume(exception -> { + Assertions.assertNotNull(exception); + assertEquals(IllegalArgumentException.class, exception.getClass()); + return Mono.empty(); + }) + .block(); + } + + private Signal getSignal() { Signal signal = new Signal(); signal.setId(this.id); From 220b503a9a84ba79c09f065ce3a1d808345d2fd6 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Fri, 20 Oct 2023 16:04:07 +0200 Subject: [PATCH 39/62] Updated some unit test --- .../mapper/DeadSignalMapperTest.java | 32 ++++++++++++++----- .../persister/mapper/SignalMapperTest.java | 30 +++++++++++++---- .../consumer/SqsInternalListenerTest.java | 19 ++++++++--- .../service/SignalServiceImplTest.java | 32 +++++++++++++------ .../persister/utility/UtilityTest.java | 13 ++++++++ 5 files changed, 97 insertions(+), 29 deletions(-) diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java index fc2c90f..ea78871 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java @@ -3,6 +3,7 @@ import it.pagopa.interop.signalhub.persister.entity.DeadSignal; import it.pagopa.interop.signalhub.persister.entity.Signal; import it.pagopa.interop.signalhub.persister.queue.model.SignalType; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; import static org.junit.jupiter.api.Assertions.*; @@ -10,16 +11,20 @@ class DeadSignalMapperTest { private final DeadSignalMapper deadSignalMapper = Mappers.getMapper(DeadSignalMapper.class); - private final Long signalId = 0L; - private final String objectId = "OBJ1"; - private final String correlationId = "0A"; - private final String eserviceId = "OBJ1"; - private final String objectType = "0E"; - private final Long indexSignal = 0L; - private final String errorReason = "404 Not Found"; - private final String signalType = SignalType.CREATE.toString(); + private Long signalId; + private String objectId; + private String correlationId; + private String eserviceId; + private String objectType; + private Long indexSignal; + private String errorReason; + private String signalType; + @BeforeEach + void preTest() { + this.setUp(); + } @Test void signalToDeadSignalTest() { @@ -99,4 +104,15 @@ private DeadSignal getDeadSignal() { deadSignal.setErrorReason(this.errorReason); return deadSignal; } + + private void setUp() { + this.signalId = 0L; + this.objectId = "OBJ1"; + this.correlationId = "0A"; + this.objectType = "0E"; + this.eserviceId = "OBJ1"; + this.indexSignal = 0L; + this.errorReason = "404 Not Found"; + this.signalType = SignalType.CREATE.toString(); + } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java index 0294dcf..af1b18a 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java @@ -3,6 +3,7 @@ import it.pagopa.interop.signalhub.persister.entity.Signal; import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; import it.pagopa.interop.signalhub.persister.queue.model.SignalType; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; import static org.junit.jupiter.api.Assertions.*; @@ -10,15 +11,20 @@ class SignalMapperTest { private final SignalMapper signalMapper = Mappers.getMapper(SignalMapper.class); - private final Long signalId = 0L; - private final String objectId = "OBJ1"; - private final String correlationId = "0A"; - private final String eserviceId = "OBJ1"; - private final String objectType = "0E"; - private final Long indexSignal = 0L; - private final String signalType = SignalType.CREATE.toString(); + private Long signalId; + private String objectId; + private String correlationId; + private String eserviceId; + private String objectType; + private Long indexSignal; + private String signalType; + @BeforeEach + void preTest() { + this.setUp(); + } + @Test void signalToSignalEventTest() { Signal signal = getSignal(); @@ -105,4 +111,14 @@ private SignalEvent getSignalEvent() { signalEvent.setIndexSignal(this.indexSignal); return signalEvent; } + + private void setUp() { + this.signalId = 0L; + this.objectId = "OBJ1"; + this.correlationId = "0A"; + this.objectType = "0E"; + this.eserviceId = "OBJ1"; + this.indexSignal = 0L; + this.signalType = SignalType.CREATE.toString(); + } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java index bc1e2f8..2cc0346 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java @@ -33,16 +33,17 @@ class SqsInternalListenerTest { @Mock private SignalMapper signalMapper; private MockedStatic utility; - private final String objectId = "OBJ1"; - private final String correlationId = "0A"; - private final String eserviceId = "OBJ1"; - private final String objectType = "0E"; - private final Long indexSignal = 0L; + private String objectId; + private String correlationId; + private String eserviceId; + private String objectType; + private Long indexSignal; @BeforeEach void preTest() { utility = Mockito.mockStatic(Utility.class); + this.setUp(); } @AfterEach @@ -162,4 +163,12 @@ private SignalEvent getSignalEvent() { signalEvent.setIndexSignal(this.indexSignal); return signalEvent; } + + private void setUp() { + this.objectId = "OBJ1"; + this.correlationId = "0A"; + this.eserviceId = "OBJ1"; + this.objectType = "0E"; + this.indexSignal = 0L; + } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java index abf82c1..b626fb6 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java @@ -8,6 +8,7 @@ import it.pagopa.interop.signalhub.persister.repository.SignalRepository; import it.pagopa.interop.signalhub.persister.service.impl.SignalServiceImpl; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mapstruct.factory.Mappers; @@ -17,9 +18,7 @@ import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import reactor.core.publisher.Mono; - import java.util.Objects; - import static org.junit.jupiter.api.Assertions.*; @@ -34,14 +33,19 @@ class SignalServiceImplTest { @Mock private DeadSignalMapper deadSignalMapper; - private final Long id = 0L; - private final Long signalId = 100L; - private final String objectId = "OBJ1"; - private final String correlationId = "0A"; - private final String eserviceId = "OBJ1"; - private final String objectType = "0E"; - private final String signalType = SignalType.CREATE.toString(); + private Long id; + private Long signalId; + private String objectId; + private String correlationId; + private String eserviceId; + private String objectType; + private String signalType; + + @BeforeEach + void preTest(){ + this.setUp(); + } @Test void signalServiceFlowTest() { @@ -184,4 +188,14 @@ private Signal getSignal() { signal.setObjectId(this.objectId); return signal; } + + private void setUp() { + this.id = 0L; + this.signalId = 100L; + this.objectId = "OBJ1"; + this.correlationId = "0A"; + this.eserviceId = "OBJ1"; + this.objectType = "0E"; + this.signalType = SignalType.CREATE.toString(); + } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java index b8ad0a3..b3b458f 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java @@ -1,9 +1,12 @@ package it.pagopa.interop.signalhub.persister.utility; +import it.pagopa.interop.signalhub.persister.exception.PDNDGenericException; import it.pagopa.interop.signalhub.persister.queue.model.SignalEvent; import it.pagopa.interop.signalhub.persister.queue.model.SignalType; import it.pagopa.interop.signalhub.persister.utils.Utility; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,4 +31,14 @@ void jsonToObjectTest() { assertEquals("E1", signalEvent.getEserviceId()); assertEquals("1", signalEvent.getIndexSignal().toString()); } + + @Test + void jsonToObjectExceptionErrorTest() { + String jsonNode = "@sa1e43r@dgr@°#cv-dsw?!"; + PDNDGenericException exception = + Assertions.assertThrows(PDNDGenericException.class, + () -> Utility.jsonToObject(jsonNode, SignalEvent.class)); + + assertEquals(MAPPER_ERROR.getMessage(), exception.getMessage()); + } } \ No newline at end of file From 0ed1569a7e6b73d744407eac2c5fd69eb9e82537 Mon Sep 17 00:00:00 2001 From: francarl77 <97600561+francarl77@users.noreply.github.com> Date: Fri, 20 Oct 2023 18:43:57 +0200 Subject: [PATCH 40/62] update test --- .../interop/signalhub/persister/utility/UtilityTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java index b3b458f..d94a7a5 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java @@ -23,6 +23,7 @@ void jsonToObjectTest() { "indexSignal": "000001" } """; + SignalEvent signalEvent = Utility.jsonToObject(jsonNode, SignalEvent.class); assertNotNull(signalEvent); assertEquals(SignalType.CREATE, signalEvent.getSignalType()); @@ -41,4 +42,4 @@ void jsonToObjectExceptionErrorTest() { assertEquals(MAPPER_ERROR.getMessage(), exception.getMessage()); } -} \ No newline at end of file +} From 3b22e2ae0a8e8ac6d5d19a9b9aff1fbbf220f455 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Thu, 26 Oct 2023 12:04:28 +0200 Subject: [PATCH 41/62] Updated some unit test --- pom.xml | 3 ++- .../pagopa/interop/signalhub/persister/utils/Utility.java | 8 +------- .../signalhub/persister/mapper/DeadSignalMapperTest.java | 5 +++-- .../signalhub/persister/mapper/SignalMapperTest.java | 5 +++-- .../persister/queue/consumer/SqsInternalListenerTest.java | 2 +- .../persister/service/SignalServiceImplTest.java | 2 +- .../interop/signalhub/persister/utility/UtilityTest.java | 1 + 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 6a28dec..f039167 100644 --- a/pom.xml +++ b/pom.xml @@ -238,9 +238,10 @@ org.jacoco jacoco-maven-plugin + 0.8.10 - it/pagopa/interop/signalhub/persister/config/* + it/pagopa/interop/signalhub/persister/config/** **/SignalHubSignalsPersisterApplication.class diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java index 1f0f552..f33af04 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Utility.java @@ -2,20 +2,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import it.pagopa.interop.signalhub.persister.exception.PDNDGenericException; import lombok.extern.slf4j.Slf4j; + import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.MAPPER_ERROR; @Slf4j public class Utility { - private Utility() { - throw new IllegalCallerException(); - } - public static T jsonToObject(String json, Class tClass){ try { ObjectMapper objectMapper = new ObjectMapper(); diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java index ea78871..df39717 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/DeadSignalMapperTest.java @@ -10,7 +10,7 @@ class DeadSignalMapperTest { - private final DeadSignalMapper deadSignalMapper = Mappers.getMapper(DeadSignalMapper.class); + private DeadSignalMapper deadSignalMapper; private Long signalId; private String objectId; private String correlationId; @@ -109,10 +109,11 @@ private void setUp() { this.signalId = 0L; this.objectId = "OBJ1"; this.correlationId = "0A"; - this.objectType = "0E"; + this.objectType = "ESERVICE"; this.eserviceId = "OBJ1"; this.indexSignal = 0L; this.errorReason = "404 Not Found"; this.signalType = SignalType.CREATE.toString(); + this.deadSignalMapper = Mappers.getMapper(DeadSignalMapper.class); } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java index af1b18a..45af576 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java @@ -10,7 +10,7 @@ class SignalMapperTest { - private final SignalMapper signalMapper = Mappers.getMapper(SignalMapper.class); + private SignalMapper signalMapper; private Long signalId; private String objectId; private String correlationId; @@ -116,9 +116,10 @@ private void setUp() { this.signalId = 0L; this.objectId = "OBJ1"; this.correlationId = "0A"; - this.objectType = "0E"; + this.objectType = "ESERVICE"; this.eserviceId = "OBJ1"; this.indexSignal = 0L; this.signalType = SignalType.CREATE.toString(); + this.signalMapper = Mappers.getMapper(SignalMapper.class); } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java index 2cc0346..cf0370f 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java @@ -168,7 +168,7 @@ private void setUp() { this.objectId = "OBJ1"; this.correlationId = "0A"; this.eserviceId = "OBJ1"; - this.objectType = "0E"; + this.objectType = "ESERVICE"; this.indexSignal = 0L; } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java index b626fb6..7778afc 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/service/SignalServiceImplTest.java @@ -195,7 +195,7 @@ private void setUp() { this.objectId = "OBJ1"; this.correlationId = "0A"; this.eserviceId = "OBJ1"; - this.objectType = "0E"; + this.objectType = "ESERVICE"; this.signalType = SignalType.CREATE.toString(); } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java index b3b458f..5880f73 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java @@ -12,6 +12,7 @@ class UtilityTest { + private final Utility utility = new Utility(); @Test void jsonToObjectTest() { String jsonNode = """ From 528199acd61960a1abbf2a0b260bb236914e66f0 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Thu, 26 Oct 2023 12:50:10 +0200 Subject: [PATCH 42/62] Updated LocalStackTestConfig --- .../interop/signalhub/persister/LocalStackTestConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java b/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java index 5ee3524..aa9b22b 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/LocalStackTestConfig.java @@ -25,7 +25,7 @@ public class LocalStackTestConfig { static LocalStackContainer localStack = new LocalStackContainer(DockerImageName.parse("localstack/localstack:1.0.4").asCompatibleSubstituteFor("localstack/localstack")) - .withServices(DYNAMODB, SQS) + .withServices(SQS) .withClasspathResourceMapping("testcontainers/init.sh", "/docker-entrypoint-initaws.d/make-storages.sh", BindMode.READ_ONLY) .withClasspathResourceMapping("testcontainers/credentials", @@ -37,7 +37,7 @@ public class LocalStackTestConfig { static { localStack.start(); - System.setProperty("aws.sqs-endpoint", localStack.getEndpointOverride(DYNAMODB).toString()); + System.setProperty("aws.sqs-endpoint", localStack.getEndpointOverride(SQS).toString()); try { System.setProperty("aws.sharedCredentialsFile", new ClassPathResource("testcontainers/credentials").getFile().getAbsolutePath()); } catch (IOException e) { From 8725a44e40e0c16ab84280f422ff3097d85d4fae Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Thu, 26 Oct 2023 18:36:36 +0200 Subject: [PATCH 43/62] Updated init_table.sql and schema-h2.sql scripts --- .../changes/init_table/init_table.sql | 18 ++++++++++----- src/test/resources/schema-h2.sql | 22 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 3f5359a..8c7680b 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -1,30 +1,35 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, producer_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id), - PRIMARY KEY (eservice_id, producer_id) + UNIQUE (eservice_id, producer_id, descriptor_id), + PRIMARY KEY (eservice_id, producer_id, descriptor_id) ); CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_DESCRIPTOR_ID ON ESERVICE USING hash (descriptor_id); CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( eservice_id VARCHAR (50) NOT NULL, consumer_id VARCHAR (50) NOT NULL, + agreement_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, consumer_id), - PRIMARY KEY (eservice_id, consumer_id) + UNIQUE (eservice_id, consumer_id, descriptor_id), + PRIMARY KEY (eservice_id, consumer_id, descriptor_id) ); CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESERVICE USING hash (descriptor_id); CREATE TABLE IF NOT EXISTS SIGNAL ( @@ -70,6 +75,7 @@ CREATE TABLE IF NOT EXISTS DEAD_EVENT ( event_id BIGINT NOT NULL, event_type VARCHAR (50) NOT NULL, object_type VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, eservice_id VARCHAR (50), agreement_id VARCHAR (50) -); +); \ No newline at end of file diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index c210a25..eb4d119 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -1,32 +1,37 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, producer_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id), - PRIMARY KEY (eservice_id, producer_id) + UNIQUE (eservice_id, producer_id, descriptor_id), + PRIMARY KEY (eservice_id, producer_id, descriptor_id) ); /* -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE (eservice_id); -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE (producer_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); +CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_DESCRIPTOR_ID ON ESERVICE USING hash (descriptor_id); */ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( eservice_id VARCHAR (50) NOT NULL, consumer_id VARCHAR (50) NOT NULL, + agreement_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT NOT NULL, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, consumer_id), - PRIMARY KEY (eservice_id, consumer_id) + UNIQUE (eservice_id, consumer_id, descriptor_id), + PRIMARY KEY (eservice_id, consumer_id, descriptor_id) ); /* -CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE (eservice_id); -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE (consumer_id); +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESERVICE USING hash (descriptor_id); */ @@ -76,6 +81,7 @@ CREATE TABLE IF NOT EXISTS DEAD_EVENT ( event_id BIGINT NOT NULL, event_type VARCHAR (50) NOT NULL, object_type VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, eservice_id VARCHAR (50), agreement_id VARCHAR (50) ); \ No newline at end of file From 9f6dec7fa658f22de3ba2a4d9cfd1b74b387becd Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Tue, 31 Oct 2023 11:28:55 +0100 Subject: [PATCH 44/62] some fixes --- .../resources/db/changelog/changes/init_table/init_table.sql | 2 +- src/test/resources/schema-h2.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 8c7680b..fa33208 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS DEAD_EVENT ( event_id BIGINT NOT NULL, event_type VARCHAR (50) NOT NULL, object_type VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50), eservice_id VARCHAR (50), agreement_id VARCHAR (50) ); \ No newline at end of file diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index eb4d119..22fc606 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -81,7 +81,7 @@ CREATE TABLE IF NOT EXISTS DEAD_EVENT ( event_id BIGINT NOT NULL, event_type VARCHAR (50) NOT NULL, object_type VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50), eservice_id VARCHAR (50), agreement_id VARCHAR (50) ); \ No newline at end of file From 2cc8c47efb910a5ca063d8e8c7f8d22dfb6a2b50 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Thu, 2 Nov 2023 10:54:12 +0100 Subject: [PATCH 45/62] remove NOT NULL constraint for event_id column --- .../resources/db/changelog/changes/init_table/init_table.sql | 4 ++-- src/test/resources/schema-h2.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index fa33208..2c016e1 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, producer_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT NOT NULL, + event_id BIGINT , state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( consumer_id VARCHAR (50) NOT NULL, agreement_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT NOT NULL, + event_id BIGINT , state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index 22fc606..806ac23 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) UNIQUE NOT NULL, producer_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT NOT NULL, + event_id BIGINT , state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, @@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( consumer_id VARCHAR (50) NOT NULL, agreement_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT NOT NULL, + event_id BIGINT , state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP NOT NULL, tmst_last_edit TIMESTAMP, From c488496f3166dd0592d643a13fac1f26d6febc0e Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Thu, 2 Nov 2023 11:10:40 +0100 Subject: [PATCH 46/62] Set default timestamp for tmst_insert column --- .../resources/db/changelog/changes/init_table/init_table.sql | 4 ++-- src/test/resources/schema-h2.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 2c016e1..e7ce328 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT , state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, producer_id, descriptor_id), PRIMARY KEY (eservice_id, producer_id, descriptor_id) @@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT , state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, consumer_id, descriptor_id), PRIMARY KEY (eservice_id, consumer_id, descriptor_id) diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index 806ac23..1f64e59 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT , state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, producer_id, descriptor_id), PRIMARY KEY (eservice_id, producer_id, descriptor_id) @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT , state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, consumer_id, descriptor_id), PRIMARY KEY (eservice_id, consumer_id, descriptor_id) From 19f77a0063f102aa7bb984ff2db520298c4acd49 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Thu, 2 Nov 2023 12:56:28 +0100 Subject: [PATCH 47/62] refactoring consumer primary key --- .../changes/init_table/init_table.sql | 25 +++++++++--------- src/test/resources/schema-h2.sql | 26 +++++++++---------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index e7ce328..c827493 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( - eservice_id VARCHAR (50) UNIQUE NOT NULL, + eservice_id VARCHAR (50) NOT NULL, producer_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT , @@ -15,21 +15,22 @@ CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (pr CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_DESCRIPTOR_ID ON ESERVICE USING hash (descriptor_id); + CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( - eservice_id VARCHAR (50) NOT NULL, - consumer_id VARCHAR (50) NOT NULL, - agreement_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT , - state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, consumer_id, descriptor_id), - PRIMARY KEY (eservice_id, consumer_id, descriptor_id) + agreement_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + consumer_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, + event_id BIGINT , + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + tmst_last_edit TIMESTAMP, + PRIMARY KEY (agreement_id) ); + CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); -CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESERVICE USING hash (descriptor_id); + CREATE TABLE IF NOT EXISTS SIGNAL ( diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index 1f64e59..ab8b713 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( - eservice_id VARCHAR (50) UNIQUE NOT NULL, + eservice_id VARCHAR (50) NOT NULL, producer_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, event_id BIGINT , @@ -17,21 +17,21 @@ CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_DESCRIPTOR_ID ON ESERVICE USING hash ( CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( - eservice_id VARCHAR (50) NOT NULL, - consumer_id VARCHAR (50) NOT NULL, - agreement_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT , - state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, consumer_id, descriptor_id), - PRIMARY KEY (eservice_id, consumer_id, descriptor_id) -); + agreement_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + consumer_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, + event_id BIGINT , + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + tmst_last_edit TIMESTAMP, + PRIMARY KEY (agreement_id) + ); + + /* CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); -CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESERVICE USING hash (descriptor_id); */ From 757427c6981572480de9bd14505c30838fdb0016 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Mon, 6 Nov 2023 17:25:04 +0100 Subject: [PATCH 48/62] Updated init_table.sql and schema-h2.sql scripts --- .../changes/init_table/init_table.sql | 46 ++++++++-------- src/test/resources/schema-h2.sql | 52 +++++++++---------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index c827493..ed0337c 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -2,39 +2,36 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) NOT NULL, producer_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT , + event_id BIGINT, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id, descriptor_id), - PRIMARY KEY (eservice_id, producer_id, descriptor_id) + UNIQUE (eservice_id, producer_id), + PRIMARY KEY (eservice_id, producer_id) ); - CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_DESCRIPTOR_ID ON ESERVICE USING hash (descriptor_id); - CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( - agreement_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - consumer_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT , - state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - tmst_last_edit TIMESTAMP, - PRIMARY KEY (agreement_id) + agreement_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + consumer_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, + event_id BIGINT, + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, consumer_id, descriptor_id), + PRIMARY KEY (eservice_id, consumer_id, descriptor_id) ); - CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); - +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESERVICE USING hash (descriptor_id); CREATE TABLE IF NOT EXISTS SIGNAL ( - id SERIAL PRIMARY KEY, + id SERIAL PRIMARY KEY, correlation_id VARCHAR(50) NOT NULL, signal_id BIGINT NOT NULL, object_id VARCHAR (50) NOT NULL, @@ -49,7 +46,7 @@ CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservi CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( - id SERIAL PRIMARY KEY, + id SERIAL PRIMARY KEY, correlation_id VARCHAR(50) NOT NULL, signal_id BIGINT NOT NULL, object_id VARCHAR (50) NOT NULL, @@ -62,13 +59,14 @@ CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( CREATE TABLE IF NOT EXISTS TRACING_BATCH ( - batch_id SERIAL PRIMARY KEY, - state VARCHAR (50) NOT NULL, - last_event_id BIGINT, - tmst_started TIMESTAMP NOT NULL, - tmst_ended TIMESTAMP + batch_id SERIAL PRIMARY KEY, + state VARCHAR (50) NOT NULL, + last_event_id BIGINT, + tmst_started TIMESTAMP NOT NULL, + tmst_ended TIMESTAMP ); + CREATE TABLE IF NOT EXISTS DEAD_EVENT ( event_tmp_id SERIAL PRIMARY KEY, tmst_insert TIMESTAMP, diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index ab8b713..68e84b0 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -2,41 +2,41 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( eservice_id VARCHAR (50) NOT NULL, producer_id VARCHAR (50) NOT NULL, descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT , + event_id BIGINT, state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id, descriptor_id), - PRIMARY KEY (eservice_id, producer_id, descriptor_id) + UNIQUE (eservice_id, producer_id), + PRIMARY KEY (eservice_id, producer_id) ); /* CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_DESCRIPTOR_ID ON ESERVICE USING hash (descriptor_id); */ -CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( - agreement_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - consumer_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT , - state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - tmst_last_edit TIMESTAMP, - PRIMARY KEY (agreement_id) - ); - +CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( + agreement_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + consumer_id VARCHAR (50) NOT NULL, + descriptor_id VARCHAR (50) NOT NULL, + event_id BIGINT, + state VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, consumer_id, descriptor_id), + PRIMARY KEY (eservice_id, consumer_id, descriptor_id) +); /* CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); +CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESERVICE USING hash (descriptor_id); */ CREATE TABLE IF NOT EXISTS SIGNAL ( - id SERIAL PRIMARY KEY, + id SERIAL PRIMARY KEY, correlation_id VARCHAR(50) NOT NULL, signal_id BIGINT NOT NULL, object_id VARCHAR (50) NOT NULL, @@ -53,15 +53,15 @@ CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservi CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( - id SERIAL PRIMARY KEY, - correlation_id VARCHAR(50) NOT NULL, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - error_reason VARCHAR(255) NOT NULL + id SERIAL PRIMARY KEY, + correlation_id VARCHAR(50) NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (50) NOT NULL, + object_type VARCHAR (50) NOT NULL, + signal_type VARCHAR (50) NOT NULL, + tmst_insert TIMESTAMP NOT NULL, + error_reason VARCHAR(255) NOT NULL ); From d81c50e752301c29cc515f0fc7b876bdbf47414e Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Tue, 7 Nov 2023 16:51:37 +0100 Subject: [PATCH 49/62] Updated init_table.sql and schema-h2.sql scripts --- .../resources/db/changelog/changes/init_table/init_table.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index ed0337c..069f9d3 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -62,8 +62,7 @@ CREATE TABLE IF NOT EXISTS TRACING_BATCH ( batch_id SERIAL PRIMARY KEY, state VARCHAR (50) NOT NULL, last_event_id BIGINT, - tmst_started TIMESTAMP NOT NULL, - tmst_ended TIMESTAMP + tmst_created TIMESTAMP NOT NULL ); From 2b42fc113ffd9c681b9050416871308fe3c7e08b Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Tue, 7 Nov 2023 16:52:45 +0100 Subject: [PATCH 50/62] Updated init_table.sql and schema-h2.sql scripts --- src/test/resources/schema-h2.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index 68e84b0..d0e2c4a 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -69,8 +69,7 @@ CREATE TABLE IF NOT EXISTS TRACING_BATCH ( batch_id SERIAL PRIMARY KEY, state VARCHAR (50) NOT NULL, last_event_id BIGINT, - tmst_started TIMESTAMP NOT NULL, - tmst_ended TIMESTAMP + tmst_created TIMESTAMP NOT NULL ); From e41e7b87f85d8d51fec035673f8ba65ef7e00ede Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Fri, 10 Nov 2023 15:13:10 +0100 Subject: [PATCH 51/62] added key into eservice table --- .../resources/db/changelog/changes/init_table/init_table.sql | 4 ++-- src/test/resources/schema-h2.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index 069f9d3..eda3250 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -6,8 +6,8 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id), - PRIMARY KEY (eservice_id, producer_id) + UNIQUE (eservice_id, producer_id, descriptor_id), + PRIMARY KEY (eservice_id, producer_id, descriptor_id) ); CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index d0e2c4a..d5cccba 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -6,8 +6,8 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( state VARCHAR (50) NOT NULL, tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id), - PRIMARY KEY (eservice_id, producer_id) + UNIQUE (eservice_id, producer_id, descriptor_id), + PRIMARY KEY (eservice_id, producer_id, descriptor_id) ); /* CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); From 6e8a8a1ab3e0bf5525756711768ab7faa0d5b232 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Thu, 16 Nov 2023 18:23:33 +0100 Subject: [PATCH 52/62] added queue error policy --- .../interop/signalhub/persister/config/AwsBeanBuilder.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java index 46a7e92..cb20932 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java @@ -2,6 +2,7 @@ import io.awspring.cloud.sqs.config.SqsBootstrapConfiguration; import io.awspring.cloud.sqs.config.SqsMessageListenerContainerFactory; +import io.awspring.cloud.sqs.listener.acknowledgement.handler.AcknowledgementMode; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Bean; @@ -35,6 +36,7 @@ public SqsMessageListenerContainerFactory defaultSqsListenerContainerFac return SqsMessageListenerContainerFactory .builder() .configure(options -> options + .acknowledgementMode(AcknowledgementMode.ON_SUCCESS) .maxConcurrentMessages(10) .maxMessagesPerPoll(10)) .sqsAsyncClient(sqsAsyncClient()) From 44cfd4e0abff0064b125e6f2cafce3336570a97a Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Mon, 20 Nov 2023 16:41:08 +0100 Subject: [PATCH 53/62] fixed column type and added type column into tracing batch --- .../changes/init_table/init_table.sql | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/main/resources/db/changelog/changes/init_table/init_table.sql b/src/main/resources/db/changelog/changes/init_table/init_table.sql index eda3250..b033211 100644 --- a/src/main/resources/db/changelog/changes/init_table/init_table.sql +++ b/src/main/resources/db/changelog/changes/init_table/init_table.sql @@ -1,9 +1,9 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( - eservice_id VARCHAR (50) NOT NULL, - producer_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, + eservice_id VARCHAR (255) NOT NULL, + producer_id VARCHAR (255) NOT NULL, + descriptor_id VARCHAR (255) NOT NULL, event_id BIGINT, - state VARCHAR (50) NOT NULL, + state VARCHAR (255) NOT NULL, tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, producer_id, descriptor_id), @@ -14,12 +14,12 @@ CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (pr CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( - agreement_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - consumer_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, + agreement_id VARCHAR (255) NOT NULL, + eservice_id VARCHAR (255) NOT NULL, + consumer_id VARCHAR (255) NOT NULL, + descriptor_id VARCHAR (255) NOT NULL, event_id BIGINT, - state VARCHAR (50) NOT NULL, + state VARCHAR (255) NOT NULL, tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, tmst_last_edit TIMESTAMP, UNIQUE (eservice_id, consumer_id, descriptor_id), @@ -32,13 +32,13 @@ CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESE CREATE TABLE IF NOT EXISTS SIGNAL ( id SERIAL PRIMARY KEY, - correlation_id VARCHAR(50) NOT NULL, + correlation_id VARCHAR(255) NOT NULL, signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + object_id VARCHAR (255) NOT NULL, + eservice_id VARCHAR (255) NOT NULL, + object_type VARCHAR (255) NOT NULL, + signal_type VARCHAR (255) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE (signal_id, eservice_id) ); CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); @@ -47,33 +47,34 @@ CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservi CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( id SERIAL PRIMARY KEY, - correlation_id VARCHAR(50) NOT NULL, + correlation_id VARCHAR(255) NOT NULL, signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, + object_id VARCHAR (255) NOT NULL, + eservice_id VARCHAR (255) NOT NULL, + object_type VARCHAR (255) NOT NULL, + signal_type VARCHAR (255) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, error_reason VARCHAR(255) NOT NULL ); CREATE TABLE IF NOT EXISTS TRACING_BATCH ( batch_id SERIAL PRIMARY KEY, - state VARCHAR (50) NOT NULL, + state VARCHAR (255) NOT NULL, + type VARCHAR (50) NOT NULL, last_event_id BIGINT, - tmst_created TIMESTAMP NOT NULL + tmst_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE IF NOT EXISTS DEAD_EVENT ( event_tmp_id SERIAL PRIMARY KEY, - tmst_insert TIMESTAMP, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, error_reason VARCHAR(255) NOT NULL, event_id BIGINT NOT NULL, - event_type VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50), - eservice_id VARCHAR (50), - agreement_id VARCHAR (50) + event_type VARCHAR (255) NOT NULL, + object_type VARCHAR (255) NOT NULL, + descriptor_id VARCHAR (255), + eservice_id VARCHAR (255), + agreement_id VARCHAR (255) ); \ No newline at end of file From eb1fb589c602b402030de6be718616f5a8d94758 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Wed, 22 Nov 2023 16:04:26 +0100 Subject: [PATCH 54/62] changed property indexSignal to signalId --- .../interop/signalhub/persister/queue/model/SignalEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java index 57886ed..0e384ae 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/model/SignalEvent.java @@ -19,5 +19,5 @@ public class SignalEvent { private String eserviceId; - private Long indexSignal; + private Long signalId; } \ No newline at end of file From 9fa187a52c40c60547615e61086fdaaa66c6b8c9 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Wed, 22 Nov 2023 16:08:18 +0100 Subject: [PATCH 55/62] removed mapping annotation --- .../interop/signalhub/persister/mapper/SignalMapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java index 758c720..3af4cb9 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapper.java @@ -10,9 +10,8 @@ public interface SignalMapper { String CORRELATION_ID_HEADER_KEY = "correlationId"; - @Mapping(target = "indexSignal", source = "signal.signalId") SignalEvent signalToSignalEvent(Signal signal); - @Mapping(target = "signalId", source = "signalEvent.indexSignal") + @Mapping(target = "correlationId", source = "correlationId") Signal signalEventToSignal(SignalEvent signalEvent, String correlationId); } From 0a8872cad37a872e63a053e38bf7fbc198469e60 Mon Sep 17 00:00:00 2001 From: "pasqualino.cristaudo" <> Date: Thu, 23 Nov 2023 17:40:43 +0100 Subject: [PATCH 56/62] Updated pom --- pom.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f039167..1835dcf 100644 --- a/pom.xml +++ b/pom.xml @@ -241,7 +241,9 @@ 0.8.10 - it/pagopa/interop/signalhub/persister/config/** + **/config/** + **/entity/** + **/queue/model/** **/SignalHubSignalsPersisterApplication.class From ab9d88e1fcd7e2479c62dfd5efa2533ba856cb9b Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Wed, 29 Nov 2023 16:00:31 +0100 Subject: [PATCH 57/62] resolved reports --- .../persister/SignalHubSignalsPersisterApplication.java | 3 --- src/test/resources/testcontainers/init.sh | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/SignalHubSignalsPersisterApplication.java b/src/main/java/it/pagopa/interop/signalhub/persister/SignalHubSignalsPersisterApplication.java index 193daf6..59a11c0 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/SignalHubSignalsPersisterApplication.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/SignalHubSignalsPersisterApplication.java @@ -11,9 +11,6 @@ public class SignalHubSignalsPersisterApplication { public static void main(String[] args) { - - log.error("AVAILABLE PROCESSOR: {}", Runtime.getRuntime().availableProcessors() ); - SpringApplication.run(SignalHubSignalsPersisterApplication.class, args); } diff --git a/src/test/resources/testcontainers/init.sh b/src/test/resources/testcontainers/init.sh index 85e6051..efad9f3 100644 --- a/src/test/resources/testcontainers/init.sh +++ b/src/test/resources/testcontainers/init.sh @@ -1,4 +1,4 @@ -echo "### CREATE PN-SERVICE-DESK QUEUES ###" +echo "### CREATE SIGNAL HUB PERSISTER QUEUES ###" queues="internal-queue" From 0dcb5d061c5c0e3ae0b4a11a4ddd84afd0bd7473 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Thu, 30 Nov 2023 10:56:45 +0100 Subject: [PATCH 58/62] addded tracing log --- .../persister/config/AwsBeanBuilder.java | 2 +- .../config/ReactorConfiguration.java | 20 +++ .../persister/logging/ContextLifter.java | 55 +++++++++ .../persister/logging/MdcContextLifter.java | 40 ++++++ .../queue/consumer/SqsInternalListener.java | 9 +- .../signalhub/persister/utils/Const.java | 5 + src/main/resources/application.properties | 1 + .../persister/mapper/SignalMapperTest.java | 12 +- .../consumer/SqsInternalListenerTest.java | 6 +- .../persister/utility/UtilityTest.java | 2 +- src/test/resources/schema-h2.sql | 115 ++++++++---------- 11 files changed, 189 insertions(+), 78 deletions(-) create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/config/ReactorConfiguration.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/logging/ContextLifter.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/logging/MdcContextLifter.java create mode 100644 src/main/java/it/pagopa/interop/signalhub/persister/utils/Const.java diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java index cb20932..27c3a05 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java @@ -36,7 +36,7 @@ public SqsMessageListenerContainerFactory defaultSqsListenerContainerFac return SqsMessageListenerContainerFactory .builder() .configure(options -> options - .acknowledgementMode(AcknowledgementMode.ON_SUCCESS) + //.acknowledgementMode(AcknowledgementMode.ON_SUCCESS) .maxConcurrentMessages(10) .maxMessagesPerPoll(10)) .sqsAsyncClient(sqsAsyncClient()) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/ReactorConfiguration.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/ReactorConfiguration.java new file mode 100644 index 0000000..81d368e --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/ReactorConfiguration.java @@ -0,0 +1,20 @@ +package it.pagopa.interop.signalhub.persister.config; + + +import it.pagopa.interop.signalhub.persister.logging.ContextLifter; +import it.pagopa.interop.signalhub.persister.logging.MdcContextLifter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import reactor.core.publisher.Hooks; +import reactor.core.publisher.Operators; + +@Configuration +public class ReactorConfiguration { + + + @Bean + public void contextLifterConfiguration() { + Hooks.onEachOperator(MdcContextLifter.class.getSimpleName(), + Operators.lift((sc, sub) -> new ContextLifter<>(sub))); + } +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/logging/ContextLifter.java b/src/main/java/it/pagopa/interop/signalhub/persister/logging/ContextLifter.java new file mode 100644 index 0000000..cb1bb17 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/logging/ContextLifter.java @@ -0,0 +1,55 @@ +package it.pagopa.interop.signalhub.persister.logging; + +import org.reactivestreams.Subscription; +import reactor.core.CoreSubscriber; +import reactor.util.context.Context; + +public class ContextLifter implements CoreSubscriber { + private final CoreSubscriber actualSubscriber; + private final Context context; + + public ContextLifter(CoreSubscriber actualSubscriber) { + this.actualSubscriber = actualSubscriber; + this.context = actualSubscriber.currentContext(); + } + + @Override + public Context currentContext() { + return context; + } + + @Override + public void onSubscribe(Subscription subscription) { + actualSubscriber.onSubscribe(subscription); + } + + @Override + public void onNext(T t) { + MdcContextLifter.setContextToMdc(context); + try { + actualSubscriber.onNext(t); + } finally { + MdcContextLifter.clearMdc(); + } + } + + @Override + public void onError(Throwable throwable) { + MdcContextLifter.setContextToMdc(context); + try { + actualSubscriber.onError(throwable); + } finally { + MdcContextLifter.clearMdc(); + } + } + + @Override + public void onComplete() { + MdcContextLifter.setContextToMdc(context); + try { + actualSubscriber.onComplete(); + } finally { + MdcContextLifter.clearMdc(); + } + } +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/logging/MdcContextLifter.java b/src/main/java/it/pagopa/interop/signalhub/persister/logging/MdcContextLifter.java new file mode 100644 index 0000000..8e18356 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/logging/MdcContextLifter.java @@ -0,0 +1,40 @@ +package it.pagopa.interop.signalhub.persister.logging; + +import org.slf4j.MDC; +import reactor.core.publisher.Signal; +import reactor.util.context.Context; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; + +import static it.pagopa.interop.signalhub.persister.utils.Const.TRACE_ID_KEY; + +public class MdcContextLifter implements Consumer> { + + @Override + public void accept(Signal signal) { + if (!signal.isOnComplete() && !signal.isOnError()) { + Optional> context = signal.getContextView().stream() + .filter(cxt -> cxt.getKey().equals(TRACE_ID_KEY)) + .findFirst(); + + context.ifPresent(ctx -> MDC.put(TRACE_ID_KEY, (String)ctx.getValue())); + } else { + MDC.clear(); + } + } + + public static void setContextToMdc(Context context) { + context.stream().forEach(entry -> { + if (entry.getKey().equals(TRACE_ID_KEY)){ + MDC.put(TRACE_ID_KEY, (String) entry.getValue()); + } + }); + } + + public static void clearMdc(){ + MDC.clear(); + } + +} diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 0562bcd..9290da0 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -12,9 +12,13 @@ import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; +import reactor.util.context.Context; + import java.util.Map; import java.util.concurrent.CompletableFuture; +import static it.pagopa.interop.signalhub.persister.utils.Const.TRACE_ID_KEY; + @Slf4j @Component @@ -26,12 +30,13 @@ public class SqsInternalListener { @SqsListener(value = "${aws.internal-queue-name}") public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @Headers Map headers) { - log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers); String correlationId = (String) headers.get(SignalMapper.CORRELATION_ID_HEADER_KEY); return Mono.just(node) + .contextWrite(Context.of(TRACE_ID_KEY, correlationId)) + .doOnNext(json -> log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers)) .map(json -> Utility.jsonToObject(node, SignalEvent.class)) - .map((signalEvent) -> signalMapper.signalEventToSignal(signalEvent, correlationId)) + .map(signalEvent -> signalMapper.signalEventToSignal(signalEvent, correlationId)) .flatMap(signalService::signalServiceFlow) .then() .toFuture(); diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/utils/Const.java b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Const.java new file mode 100644 index 0000000..c117dc5 --- /dev/null +++ b/src/main/java/it/pagopa/interop/signalhub/persister/utils/Const.java @@ -0,0 +1,5 @@ +package it.pagopa.interop.signalhub.persister.utils; + +public class Const { + public static final String TRACE_ID_KEY = "traceId"; +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9b14208..0af9b1e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,7 @@ logging.level.root=INFO spring.main.web-appplication-type=reactive management.endpoint.health.show-details=always +logging.pattern.level="%2p [%X{traceId:-}]" # Disable auto cloud formation cloud.aws.stack.auto=false diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java index 45af576..b3ecad0 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/mapper/SignalMapperTest.java @@ -16,7 +16,6 @@ class SignalMapperTest { private String correlationId; private String eserviceId; private String objectType; - private Long indexSignal; private String signalType; @@ -32,9 +31,9 @@ void signalToSignalEventTest() { assertNotNull(signalEvent); assertEquals(signalEvent.getObjectId(), this.objectId); assertEquals(signalEvent.getEserviceId(), this.eserviceId); - assertEquals(signalEvent.getSignalType(), SignalType.CREATE); + assertEquals(SignalType.CREATE, signalEvent.getSignalType()); assertEquals(signalEvent.getObjectType(), this.objectType); - assertEquals(signalEvent.getIndexSignal(), this.indexSignal); + assertEquals(signalEvent.getSignalId(), this.signalId); } @Test @@ -57,7 +56,7 @@ void signalEventToSignalTest() { SignalEvent signalEvent = getSignalEvent(); Signal signal = signalMapper.signalEventToSignal(signalEvent, this.correlationId); assertNotNull(signal); - assertEquals(signal.getSignalId(), this.indexSignal); + assertEquals(signal.getSignalId(), this.signalId); assertEquals(signal.getObjectId(), this.objectId); assertEquals(signal.getEserviceId(), this.eserviceId); assertEquals(signal.getCorrelationId(), this.correlationId); @@ -76,7 +75,7 @@ void signalEventToSignalNullCaseTest() { SignalEvent signalEvent = getSignalEvent(); signal = signalMapper.signalEventToSignal(signalEvent, null); assertNotNull(signal); - assertEquals(signal.getSignalId(), this.indexSignal); + assertEquals(signal.getSignalId(), this.signalId); assertEquals(signal.getObjectId(), this.objectId); assertEquals(signal.getEserviceId(), this.eserviceId); assertEquals(signal.getObjectType(), this.objectType); @@ -108,7 +107,7 @@ private SignalEvent getSignalEvent() { signalEvent.setObjectType(this.objectType); signalEvent.setEserviceId(this.eserviceId); signalEvent.setObjectId(this.objectId); - signalEvent.setIndexSignal(this.indexSignal); + signalEvent.setSignalId(this.signalId); return signalEvent; } @@ -118,7 +117,6 @@ private void setUp() { this.correlationId = "0A"; this.objectType = "ESERVICE"; this.eserviceId = "OBJ1"; - this.indexSignal = 0L; this.signalType = SignalType.CREATE.toString(); this.signalMapper = Mappers.getMapper(SignalMapper.class); } diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java index cf0370f..a692ec0 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListenerTest.java @@ -37,7 +37,7 @@ class SqsInternalListenerTest { private String correlationId; private String eserviceId; private String objectType; - private Long indexSignal; + private Long signalId; @BeforeEach @@ -160,7 +160,7 @@ private SignalEvent getSignalEvent() { signalEvent.setObjectType(this.objectType); signalEvent.setEserviceId(this.eserviceId); signalEvent.setObjectId(this.objectId); - signalEvent.setIndexSignal(this.indexSignal); + signalEvent.setSignalId(this.signalId); return signalEvent; } @@ -169,6 +169,6 @@ private void setUp() { this.correlationId = "0A"; this.eserviceId = "OBJ1"; this.objectType = "ESERVICE"; - this.indexSignal = 0L; + this.signalId = 0L; } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java index 9001abb..ec633d2 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java @@ -31,7 +31,7 @@ void jsonToObjectTest() { assertEquals("OBJ1", signalEvent.getObjectId()); assertEquals("T1", signalEvent.getObjectType()); assertEquals("E1", signalEvent.getEserviceId()); - assertEquals("1", signalEvent.getIndexSignal().toString()); + assertEquals("1", signalEvent.getSignalId().toString()); } @Test diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql index d5cccba..6572b2a 100644 --- a/src/test/resources/schema-h2.sql +++ b/src/test/resources/schema-h2.sql @@ -1,86 +1,73 @@ CREATE TABLE IF NOT EXISTS ESERVICE ( - eservice_id VARCHAR (50) NOT NULL, - producer_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT, - state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, producer_id, descriptor_id), - PRIMARY KEY (eservice_id, producer_id, descriptor_id) + eservice_id VARCHAR (255) NOT NULL, + producer_id VARCHAR (255) NOT NULL, + descriptor_id VARCHAR (255) NOT NULL, + event_id BIGINT, + state VARCHAR (255) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, producer_id, descriptor_id), + PRIMARY KEY (eservice_id, producer_id, descriptor_id) ); -/* -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_ID ON ESERVICE USING hash (eservice_id); -CREATE INDEX IF NOT EXISTS ESERVICE_INDEX_PRODUCER_ID ON ESERVICE USING hash (producer_id); -*/ - CREATE TABLE IF NOT EXISTS CONSUMER_ESERVICE ( - agreement_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - consumer_id VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50) NOT NULL, - event_id BIGINT, - state VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - tmst_last_edit TIMESTAMP, - UNIQUE (eservice_id, consumer_id, descriptor_id), - PRIMARY KEY (eservice_id, consumer_id, descriptor_id) + agreement_id VARCHAR (255) NOT NULL, + eservice_id VARCHAR (255) NOT NULL, + consumer_id VARCHAR (255) NOT NULL, + descriptor_id VARCHAR (255) NOT NULL, + event_id BIGINT, + state VARCHAR (255) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + tmst_last_edit TIMESTAMP, + UNIQUE (eservice_id, consumer_id, descriptor_id), + PRIMARY KEY (eservice_id, consumer_id, descriptor_id) ); -/* -CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_ID ON CONSUMER_ESERVICE USING hash (eservice_id); -CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_CONSUMER_ID ON CONSUMER_ESERVICE USING hash (consumer_id); -CREATE INDEX IF NOT EXISTS CONSUMER_ESERVICE_INDEX_DESCRIPTOR_ID ON CONSUMER_ESERVICE USING hash (descriptor_id); -*/ CREATE TABLE IF NOT EXISTS SIGNAL ( - id SERIAL PRIMARY KEY, - correlation_id VARCHAR(50) NOT NULL, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - UNIQUE (signal_id, eservice_id) + id SERIAL PRIMARY KEY, + correlation_id VARCHAR(255) NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (255) NOT NULL, + eservice_id VARCHAR (255) NOT NULL, + object_type VARCHAR (255) NOT NULL, + signal_type VARCHAR (255) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + UNIQUE (signal_id, eservice_id) ); -/* H2 not support USING constructor -CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_SIGNAL_ID ON SIGNAL USING hash (signal_id); -CREATE INDEX IF NOT EXISTS SIGNAL_INDEX_ESERVICE_ID ON SIGNAL USING hash (eservice_id); -*/ CREATE TABLE IF NOT EXISTS DEAD_SIGNAL ( - id SERIAL PRIMARY KEY, - correlation_id VARCHAR(50) NOT NULL, - signal_id BIGINT NOT NULL, - object_id VARCHAR (50) NOT NULL, - eservice_id VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - signal_type VARCHAR (50) NOT NULL, - tmst_insert TIMESTAMP NOT NULL, - error_reason VARCHAR(255) NOT NULL + id SERIAL PRIMARY KEY, + correlation_id VARCHAR(255) NOT NULL, + signal_id BIGINT NOT NULL, + object_id VARCHAR (255) NOT NULL, + eservice_id VARCHAR (255) NOT NULL, + object_type VARCHAR (255) NOT NULL, + signal_type VARCHAR (255) NOT NULL, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + error_reason VARCHAR(255) NOT NULL ); CREATE TABLE IF NOT EXISTS TRACING_BATCH ( - batch_id SERIAL PRIMARY KEY, - state VARCHAR (50) NOT NULL, - last_event_id BIGINT, - tmst_created TIMESTAMP NOT NULL + batch_id SERIAL PRIMARY KEY, + state VARCHAR (255) NOT NULL, + type VARCHAR (50) NOT NULL, + last_event_id BIGINT, + tmst_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE IF NOT EXISTS DEAD_EVENT ( - event_tmp_id SERIAL PRIMARY KEY, - tmst_insert TIMESTAMP, - error_reason VARCHAR(255) NOT NULL, - event_id BIGINT NOT NULL, - event_type VARCHAR (50) NOT NULL, - object_type VARCHAR (50) NOT NULL, - descriptor_id VARCHAR (50), - eservice_id VARCHAR (50), - agreement_id VARCHAR (50) + event_tmp_id SERIAL PRIMARY KEY, + tmst_insert TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + error_reason VARCHAR(255) NOT NULL, + event_id BIGINT NOT NULL, + event_type VARCHAR (255) NOT NULL, + object_type VARCHAR (255) NOT NULL, + descriptor_id VARCHAR (255), + eservice_id VARCHAR (255), + agreement_id VARCHAR (255) ); \ No newline at end of file From f5ef17a2c10d20d92d285fb1b190aa0e7457b85e Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Thu, 30 Nov 2023 11:35:05 +0100 Subject: [PATCH 59/62] added logs --- .../service/impl/SignalServiceImpl.java | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java b/src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java index 756fa7a..e49cf9c 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/service/impl/SignalServiceImpl.java @@ -6,22 +6,20 @@ import it.pagopa.interop.signalhub.persister.repository.DeadSignalRepository; import it.pagopa.interop.signalhub.persister.repository.SignalRepository; import it.pagopa.interop.signalhub.persister.service.SignalService; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Mono; import static it.pagopa.interop.signalhub.persister.exception.ExceptionTypeEnum.DUPLICATE_SIGNAL_ERROR; -@Service @Slf4j +@Service +@AllArgsConstructor public class SignalServiceImpl implements SignalService { - @Autowired private SignalRepository signalRepository; - @Autowired private DeadSignalRepository deadSignalRepository; - @Autowired private DeadSignalMapper deadSignalMapper; @@ -35,9 +33,32 @@ public Mono signalServiceFlow(Signal signal) { .switchIfEmpty(Mono.defer(() -> saveToDeadSignal(signal))); } - private Mono getSignalById(Long signalId, String eserviceId) { return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId); } - private Mono createSignal(Signal signal) { return this.signalRepository.save(signal); } - private Mono createDeadSignal(DeadSignal signal) { return this.deadSignalRepository.save(signal); } + private Mono getSignalById(Long signalId, String eserviceId) { + return this.signalRepository.findByIndexSignalAndEserviceId(signalId, eserviceId) + .switchIfEmpty(Mono.defer(() -> { + log.info("[{}] Signal not present with {} signalId", eserviceId, signalId); + return Mono.empty(); + })) + .doOnNext(signal -> log.info("[{}] Signal is present with {} signalId", eserviceId, signalId)); + } + + private Mono createSignal(Signal signal) { + return this.signalRepository.save(signal) + .doOnNext(data -> log.info("[{}] Signal saved with {} signal id", signal.getEserviceId(), signal.getSignalId())) + .doOnError(error -> + log.error("[{}] Error saving signal with {} signal id", signal.getEserviceId(), signal.getSignalId()) + ); + } + + private Mono createDeadSignal(DeadSignal signal) { + log.info("[{}] Save dead signal with {} signal id", signal.getEserviceId(), signal.getSignalId()); + return this.deadSignalRepository.save(signal) + .doOnNext(data -> log.info("[{}] Dead signal saved with {} signal id", signal.getEserviceId(), signal.getSignalId())) + .doOnError(error -> + log.error("[{}] Error saving dead signal with {} signal id", signal.getEserviceId(), signal.getSignalId()) + ); + + } private Mono getDeadSignal(Signal signal) { DeadSignal deadSignal = deadSignalMapper.signalToDeadSignal(signal); From 9a267b93403586be9a78194bb614a2af2a7955d8 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Thu, 30 Nov 2023 12:56:42 +0100 Subject: [PATCH 60/62] some fix --- config/application.properties | 2 +- .../interop/signalhub/persister/config/AwsBeanBuilder.java | 2 +- .../persister/queue/consumer/SqsInternalListener.java | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/application.properties b/config/application.properties index 4bc1109..553af30 100644 --- a/config/application.properties +++ b/config/application.properties @@ -1,2 +1,2 @@ aws.profile=default - +aws.region=eu-south-1 diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java index 27c3a05..cb20932 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/config/AwsBeanBuilder.java @@ -36,7 +36,7 @@ public SqsMessageListenerContainerFactory defaultSqsListenerContainerFac return SqsMessageListenerContainerFactory .builder() .configure(options -> options - //.acknowledgementMode(AcknowledgementMode.ON_SUCCESS) + .acknowledgementMode(AcknowledgementMode.ON_SUCCESS) .maxConcurrentMessages(10) .maxMessagesPerPoll(10)) .sqsAsyncClient(sqsAsyncClient()) diff --git a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java index 9290da0..2798173 100644 --- a/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java +++ b/src/main/java/it/pagopa/interop/signalhub/persister/queue/consumer/SqsInternalListener.java @@ -37,7 +37,9 @@ public CompletableFuture pullFromAwsInternalQueue(@Payload String node, @H .doOnNext(json -> log.info("payloadBody: {}, headers: {}, PullFromInternalQueue received input", node, headers)) .map(json -> Utility.jsonToObject(node, SignalEvent.class)) .map(signalEvent -> signalMapper.signalEventToSignal(signalEvent, correlationId)) - .flatMap(signalService::signalServiceFlow) + .flatMap(signalEvent -> signalService.signalServiceFlow(signalEvent) + .contextWrite(Context.of(TRACE_ID_KEY, correlationId)) + ) .then() .toFuture(); } From 78bd4fe1c3efd60221fcd18c4e6cb5fe99d410cb Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Tue, 5 Dec 2023 11:09:19 +0100 Subject: [PATCH 61/62] fixed properties --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0af9b1e..3cbb16d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ logging.level.root=INFO spring.main.web-appplication-type=reactive management.endpoint.health.show-details=always -logging.pattern.level="%2p [%X{traceId:-}]" +logging.pattern.level=%2p [%X{traceId:-}] # Disable auto cloud formation cloud.aws.stack.auto=false @@ -10,7 +10,7 @@ aws.sqs-endpoint=${AWS_SQS_ENDPOINT:http://localhost:4566/000000000000/} aws.internal-queue-name=local-internal-signal-hub database.name=${DB_NAME:signal-hub} -database.host=${DB_HOST:localhost} +database.host=${DATABASE_WRITER_HOST:localhost} database.port=${DB_PORT:5432} database.username=${DB_USER:postgres} database.password=${DB_PASSWORD:postgres} From 932a83fe3c5e5163c5509fa75d4f227b323f4334 Mon Sep 17 00:00:00 2001 From: "cristopher.moccia" Date: Fri, 15 Dec 2023 14:53:44 +0100 Subject: [PATCH 62/62] some fix --- .../interop/signalhub/persister/utility/UtilityTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java index ec633d2..bebb6ff 100644 --- a/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/persister/utility/UtilityTest.java @@ -12,7 +12,7 @@ class UtilityTest { - private final Utility utility = new Utility(); + @Test void jsonToObjectTest() { String jsonNode = """ @@ -21,7 +21,7 @@ void jsonToObjectTest() { "objectId": "OBJ1", "objectType": "T1", "eserviceId": "E1", - "indexSignal": "000001" + "signalId": "000001" } """;