diff options
-rw-r--r-- | cmso-topology/etc/config/README.txt | 3 | ||||
-rw-r--r-- | cmso-topology/etc/config/cadi.properties | 4 | ||||
-rw-r--r-- | cmso-topology/etc/config/topology.properties | 30 | ||||
-rw-r--r-- | cmso-topology/pom.xml | 516 | ||||
-rw-r--r-- | cmso-topology/src/main/docker/Dockerfile | 33 | ||||
-rw-r--r-- | cmso-topology/src/main/docker/assembly/cmso-files.xml | 64 | ||||
-rw-r--r-- | cmso-topology/src/main/docker/extra-files/startService.sh | 7 | ||||
-rw-r--r-- | cmso-topology/src/main/java/org/onap/observations/Mdc.java | 278 |
8 files changed, 935 insertions, 0 deletions
diff --git a/cmso-topology/etc/config/README.txt b/cmso-topology/etc/config/README.txt new file mode 100644 index 0000000..f815955 --- /dev/null +++ b/cmso-topology/etc/config/README.txt @@ -0,0 +1,3 @@ +The files in this etc/config folder are here for testing locally on eclipse. + +The files actually deployed are elsewhere diff --git a/cmso-topology/etc/config/cadi.properties b/cmso-topology/etc/config/cadi.properties new file mode 100644 index 0000000..5135d1d --- /dev/null +++ b/cmso-topology/etc/config/cadi.properties @@ -0,0 +1,4 @@ + +cadi_loglevel=DEBUG +cadi_prop_files=src/main/resources/aaf/org.onap.oof.props + diff --git a/cmso-topology/etc/config/topology.properties b/cmso-topology/etc/config/topology.properties new file mode 100644 index 0000000..5ca252f --- /dev/null +++ b/cmso-topology/etc/config/topology.properties @@ -0,0 +1,30 @@ +#------------------------------------------------------------------------------- +# Copyright 2017-2019 AT&T Intellectual Property. +# Modifications Copyright 2018 IBM. +# +# 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. +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the ??License?); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# 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. +#------------------------------------------------------------------------------- diff --git a/cmso-topology/pom.xml b/cmso-topology/pom.xml new file mode 100644 index 0000000..a426a82 --- /dev/null +++ b/cmso-topology/pom.xml @@ -0,0 +1,516 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- ============LICENSE_START======================================================= + org.onap.optf.cmso ================================================================================ + Copyright © 2019 AT&T Intellectual Property. All rights reserved. ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); you may not + use this file except in compliance with the License. You may obtain a copy + of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required + by applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied. See the License for the specific + language governing permissions and limitations under the License. ============LICENSE_END========================================================= --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.optf.cmso</groupId> + <artifactId>cmso</artifactId> + <version>1.0.1-SNAPSHOT</version> + </parent> + + <groupId>org.onap.optf.cmso.topology</groupId> + <artifactId>cmso-topology</artifactId> + + <packaging>jar</packaging> + + <name>cmso</name> + + <properties> + <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> + + <cmso.project.version>${project.version}</cmso.project.version> + <cmso.build.timestamp>${maven.build.timestamp}</cmso.build.timestamp> + + <service.name>cmso</service.name> + <release-tag>Casablanca</release-tag> + <name.space>org.onap.optf.cmso</name.space> + <serviceArtifactName>cmso</serviceArtifactName> + + <java.version>1.8</java.version> + <eelf.version>1.0.0</eelf.version> + <pact.version>3.3.9</pact.version> + <spring.version>5.0.10.RELEASE</spring.version> + <spring.boot.version>2.1.3.RELEASE</spring.boot.version> + <swagger.core.version>2.0.0</swagger.core.version> + + <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>1.8</maven.compiler.source> + <build.number>${maven.build.timestamp}</build.number> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> + <mariadb.version>2.2.1</mariadb.version> + <swagger.directory>${basedir}/src/main/resources/META-INF/resources/swagger/</swagger.directory> + <aaf.version>2.1.4</aaf.version> + + <!-- Sonar --> + <ilib.version>2.0.7</ilib.version> + <sonar.language>java</sonar.language> + <jacoco.path>${basedir}/target/jacoco_report</jacoco.path> + <jacoco.itPath>${basedir}/target/jacoco_itReport</jacoco.itPath> + <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> + <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> + <sonar.jacoco.reportPath>${basedir}/target/jacoco-ut.exec</sonar.jacoco.reportPath> + <sonar.jacoco.itReportPath>${basedir}/target/jacoco-it.exec</sonar.jacoco.itReportPath> + <sonar.surefire.reportsPath>${basedir}/target/surefire-reports</sonar.surefire.reportsPath> + <sonar.failsafe.reportsPath>${basedir}/target/failsafe-reports</sonar.failsafe.reportsPath> + + <docker.push.registry>localhost:5000</docker.push.registry> + <docker.pull.registry>nexus3.onap.org:10001</docker.pull.registry> + <docker.skip.build>false</docker.skip.build> + <docker.skip.push>false</docker.skip.push> + <docker.skip.tag>false</docker.skip.tag> + <skip.staging.artifacts>false</skip.staging.artifacts> + + </properties> + + <dependencyManagement> + <dependencies> + <!-- Spring boot --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-dependencies</artifactId> + <version>${spring.boot.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jersey</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-loader-tools</artifactId> + </dependency> --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </dependency> + <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> + </dependency> --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-tx</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context-support</artifactId> + </dependency> + <dependency> + <groupId>com.att.eelf</groupId> + <artifactId>eelf-core</artifactId> + <version>${eelf.version}</version> + <exclusions> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </exclusion> + <exclusion> + <groupId>org.powermock</groupId> + <artifactId>powermock-module</artifactId> + </exclusion> + <exclusion> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + </exclusion> + <exclusion> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + </exclusion> + + </exclusions> + </dependency> + <!-- <dependency> <groupId>org.onap.aaf.authz</groupId> <artifactId>aaf-cadi-aaf</artifactId> + <version>2.1.1</version> </dependency> --> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + <version>2.1</version> + </dependency> + + <!--Swagger Dependencies --> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-jaxrs2</artifactId> + <version>${swagger.core.version}</version> + </dependency> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-jaxrs2-servlet-initializer</artifactId> + <version>${swagger.core.version}</version> + </dependency> + + <dependency> + <groupId>io.swagger</groupId> + <artifactId>swagger-jersey2-jaxrs</artifactId> + <version>1.5.0</version> + </dependency> + + + <!-- Database --> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + </dependency> + + <dependency> + <groupId>joda-time</groupId> + <artifactId>joda-time</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-text</artifactId> + <version>1.6</version> + </dependency> + <!-- Testing Dependencies --> + <!-- <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito2</artifactId> + <version>1.7.4</version> <scope>test</scope> </dependency> --> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>1.9.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.aaf.authz</groupId> + <artifactId>aaf-cadi-aaf</artifactId> + <version>${aaf.version}</version> + </dependency> + </dependencies> + + <build> + <finalName>cmso-topology</finalName> + <plugins> + <plugin> + <groupId>au.com.dius</groupId> + <artifactId>pact-jvm-provider-maven_2.11</artifactId> + <version>${pact.version}</version> + <configuration> + <!--pactBrokerUrl,user name,password and project version required only + for consumer --> + <pactBrokerUrl>${BROKER_URL}</pactBrokerUrl> + <pactBrokerUsername>pactadmin</pactBrokerUsername> + <pactBrokerPassword>pactadmin</pactBrokerPassword> + <projectVersion>1.0.0</projectVersion> + <!-- service provider required only for producer --> + <serviceProviders> + <serviceProvider> + <name>core</name> + <protocol>http</protocol> + <host>${APP_URL}</host> + <port>${APP_PORT}</port> + <path>/</path> + <pactBroker> + <url>${BROKER_URL}</url> + <authentication> + <username>pactadmin</username> + <password>pactadmin</password> + </authentication> + </pactBroker> + </serviceProvider> + </serviceProviders> + </configuration> + </plugin> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + </plugin> + <plugin> + <groupId>com.github.kongchen</groupId> + <artifactId>swagger-maven-plugin</artifactId> + <version>3.1.5</version> + <configuration> + <apiSources> + <apiSource> + <locations> + <location>org.onap.optf.cmso.topology.service.rs</location> + </locations> + <basePath>/topology</basePath> + <info> + <title>${project.artifactId}</title> + <version>${project.version}</version> + </info> + <swaggerDirectory>${swagger.directory}</swaggerDirectory> + </apiSource> + </apiSources> + </configuration> + <executions> + <execution> + <phase>compile</phase> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.groovy.maven</groupId> + <artifactId>gmaven-plugin</artifactId> + <version>1.0</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <source>${project.basedir}/src/main/script/TagVersion.groovy</source> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>exec-maven-plugin</artifactId> + <groupId>org.codehaus.mojo</groupId> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${spring.boot.version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + <version>0.26.0</version> + <configuration> + <verbose>true</verbose> + <apiVersion>1.23</apiVersion> + <images> + <image> + <name>onap/optf-cmso-tciketmgt</name> + <alias>onap-optf-cmso-tciketmgt</alias> + <build> + <cleanup>true</cleanup> + <tags> + <tag>latest</tag> + <tag>${project.docker.latesttagtimestamp.version}</tag> + <tag>${project.docker.latesttag.version}</tag> + </tags> + <dockerFile>${project.basedir}/src/main/docker/Dockerfile</dockerFile> + <assembly> + <descriptor>${project.basedir}/src/main/docker/assembly/cmso-files.xml</descriptor> + <name>onap-cmso-topology</name> + </assembly> + </build> + </image> + </images> + </configuration> + <executions> + <execution> + <id>generate-images</id> + <phase>install</phase> + <goals> + <goal>build</goal> + </goals> + </execution> + <execution> + <id>push-images</id> + <phase>deploy</phase> + <goals> + <goal>build</goal> + <goal>push</goal> + </goals> + <configuration> + <image>onap/optf-cmso-topology:%l</image> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + <!-- mention the logback.xml location through system property or environment + variable to edit logback.xml at run time --> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <directory>etc/config</directory> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <directory>${basedir}/truststore</directory> + <targetPath>${basedir}/target/truststore</targetPath> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <directory>${basedir}/bin</directory> + <targetPath>${basedir}/target/bin</targetPath> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <directory>${basedir}/data</directory> + <targetPath>${basedir}/target/data</targetPath> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + </resources> + <pluginManagement> + <plugins> + <!--This plugin's configuration is used to store Eclipse m2e settings + only. It has no influence on the Maven build itself. --> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId> + com.github.kongchen + </groupId> + <artifactId> + swagger-maven-plugin + </artifactId> + <versionRange> + [3.1.5] + </versionRange> + <goals> + <goal>generate</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore></ignore> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + + <profiles> + <profile> + <id>snapshot</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <properties> + <versionSuffix>-${build.number}-${release-tag}</versionSuffix> + </properties> + </profile> + <profile> + <id>next-stable</id> + <properties> + <versionSuffix>-${release-tag}</versionSuffix> + </properties> + </profile> + <profile> + <id>last-stable</id> + <properties> + <versionSuffix>-${release-tag}</versionSuffix> + </properties> + </profile> + </profiles> +</project> diff --git a/cmso-topology/src/main/docker/Dockerfile b/cmso-topology/src/main/docker/Dockerfile new file mode 100644 index 0000000..4c663b4 --- /dev/null +++ b/cmso-topology/src/main/docker/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:16.04 + +MAINTAINER "The Onap Team" +LABEL Description="This image contains ubuntu 16.04 with the openjdk installed" Version="16.04-8" +ENV APP_HOME=/opt/app/cmso +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 + +RUN test -n "$http_proxy" && echo "Acquire::Proxy \"http://$http_proxy\";" > /etc/apt/apt.conf.d/02proxy || true && \ + apt-get update && \ + apt-get -y dist-upgrade && \ + apt-get install -y openjdk-8-jre-headless + +COPY onap-cmso-topology/cmso-topology.jar ${APP_HOME}/app.jar + +VOLUME /share/etc +VOLUME /share/logs +VOLUME /share/debug-logs + +COPY onap-cmso-topology/startService.sh ${APP_HOME}/startService.sh +COPY onap-cmso-topology/data ${APP_HOME}/data + +RUN chmod 700 ${APP_HOME}/startService.sh +RUN ln -s /share/etc ${APP_HOME}/etc +RUN ln -s /share/logs ${APP_HOME}/logs +RUN ln -s /share/debug-logs ${APP_HOME}/debug-logs + +WORKDIR ${APP_HOME} +ENTRYPOINT ./startService.sh diff --git a/cmso-topology/src/main/docker/assembly/cmso-files.xml b/cmso-topology/src/main/docker/assembly/cmso-files.xml new file mode 100644 index 0000000..8d6b2f3 --- /dev/null +++ b/cmso-topology/src/main/docker/assembly/cmso-files.xml @@ -0,0 +1,64 @@ +<!-- ============LICENSE_START======================================================= + CMSO ================================================================================ + Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); you may not + use this file except in compliance with the License. You may obtain a copy + of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required + by applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied. See the License for the specific + language governing permissions and limitations under the License. ============LICENSE_END========================================================= --> + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"> + <id>cmso-files</id> + + <formats> + <format>tar.gz</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + + + <fileSets> + <!-- include config files --> + <fileSet> + <includes> + <include>${project.build.finalName}.jar</include> + </includes> + <directory>${project.build.directory}</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + <fileSet> + <includes> + <include>**</include> + </includes> + <directory>src/main/docker/extra-files</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + <fileSet> + <includes> + <include>**</include> + </includes> + <directory>data</directory> + <outputDirectory>/data</outputDirectory> + </fileSet> + <fileSet> + <directory>${project.basedir}/src/main/resources</directory> + <outputDirectory>./resources</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + <fileSet> + <directory>${project.basedir}/etc/config</directory> + <outputDirectory>./</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + + </fileSets> + +</assembly> diff --git a/cmso-topology/src/main/docker/extra-files/startService.sh b/cmso-topology/src/main/docker/extra-files/startService.sh new file mode 100644 index 0000000..199c637 --- /dev/null +++ b/cmso-topology/src/main/docker/extra-files/startService.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +VM_ARGS="${VM_ARGS} -Dserver.local.startpath=${RESOURCES_HOME}" + +echo "VM_ARGS="${VM_ARGS} + +java -Djava.security.egd=file:/dev/./urandom ${VM_ARGS} -Xms256m -Xmx1024m -jar ./app.jar diff --git a/cmso-topology/src/main/java/org/onap/observations/Mdc.java b/cmso-topology/src/main/java/org/onap/observations/Mdc.java new file mode 100644 index 0000000..5c2bd5f --- /dev/null +++ b/cmso-topology/src/main/java/org/onap/observations/Mdc.java @@ -0,0 +1,278 @@ +/* + * Copyright © 2019 AT&T Intellectual Property. + * + * 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. + * + * + * Unless otherwise specified, all documentation contained herein is licensed under the Creative + * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except + * in compliance with the License. You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation 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. + */ + +package org.onap.observations; + +import static com.att.eelf.configuration.Configuration.MDC_BEGIN_TIMESTAMP; +import static com.att.eelf.configuration.Configuration.MDC_END_TIMESTAMP; +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; +import static com.att.eelf.configuration.Configuration.MDC_PARTNER_NAME; +import static com.att.eelf.configuration.Configuration.MDC_REMOTE_HOST; +import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_CODE; +import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_DESC; +import static com.att.eelf.configuration.Configuration.MDC_STATUS_CODE; +import static com.att.eelf.configuration.Configuration.MDC_TARGET_ENTITY; +import static com.att.eelf.configuration.Configuration.MDC_TARGET_SERVICE_NAME; + +import com.att.eelf.utils.Stopwatch; +import java.net.URI; +import java.util.Date; +import java.util.Map; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientResponseContext; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response.StatusType; +import org.onap.observations.MessageHeaders.HeadersEnum; +import org.slf4j.MDC; + +/** + * ECOMP EELF logging MDC fields not defined in the MDC Configuration (i.e. MDC_ALERT_SEVERITY) + **/ +public class Mdc { + + /** The Constant SERVICE_NAME. */ + public static final String SERVICE_NAME = "CSS-Scheduler"; + + /** + * The Enum Enum. + */ + public enum Enum { + // BeginTimestamp, + // EndTimeStamp, + // RequestId, + // ServiceInstanceId, + VirtualServerName, + // ServiceName, + // PartnerName, + // StatusCOde, + // ResponseCode, + // ResponseDescription, + // InstanceUUID, + // AlertSeverity, + // ServerIPAddress, + // ElapsedTime, + // ServerFQDN, + // RemoteHost, + ClassName, + Unused, + // ProcessKey, + CustomField1, + CustomField2, + CustomField3, + CustomField4, + // TargetVirtualEntity, + // TargetEntity, + // TargetServiceName, + ErrorCode, + ErrorDescription, + Timer, + } + + /** + * Gets the caller. + * + * @param back the back + * @return the caller + */ + public static String getCaller(int back) { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + return stackTraceElements[back].getClassName() + "." + stackTraceElements[back].getMethodName(); + } + + /** + * Sets the caller. + * + * @param back the new caller + */ + public static void setCaller(int back) { + String caller = MDC.get(Enum.ClassName.name()); + if (caller == null) { + MDC.put(Enum.ClassName.name(), getCaller(back)); + } + } + + /** + * Sets the observation. + * + * @param obs the new observation + */ + public static void setObservation(ObservationInterface obs) { + MDC.put(Enum.CustomField4.name(), obs.name()); + } + + /** + * Clear caller. + */ + public static void clearCaller() { + MDC.remove(Enum.ClassName.name()); + } + + /** + * Save. + * + * @return the map + */ + public static Map<String, String> save() { + Map<String, String> save = MDC.getCopyOfContextMap(); + return save; + } + + /** + * Restore. + * + * @param mdcSave the mdc save + */ + public static void restore(Map<String, String> mdcSave) { + MDC.clear(); + for (String name : mdcSave.keySet()) { + MDC.put(name, mdcSave.get(name)); + } + } + + + + /** + * Sets the request id if not set. + * + * @param requestId the new request id if not set + */ + public static void setRequestIdIfNotSet(String requestId) { + if (MDC.get(MDC_KEY_REQUEST_ID) == null || MDC.get(MDC_KEY_REQUEST_ID).equals("")) { + setRequestId(requestId); + } + } + + /** + * Sets the request id. + * + * @param requestId the new request id + */ + public static void setRequestId(String requestId) { + MDC.put(MDC_KEY_REQUEST_ID, requestId); + } + + /** + * Metric start. + * + * @param requestContext the request context + */ + public static void metricStart(ClientRequestContext requestContext) { + MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date())); + MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP)); + setPartnerTargetFromUri(requestContext.getUri()); + } + + /** + * Metric end. + * + * @param response the response + */ + public static void metricEnd(ClientResponseContext response) { + + Date now = new Date(); + // MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + setResponseInfo(response.getStatusInfo()); + + } + + /** + * Audit start. + * + * @param requestContext the request context + * @param servletRequest the servlet request + */ + public static void auditStart(ContainerRequestContext requestContext, HttpServletRequest servletRequest) { + MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date())); + MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP)); + MDC.put(MDC_REMOTE_HOST, servletRequest.getRemoteHost()); + MDC.put(Enum.ClassName.name(), getCaller(4)); + MultivaluedMap<String, String> headers = requestContext.getHeaders(); + String transactionId = headers.getFirst(HeadersEnum.TransactionID.toString()); + if (transactionId != null) { + setRequestId(transactionId); + } else { + setRequestId(UUID.randomUUID().toString()); + } + + } + + /** + * Audit end. + * + * @param requestContext the request context + * @param response the response + */ + public static void auditEnd(ContainerRequestContext requestContext, ContainerResponseContext response) { + Date now = new Date(); + // MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(now)); + MDC.put(Enum.ClassName.name(), getCaller(4)); + + setResponseInfo(response.getStatusInfo()); + + } + + private static void setResponseInfo(StatusType statusInfo) { + Integer status = statusInfo.getStatusCode(); + String completed = "ERROR"; + if (status >= 200 && status < 300) { + completed = "COMPLETE"; + } + MDC.put(MDC_RESPONSE_CODE, status.toString()); + MDC.put(MDC_RESPONSE_DESC, statusInfo.getReasonPhrase()); + MDC.put(MDC_STATUS_CODE, completed); + } + + /** + * Sets the event. + * + * @param requestId the new event + */ + public static void setEvent(String requestId) { + MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date())); + MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP)); + setRequestId(requestId); + } + + private static void setPartnerTargetFromUri(URI uri) { + try { + MDC.put(MDC_PARTNER_NAME, uri.getHost()); + MDC.put(MDC_TARGET_ENTITY, uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort()); + MDC.put(MDC_TARGET_SERVICE_NAME, uri.getPath()); + } catch (Exception e) { + MDC.put(MDC_PARTNER_NAME, "UNKNOWN"); + MDC.put(MDC_TARGET_ENTITY, "UNKNOWN"); + MDC.put(MDC_TARGET_SERVICE_NAME, "UNKNOWN"); + } + } + + +} |