From 86ba43b6e0d298c469ee93ecfc08052d6e8ab8c9 Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Tue, 4 Aug 2020 09:19:10 +0200 Subject: [PATCH] Create base of Truststore Merger subproject Issue-ID: DCAEGEN2-2253 Signed-off-by: Remigiusz Janeczek Change-Id: Ieea2ed6eae212e09a1c818e54d1660ff566e3b09 --- pom.xml | 1 + trustStoreMerger/Dockerfile | 13 ++ trustStoreMerger/pom.xml | 169 +++++++++++++++++++++ .../onap/oom/truststoremerger/AppExitHandler.java | 34 +++++ .../org/onap/oom/truststoremerger/MainApp.java | 28 ++++ .../oom/truststoremerger/TrustStoreMerger.java | 35 +++++ .../onap/oom/truststoremerger/api/ExitStatus.java | 41 +++++ .../truststoremerger/api/ExitableException.java | 39 +++++ trustStoreMerger/src/main/resources/log4j2.xml | 30 ++++ .../oom/truststoremerger/TrustStoreMergerTest.java | 42 +++++ 10 files changed, 432 insertions(+) create mode 100644 trustStoreMerger/Dockerfile create mode 100644 trustStoreMerger/pom.xml create mode 100644 trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java create mode 100644 trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/MainApp.java create mode 100644 trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java create mode 100644 trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java create mode 100644 trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitableException.java create mode 100644 trustStoreMerger/src/main/resources/log4j2.xml create mode 100644 trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/TrustStoreMergerTest.java diff --git a/pom.xml b/pom.xml index 8126ee99..59be1bac 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ certService certServiceClient + trustStoreMerger diff --git a/trustStoreMerger/Dockerfile b/trustStoreMerger/Dockerfile new file mode 100644 index 00000000..63d15c42 --- /dev/null +++ b/trustStoreMerger/Dockerfile @@ -0,0 +1,13 @@ +FROM docker.io/openjdk:11-jre-slim + +ARG VERSION=${version} + +RUN groupadd onap && useradd -g onap truststoreMerger + +RUN chown -R truststoreMerger:onap /var/log + +USER truststoreMerger:onap + +COPY target/oom-truststore-merger-${VERSION}.jar ./opt/onap/oom/truststoremerger/oom-truststore-merger.jar + +ENTRYPOINT ["java","-jar","./opt/onap/oom/truststoremerger/oom-truststore-merger.jar"] diff --git a/trustStoreMerger/pom.xml b/trustStoreMerger/pom.xml new file mode 100644 index 00000000..7f0db366 --- /dev/null +++ b/trustStoreMerger/pom.xml @@ -0,0 +1,169 @@ + + + + aaf-certservice + org.onap.aaf.certservice + 1.2.0-SNAPSHOT + + 4.0.0 + + oom-truststore-merger + 1.2.0-SNAPSHOT + oom-truststore-merger + Truststore merging application + jar + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + + docker-staging + + ${project.version}-STAGING-${maven.build.timestamp} + ${project.version}-STAGING-latest + + + + + docker + + false + + + linux + x86_64 + ${os.detected.name}-${os.detected.arch} + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + package + + shade + + + false + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + org.onap.oom.truststoremerger.MainApp + + + + + + + + io.fabric8 + docker-maven-plugin + ${docker-maven-plugin.version} + + + docker-build-image + package + + build + + + + docker-push-image + deploy + + push + + + + + ${skipDockerPush} + true + IfNotPresent + + + ${project.artifactId} + ${docker-image.namespace}/${docker-image.name}:${docker-image.tag.latest} + + ${docker-image.registry} + + ${project.basedir} + + ${project.version}-${maven.build.timestamp}Z + + + + + + + + + + + + + + ecomp-releases + ONAP Release Repository + ${nexusproxy}${releaseNexusPath} + + + ecomp-snapshots + ONAP Snapshot Repository + ${nexusproxy}${snapshotNexusPath} + + + ecomp-site + dav:${nexusproxy}${sitePath} + + + + + + + org.assertj + assertj-core + + + org.junit.jupiter + junit-jupiter + + + org.mockito + mockito-core + + + org.mockito + mockito-junit-jupiter + + + org.slf4j + slf4j-api + + + org.springframework.boot + spring-boot-starter-log4j2 + + + diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java new file mode 100644 index 00000000..c257756a --- /dev/null +++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/AppExitHandler.java @@ -0,0 +1,34 @@ +/*============LICENSE_START======================================================= + * oom-truststore-merger + * ================================================================================ + * Copyright (C) 2020 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.oom.truststoremerger; + +import org.onap.oom.truststoremerger.api.ExitStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AppExitHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(AppExitHandler.class); + + public void exit(ExitStatus exitStatus) { + LOGGER.info("Application exits with following exit code: {} and message: {}", + exitStatus.getExitCodeValue(), exitStatus.getMessage()); + System.exit(exitStatus.getExitCodeValue()); + } +} diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/MainApp.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/MainApp.java new file mode 100644 index 00000000..a26b9def --- /dev/null +++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/MainApp.java @@ -0,0 +1,28 @@ +/*============LICENSE_START======================================================= + * oom-truststore-merger + * ================================================================================ + * Copyright (C) 2020 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.oom.truststoremerger; + +public class MainApp { + + public static void main(String[] args) { + TrustStoreMerger trustStoreMerger = new TrustStoreMerger(new AppExitHandler()); + trustStoreMerger.run(); + } +} diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java new file mode 100644 index 00000000..f280800b --- /dev/null +++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java @@ -0,0 +1,35 @@ +/*============LICENSE_START======================================================= + * oom-truststore-merger + * ================================================================================ + * Copyright (C) 2020 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.oom.truststoremerger; + +import org.onap.oom.truststoremerger.api.ExitStatus; + +class TrustStoreMerger { + + private final AppExitHandler appExitHandler; + + TrustStoreMerger(AppExitHandler appExitHandler) { + this.appExitHandler = appExitHandler; + } + + void run() { + appExitHandler.exit(ExitStatus.SUCCESS); + } +} diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java new file mode 100644 index 00000000..84184e89 --- /dev/null +++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java @@ -0,0 +1,41 @@ +/*============LICENSE_START======================================================= + * oom-truststore-merger + * ================================================================================ + * Copyright (C) 2020 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.oom.truststoremerger.api; + +public enum ExitStatus { + + SUCCESS(0, "Success"); + + private final int value; + private final String message; + + ExitStatus(int value, String message) { + this.value = value; + this.message = message; + } + + public int getExitCodeValue() { + return value; + } + + public String getMessage() { + return message; + } +} diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitableException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitableException.java new file mode 100644 index 00000000..3cc46730 --- /dev/null +++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitableException.java @@ -0,0 +1,39 @@ +/*============LICENSE_START======================================================= + * oom-truststore-merger + * ================================================================================ + * Copyright (C) 2020 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.oom.truststoremerger.api; + +public class ExitableException extends Exception { + + private final ExitStatus exitStatus; + + public ExitableException(Throwable cause, ExitStatus exitStatus) { + super(cause); + this.exitStatus = exitStatus; + } + + public ExitableException(String message, ExitStatus exitStatus) { + super(message); + this.exitStatus = exitStatus; + } + + public ExitStatus applicationExitStatus() { + return exitStatus; + }; +} diff --git a/trustStoreMerger/src/main/resources/log4j2.xml b/trustStoreMerger/src/main/resources/log4j2.xml new file mode 100644 index 00000000..697017e3 --- /dev/null +++ b/trustStoreMerger/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/TrustStoreMergerTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/TrustStoreMergerTest.java new file mode 100644 index 00000000..11b18bf1 --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/TrustStoreMergerTest.java @@ -0,0 +1,42 @@ +/*============LICENSE_START======================================================= + * oom-truststore-merger + * ================================================================================ + * Copyright (C) 2020 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.oom.truststoremerger; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.oom.truststoremerger.api.ExitStatus; + +import static org.mockito.Mockito.verify; + +@ExtendWith(MockitoExtension.class) +class TrustStoreMergerTest { + + @Mock + AppExitHandler appExitHandler; + + @Test + void shouldExitWithSuccess() { + new TrustStoreMerger(appExitHandler).run(); + + verify(appExitHandler).exit(ExitStatus.SUCCESS); + } +} -- 2.16.6