diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-03-22 15:33:06 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-03-24 06:59:47 +0000 |
commit | d378c37fbd1ecec7b43394926f1ca32a695e07de (patch) | |
tree | 5c8a085f8732f980d871d966ac49361644efa698 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java | |
parent | a6ae7294ecd336d7e88f915710b08e2658eaee00 (diff) |
Reformat openecomp-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3449
Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java')
21 files changed, 108 insertions, 194 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/LoggingConstants.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/LoggingConstants.java index e8635b2418..522ad28caf 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/LoggingConstants.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/LoggingConstants.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging; /** @@ -28,7 +27,6 @@ public class LoggingConstants { * Default HTTP header for propagation of a request ID for distributed tracing. */ public static final String DEFAULT_REQUEST_ID_HEADER = "X-ECOMP-RequestID"; - /** * Default HTTP header for exchanging a partner name between components. */ diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java index 090f680aa7..8bf8852354 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; -import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; import lombok.Getter; +import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; /** - * Builder to populate <i>audit</i> data. This includes only data known to an application, and not otherwise available - * to the logging framework. As opposed, for example, to local runtime, host address, etc. + * Builder to populate <i>audit</i> data. This includes only data known to an application, and not otherwise available to the logging framework. As + * opposed, for example, to local runtime, host address, etc. * * @author KATYR, evitaliy * @since February 15, 2018 @@ -30,7 +29,6 @@ import lombok.Getter; public class AuditData { // don't inherit from MetricsData because it has a very different meaning - private final long startTime; private final long endTime; private final ResponseStatus statusCode; @@ -47,17 +45,16 @@ public class AuditData { this.clientIpAddress = builder.clientIpAddress; } - @Override - public String toString() { - return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode - + ", responseCode=" + responseCode + ", responseDescription=" + responseDescription - + ", clientIpAddress=" + clientIpAddress + '}'; - } - public static AuditDataBuilder builder() { return new AuditDataBuilder(); } + @Override + public String toString() { + return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode + ", responseCode=" + responseCode + + ", responseDescription=" + responseDescription + ", clientIpAddress=" + clientIpAddress + '}'; + } + /** * Fluent API for building audit data. */ @@ -95,8 +92,8 @@ public class AuditData { } /** - * Indicate whether an invocation was successful. It is up the the application to decide if a particular result - * must be treated as a success or a failure. + * Indicate whether an invocation was successful. It is up the the application to decide if a particular result must be treated as a success + * or a failure. * * @param statusCode invocation status success/failure * @return this builder for fluent API @@ -118,8 +115,8 @@ public class AuditData { } /** - * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it - * is likely to be a standard HTTP response phrase. + * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it is likely to be a standard HTTP + * response phrase. * * @param responseDescription human-friendly response description * @return this builder for fluent API diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java index 6eb747f9d9..ba556caac3 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ContextData.java @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Objects; /** - * Builder to populate logging <i>context</i> data, i.e. data that should be available to any log writing event - * throughout an application. This includes only data known at some point to the application (e.g. at an API call), - * and not otherwise available to the logging framework (e.g. information about local runtime, machine, etc.). + * Builder to populate logging <i>context</i> data, i.e. data that should be available to any log writing event throughout an application. This + * includes only data known at some point to the application (e.g. at an API call), and not otherwise available to the logging framework (e.g. + * information about local runtime, machine, etc.). * * @author evitaliy * @since Mar 22, 2018 @@ -38,6 +37,10 @@ public class ContextData { this.partnerName = builder.partnerName; } + public static ContextDataBuilder builder() { + return new ContextDataBuilder(); + } + /** * Uniques request ID received from a calling peer, or created. * @@ -67,18 +70,15 @@ public class ContextData { @Override public boolean equals(Object o) { - if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { return false; } - ContextData that = (ContextData) o; - return Objects.equals(requestId, that.requestId) && Objects.equals(serviceName, that.serviceName) - && Objects.equals(partnerName, that.partnerName); + return Objects.equals(requestId, that.requestId) && Objects.equals(serviceName, that.serviceName) && Objects + .equals(partnerName, that.partnerName); } @Override @@ -88,12 +88,7 @@ public class ContextData { @Override public String toString() { - return "ContextData{responseCode=" + requestId + ", responseDescription=" + serviceName - + ", clientIpAddress=" + partnerName + '}'; - } - - public static ContextDataBuilder builder() { - return new ContextDataBuilder(); + return "ContextData{responseCode=" + requestId + ", responseDescription=" + serviceName + ", clientIpAddress=" + partnerName + '}'; } /** diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java index 6fbd25a134..9d670e8dcb 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java @@ -4,16 +4,15 @@ * 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. */ - package org.openecomp.sdc.logging.api; /** diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java index 6ef57761d8..b772f5682c 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Objects; @@ -22,22 +21,19 @@ import org.openecomp.sdc.logging.spi.LoggerCreationService; /** * <a>Factory to hide a concrete, framework-specific implementation of logger creation.</a> * <p>The service used by this factory must implement {@link LoggerCreationService}. If no - * implementation has been configured or could be instantiated, a <b>no-op logger</b> will be - * used, and <b>no events</b> will be logged. This is done to prevent recursion if attempts are - * being made to log exceptions that resulted from logger initialization. </p> + * implementation has been configured or could be instantiated, a <b>no-op logger</b> will be used, and <b>no events</b> will be logged. This is done + * to prevent recursion if attempts are being made to log exceptions that resulted from logger initialization. </p> * * @author evitaliy - * @since 13/09/2016. - * * @see ServiceBinder * @see LoggerCreationService + * @since 13/09/2016. */ public class LoggerFactory { - // use the no-op service to prevent recursion in case of an attempt to log an exception as a + // result of a logger initialization error - private static final LoggerCreationService SERVICE = ServiceBinder.getCreationServiceBinding().orElseGet( - NoOpLoggerCreationService::new); + private static final LoggerCreationService SERVICE = ServiceBinder.getCreationServiceBinding().orElseGet(NoOpLoggerCreationService::new); private LoggerFactory() { // prevent instantiation @@ -53,6 +49,18 @@ public class LoggerFactory { private static class NoOpLoggerCreationService implements LoggerCreationService { + @Override + public Logger getLogger(String className) { + Objects.requireNonNull(className, "Name cannot be null"); + return NoOpLogger.INSTANCE; + } + + @Override + public Logger getLogger(Class<?> clazz) { + Objects.requireNonNull(clazz, "Class cannot be null"); + return NoOpLogger.INSTANCE; + } + private static class NoOpLogger implements Logger { private static final Logger INSTANCE = new NoOpLogger(); @@ -212,18 +220,5 @@ public class LoggerFactory { // no-op } } - - @Override - public Logger getLogger(String className) { - Objects.requireNonNull(className, "Name cannot be null"); - return NoOpLogger.INSTANCE; - } - - @Override - public Logger getLogger(Class<?> clazz) { - Objects.requireNonNull(clazz, "Class cannot be null"); - return NoOpLogger.INSTANCE; - } } } - diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java index 894dd2c00c..29e3f33fa0 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggingContext.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Objects; @@ -24,9 +23,8 @@ import org.openecomp.sdc.logging.spi.LoggingContextService; * <p>Factory to hide a concrete, framework-specific implementation of diagnostic context.</p> * * <p>The service used by this factory must implement {@link LoggingContextService}. If no implementation has been - * configured or could be instantiated, a <b>no-op context service</b> will be used, and <b>no context</b> will be - * stored or propagated. No errors will be generated, so that the application can still work (albeit without proper - * logging).</p> + * configured or could be instantiated, a <b>no-op context service</b> will be used, and <b>no context</b> will be stored or propagated. No errors + * will be generated, so that the application can still work (albeit without proper logging).</p> * * @author evitaliy * @see ServiceBinder @@ -35,8 +33,7 @@ import org.openecomp.sdc.logging.spi.LoggingContextService; */ public class LoggingContext { - private static final LoggingContextService SERVICE = - ServiceBinder.getContextServiceBinding().orElseGet(NoOpLoggingContextService::new); + private static final LoggingContextService SERVICE = ServiceBinder.getContextServiceBinding().orElseGet(NoOpLoggingContextService::new); private LoggingContext() { // prevent instantiation diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java index 2fef96d2bb..e85c22cb67 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/MetricsData.java @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; -import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; import lombok.Getter; +import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; /** - * Builder to populate <i>metrics</i> data. This includes only data known to an application, and not otherwise available - * to the logging framework. + * Builder to populate <i>metrics</i> data. This includes only data known to an application, and not otherwise available to the logging framework. * * @author evitaliy * @since 26 Mar 2018 @@ -30,7 +28,6 @@ import lombok.Getter; public class MetricsData { // don't inherit from AuditData because it has a very different meaning - private final long startTime; private final long endTime; private final ResponseStatus statusCode; @@ -51,17 +48,16 @@ public class MetricsData { this.targetVirtualEntity = builder.targetVirtualEntity; } - @Override - public String toString() { - return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode - + ", responseCode=" + responseCode + ", responseDescription=" + responseDescription - + ", clientIpAddress=" + clientIpAddress + '}'; - } - public static MetricsDataBuilder builder() { return new MetricsDataBuilder(); } + @Override + public String toString() { + return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode + ", responseCode=" + responseCode + + ", responseDescription=" + responseDescription + ", clientIpAddress=" + clientIpAddress + '}'; + } + /** * Fluent API for building metrics data. */ @@ -101,8 +97,8 @@ public class MetricsData { } /** - * Indicate whether an invocation was successful. It is up the the application to decide if a particular result - * must be treated as a success or a failure. + * Indicate whether an invocation was successful. It is up the the application to decide if a particular result must be treated as a success + * or a failure. * * @param statusCode invocation status success/failure * @return this builder for fluent API @@ -124,8 +120,8 @@ public class MetricsData { } /** - * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it - * is likely to be a standard HTTP response phrase. + * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it is likely to be a standard HTTP + * response phrase. * * @param responseDescription human-friendly response description * @return this builder for fluent API diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java index 6e5b3e3501..65d624aa86 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/ServiceBinder.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.api; import java.util.Iterator; @@ -35,6 +34,7 @@ import org.openecomp.sdc.logging.spi.LoggingServiceProvider; */ // No advanced logging can be used here because we don't know + // which underlying implementation will be used @SuppressWarnings({"UseOfSystemOutOrSystemErr", "squid:S106", "squid:S1166"}) class ServiceBinder { @@ -46,31 +46,23 @@ class ServiceBinder { } private static LoggingServiceProvider lookupProvider() { - ServiceLoader<LoggingServiceProvider> loader = ServiceLoader.load(LoggingServiceProvider.class); Iterator<LoggingServiceProvider> iterator = loader.iterator(); - if (!iterator.hasNext()) { - System.err.printf("[ERROR] No provider configured for logging services %s. " - + "Default implementation will be used.\n", LoggingServiceProvider.class.getName()); + System.err.printf("[ERROR] No provider configured for logging services %s. " + "Default implementation will be used.\n", + LoggingServiceProvider.class.getName()); return null; } - try { - LoggingServiceProvider provider = iterator.next(); if (!iterator.hasNext()) { return provider; } - Logger logger = provider.getLogger(ServiceBinder.class); if (logger.isWarnEnabled()) { - logger.warn("More than one provider for logging services {} found", - LoggingServiceProvider.class.getName()); + logger.warn("More than one provider for logging services {} found", LoggingServiceProvider.class.getName()); } - return provider; - } catch (Exception e) { // don't fail if the provider cannot be instantiated e.printStackTrace(System.err); @@ -86,4 +78,3 @@ class ServiceBinder { return Optional.ofNullable(PROVIDER); } } - diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java index cfe80da244..5faad5a7a3 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/package-info.java @@ -17,9 +17,9 @@ /** * <p>Client-visible API for logging, implemented according to * <a href="https://wiki.onap.org/download/attachments/1015849/ONAP%20application%20logging%20guidelines.pdf?api=v2"> - * ONAP application logging guidelines</a>. The actual implementation is delegated to a service provider bound through - * the <a href="https://docs.oracle.com/javase/tutorial/ext/basics/spi.html">Java SPI</a> mechanism. The provider must - * implement {@link org.openecomp.sdc.logging.spi.LoggingServiceProvider}.</p> + * ONAP application logging guidelines</a>. The actual implementation is delegated to a service provider bound through the <a + * href="https://docs.oracle.com/javase/tutorial/ext/basics/spi.html">Java SPI</a> mechanism. The provider must implement {@link + * org.openecomp.sdc.logging.spi.LoggingServiceProvider}.</p> * <p>The logging API collects the following types of data:</p> * <ol> * <li>Context that must be propagated throughout the application, and available at any point for debug and error @@ -35,4 +35,4 @@ * @author evitaliy * @since 26 Mar 2018 */ -package org.openecomp.sdc.logging.api; +package org.openecomp.sdc.logging.api; diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/AuditTracker.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/AuditTracker.java index 2aeacf1ad5..371aaf68b6 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/AuditTracker.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/AuditTracker.java @@ -13,20 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet; +import static org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus.COMPLETE; + import java.util.Objects; import javax.servlet.http.HttpServletRequest; import org.openecomp.sdc.logging.api.AuditData; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import static org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus.COMPLETE; - /** - * Tracks and logs audit information when a request is being processed. An instance of this class cannot be reused, and - * the pre- and post-request methods must be called only once. + * Tracks and logs audit information when a request is being processed. An instance of this class cannot be reused, and the pre- and post-request + * methods must be called only once. * * @author evitaliy * @since 31 Jul 2018 @@ -57,35 +56,27 @@ public class AuditTracker implements Tracker { @Override public synchronized void preRequest(HttpServletRequest request) { - if (this.started > 0) { throw new IllegalStateException("Pre-request has been already called"); } - this.started = System.currentTimeMillis(); this.clientIpAddress = request.getRemoteAddr(); - AuditData auditData = AuditData.builder().startTime(started).endTime(started).statusCode(COMPLETE) - .clientIpAddress(clientIpAddress) - .build(); + AuditData auditData = AuditData.builder().startTime(started).endTime(started).statusCode(COMPLETE).clientIpAddress(clientIpAddress).build(); logger.auditEntry(auditData); } @Override public synchronized void postRequest(RequestProcessingResult result) { - if (this.started == 0) { throw new IllegalStateException("Pre-request must be called first"); } - if (!logger.isAuditEnabled()) { return; } - long end = System.currentTimeMillis(); AuditData auditData = AuditData.builder().startTime(started).endTime(end).statusCode(result.getStatusCode()) - .responseCode(Integer.toString(result.getStatus())) - .responseDescription(result.getStatusPhrase()).clientIpAddress(clientIpAddress) - .build(); + .responseCode(Integer.toString(result.getStatus())).responseDescription(result.getStatusPhrase()).clientIpAddress(clientIpAddress) + .build(); logger.auditExit(auditData); } } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java index 5d940aa821..513a8a0361 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet; import javax.servlet.http.HttpServletRequest; /** - * Tracker for all the elements of ONAP logging and tracing at an entry point to an application. - * The order of invocations is important, and on {@link #preRequest(HttpServletRequest)} it respects the order of - * trackers passed to the constructor. On {@link #postRequest(RequestProcessingResult)}, the invocation will be in the + * Tracker for all the elements of ONAP logging and tracing at an entry point to an application. The order of invocations is important, and on {@link + * #preRequest(HttpServletRequest)} it respects the order of trackers passed to the constructor. On {@link #postRequest(RequestProcessingResult)}, the + * invocation will be in the * <b>reverse</b> order. * * @author evitaliy @@ -38,7 +37,6 @@ public class CombinedTracker implements Tracker { @Override public void preRequest(HttpServletRequest request) { - for (Tracker t : trackers) { t.preRequest(request); } @@ -46,7 +44,6 @@ public class CombinedTracker implements Tracker { @Override public void postRequest(RequestProcessingResult result) { - for (int i = trackers.length - 1; i > -1; i--) { trackers[i].postRequest(result); } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ContextTracker.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ContextTracker.java index 02745f6287..51ba005521 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ContextTracker.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ContextTracker.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet; import java.util.Objects; @@ -34,13 +33,12 @@ public class ContextTracker implements Tracker { private final HttpHeader partnerNameHeaders; private final HttpHeader requestIdHeaders; - private final Supplier<Void> loggingContextClear; private final Consumer<ContextData> loggingContextPut; /** - * Constructs tracker to handle required logging context in Servlet-based applications. Refer to ONAP logging - * guidelines for fields required to be put on logging context. + * Constructs tracker to handle required logging context in Servlet-based applications. Refer to ONAP logging guidelines for fields required to be + * put on logging context. * * @param partnerNameHeaders HTTP headers to check for a partner name, cannot be null * @param requestIdHeaders HTTP headers to check for a request ID, cannot be null @@ -56,36 +54,30 @@ public class ContextTracker implements Tracker { } /** - * Package level constructor used for tests. Clean and Put are passed as functions - * in order to avoid static mock and service loader config - LoggingServiceProvider in LoggingContext + * Package level constructor used for tests. Clean and Put are passed as functions in order to avoid static mock and service loader config - + * LoggingServiceProvider in LoggingContext * * @param partnerNameHeaders * @param requestIdHeaders * @param loggingContextClear * @param loggingContextPut */ - ContextTracker(HttpHeader partnerNameHeaders, - HttpHeader requestIdHeaders, - Supplier<Void> loggingContextClear, - Consumer<ContextData> loggingContextPut) { + ContextTracker(HttpHeader partnerNameHeaders, HttpHeader requestIdHeaders, Supplier<Void> loggingContextClear, + Consumer<ContextData> loggingContextPut) { this.partnerNameHeaders = Objects.requireNonNull(partnerNameHeaders); this.requestIdHeaders = Objects.requireNonNull(requestIdHeaders); this.loggingContextPut = loggingContextPut; - this.loggingContextClear =loggingContextClear; + this.loggingContextClear = loggingContextClear; } @Override public void preRequest(HttpServletRequest request) { - loggingContextClear.get(); - String serviceName = ServiceNameFormatter.format(request); String requestId = requestIdHeaders.getAny(request::getHeader).orElse(UUID.randomUUID().toString()); - ContextData.ContextDataBuilder contextBuilder = - ContextData.builder().serviceName(serviceName).requestId(requestId); + ContextData.ContextDataBuilder contextBuilder = ContextData.builder().serviceName(serviceName).requestId(requestId); String partnerName = partnerNameHeaders.getAny(request::getHeader).orElse("UNKNOWN"); contextBuilder.partnerName(partnerName); - loggingContextPut.accept(contextBuilder.build()); } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java index dd5af859d4..95963b504f 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet; import java.util.ArrayList; @@ -24,9 +23,9 @@ import java.util.Optional; import java.util.function.Function; /** - * Handles any of possible header names to read a value for that header. This is useful for backward compatibility, if - * multiple headers may have the same meaning. For instance, when requests come from multiple service, some using an old - * header and others using a new header to pass the same information. + * Handles any of possible header names to read a value for that header. This is useful for backward compatibility, if multiple headers may have the + * same meaning. For instance, when requests come from multiple service, some using an old header and others using a new header to pass the same + * information. * * @author evitaliy * @since 25 Mar 2018 @@ -35,7 +34,6 @@ public class HttpHeader { private static final String NAMES_CANNOT_BE_NULL = "Names cannot be null"; private static final String AT_LEAST_ONE_NAME_REQUIRED = "At least one name required"; - private final List<String> headerNames; /** @@ -44,11 +42,9 @@ public class HttpHeader { * @param headerNames cannot be null or empty */ public HttpHeader(String... headerNames) { - if (Objects.requireNonNull(headerNames, NAMES_CANNOT_BE_NULL).length < 1) { throw new IllegalArgumentException(AT_LEAST_ONE_NAME_REQUIRED); } - this.headerNames = Arrays.asList(headerNames); } @@ -58,11 +54,9 @@ public class HttpHeader { * @param headerNames cannot be null or empty */ public HttpHeader(List<String> headerNames) { - if (Objects.requireNonNull(headerNames, NAMES_CANNOT_BE_NULL).isEmpty()) { throw new IllegalArgumentException(AT_LEAST_ONE_NAME_REQUIRED); } - this.headerNames = new ArrayList<>(headerNames); } @@ -73,29 +67,23 @@ public class HttpHeader { * @return value or empty if not found */ public Optional<String> getAny(Function<String, String> reader) { - for (String k : headerNames) { - String value = reader.apply(k); if (value != null) { return Optional.of(value); } } - return Optional.empty(); } @Override public boolean equals(Object o) { - if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { return false; } - HttpHeader that = (HttpHeader) o; return Objects.equals(headerNames, that.headerNames); } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/RequestProcessingResult.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/RequestProcessingResult.java index ff77ef8a93..bf1d1e5d0f 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/RequestProcessingResult.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/RequestProcessingResult.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet; import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ServiceNameFormatter.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ServiceNameFormatter.java index fcbd281e88..dd5c0a7153 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ServiceNameFormatter.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/ServiceNameFormatter.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet; import javax.servlet.http.HttpServletRequest; diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/Tracker.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/Tracker.java index c0337cfb4d..98b1d71969 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/Tracker.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/Tracker.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet; import javax.servlet.http.HttpServletRequest; @@ -34,9 +33,9 @@ public interface Tracker { void preRequest(HttpServletRequest request); /** - * Will be executed after a request has been processed. Results may be treated differently depending on a container - * and application. For instance, JAX-RS applications may take into account exception mappers before generating a - * response; some applications may Swagger annotations to map a response status to a human-friendly message, etc. + * Will be executed after a request has been processed. Results may be treated differently depending on a container and application. For + * instance, JAX-RS applications may take into account exception mappers before generating a response; some applications may Swagger annotations + * to map a response status to a human-friendly message, etc. * * @param result application- and container-specific request results */ diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java index fb651495ac..71d61b0de2 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet.jaxrs; import static org.openecomp.sdc.logging.LoggingConstants.DEFAULT_PARTNER_NAME_HEADER; @@ -35,8 +34,7 @@ import org.openecomp.sdc.logging.servlet.Tracker; /** * <p>Takes care of logging initialization an HTTP request hits the application. This includes populating logging - * context and tracking the request for audit. The filter <b>works in tandem</b> with {@link LoggingResponseFilter} or - * a similar implementation.</p> + * context and tracking the request for audit. The filter <b>works in tandem</b> with {@link LoggingResponseFilter} or a similar implementation.</p> * <p>The filter requires a few HTTP header names to be configured. These HTTP headers are used for propagating logging * and tracing information between ONAP components. Sample configuration for a Spring environment:</p> * <pre> @@ -59,15 +57,11 @@ import org.openecomp.sdc.logging.servlet.Tracker; public class LoggingRequestFilter implements ContainerRequestFilter { static final String LOGGING_TRACKER_KEY = "onap.logging.tracker"; - private static final String MULTI_VALUE_SEPARATOR = ","; private static final Logger LOGGER = LoggerFactory.getLogger(LoggingRequestFilter.class); - private HttpServletRequest httpRequest; - private HttpHeader requestIdHeader = new HttpHeader(DEFAULT_REQUEST_ID_HEADER); private HttpHeader partnerNameHeader = new HttpHeader(DEFAULT_PARTNER_NAME_HEADER); - private ResourceInfo resource; /** @@ -109,9 +103,7 @@ public class LoggingRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { Class<?> resourceClass = resource.getResourceMethod().getDeclaringClass(); - Tracker tracker = new CombinedTracker( - new ContextTracker(partnerNameHeader, requestIdHeader), - new AuditTracker(resourceClass)); + Tracker tracker = new CombinedTracker(new ContextTracker(partnerNameHeader, requestIdHeader), new AuditTracker(resourceClass)); requestContext.setProperty(LOGGING_TRACKER_KEY, tracker); tracker.preRequest(httpRequest); } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingResponseFilter.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingResponseFilter.java index b0ae88ccaa..e5bdd56534 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingResponseFilter.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingResponseFilter.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.servlet.jaxrs; import static javax.ws.rs.core.Response.Status.Family.REDIRECTION; import static javax.ws.rs.core.Response.Status.Family.SUCCESSFUL; -import static org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus.*; +import static org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus.COMPLETE; +import static org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus.ERROR; import static org.openecomp.sdc.logging.servlet.jaxrs.LoggingRequestFilter.LOGGING_TRACKER_KEY; import javax.ws.rs.container.ContainerRequestContext; @@ -26,7 +26,6 @@ import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.Response; import javax.ws.rs.ext.Provider; - import org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; @@ -35,8 +34,7 @@ import org.openecomp.sdc.logging.servlet.Tracker; /** * <p>Takes care of logging when an HTTP request leaves the application. This includes writing to audit and clearing - * logging context. This filter <b>only works properly in tandem</b> with {@link LoggingRequestFilter} or a similar - * implementation.</p> + * logging context. This filter <b>only works properly in tandem</b> with {@link LoggingRequestFilter} or a similar implementation.</p> * <p>Sample configuration for a Spring environment:</p> * <pre> * <jaxrs:providers> @@ -57,14 +55,11 @@ public class LoggingResponseFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { - Tracker tracker = (Tracker) requestContext.getProperty(LOGGING_TRACKER_KEY); - if (tracker == null) { LOGGER.debug("No logging tracker received"); return; } - tracker.postRequest(new ContainerResponseResult(responseContext.getStatusInfo())); } @@ -93,4 +88,3 @@ public class LoggingResponseFilter implements ContainerResponseFilter { } } } - diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggerCreationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggerCreationService.java index 54b5be3a27..d30412557a 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggerCreationService.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggerCreationService.java @@ -4,16 +4,15 @@ * 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. */ - package org.openecomp.sdc.logging.spi; import org.openecomp.sdc.logging.api.Logger; diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java index 37e212ac54..7d08b2559c 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingContextService.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.spi; import java.util.concurrent.Callable; @@ -22,16 +21,14 @@ import org.openecomp.sdc.logging.api.ContextData; /** * Should be used to implement a framework-specific mechanism of managing a per-thread diagnostic context (for instance * <a href="http://www.slf4j.org/manual.html#mdc">MDC</a>), and propagating it to child threads if needed. Context - * propagation should be used when creating a child thread directly, or submitting tasks for potentially postponed - * execution via an <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html">Executor</a> - * (including any of the <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html"> - * executor services</a> and <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html"> - * ForkJoinPool</a>). + * propagation should be used when creating a child thread directly, or submitting tasks for potentially postponed execution via an <a + * href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html">Executor</a> (including any of the <a + * href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html"> executor services</a> and <a + * href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html"> ForkJoinPool</a>). * * @author evitaliy * @since 07 Jan 2018 */ - public interface LoggingContextService { /** @@ -50,14 +47,14 @@ public interface LoggingContextService { void clear(); /** - * Copies logging context of current thread onto a {@link Runnable}, so that the context is available when this - * {@link Runnable} runs in another thread. + * Copies logging context of current thread onto a {@link Runnable}, so that the context is available when this {@link Runnable} runs in another + * thread. */ Runnable copyToRunnable(Runnable runnable); /** - * Copies logging context of current thread onto a {@link Callable}, so that the context is available when this - * {@link Callable} runs in another thread + * Copies logging context of current thread onto a {@link Callable}, so that the context is available when this {@link Callable} runs in another + * thread */ <V> Callable<V> copyToCallable(Callable<V> callable); } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingServiceProvider.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingServiceProvider.java index 12e4040feb..4af0baebd2 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingServiceProvider.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/spi/LoggingServiceProvider.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.logging.spi; /** * <p>From the application code (consumer) perspective, logger creation (factory) and logging context are independent - * services. From the service provider perspective, however, these services are related and must be implemented together - * using the same underlying mechanism. Therefore, the service provider-facing interface combines the two services - * — to eliminate the chance that their implementations don't work well together.</p> + * services. From the service provider perspective, however, these services are related and must be implemented together using the same underlying + * mechanism. Therefore, the service provider-facing interface combines the two services — to eliminate the chance that their implementations + * don't work well together.</p> * * @author EVITALIY * @since 07 Jan 18 */ public interface LoggingServiceProvider extends LoggerCreationService, LoggingContextService { // single provider must implement two separate consumer services -} +} |