From b21d6a299d1c39723823994aa77339f8596b1add Mon Sep 17 00:00:00 2001 From: Jerry Flood Date: Tue, 26 Mar 2019 15:00:17 -0400 Subject: Commit 1 for Define Topology API mS Multiple commits required due to commit size limitation. Change-Id: If6188c73d9012fb72b4054cc6e88ecd794449710 Issue-ID: OPTFRA-430 Signed-off-by: Jerry Flood --- cmso-topology/etc/config/README.txt | 3 + cmso-topology/etc/config/cadi.properties | 4 + cmso-topology/etc/config/topology.properties | 30 ++ cmso-topology/pom.xml | 516 +++++++++++++++++++++ cmso-topology/src/main/docker/Dockerfile | 33 ++ .../src/main/docker/assembly/cmso-files.xml | 64 +++ .../src/main/docker/extra-files/startService.sh | 7 + .../src/main/java/org/onap/observations/Mdc.java | 278 +++++++++++ 8 files changed, 935 insertions(+) create mode 100644 cmso-topology/etc/config/README.txt create mode 100644 cmso-topology/etc/config/cadi.properties create mode 100644 cmso-topology/etc/config/topology.properties create mode 100644 cmso-topology/pom.xml create mode 100644 cmso-topology/src/main/docker/Dockerfile create mode 100644 cmso-topology/src/main/docker/assembly/cmso-files.xml create mode 100644 cmso-topology/src/main/docker/extra-files/startService.sh create mode 100644 cmso-topology/src/main/java/org/onap/observations/Mdc.java (limited to 'cmso-topology') 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 @@ + + + + + + 4.0.0 + + + org.onap.optf.cmso + cmso + 1.0.1-SNAPSHOT + + + org.onap.optf.cmso.topology + cmso-topology + + jar + + cmso + + + yyyyMMdd'T'HHmmss'Z' + + ${project.version} + ${maven.build.timestamp} + + cmso + Casablanca + org.onap.optf.cmso + cmso + + 1.8 + 1.0.0 + 3.3.9 + 5.0.10.RELEASE + 2.1.3.RELEASE + 2.0.0 + + 1.8 + 1.8 + ${maven.build.timestamp} + UTF-8 + UTF-8 + yyyyMMdd'T'HHmmss'Z' + 2.2.1 + ${basedir}/src/main/resources/META-INF/resources/swagger/ + 2.1.4 + + + 2.0.7 + java + ${basedir}/target/jacoco_report + ${basedir}/target/jacoco_itReport + reuseReports + jacoco + ${basedir}/target/jacoco-ut.exec + ${basedir}/target/jacoco-it.exec + ${basedir}/target/surefire-reports + ${basedir}/target/failsafe-reports + + localhost:5000 + nexus3.onap.org:10001 + false + false + false + false + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-jersey + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-security + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-tomcat + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.mockito + mockito-core + + + + + org.apache.httpcomponents + httpclient + + + org.springframework + spring-test + test + + + org.springframework + spring-beans + + + org.springframework + spring-beans + + + org.springframework + spring-context + + + org.springframework + spring-core + + + org.springframework + spring-expression + + + org.springframework + spring-web + + + org.springframework + spring-tx + + + org.springframework + spring-context-support + + + com.att.eelf + eelf-core + ${eelf.version} + + + org.mockito + mockito-core + + + org.powermock + powermock-module + + + org.powermock + powermock-api-mockito + + + org.powermock + powermock-module-junit4 + + + + + + + javax.ws.rs + javax.ws.rs-api + 2.1 + + + + + io.swagger.core.v3 + swagger-jaxrs2 + ${swagger.core.version} + + + io.swagger.core.v3 + swagger-jaxrs2-servlet-initializer + ${swagger.core.version} + + + + io.swagger + swagger-jersey2-jaxrs + 1.5.0 + + + + + + org.mariadb.jdbc + mariadb-java-client + + + + joda-time + joda-time + + + org.apache.commons + commons-text + 1.6 + + + + + org.mockito + mockito-all + 1.9.5 + test + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + test + + + org.onap.aaf.authz + aaf-cadi-aaf + ${aaf.version} + + + + + cmso-topology + + + au.com.dius + pact-jvm-provider-maven_2.11 + ${pact.version} + + + ${BROKER_URL} + pactadmin + pactadmin + 1.0.0 + + + + core + http + ${APP_URL} + ${APP_PORT} + / + + ${BROKER_URL} + + pactadmin + pactadmin + + + + + + + + maven-dependency-plugin + + + com.github.kongchen + swagger-maven-plugin + 3.1.5 + + + + + org.onap.optf.cmso.topology.service.rs + + /topology + + ${project.artifactId} + ${project.version} + + ${swagger.directory} + + + + + + compile + + generate + + + + + + org.codehaus.groovy.maven + gmaven-plugin + 1.0 + + + validate + + execute + + + ${project.basedir}/src/main/script/TagVersion.groovy + + + + + + exec-maven-plugin + org.codehaus.mojo + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + + + + io.fabric8 + docker-maven-plugin + 0.26.0 + + true + 1.23 + + + onap/optf-cmso-tciketmgt + onap-optf-cmso-tciketmgt + + true + + latest + ${project.docker.latesttagtimestamp.version} + ${project.docker.latesttag.version} + + ${project.basedir}/src/main/docker/Dockerfile + + ${project.basedir}/src/main/docker/assembly/cmso-files.xml + onap-cmso-topology + + + + + + + + generate-images + install + + build + + + + push-images + deploy + + build + push + + + onap/optf-cmso-topology:%l + + + + + + + + + src/main/resources + true + + **/* + + + + etc/config + true + + **/* + + + + ${basedir}/truststore + ${basedir}/target/truststore + true + + **/* + + + + ${basedir}/bin + ${basedir}/target/bin + true + + **/* + + + + ${basedir}/data + ${basedir}/target/data + true + + **/* + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + com.github.kongchen + + + swagger-maven-plugin + + + [3.1.5] + + + generate + + + + + + + + + + + + + + + + + snapshot + + true + + + -${build.number}-${release-tag} + + + + next-stable + + -${release-tag} + + + + last-stable + + -${release-tag} + + + + 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 @@ + + + + cmso-files + + + tar.gz + + false + + + + + + + ${project.build.finalName}.jar + + ${project.build.directory} + / + + + + ** + + src/main/docker/extra-files + / + + + + ** + + data + /data + + + ${project.basedir}/src/main/resources + ./resources + + **/* + + + + ${project.basedir}/etc/config + ./ + + **/* + + + + + + 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 save() { + Map save = MDC.getCopyOfContextMap(); + return save; + } + + /** + * Restore. + * + * @param mdcSave the mdc save + */ + public static void restore(Map 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 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"); + } + } + + +} -- cgit 1.2.3-korg