From e025ede411c4811d4c899e1691ec0c97e26c2ed8 Mon Sep 17 00:00:00 2001 From: "mukesh.paliwal" Date: Mon, 1 Mar 2021 23:11:02 +0530 Subject: docker stage build failed in jenkins Issue-ID: SO-3559 Signed-off-by: mukesh.paliwal Change-Id: I834dc0091d2353941e0e77bfe2dab693e11d42c1 --- Dockerfile | 31 -- ca-certificates/onap-ca.crt | 31 -- configs/logging/logback-spring.xml | 203 ------------- onap-eclipse-format.xml | 313 --------------------- packages/docker/pom.xml | 157 +++++++++++ .../src/main/docker/docker-files/Dockerfile.so-app | 31 ++ .../docker/docker-files/Dockerfile.so-base-image | 19 ++ .../docker-files/ca-certificates/onap-ca.crt | 31 ++ .../configs/logging/logback-spring.xml | 199 +++++++++++++ .../main/docker/docker-files/scripts/start-app.sh | 95 +++++++ .../main/docker/docker-files/scripts/wait-for.sh | 85 ++++++ packages/pom.xml | 35 +++ pom-format.properties | 5 - pom.xml | 284 +++++-------------- scripts/.gitattributes | 5 - scripts/start-app.sh | 89 ------ scripts/wait-for.sh | 85 ------ so-oof-adapter-application/pom.xml | 128 +++++++++ .../so/adapters/oof/MsoOofAdapterApplication.java | 32 +++ .../so/adapters/oof/OofAdapterClientConfig.java | 76 +++++ .../onap/so/adapters/oof/WebSecurityConfig.java | 37 +++ .../onap/so/adapters/oof/constants/Constants.java | 31 ++ .../oof/exceptions/OofAdapterException.java | 39 +++ .../org/onap/so/adapters/oof/model/OofRequest.java | 52 ++++ .../so/adapters/oof/rest/OofCallbackHandler.java | 71 +++++ .../org/onap/so/adapters/oof/rest/OofClient.java | 67 +++++ .../org/onap/so/adapters/oof/utils/OofUtils.java | 110 ++++++++ .../adapters/oof/rest/OofCallbackHandlerTest.java | 85 ++++++ .../onap/so/adapters/oof/rest/OofClientTest.java | 86 ++++++ .../onap/so/adapters/oof/utils/OofUtilsTest.java | 76 +++++ .../testInputs/NsiSelectionOofRequest.json | 84 ++++++ .../resources/testInputs/NsiSelectionResponse.json | 20 ++ .../so/adapters/oof/MsoOofAdapterApplication.java | 32 --- .../so/adapters/oof/OofAdapterClientConfig.java | 76 ----- .../onap/so/adapters/oof/WebSecurityConfig.java | 37 --- .../onap/so/adapters/oof/constants/Constants.java | 31 -- .../oof/exceptions/OofAdapterException.java | 39 --- .../org/onap/so/adapters/oof/model/OofRequest.java | 52 ---- .../so/adapters/oof/rest/OofCallbackHandler.java | 71 ----- .../org/onap/so/adapters/oof/rest/OofClient.java | 67 ----- .../org/onap/so/adapters/oof/utils/OofUtils.java | 110 -------- .../adapters/oof/rest/OofCallbackHandlerTest.java | 85 ------ .../onap/so/adapters/oof/rest/OofClientTest.java | 86 ------ .../onap/so/adapters/oof/utils/OofUtilsTest.java | 76 ----- .../testInputs/NsiSelectionOofRequest.json | 84 ------ .../resources/testInputs/NsiSelectionResponse.json | 20 -- 46 files changed, 1716 insertions(+), 1842 deletions(-) delete mode 100755 Dockerfile delete mode 100644 ca-certificates/onap-ca.crt delete mode 100644 configs/logging/logback-spring.xml delete mode 100755 onap-eclipse-format.xml create mode 100755 packages/docker/pom.xml create mode 100644 packages/docker/src/main/docker/docker-files/Dockerfile.so-app create mode 100644 packages/docker/src/main/docker/docker-files/Dockerfile.so-base-image create mode 100644 packages/docker/src/main/docker/docker-files/ca-certificates/onap-ca.crt create mode 100644 packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml create mode 100755 packages/docker/src/main/docker/docker-files/scripts/start-app.sh create mode 100755 packages/docker/src/main/docker/docker-files/scripts/wait-for.sh create mode 100644 packages/pom.xml delete mode 100755 pom-format.properties delete mode 100644 scripts/.gitattributes delete mode 100755 scripts/start-app.sh delete mode 100755 scripts/wait-for.sh create mode 100755 so-oof-adapter-application/pom.xml create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/constants/Constants.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java create mode 100644 so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java create mode 100644 so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java create mode 100644 so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java create mode 100644 so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java create mode 100644 so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionOofRequest.json create mode 100644 so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionResponse.json delete mode 100644 src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/constants/Constants.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/model/OofRequest.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/rest/OofClient.java delete mode 100644 src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java delete mode 100644 src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java delete mode 100644 src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java delete mode 100644 src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java delete mode 100644 src/test/resources/testInputs/NsiSelectionOofRequest.json delete mode 100644 src/test/resources/testInputs/NsiSelectionResponse.json diff --git a/Dockerfile b/Dockerfile deleted file mode 100755 index 751e08c..0000000 --- a/Dockerfile +++ /dev/null @@ -1,31 +0,0 @@ -FROM adoptopenjdk/openjdk11:jre-11.0.8_10-alpine - -ARG JAR_FILE=*.jar -ARG http_proxy -ENV HTTP_PROXY=$http_proxy -ENV http_proxy=$HTTP_PROXY -ARG https_proxy -ENV HTTPS_PROXY=$https_proxy -ENV https_proxy=$HTTPS_PROXY -USER root -RUN mkdir -p /app/config -RUN mkdir -p /app/certificates -RUN mkdir -p /app/logs -RUN mkdir -p /app/ca-certificates -RUN apk update && apk add apache2-utils - -COPY target/${JAR_FILE} /app/app.jar - -COPY configs/logging/logback-spring.xml /app -COPY scripts/start-app.sh /app -COPY scripts/wait-for.sh /app -COPY ca-certificates/onap-ca.crt /app/ca-certificates/onap-ca.crt -#RUN chown -R so:so /app -#USER so -# Springboot configuration (required) -VOLUME /app/config -# Root certificates (optional) -VOLUME /app/ca-certificates -WORKDIR /app -ENTRYPOINT ["/app/start-app.sh"] - diff --git a/ca-certificates/onap-ca.crt b/ca-certificates/onap-ca.crt deleted file mode 100644 index e9a50d7..0000000 --- a/ca-certificates/onap-ca.crt +++ /dev/null @@ -1,31 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFPjCCAyagAwIBAgIJAJ6u7cCnzrWdMA0GCSqGSIb3DQEBCwUAMCwxDjAMBgNV -BAsMBU9TQUFGMQ0wCwYDVQQKDARPTkFQMQswCQYDVQQGEwJVUzAeFw0xODA0MDUx -NDE1MjhaFw0zODAzMzExNDE1MjhaMCwxDjAMBgNVBAsMBU9TQUFGMQ0wCwYDVQQK -DARPTkFQMQswCQYDVQQGEwJVUzCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC -ggIBAMA5pkgRs7NhGG4ew5JouhyYakgYUyFaG121+/h8qbSdt0hVQv56+EA41Yq7 -XGie7RYDQK9NmAFF3gruE+6X7wvJiChp+Cyd7sFMnb65uWhxEdxWTM2BJFrgfzUn -H8ZCxgaCo3XH4PzlKRy2LQQJEJECwl/RZmRCXijMt5e9h8XoZY/fKkKcZZUsWNCM -pTo266wjvA9MXLmdgReRj0+vrCjrNqy+htwJDztoiHWiYPqT6o8EvGcgjNqjlZx7 -NUNf8MfLDByqKF6+wRbHv1GKjn3/Vijd45Fv8riyRYROiFanvbV6jIfBkv8PZbXg -2VDWsYsgp8NAvMxK+iV8cO+Ck3lBI2GOPZbCEqpPVTYbLUz6sczAlCXwQoPzDIZY -wYa3eR/gYLY1gP2iEVHORag3bLPap9ZX5E8DZkzTNTjovvLk8KaCmfcaUMJsBtDd -ApcUitz10cnRyZc1sX3gE1f3DpzQM6t9C5sOVyRhDcSrKqqwb9m0Ss04XAS9FsqM -P3UWYQyqDXSxlUAYaX892u8mV1hxnt2gjb22RloXMM6TovM3sSrJS0wH+l1nznd6 -aFXftS/G4ZVIVZ/LfT1is4StoyPWZCwwwly1z8qJQ/zhip5NgZTxQw4mi7ww35DY -PdAQOCoajfSvFjqslQ/cPRi/MRCu079heVb5fQnnzVtnpFQRAgMBAAGjYzBhMB0G -A1UdDgQWBBRTVTPyS+vQUbHBeJrBKDF77+rtSTAfBgNVHSMEGDAWgBRTVTPyS+vQ -UbHBeJrBKDF77+rtSTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAN -BgkqhkiG9w0BAQsFAAOCAgEAPx/IaK94n02wPxpnYTy+LVLIxwdq/kawNd6IbiMz -L87zmNMDmHcGbfoRCj8OkhuggX9Lx1/CkhpXimuYsZOFQi5blr/u+v4mIbsgbmi9 -7j+cUHDP0zLycvSvxKHty51LwmaX9a4wkJl5zBU4O1sd/H9tWcEmwJ39ltKoBKBx -c94Zc3iMm5ytRWGj+0rKzLDAXEWpoZ5bE5PLJauA6UDCxDLfs3FwhbS7uDggxYvf -jySF5FCNET94oJ+m8s7VeHvoa8iPGKvXrIqdd7XDHnqJJlVKr7m9S0fMbyEB8ci2 -RtOXDt93ifY1uhoEtEykn4dqBSp8ezvNMnwoXdYPDvTd9uCAFeWFLVreBAWxd25h -PsBTkZA5hpa/rA+mKv6Af4VBViYr8cz4dZCsFChuioVebe9ighrfjB//qKepFjPF -CyjzKN1u0JKm/2x/ORqxkTONG8p3uDwoIOyimUcTtTMv42bfYD88RKakqSFXE9G+ -Z0LlaKABqfjK49o/tsAp+c5LoNlYllKhnetO3QAdraHwdmC36BhoghzR1jpX751A -cZn2VH3Q4XKyp01cJNCJIrua+A+bx6zh3RyW6zIIkbRCbET+UD+4mr8WIcSE3mtR -ZVlnhUDO4z9//WKMVzwS9Rh8/kuszrGFI1KQozXCHLrce3YP6RYZfOed79LXaRwX -dYY= ------END CERTIFICATE----- diff --git a/configs/logging/logback-spring.xml b/configs/logging/logback-spring.xml deleted file mode 100644 index e4be709..0000000 --- a/configs/logging/logback-spring.xml +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${errorPattern} - - - - - - - EXIT - - DENY - ACCEPT - - ${logs_dir:-.}/${auditLogName}.log - - ${logs_dir:-.}/${auditLogName}.%d{yyyy-MM-dd}.%i.log.zip - - ${maxFileSize} - ${maxHistory} - ${totalSizeCap} - - - ${auditPattern} - - - - - 256 - - - - - - - INVOKE-RETURN - - DENY - ACCEPT - - ${logs_dir:-.}/${metricsLogName}.log - - ${logs_dir:-.}/${metricsLogName}.%d{yyyy-MM-dd}.%i.log.zip - - ${maxFileSize} - ${maxHistory} - ${totalSizeCap} - - - ${metricPattern} - - - - - - 256 - - - - - - ERROR - ACCEPT - DENY - - ${logs_dir:-.}/${errorLogName}.log - - ${logs_dir:-.}/${errorLogName}.%d{yyyy-MM-dd}.%i.log.zip - - ${maxFileSize} - ${maxHistory} - ${totalSizeCap} - - - ${errorPattern} - - - - - 256 - - - - - - - INVOKE - INVOKE-RETURN - ENTRY - EXIT - - ACCEPT - DENY - - ${logs_dir:-.}/${debugLogName}.log - - ${logs_dir:-.}/${debugLogName}.%d{yyyy-MM-dd}.%i.log.zip - - ${maxFileSize} - ${maxHistory} - ${totalSizeCap} - - - ${debugPattern} - - - - - 256 - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/onap-eclipse-format.xml b/onap-eclipse-format.xml deleted file mode 100755 index 093866a..0000000 --- a/onap-eclipse-format.xml +++ /dev/null @@ -1,313 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/docker/pom.xml b/packages/docker/pom.xml new file mode 100755 index 0000000..e444d6a --- /dev/null +++ b/packages/docker/pom.xml @@ -0,0 +1,157 @@ + + 4.0.0 + + org.onap.so.adapters.so-oof-adapter + packages + 1.8.0-SNAPSHOT + + org.onap.so.adapters.so-oof-adapter.packages + 1.8.0-SNAPSHOT + pom + docker + SO OOF Adapter Docker Packaging + + + ${project.version} + false + false + false + nexus3.onap.org:10001 + nexus3.onap.org:10003 + onap/so + deploy + + + + ${project.artifactId}-${project.version} + + + org.codehaus.groovy.maven + gmaven-plugin + 1.0 + + + validate + + execute + + + + println 'Project version: ' + project.properties['oof-adapter-project-version']; + def versionArray; + if (project.properties['oof-adapter-project-version'] != null) { + versionArray = project.properties['oof-adapter-project-version'].split('-'); + } + + if (project.properties['oof-adapter-project-version'].endsWith("-SNAPSHOT")) { + project.properties['project.docker.latesttag.version'] = versionArray[0] + "-SNAPSHOT-latest"; + } else { + project.properties['project.docker.latesttag.version'] = versionArray[0] + "-STAGING-latest"; + } + + println 'New tag for docker: ' + project.properties['project.docker.latesttag.version']; + + + + + + + + io.fabric8 + docker-maven-plugin + + true + 1.23 + ${docker.pull.registry} + ${docker.push.registry} + + + ${docker.image.prefix}/base-image:1.0 + + try + docker-files/Dockerfile.so-base-image + + + + ${docker.image.prefix}/so-oof-adapter + + try + docker-files/Dockerfile.so-app + + ${project.version} + ${project.version}-${maven.build.timestamp} + ${project.docker.latesttag.version} + + + + + + + + org.onap.so.adapters.so-oof-adapter:so-oof-adapter-application + + + app.jar + + + + + + + + + + + + + clean-images + pre-clean + + remove + + + true + + + + + generate-images + generate-sources + + build + + + + + push-images + ${docker.push.phase} + + build + push + + + ${docker.image.prefix}/so-oof-adapter + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + + + org.onap.so.adapters.so-oof-adapter + so-oof-adapter-application + ${project.version} + + + \ No newline at end of file diff --git a/packages/docker/src/main/docker/docker-files/Dockerfile.so-app b/packages/docker/src/main/docker/docker-files/Dockerfile.so-app new file mode 100644 index 0000000..dc86ff8 --- /dev/null +++ b/packages/docker/src/main/docker/docker-files/Dockerfile.so-app @@ -0,0 +1,31 @@ +FROM onap/so/base-image:1.0 + +ARG http_proxy +ENV HTTP_PROXY=$http_proxy +ENV http_proxy=$HTTP_PROXY +ARG https_proxy +ENV HTTPS_PROXY=$https_proxy +ENV https_proxy=$HTTPS_PROXY + +USER root +RUN mkdir -p /app/config +RUN mkdir -p /app/certificates +RUN mkdir -p /app/logs +RUN mkdir -p /app/ca-certificates + +COPY maven/app.jar /app +COPY configs/logging/logback-spring.xml /app +COPY scripts/start-app.sh /app +COPY scripts/wait-for.sh /app +COPY ca-certificates/onap-ca.crt /app/ca-certificates/onap-ca.crt +RUN chown -R so:so /app + +USER so +# Springboot configuration (required) +VOLUME /app/config + +# Root certificates (optional) +VOLUME /app/ca-certificates + +WORKDIR /app +ENTRYPOINT ["/app/start-app.sh"] diff --git a/packages/docker/src/main/docker/docker-files/Dockerfile.so-base-image b/packages/docker/src/main/docker/docker-files/Dockerfile.so-base-image new file mode 100644 index 0000000..a1f4fc1 --- /dev/null +++ b/packages/docker/src/main/docker/docker-files/Dockerfile.so-base-image @@ -0,0 +1,19 @@ +FROM adoptopenjdk/openjdk11:jre-11.0.8_10-alpine + +ARG http_proxy +ARG https_proxy +ENV HTTP_PROXY=$http_proxy +ENV HTTPS_PROXY=$https_proxy +ENV http_proxy=$HTTP_PROXY +ENV https_proxy=$HTTPS_PROXY + +# Install commonly needed tools +RUN apk --no-cache add curl netcat-openbsd nss apache2-utils java-cacerts + +# Create symlink for default Java truststore +RUN set -eux; \ + rm -rf "$JAVA_HOME/lib/security/cacerts"; \ + ln -sT /etc/ssl/certs/java/cacerts "$JAVA_HOME/lib/security/cacerts" + +# Create 'so' user +RUN addgroup -g 1000 so && adduser -S -u 1000 -G so -s /bin/sh so diff --git a/packages/docker/src/main/docker/docker-files/ca-certificates/onap-ca.crt b/packages/docker/src/main/docker/docker-files/ca-certificates/onap-ca.crt new file mode 100644 index 0000000..e9a50d7 --- /dev/null +++ b/packages/docker/src/main/docker/docker-files/ca-certificates/onap-ca.crt @@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFPjCCAyagAwIBAgIJAJ6u7cCnzrWdMA0GCSqGSIb3DQEBCwUAMCwxDjAMBgNV +BAsMBU9TQUFGMQ0wCwYDVQQKDARPTkFQMQswCQYDVQQGEwJVUzAeFw0xODA0MDUx +NDE1MjhaFw0zODAzMzExNDE1MjhaMCwxDjAMBgNVBAsMBU9TQUFGMQ0wCwYDVQQK +DARPTkFQMQswCQYDVQQGEwJVUzCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC +ggIBAMA5pkgRs7NhGG4ew5JouhyYakgYUyFaG121+/h8qbSdt0hVQv56+EA41Yq7 +XGie7RYDQK9NmAFF3gruE+6X7wvJiChp+Cyd7sFMnb65uWhxEdxWTM2BJFrgfzUn +H8ZCxgaCo3XH4PzlKRy2LQQJEJECwl/RZmRCXijMt5e9h8XoZY/fKkKcZZUsWNCM +pTo266wjvA9MXLmdgReRj0+vrCjrNqy+htwJDztoiHWiYPqT6o8EvGcgjNqjlZx7 +NUNf8MfLDByqKF6+wRbHv1GKjn3/Vijd45Fv8riyRYROiFanvbV6jIfBkv8PZbXg +2VDWsYsgp8NAvMxK+iV8cO+Ck3lBI2GOPZbCEqpPVTYbLUz6sczAlCXwQoPzDIZY +wYa3eR/gYLY1gP2iEVHORag3bLPap9ZX5E8DZkzTNTjovvLk8KaCmfcaUMJsBtDd +ApcUitz10cnRyZc1sX3gE1f3DpzQM6t9C5sOVyRhDcSrKqqwb9m0Ss04XAS9FsqM +P3UWYQyqDXSxlUAYaX892u8mV1hxnt2gjb22RloXMM6TovM3sSrJS0wH+l1nznd6 +aFXftS/G4ZVIVZ/LfT1is4StoyPWZCwwwly1z8qJQ/zhip5NgZTxQw4mi7ww35DY +PdAQOCoajfSvFjqslQ/cPRi/MRCu079heVb5fQnnzVtnpFQRAgMBAAGjYzBhMB0G +A1UdDgQWBBRTVTPyS+vQUbHBeJrBKDF77+rtSTAfBgNVHSMEGDAWgBRTVTPyS+vQ +UbHBeJrBKDF77+rtSTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAN +BgkqhkiG9w0BAQsFAAOCAgEAPx/IaK94n02wPxpnYTy+LVLIxwdq/kawNd6IbiMz +L87zmNMDmHcGbfoRCj8OkhuggX9Lx1/CkhpXimuYsZOFQi5blr/u+v4mIbsgbmi9 +7j+cUHDP0zLycvSvxKHty51LwmaX9a4wkJl5zBU4O1sd/H9tWcEmwJ39ltKoBKBx +c94Zc3iMm5ytRWGj+0rKzLDAXEWpoZ5bE5PLJauA6UDCxDLfs3FwhbS7uDggxYvf +jySF5FCNET94oJ+m8s7VeHvoa8iPGKvXrIqdd7XDHnqJJlVKr7m9S0fMbyEB8ci2 +RtOXDt93ifY1uhoEtEykn4dqBSp8ezvNMnwoXdYPDvTd9uCAFeWFLVreBAWxd25h +PsBTkZA5hpa/rA+mKv6Af4VBViYr8cz4dZCsFChuioVebe9ighrfjB//qKepFjPF +CyjzKN1u0JKm/2x/ORqxkTONG8p3uDwoIOyimUcTtTMv42bfYD88RKakqSFXE9G+ +Z0LlaKABqfjK49o/tsAp+c5LoNlYllKhnetO3QAdraHwdmC36BhoghzR1jpX751A +cZn2VH3Q4XKyp01cJNCJIrua+A+bx6zh3RyW6zIIkbRCbET+UD+4mr8WIcSE3mtR +ZVlnhUDO4z9//WKMVzwS9Rh8/kuszrGFI1KQozXCHLrce3YP6RYZfOed79LXaRwX +dYY= +-----END CERTIFICATE----- diff --git a/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml b/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml new file mode 100644 index 0000000..ad5fe30 --- /dev/null +++ b/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${errorPattern} + + + + + + + EXIT + + DENY + ACCEPT + + ${logs_dir:-.}/${auditLogName}.log + + ${logs_dir:-.}/${auditLogName}.%d{yyyy-MM-dd}.%i.log.zip + + ${maxFileSize} + ${maxHistory} + ${totalSizeCap} + + + ${auditPattern} + + + + + 256 + + + + + + + INVOKE-RETURN + + DENY + ACCEPT + + ${logs_dir:-.}/${metricsLogName}.log + + ${logs_dir:-.}/${metricsLogName}.%d{yyyy-MM-dd}.%i.log.zip + + ${maxFileSize} + ${maxHistory} + ${totalSizeCap} + + + ${metricPattern} + + + + + + 256 + + + + + + ERROR + ACCEPT + DENY + + ${logs_dir:-.}/${errorLogName}.log + + ${logs_dir:-.}/${errorLogName}.%d{yyyy-MM-dd}.%i.log.zip + + ${maxFileSize} + ${maxHistory} + ${totalSizeCap} + + + ${errorPattern} + + + + + 256 + + + + + + + INVOKE + INVOKE-RETURN + ENTRY + EXIT + + ACCEPT + DENY + + ${logs_dir:-.}/${debugLogName}.log + + ${logs_dir:-.}/${debugLogName}.%d{yyyy-MM-dd}.%i.log.zip + + ${maxFileSize} + ${maxHistory} + ${totalSizeCap} + + + ${debugPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/docker/src/main/docker/docker-files/scripts/start-app.sh b/packages/docker/src/main/docker/docker-files/scripts/start-app.sh new file mode 100755 index 0000000..618d55f --- /dev/null +++ b/packages/docker/src/main/docker/docker-files/scripts/start-app.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +if [ `id -u` = 0 ] +then + # Install certificates found in the /app/ca-certificates volume, if any. + + needUpdate=FALSE + + for certificate in `ls -1 /app/ca-certificates`; do + echo "Installing $certificate in /usr/local/share/ca-certificates" + cp /app/ca-certificates/$certificate /usr/local/share/ca-certificates/$certificate + needUpdate=TRUE + done + + if [ $needUpdate = TRUE ]; then + update-ca-certificates --fresh + fi + + # Re-exec this script as the 'onap' user. + this=`readlink -f $0` + exec su so -c "$this" +fi + +touch /app/app.jar + +if [ ! -z "$DB_HOST" -a -z "$DB_PORT" ]; then + export DB_PORT=3306 +fi + +if [ -z "${CONFIG_PATH}" ]; then + export CONFIG_PATH=/app/config/override.yaml +fi + +if [ -z "${LOG_PATH}" ]; then + export LOG_PATH="logs/${APP}" +fi + +if [ "${SSL_DEBUG}" = "log" ]; then + export SSL_DEBUG="-Djavax.net.debug=all" +else + export SSL_DEBUG= +fi + +# Set java keystore and truststore options, if specified in the environment. + +jksargs= + +if [ ! -z "${KEYSTORE}" ]; then + jksargs="$jksargs -Dmso.load.ssl.client.keystore=true" + jksargs="$jksargs -Djavax.net.ssl.keyStore=$KEYSTORE" + jksargs="$jksargs -Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWORD}" +fi + +if [ ! -z "${TRUSTSTORE}" ]; then + jksargs="$jksargs -Djavax.net.ssl.trustStore=${TRUSTSTORE}" + jksargs="$jksargs -Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}" +fi + +if [ -z "${ACTIVE_PROFILE}" ]; then + export ACTIVE_PROFILE="basic" +fi + +jvmargs="${JVM_ARGS} -Dspring.profiles.active=${ACTIVE_PROFILE} -Djava.security.egd=file:/dev/./urandom -Dlogs_dir=${LOG_PATH} -Dlogging.config=/app/logback-spring.xml $jksargs -Dspring.config.additional-location=$CONFIG_PATH ${SSL_DEBUG} ${DISABLE_SNI}" + + +read_properties(){ + while IFS="=" read -r key value; do + case "${key}" in + '#'*) ;; + *) + eKey=$(echo $key | tr '[:lower:]' '[:upper:]') + export "$eKey"="$value" + esac + done <<-EOF + $1 + EOF +} + +if [ -n "${AAF_SSL_CERTS_ENABLED}" ]; then +read_properties "$(head -n 4 /app/certs/.passphrases)" +fi + +echo "JVM Arguments: ${jvmargs}" + +java ${jvmargs} -jar app.jar +rc=$? + +echo "Application exiting with status code $rc" + +if [ ! -z "${EXIT_DELAY}" -a "${EXIT_DELAY}" != 0 ]; then + echo "Delaying $APP exit for $EXIT_DELAY seconds" + sleep $EXIT_DELAY +fi + +exit $rc \ No newline at end of file diff --git a/packages/docker/src/main/docker/docker-files/scripts/wait-for.sh b/packages/docker/src/main/docker/docker-files/scripts/wait-for.sh new file mode 100755 index 0000000..2525821 --- /dev/null +++ b/packages/docker/src/main/docker/docker-files/scripts/wait-for.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# https://github.com/Eficode/wait-for.git +# MIT License + +TIMEOUT=15 +QUIET=0 + +echoerr() { + if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi +} + +usage() { + exitcode="$1" + cat << USAGE >&2 +Usage: + $cmdname host:port [-t timeout] [-- command args] + -q | --quiet Do not output any status messages + -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit "$exitcode" +} + +wait_for() { + command="$*" + if [ "$QUIET" -ne 1 ]; then echo "$0: probing host $HOST port $PORT"; fi + for i in `seq $TIMEOUT` ; do + nc -z "$HOST" "$PORT" > /dev/null 2>&1 + result=$? + if [ $result -eq 0 ] ; then + if [ "$QUIET" -ne 1 ]; then echo "$0: operation succeeded on try $i"; fi + if [ -n "$command" ] ; then + if [ "$QUIET" -ne 1 ]; then echo "$0: exec-ing command $command"; fi + exec $command + fi + exit 0 + fi + if [ "$QUIET" -ne 1 ]; then echo "$0: sleeping after try $i"; fi + sleep 1 + done + echo "$0: Operation timed out" >&2 + exit 1 +} + +while [ $# -gt 0 ] +do + case "$1" in + *:* ) + HOST=$(printf "%s\n" "$1"| cut -d : -f 1) + PORT=$(printf "%s\n" "$1"| cut -d : -f 2) + shift 1 + ;; + -q | --quiet) + QUIET=1 + shift 1 + ;; + -t) + TIMEOUT="$2" + if [ "$TIMEOUT" = "" ]; then break; fi + shift 2 + ;; + --timeout=*) + TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + break + ;; + --help) + usage 0 + ;; + *) + echoerr "Unknown argument: $1" + usage 1 + ;; + esac +done + +if [ "$HOST" = "" -o "$PORT" = "" ]; then + echoerr "Error: you need to provide a host and port to test." + usage 2 +fi + +wait_for "$@" diff --git a/packages/pom.xml b/packages/pom.xml new file mode 100644 index 0000000..6a04756 --- /dev/null +++ b/packages/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + + org.onap.so.adapters.so-oof-adapter + so-oof-adapter + 1.8.0-SNAPSHOT + + packages + pom + 1.8.0-SNAPSHOT + SO OOF Adapter Packages + + + + + + default + + true + + + + + + docker + + docker + + + false + + + + \ No newline at end of file diff --git a/pom-format.properties b/pom-format.properties deleted file mode 100755 index 4452c2a..0000000 --- a/pom-format.properties +++ /dev/null @@ -1,5 +0,0 @@ -maxLineLength=120 -wrapLongLines=true -tabInsteadOfSpaces=false -tabWidth=2 -splitMultiAttrs=false \ No newline at end of file diff --git a/pom.xml b/pom.xml index 40fa3f9..44cd6d0 100755 --- a/pom.xml +++ b/pom.xml @@ -1,218 +1,74 @@ - - 4.0.0 - - org.onap.so - adapters + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.onap.so + so + 1.8.0-SNAPSHOT + + org.onap.so.adapters.so-oof-adapter + so-oof-adapter 1.8.0-SNAPSHOT - - org.onap.so.adapters - so-oof-adapter - 1.8.0-SNAPSHOT - so-oof-adapter - mso oof adapter + SO OOF Adapter + pom + + + + net.revelc.code.formatter + formatter-maven-plugin + 2.9.0 + + + format-java + + format + + process-sources + + true + + + + format-xml + + format + + process-sources + + true + + pom.xml + + + + + validate-java + + validate + + + true + + + + validate-poms + + validate + + + true + + pom.xml + + + + + + + - - - - org.springframework.boot - spring-boot-dependencies - ${springboot.version} - pom - import - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-webflux - - - - org.apache.cxf - cxf-spring-boot-starter-jaxrs - - - org.apache.cxf - cxf-rt-rs-service-description-swagger - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - org.junit.jupiter - junit-jupiter-api - test - - - junit - junit - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.vintage - junit-vintage-engine - test - - - - ${project.artifactId}-${project.version} - ${project.basedir}/src/test/java - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - org.springframework.boot - spring-boot-maven-plugin - - org.onap.so.adapters.oof.MsoOofAdapterApplication - - - - - repackage - - - - - - org.jacoco - jacoco-maven-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - 2.9.0 - - - format-java - - format - - process-sources - - ${format.skipExecute} - ${project.basedir}/onap-eclipse-format.xml - - - - format-xml - - format - - process-sources - - ${format.skipExecute} - ${project.basedir} - ${project.basedir}/pom-format.properties - - pom.xml - - - - - validate-java - - validate - - - ${format.skipValidate} - ${project.basedir}/onap-eclipse-format.xml - - - - validate-poms - - validate - - - ${format.skipValidate} - ${project.basedir}/pom-format.properties - - pom.xml - - - - - - - com.fasterxml.jackson.core - jackson-annotations - 2.9.8 - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - docker-build - install - - exec - - - Dockerfile - docker - ${project.basedir} - - build - -t - ${project.artifactId}:${project.version} - . - - - ${project.artifactId}-${project.version}.jar - ${project.artifactId} - - - - - - - - - src/main/resources - true - - **/*.p12 - **/*.jks - - - - src/main/resources - false - - **/*.p12 - **/*.jks - - - - + + so-oof-adapter-application + packages + diff --git a/scripts/.gitattributes b/scripts/.gitattributes deleted file mode 100644 index b905d1d..0000000 --- a/scripts/.gitattributes +++ /dev/null @@ -1,5 +0,0 @@ -# Default behavior -* text=auto - -# Files to have unix style line endings on checkout -*.sh text eol=lf \ No newline at end of file diff --git a/scripts/start-app.sh b/scripts/start-app.sh deleted file mode 100755 index 54ed9ed..0000000 --- a/scripts/start-app.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/sh -#temprary condition -if [ `id -u` = 0 ] -then - # Install certificates found in the /app/ca-certificates volume, if any. - - needUpdate=FALSE - - for certificate in `ls -1 /app/ca-certificates`; do - echo "Installing $certificate in /usr/local/share/ca-certificates" - # cp /app/ca-certificates/$certificate /usr/local/share/ca-certificates/$certificate - needUpdate=FALSE - done - - # Re-exec this script as the 'onap' user. - this=`readlink -f $0` - # exec su so -c "$this" -fi - -touch /app/app.jar - -if [ ! -z "$DB_HOST" -a -z "$DB_PORT" ]; then - export DB_PORT=3306 -fi - -if [ -z "${CONFIG_PATH}" ]; then - export CONFIG_PATH=/app/config/override.yaml -fi - -if [ "${SSL_DEBUG}" = "log" ]; then - export SSL_DEBUG="-Djavax.net.debug=all" -else - export SSL_DEBUG= -fi - -# Set java keystore and truststore options, if specified in the environment. - -jksargs= - -if [ ! -z "${KEYSTORE}" ]; then - jksargs="$jksargs -Dmso.load.ssl.client.keystore=true" - jksargs="$jksargs -Djavax.net.ssl.keyStore=$KEYSTORE" - jksargs="$jksargs -Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWORD}" -fi - -if [ ! -z "${TRUSTSTORE}" ]; then - jksargs="$jksargs -Djavax.net.ssl.trustStore=${TRUSTSTORE}" - jksargs="$jksargs -Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}" -fi - -if [ -z "${ACTIVE_PROFILE}" ]; then - export ACTIVE_PROFILE="basic" -fi - -jvmargs="${JVM_ARGS} -Dspring.profiles.active=${ACTIVE_PROFILE} -Djava.security.egd=file:/dev/./urandom -Dlogs_dir=${LOG_PATH} -Dlogging.config=/app/logback-spring.xml $jksargs -Dspring.config.additional-location=$CONFIG_PATH ${SSL_DEBUG} ${DISABLE_SNI}" - - -read_properties(){ - while IFS="=" read -r key value; do - case "${key}" in - '#'*) ;; - *) - eKey=$(echo $key | tr '[:lower:]' '[:upper:]') - export "$eKey"="$value" - esac - done <<-EOF - $1 - EOF -} - - - -if [ -n "${AAF_SSL_CERTS_ENABLED}" ]; then -read_properties "$(head -n 4 /app/certs/.passphrases)" -fi - -echo "JVM Arguments: ${jvmargs}" - -java ${jvmargs} -jar app.jar -rc=$? - -echo "Application exiting with status code $rc" - -if [ ! -z "${EXIT_DELAY}" -a "${EXIT_DELAY}" != 0 ]; then - echo "Delaying $APP exit for $EXIT_DELAY seconds" - sleep $EXIT_DELAY -fi - -exit $rc diff --git a/scripts/wait-for.sh b/scripts/wait-for.sh deleted file mode 100755 index 2525821..0000000 --- a/scripts/wait-for.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/sh -# https://github.com/Eficode/wait-for.git -# MIT License - -TIMEOUT=15 -QUIET=0 - -echoerr() { - if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi -} - -usage() { - exitcode="$1" - cat << USAGE >&2 -Usage: - $cmdname host:port [-t timeout] [-- command args] - -q | --quiet Do not output any status messages - -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout - -- COMMAND ARGS Execute command with args after the test finishes -USAGE - exit "$exitcode" -} - -wait_for() { - command="$*" - if [ "$QUIET" -ne 1 ]; then echo "$0: probing host $HOST port $PORT"; fi - for i in `seq $TIMEOUT` ; do - nc -z "$HOST" "$PORT" > /dev/null 2>&1 - result=$? - if [ $result -eq 0 ] ; then - if [ "$QUIET" -ne 1 ]; then echo "$0: operation succeeded on try $i"; fi - if [ -n "$command" ] ; then - if [ "$QUIET" -ne 1 ]; then echo "$0: exec-ing command $command"; fi - exec $command - fi - exit 0 - fi - if [ "$QUIET" -ne 1 ]; then echo "$0: sleeping after try $i"; fi - sleep 1 - done - echo "$0: Operation timed out" >&2 - exit 1 -} - -while [ $# -gt 0 ] -do - case "$1" in - *:* ) - HOST=$(printf "%s\n" "$1"| cut -d : -f 1) - PORT=$(printf "%s\n" "$1"| cut -d : -f 2) - shift 1 - ;; - -q | --quiet) - QUIET=1 - shift 1 - ;; - -t) - TIMEOUT="$2" - if [ "$TIMEOUT" = "" ]; then break; fi - shift 2 - ;; - --timeout=*) - TIMEOUT="${1#*=}" - shift 1 - ;; - --) - shift - break - ;; - --help) - usage 0 - ;; - *) - echoerr "Unknown argument: $1" - usage 1 - ;; - esac -done - -if [ "$HOST" = "" -o "$PORT" = "" ]; then - echoerr "Error: you need to provide a host and port to test." - usage 2 -fi - -wait_for "$@" diff --git a/so-oof-adapter-application/pom.xml b/so-oof-adapter-application/pom.xml new file mode 100755 index 0000000..a563fe2 --- /dev/null +++ b/so-oof-adapter-application/pom.xml @@ -0,0 +1,128 @@ + + + 4.0.0 + + org.onap.so.adapters.so-oof-adapter + so-oof-adapter + 1.8.0-SNAPSHOT + + so-oof-adapter-application + 1.8.0-SNAPSHOT + SO OOF Application Jar + + + + org.springframework.boot + spring-boot-dependencies + ${springboot.version} + pom + import + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.apache.cxf + cxf-spring-boot-starter-jaxrs + + + org.apache.cxf + cxf-rt-rs-service-description-swagger + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.junit.jupiter + junit-jupiter-api + test + + + junit + junit + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.vintage + junit-vintage-engine + test + + + org.onap.so + aai-client + 1.8.0-SNAPSHOT + + + + ${project.artifactId}-${project.version} + ${project.basedir}/src/test/java + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.springframework.boot + spring-boot-maven-plugin + + org.onap.so.adapters.oof.MsoOofAdapterApplication + + + + + repackage + + + + + + org.jacoco + jacoco-maven-plugin + + + + + src/main/resources + true + + **/*.p12 + **/*.jks + + + + src/main/resources + false + + **/*.p12 + **/*.jks + + + + + diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java new file mode 100644 index 0000000..78fbe6e --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MsoOofAdapterApplication { + + public static void main(String[] args) { + SpringApplication.run(MsoOofAdapterApplication.class, args); + } +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java new file mode 100644 index 0000000..5e13c59 --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class OofAdapterClientConfig { + + @Bean + public RestTemplate getRestTemplate() { + HttpComponentsClientHttpRequestFactory requestFactory = + new HttpComponentsClientHttpRequestFactory(getHttpsClient()); + requestFactory.setConnectTimeout(60000); + requestFactory.setReadTimeout(60000); + return new RestTemplate(requestFactory); + } + + private HttpClient getHttpsClient() { + TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {} + + public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {} + }}; + + // Install the all-trusting trust manager + try { + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HostnameVerifier hostnameVerifier = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sc, + new String[] {"TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}, null, hostnameVerifier); + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java new file mode 100644 index 0000000..9a07b01 --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +@Configuration +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable(); + } + +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/constants/Constants.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/constants/Constants.java new file mode 100644 index 0000000..5d91bf3 --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/constants/Constants.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.adapters.oof.constants; + +public class Constants { + + public static final String OOF_ENDPOINT = "mso.oof.endpoint"; + public static final String OOF_AUTH = "mso.oof.auth"; + public static final String MSO_KEY = "mso.msoKey"; + public static final String CAMUNDA_URL = "mso.camundaURL"; + public static final String CAMUNDA_AUTH = "mso.camundaAuth"; + public static final String WORKFLOW_MESSAGE_ENPOINT = "mso.workflow.message.endpoint"; + +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java new file mode 100644 index 0000000..ff16d74 --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.exceptions; + +public class OofAdapterException extends Exception { + + private static final long serialVersionUID = 1L; + + public OofAdapterException(String message) { + super(message); + } + + public OofAdapterException(Throwable e) { + super(e); + } + + public OofAdapterException(String message, Throwable e) { + super(message, e); + } + +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java new file mode 100644 index 0000000..1eb694f --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.adapters.oof.model; + +/** + * POJO representing generic request payload from BPMN processes + */ +public class OofRequest { + + private String apiPath; + + private Object requestDetails; + + public String getApiPath() { + return apiPath; + } + + public void setApiPath(String apiPath) { + this.apiPath = apiPath; + } + + public Object getRequestDetails() { + return requestDetails; + } + + public void setRequestDetails(Object requestDetails) { + this.requestDetails = requestDetails; + } + + @Override + public String toString() { + return "{\"apiPath:\"\"" + apiPath + "\"\", requestDetails:\"\"" + requestDetails + "}"; + } + +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java new file mode 100644 index 0000000..f8da6c6 --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import org.onap.so.adapters.oof.exceptions.OofAdapterException; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * A generic call back handler to receive async response from OOF + */ +@RestController +@RequestMapping("/so/adapters/oof/callback/") +public class OofCallbackHandler { + + @Autowired + OofUtils utils; + + @Autowired + RestTemplate restTemplate; + + private static final Logger logger = LoggerFactory.getLogger(OofCallbackHandler.class); + + @PostMapping("/{version:[vV][1]}/{messageEventName}/{correlator}") + public ResponseEntity processCallback(@PathVariable("messageEventName") String messageEventName, + @PathVariable("correlator") String correlator, @RequestBody String oofCallbackRequest) + throws OofAdapterException { + logger.debug("Oof Async response received for event : {} , callback request body : {} ", messageEventName, + oofCallbackRequest); + String camundaMsgUrl = utils.getCamundaMsgUrl(messageEventName, correlator); + HttpEntity request = new HttpEntity(oofCallbackRequest, utils.getCamundaHeaders()); + try { + ResponseEntity response = restTemplate.postForEntity(camundaMsgUrl, request, String.class); + logger.debug("Response from BPMN : {} ", response); + return response; + } catch (Exception e) { + logger.warn("Error injecting message event into BPMN {} {} ", e.getCause(), e.getMessage()); + throw new OofAdapterException(e); + } + + } + +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java new file mode 100644 index 0000000..3a91ec4 --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import org.onap.so.adapters.oof.exceptions.OofAdapterException; +import org.onap.so.adapters.oof.model.OofRequest; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * A generic client class to call OOF with request from BPMN + */ +@RestController +@RequestMapping("/so/adapters/oof/") +public class OofClient { + + @Autowired + RestTemplate restTemplate; + + @Autowired + OofUtils utils; + + private static final Logger logger = LoggerFactory.getLogger(OofClient.class); + + @PostMapping("/{version:[vV][1]}") + public ResponseEntity callOof(@RequestBody OofRequest oofRequest) throws OofAdapterException { + try { + logger.debug("Received Request from BPEL {} ", oofRequest); + String oofUrl = utils.getOofurl(oofRequest.getApiPath()); + HttpEntity request = new HttpEntity<>(oofRequest.getRequestDetails(), utils.getOofHttpHeaders()); + ResponseEntity response = restTemplate.postForEntity(oofUrl, request, String.class); + logger.debug("Response from OOF : {} ", response); + return response; + } catch (Exception e) { + logger.warn("Error while calling OOF {} {} ", e.getCause(), e.getMessage()); + throw new OofAdapterException(e); + } + } + +} diff --git a/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java new file mode 100644 index 0000000..f45baa3 --- /dev/null +++ b/so-oof-adapter-application/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.utils; + +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.DatatypeConverter; +import org.onap.so.adapters.oof.constants.Constants; +import org.onap.so.utils.CryptoUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +@Component +public class OofUtils { + private static Logger logger = LoggerFactory.getLogger(OofUtils.class); + + @Autowired + private Environment env; + + /** + * @param messageEventName + * @param correlator + * @return + */ + public String getCamundaMsgUrl(String messageEventName, String correlator) { + System.out.println(env); + String camundaMsgUrl = new StringBuilder(env.getRequiredProperty(Constants.WORKFLOW_MESSAGE_ENPOINT)) + .append("/").append(messageEventName).append("/").append(correlator).toString(); + return camundaMsgUrl; + } + + /** + * @return + */ + public HttpHeaders getCamundaHeaders() { + HttpHeaders headers = new HttpHeaders(); + List acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(MediaType.ALL); + headers.setAccept(acceptableMediaTypes); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add(HttpHeaders.AUTHORIZATION, addAuthorizationHeader(env.getRequiredProperty(Constants.CAMUNDA_AUTH), + env.getRequiredProperty(Constants.MSO_KEY))); + return headers; + } + + /** + * @param auth + * @param msoKey + * @return + */ + protected String addAuthorizationHeader(String auth, String msoKey) { + String basicAuth = null; + try { + String userCredentials = CryptoUtils.decrypt(auth, msoKey); + if (userCredentials != null) { + basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); + } + } catch (GeneralSecurityException e) { + logger.error("Security exception", e); + } + return basicAuth; + } + + /** + * @return + * @throws Exception + */ + public HttpHeaders getOofHttpHeaders() throws Exception { + HttpHeaders headers = new HttpHeaders(); + List acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(MediaType.APPLICATION_JSON); + headers.setAccept(acceptableMediaTypes); + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } + + /** + * @param apiPath + * @return + */ + public String getOofurl(String apiPath) { + return new StringBuilder(env.getRequiredProperty(Constants.OOF_ENDPOINT)).append(apiPath).toString(); + } + + +} diff --git a/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java b/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java new file mode 100644 index 0000000..3a2f7f5 --- /dev/null +++ b/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import static org.mockito.Mockito.when; +import java.io.File; +import java.io.IOException; +import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.databind.ObjectMapper; + + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class OofCallbackHandlerTest { + + @Autowired + TestRestTemplate restTemplate; + + @MockBean + OofUtils oofutils; + + @MockBean + RestTemplate mockrestTemplate; + + @Before + void prepareMocks() throws Exception { + ResponseEntity responseEntity = new ResponseEntity<>(HttpStatus.OK); + when(oofutils.getCamundaHeaders()).thenReturn(new HttpHeaders()); + when(oofutils.getCamundaMsgUrl(Mockito.anyString(), Mockito.anyString())).thenReturn("oofurl"); + when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any())) + .thenReturn(responseEntity); + } + + @Test + void processCallbackTest() throws Exception { + Object request = prepareOofResponse(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity(request, headers); + ResponseEntity response = restTemplate.postForEntity( + "/so/adapters/oof/callback/v1/NSISelectionResponse/d88da85c-d9e8-4f73-b837-3a72a431622a", entity, + String.class); + Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + private Object prepareOofResponse() throws IOException { + File file = new ClassPathResource("testInputs/NsiSelectionResponse.json").getFile(); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(file, Object.class); + } + +} diff --git a/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java b/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java new file mode 100644 index 0000000..ff38a9a --- /dev/null +++ b/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import static org.mockito.Mockito.when; +import java.io.File; +import java.io.IOException; +import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.so.adapters.oof.model.OofRequest; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.databind.ObjectMapper; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class OofClientTest { + + @Autowired + TestRestTemplate restTemplate; + + @MockBean + OofUtils oofutils; + + @MockBean + RestTemplate mockrestTemplate; + + @Before + void prepareMocks() throws Exception { + ResponseEntity responseEntity = new ResponseEntity<>(HttpStatus.OK); + when(oofutils.getOofHttpHeaders()).thenReturn(new HttpHeaders()); + when(oofutils.getOofurl(Mockito.anyString())).thenReturn("oofurl"); + when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any())) + .thenReturn(responseEntity); + } + + @Test + void callOofTest() throws Exception { + OofRequest request = prepareOofRequest(); + System.out.println(request); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity(request, headers); + ResponseEntity response = restTemplate.postForEntity("/so/adapters/oof/v1", entity, String.class); + Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + private OofRequest prepareOofRequest() throws IOException { + File file = new ClassPathResource("testInputs/NsiSelectionOofRequest.json").getFile(); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(file, OofRequest.class); + } + + +} diff --git a/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java b/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java new file mode 100644 index 0000000..e68fa10 --- /dev/null +++ b/so-oof-adapter-application/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.utils; + +import static org.mockito.Mockito.when; +import java.security.GeneralSecurityException; +import javax.xml.bind.DatatypeConverter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.so.utils.CryptoUtils; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpHeaders; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +class OofUtilsTest { + + @InjectMocks + OofUtils oofUtils; + + @Mock + Environment env; + + @Test + void testGetCamundaMsgUrl() { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + String camundamsgUrl = oofUtils.getCamundaMsgUrl("samplemessage", "sampleCorrelator"); + Assertions.assertNotNull(camundamsgUrl); + } + + + void testGetCamundaHeaders() throws GeneralSecurityException { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + when(CryptoUtils.decrypt(Mockito.anyString(), Mockito.anyString())).thenReturn("decryptedString"); + HttpHeaders headers = oofUtils.getCamundaHeaders(); + Assertions.assertNotNull(headers); + } + + + @Test + void testGetOofHttpHeaders() throws Exception { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + HttpHeaders headers = oofUtils.getOofHttpHeaders(); + Assertions.assertNotNull(headers); + } + + @Test + void testGetOofurl() { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + String oofurl = oofUtils.getOofurl("/api/v1/"); + Assertions.assertNotNull(oofurl); + } + +} diff --git a/so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionOofRequest.json b/so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionOofRequest.json new file mode 100644 index 0000000..569aae9 --- /dev/null +++ b/so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionOofRequest.json @@ -0,0 +1,84 @@ +{ + "apiPath":"/api/oof/selection/nsi/v1", + "requestDetails":{ + "serviceProfile":{ + "blob":"content" + }, + "requestInfo":{ + "transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "callbackUrl":"myDomain.com/myCallback", + "callbackHeader":{ + "blob":"content" + }, + "sourceId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "timeout":5, + "numSolutions":1 + }, + "NSTInfo":{ + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa1", + "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-nst" + }, + "NSSTInfo":[ + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa2", + "invariantUUID":"2fa85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-an-nf" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa3", + "invariantUUID":"4fa85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-cn" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa4", + "invariantUUID":"5ta85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-tn-fh" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa5", + "invariantUUID":"6ya85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-tn-mh" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa7", + "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-tn-bh" + } + ], + "preferReuse":false, + "subnetCapabilities":[ + { + "domainType":"AN-NF", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"CN", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"TN-FH", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"TN-MH", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"TN-BH", + "capabilityDetails":{ + "blob":"content" + } + } + ] +} +} \ No newline at end of file diff --git a/so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionResponse.json b/so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionResponse.json new file mode 100644 index 0000000..4ddca3e --- /dev/null +++ b/so-oof-adapter-application/src/test/resources/testInputs/NsiSelectionResponse.json @@ -0,0 +1,20 @@ +{ + "transactionId": "s4r0f1ee-6c54-4b01-90e6-d701748f0851", + "requestId": "r500f1ee-6c54-4b01-90e6-d701748f0851", + "requestStatus": "completed", + "solutions": [ + { + "existingNSI": false, + "newNSISolution": { + "sliceProfiles": [ + { + "domainType":"CN" + } + ], + "matchLevel": { + "blob": "content" + } + } + } + ] +} diff --git a/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java b/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java deleted file mode 100644 index 78fbe6e..0000000 --- a/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class MsoOofAdapterApplication { - - public static void main(String[] args) { - SpringApplication.run(MsoOofAdapterApplication.class, args); - } -} diff --git a/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java b/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java deleted file mode 100644 index 5e13c59..0000000 --- a/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import org.apache.http.client.HttpClient; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.HttpClients; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.web.client.RestTemplate; - -@Configuration -public class OofAdapterClientConfig { - - @Bean - public RestTemplate getRestTemplate() { - HttpComponentsClientHttpRequestFactory requestFactory = - new HttpComponentsClientHttpRequestFactory(getHttpsClient()); - requestFactory.setConnectTimeout(60000); - requestFactory.setReadTimeout(60000); - return new RestTemplate(requestFactory); - } - - private HttpClient getHttpsClient() { - TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {} - - public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {} - }}; - - // Install the all-trusting trust manager - try { - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - HostnameVerifier hostnameVerifier = new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sc, - new String[] {"TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}, null, hostnameVerifier); - return HttpClients.custom().setSSLSocketFactory(sslsf).build(); - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - } -} diff --git a/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java b/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java deleted file mode 100644 index 9a07b01..0000000 --- a/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof; - -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -@EnableWebSecurity -@Configuration -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable(); - } - -} diff --git a/src/main/java/org/onap/so/adapters/oof/constants/Constants.java b/src/main/java/org/onap/so/adapters/oof/constants/Constants.java deleted file mode 100644 index 5d91bf3..0000000 --- a/src/main/java/org/onap/so/adapters/oof/constants/Constants.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.oof.constants; - -public class Constants { - - public static final String OOF_ENDPOINT = "mso.oof.endpoint"; - public static final String OOF_AUTH = "mso.oof.auth"; - public static final String MSO_KEY = "mso.msoKey"; - public static final String CAMUNDA_URL = "mso.camundaURL"; - public static final String CAMUNDA_AUTH = "mso.camundaAuth"; - public static final String WORKFLOW_MESSAGE_ENPOINT = "mso.workflow.message.endpoint"; - -} diff --git a/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java b/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java deleted file mode 100644 index ff16d74..0000000 --- a/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof.exceptions; - -public class OofAdapterException extends Exception { - - private static final long serialVersionUID = 1L; - - public OofAdapterException(String message) { - super(message); - } - - public OofAdapterException(Throwable e) { - super(e); - } - - public OofAdapterException(String message, Throwable e) { - super(message, e); - } - -} diff --git a/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java b/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java deleted file mode 100644 index 1eb694f..0000000 --- a/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.oof.model; - -/** - * POJO representing generic request payload from BPMN processes - */ -public class OofRequest { - - private String apiPath; - - private Object requestDetails; - - public String getApiPath() { - return apiPath; - } - - public void setApiPath(String apiPath) { - this.apiPath = apiPath; - } - - public Object getRequestDetails() { - return requestDetails; - } - - public void setRequestDetails(Object requestDetails) { - this.requestDetails = requestDetails; - } - - @Override - public String toString() { - return "{\"apiPath:\"\"" + apiPath + "\"\", requestDetails:\"\"" + requestDetails + "}"; - } - -} diff --git a/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java b/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java deleted file mode 100644 index f8da6c6..0000000 --- a/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof.rest; - -import org.onap.so.adapters.oof.exceptions.OofAdapterException; -import org.onap.so.adapters.oof.utils.OofUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -/** - * A generic call back handler to receive async response from OOF - */ -@RestController -@RequestMapping("/so/adapters/oof/callback/") -public class OofCallbackHandler { - - @Autowired - OofUtils utils; - - @Autowired - RestTemplate restTemplate; - - private static final Logger logger = LoggerFactory.getLogger(OofCallbackHandler.class); - - @PostMapping("/{version:[vV][1]}/{messageEventName}/{correlator}") - public ResponseEntity processCallback(@PathVariable("messageEventName") String messageEventName, - @PathVariable("correlator") String correlator, @RequestBody String oofCallbackRequest) - throws OofAdapterException { - logger.debug("Oof Async response received for event : {} , callback request body : {} ", messageEventName, - oofCallbackRequest); - String camundaMsgUrl = utils.getCamundaMsgUrl(messageEventName, correlator); - HttpEntity request = new HttpEntity(oofCallbackRequest, utils.getCamundaHeaders()); - try { - ResponseEntity response = restTemplate.postForEntity(camundaMsgUrl, request, String.class); - logger.debug("Response from BPMN : {} ", response); - return response; - } catch (Exception e) { - logger.warn("Error injecting message event into BPMN {} {} ", e.getCause(), e.getMessage()); - throw new OofAdapterException(e); - } - - } - -} diff --git a/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java b/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java deleted file mode 100644 index 3a91ec4..0000000 --- a/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof.rest; - -import org.onap.so.adapters.oof.exceptions.OofAdapterException; -import org.onap.so.adapters.oof.model.OofRequest; -import org.onap.so.adapters.oof.utils.OofUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -/** - * A generic client class to call OOF with request from BPMN - */ -@RestController -@RequestMapping("/so/adapters/oof/") -public class OofClient { - - @Autowired - RestTemplate restTemplate; - - @Autowired - OofUtils utils; - - private static final Logger logger = LoggerFactory.getLogger(OofClient.class); - - @PostMapping("/{version:[vV][1]}") - public ResponseEntity callOof(@RequestBody OofRequest oofRequest) throws OofAdapterException { - try { - logger.debug("Received Request from BPEL {} ", oofRequest); - String oofUrl = utils.getOofurl(oofRequest.getApiPath()); - HttpEntity request = new HttpEntity<>(oofRequest.getRequestDetails(), utils.getOofHttpHeaders()); - ResponseEntity response = restTemplate.postForEntity(oofUrl, request, String.class); - logger.debug("Response from OOF : {} ", response); - return response; - } catch (Exception e) { - logger.warn("Error while calling OOF {} {} ", e.getCause(), e.getMessage()); - throw new OofAdapterException(e); - } - } - -} diff --git a/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java b/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java deleted file mode 100644 index f45baa3..0000000 --- a/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java +++ /dev/null @@ -1,110 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof.utils; - -import java.security.GeneralSecurityException; -import java.util.ArrayList; -import java.util.List; -import javax.xml.bind.DatatypeConverter; -import org.onap.so.adapters.oof.constants.Constants; -import org.onap.so.utils.CryptoUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; - -@Component -public class OofUtils { - private static Logger logger = LoggerFactory.getLogger(OofUtils.class); - - @Autowired - private Environment env; - - /** - * @param messageEventName - * @param correlator - * @return - */ - public String getCamundaMsgUrl(String messageEventName, String correlator) { - System.out.println(env); - String camundaMsgUrl = new StringBuilder(env.getRequiredProperty(Constants.WORKFLOW_MESSAGE_ENPOINT)) - .append("/").append(messageEventName).append("/").append(correlator).toString(); - return camundaMsgUrl; - } - - /** - * @return - */ - public HttpHeaders getCamundaHeaders() { - HttpHeaders headers = new HttpHeaders(); - List acceptableMediaTypes = new ArrayList<>(); - acceptableMediaTypes.add(MediaType.ALL); - headers.setAccept(acceptableMediaTypes); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.add(HttpHeaders.AUTHORIZATION, addAuthorizationHeader(env.getRequiredProperty(Constants.CAMUNDA_AUTH), - env.getRequiredProperty(Constants.MSO_KEY))); - return headers; - } - - /** - * @param auth - * @param msoKey - * @return - */ - protected String addAuthorizationHeader(String auth, String msoKey) { - String basicAuth = null; - try { - String userCredentials = CryptoUtils.decrypt(auth, msoKey); - if (userCredentials != null) { - basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); - } - } catch (GeneralSecurityException e) { - logger.error("Security exception", e); - } - return basicAuth; - } - - /** - * @return - * @throws Exception - */ - public HttpHeaders getOofHttpHeaders() throws Exception { - HttpHeaders headers = new HttpHeaders(); - List acceptableMediaTypes = new ArrayList<>(); - acceptableMediaTypes.add(MediaType.APPLICATION_JSON); - headers.setAccept(acceptableMediaTypes); - headers.setContentType(MediaType.APPLICATION_JSON); - return headers; - } - - /** - * @param apiPath - * @return - */ - public String getOofurl(String apiPath) { - return new StringBuilder(env.getRequiredProperty(Constants.OOF_ENDPOINT)).append(apiPath).toString(); - } - - -} diff --git a/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java b/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java deleted file mode 100644 index 3a2f7f5..0000000 --- a/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof.rest; - -import static org.mockito.Mockito.when; -import java.io.File; -import java.io.IOException; -import org.junit.Before; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import org.onap.so.adapters.oof.utils.OofUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; -import com.fasterxml.jackson.databind.ObjectMapper; - - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class OofCallbackHandlerTest { - - @Autowired - TestRestTemplate restTemplate; - - @MockBean - OofUtils oofutils; - - @MockBean - RestTemplate mockrestTemplate; - - @Before - void prepareMocks() throws Exception { - ResponseEntity responseEntity = new ResponseEntity<>(HttpStatus.OK); - when(oofutils.getCamundaHeaders()).thenReturn(new HttpHeaders()); - when(oofutils.getCamundaMsgUrl(Mockito.anyString(), Mockito.anyString())).thenReturn("oofurl"); - when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any())) - .thenReturn(responseEntity); - } - - @Test - void processCallbackTest() throws Exception { - Object request = prepareOofResponse(); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity(request, headers); - ResponseEntity response = restTemplate.postForEntity( - "/so/adapters/oof/callback/v1/NSISelectionResponse/d88da85c-d9e8-4f73-b837-3a72a431622a", entity, - String.class); - Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()); - } - - private Object prepareOofResponse() throws IOException { - File file = new ClassPathResource("testInputs/NsiSelectionResponse.json").getFile(); - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.readValue(file, Object.class); - } - -} diff --git a/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java b/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java deleted file mode 100644 index ff38a9a..0000000 --- a/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof.rest; - -import static org.mockito.Mockito.when; -import java.io.File; -import java.io.IOException; -import org.junit.Before; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.so.adapters.oof.model.OofRequest; -import org.onap.so.adapters.oof.utils.OofUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; -import com.fasterxml.jackson.databind.ObjectMapper; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class OofClientTest { - - @Autowired - TestRestTemplate restTemplate; - - @MockBean - OofUtils oofutils; - - @MockBean - RestTemplate mockrestTemplate; - - @Before - void prepareMocks() throws Exception { - ResponseEntity responseEntity = new ResponseEntity<>(HttpStatus.OK); - when(oofutils.getOofHttpHeaders()).thenReturn(new HttpHeaders()); - when(oofutils.getOofurl(Mockito.anyString())).thenReturn("oofurl"); - when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any())) - .thenReturn(responseEntity); - } - - @Test - void callOofTest() throws Exception { - OofRequest request = prepareOofRequest(); - System.out.println(request); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity(request, headers); - ResponseEntity response = restTemplate.postForEntity("/so/adapters/oof/v1", entity, String.class); - Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()); - } - - private OofRequest prepareOofRequest() throws IOException { - File file = new ClassPathResource("testInputs/NsiSelectionOofRequest.json").getFile(); - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.readValue(file, OofRequest.class); - } - - -} diff --git a/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java b/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java deleted file mode 100644 index e68fa10..0000000 --- a/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Wipro Limited. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.oof.utils; - -import static org.mockito.Mockito.when; -import java.security.GeneralSecurityException; -import javax.xml.bind.DatatypeConverter; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.onap.so.utils.CryptoUtils; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpHeaders; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -class OofUtilsTest { - - @InjectMocks - OofUtils oofUtils; - - @Mock - Environment env; - - @Test - void testGetCamundaMsgUrl() { - when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); - String camundamsgUrl = oofUtils.getCamundaMsgUrl("samplemessage", "sampleCorrelator"); - Assertions.assertNotNull(camundamsgUrl); - } - - - void testGetCamundaHeaders() throws GeneralSecurityException { - when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); - when(CryptoUtils.decrypt(Mockito.anyString(), Mockito.anyString())).thenReturn("decryptedString"); - HttpHeaders headers = oofUtils.getCamundaHeaders(); - Assertions.assertNotNull(headers); - } - - - @Test - void testGetOofHttpHeaders() throws Exception { - when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); - HttpHeaders headers = oofUtils.getOofHttpHeaders(); - Assertions.assertNotNull(headers); - } - - @Test - void testGetOofurl() { - when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); - String oofurl = oofUtils.getOofurl("/api/v1/"); - Assertions.assertNotNull(oofurl); - } - -} diff --git a/src/test/resources/testInputs/NsiSelectionOofRequest.json b/src/test/resources/testInputs/NsiSelectionOofRequest.json deleted file mode 100644 index 569aae9..0000000 --- a/src/test/resources/testInputs/NsiSelectionOofRequest.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "apiPath":"/api/oof/selection/nsi/v1", - "requestDetails":{ - "serviceProfile":{ - "blob":"content" - }, - "requestInfo":{ - "transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851", - "requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851", - "callbackUrl":"myDomain.com/myCallback", - "callbackHeader":{ - "blob":"content" - }, - "sourceId":"d290f1ee-6c54-4b01-90e6-d701748f0851", - "timeout":5, - "numSolutions":1 - }, - "NSTInfo":{ - "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa1", - "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6", - "name":"embb-nst" - }, - "NSSTInfo":[ - { - "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa2", - "invariantUUID":"2fa85f64-5717-4562-b3fc-2c963f66afa6", - "name":"embb-an-nf" - }, - { - "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa3", - "invariantUUID":"4fa85f64-5717-4562-b3fc-2c963f66afa6", - "name":"embb-cn" - }, - { - "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa4", - "invariantUUID":"5ta85f64-5717-4562-b3fc-2c963f66afa6", - "name":"embb-tn-fh" - }, - { - "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa5", - "invariantUUID":"6ya85f64-5717-4562-b3fc-2c963f66afa6", - "name":"embb-tn-mh" - }, - { - "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa7", - "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6", - "name":"embb-tn-bh" - } - ], - "preferReuse":false, - "subnetCapabilities":[ - { - "domainType":"AN-NF", - "capabilityDetails":{ - "blob":"content" - } - }, - { - "domainType":"CN", - "capabilityDetails":{ - "blob":"content" - } - }, - { - "domainType":"TN-FH", - "capabilityDetails":{ - "blob":"content" - } - }, - { - "domainType":"TN-MH", - "capabilityDetails":{ - "blob":"content" - } - }, - { - "domainType":"TN-BH", - "capabilityDetails":{ - "blob":"content" - } - } - ] -} -} \ No newline at end of file diff --git a/src/test/resources/testInputs/NsiSelectionResponse.json b/src/test/resources/testInputs/NsiSelectionResponse.json deleted file mode 100644 index 4ddca3e..0000000 --- a/src/test/resources/testInputs/NsiSelectionResponse.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "transactionId": "s4r0f1ee-6c54-4b01-90e6-d701748f0851", - "requestId": "r500f1ee-6c54-4b01-90e6-d701748f0851", - "requestStatus": "completed", - "solutions": [ - { - "existingNSI": false, - "newNSISolution": { - "sliceProfiles": [ - { - "domainType":"CN" - } - ], - "matchLevel": { - "blob": "content" - } - } - } - ] -} -- cgit 1.2.3-korg