diff options
Diffstat (limited to 'dcae-analytics')
24 files changed, 273 insertions, 108 deletions
diff --git a/dcae-analytics/dcae-analytics-model/pom.xml b/dcae-analytics/dcae-analytics-model/pom.xml index fc6c32d..c7d6ddb 100644 --- a/dcae-analytics/dcae-analytics-model/pom.xml +++ b/dcae-analytics/dcae-analytics-model/pom.xml @@ -114,6 +114,11 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>org.onap.dcaegen2.analytics.tca-gen2</groupId> + <artifactId>eelf-logger-logback-impl</artifactId> + </dependency> + </dependencies> </project> diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/DmaapMrConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/DmaapMrConstants.java index 26f2210..ca14ff6 100644 --- a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/DmaapMrConstants.java +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/DmaapMrConstants.java @@ -30,13 +30,6 @@ public abstract class DmaapMrConstants { // ================== DMaaP MR CONSTANTS ============================== // - public static final Set<String> DMAAP_MAPPED_HEADERS = Stream.of( - AnalyticsHttpConstants.REQUEST_ID_HEADER_KEY, - AnalyticsHttpConstants.REQUEST_TRANSACTION_ID_HEADER_KEY, - AnalyticsHttpConstants.REQUEST_BEGIN_TS_HEADER_KEY, - AnalyticsHttpConstants.REQUEST_END_TS_HEADER_KEY).collect(Collectors.toSet()); - - // MR SUBSCRIBER public static final String SUBSCRIBER_EMPTY_MESSAGE_RESPONSE_STRING = "[]"; public static final String SUBSCRIBER_RANDOM_CONSUMER_GROUP_PREFIX = "DCAE-SUB-"; @@ -67,4 +60,15 @@ public abstract class DmaapMrConstants { private DmaapMrConstants() { // private constructor } + + /** + * getDmaapmappedHeaders + */ + public static final Set<String> getDmaapmappedHeaders () { + return Stream.of( + AnalyticsHttpConstants.REQUEST_ID_HEADER_KEY, + AnalyticsHttpConstants.REQUEST_TRANSACTION_ID_HEADER_KEY, + AnalyticsHttpConstants.REQUEST_BEGIN_TS_HEADER_KEY, + AnalyticsHttpConstants.REQUEST_END_TS_HEADER_KEY).collect(Collectors.toSet()); + } } diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java index 7384e97..423e951 100644 --- a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java @@ -40,8 +40,6 @@ public abstract class ConfigBindingServiceConstants { public static final String ENV_CBS_PORT = "CONFIG_BINDING_SERVICE_SERVICE_PORT"; public static final String CONFIG_BINDING_SERVICE_PROPERTIES_KEY = "config-binding-service"; - public static final Set<String> SPRING_RESERVED_PROPERTIES_KEY_PREFIXES = - Stream.of("spring", "endpoints", "server", "logging", "management").collect(Collectors.toSet()); public static final String CONFIG_SERVICE_MESSAGE_ROUTER_VALUE = "message_router"; // CONVERT JSON TO MAP public static final String KEY_SEPARATOR = "."; @@ -86,4 +84,11 @@ public abstract class ConfigBindingServiceConstants { private ConfigBindingServiceConstants() { // private constructor } + + /** + * getSpringReservedPropertiesKeyPrefixes + */ + public static final Set<String> getSpringReservedPropertiesKeyPrefixes() { + return Stream.of("spring", "endpoints", "server", "logging", "management").collect(Collectors.toSet()); + } } diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/exception/AnalyticsParsingException.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/exception/AnalyticsParsingException.java index 1af40f2..b06f2fb 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/exception/AnalyticsParsingException.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/exception/AnalyticsParsingException.java @@ -17,7 +17,7 @@ * */ -package org.onap.dcae.analytics.web.exception; +package org.onap.dcae.analytics.tca.core.exception; /** * @author Rajiv Singla diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/LogSpec.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/LogSpec.java new file mode 100644 index 0000000..002cf07 --- /dev/null +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/LogSpec.java @@ -0,0 +1,103 @@ +/* + * ================================================================================ + * Copyright (c) 2018 China Mobile. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.dcae.analytics.tca.core.util; + +import java.util.Date; + +import org.onap.dcae.analytics.model.TcaModelConstants; +import org.onap.dcae.analytics.model.ecomplogger.AnalyticsErrorType; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; +import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; + +/** + * @author Kai Lu + */ +public final class LogSpec { + + private LogSpec( ) { + // private constructor + } + + /** + * create ErrorLogSpec + * + * @param requestId requestId + * + * @return ErrorLogSpecImpl object + * + */ + public static ErrorLogSpec createErrorLogSpec(final String requestId) { + final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId); + final TargetServiceLogInfo targetServiceLogInfo = new TargetServiceLogInfoImpl( + "DCAE-TCA", TcaModelConstants.TCA_SERVICE_NAME, ""); + final ErrorLogInfo errorLogInfo = + new ErrorLogInfoImpl(AnalyticsErrorType.SCHEMA_ERROR.getErrorCode(), + AnalyticsErrorType.SCHEMA_ERROR.getErrorDescription()); + return new ErrorLogSpecImpl(requestIdLogInfo, + TcaUtils.TCA_SERVICE_LOG_INFO, targetServiceLogInfo, errorLogInfo); + } + + /** + * create DebugLogSpec + * + * @param requestId requestId + * + * @return DebugLogSpecImpl object + * + */ + public static DebugLogSpec createDebugLogSpec(final String requestId) { + final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId); + return new DebugLogSpecImpl(requestIdLogInfo); + } + + /** + * create AuditLogSpec + * + * @param requestId requestId + * @param requestBeginTimestamp requestBeginTimestamp + * + * @return AuditLogSpec object + * + */ + public static AuditLogSpec createAuditLogSpec(final String requestId, + final Date requestBeginTimestamp) { + final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId); + final Date endTimestamp = new Date(); + final RequestTimingLogInfoImpl requestTimingLogInfo = new RequestTimingLogInfoImpl(requestBeginTimestamp, + endTimestamp, endTimestamp.getTime() - requestBeginTimestamp.getTime()); + final ResponseLogInfo responseLogInfo = + new ResponseLogInfoImpl(AnalyticsErrorType.SUCCESSFUL.getErrorCode(), + AnalyticsErrorType.SUCCESSFUL.getErrorDescription()); + return new AuditLogSpecImpl(requestIdLogInfo, TcaUtils.TCA_SERVICE_LOG_INFO, + requestTimingLogInfo, responseLogInfo); + } + +} diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/util/TcaUtils.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/TcaUtils.java index 6744cee..bbadcac 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/util/TcaUtils.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/TcaUtils.java @@ -17,7 +17,7 @@ * */ -package org.onap.dcae.analytics.tca.web.util; +package org.onap.dcae.analytics.tca.core.util; import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion.TCA_OBJECT_MAPPER; @@ -30,8 +30,8 @@ import java.util.stream.Collectors; import org.onap.dcae.analytics.model.TcaModelConstants; import org.onap.dcae.analytics.model.cef.EventListener; +import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; -import org.onap.dcae.analytics.web.exception.AnalyticsParsingException; import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl; /** diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaAbatementCalculator.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaAbatementCalculator.java index 0322456..3dff203 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaAbatementCalculator.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaAbatementCalculator.java @@ -36,15 +36,17 @@ import org.onap.dcae.analytics.tca.core.service.TcaResultContext; import org.onap.dcae.analytics.tca.model.policy.ClosedLoopEventStatus; import org.onap.dcae.analytics.tca.model.policy.MetricsPerEventName; import org.onap.dcae.analytics.tca.model.policy.Threshold; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; /** * @author Rajiv Singla */ public class TcaAbatementCalculator implements TcaCalculationFunction { - private static final Logger logger = LoggerFactory.getLogger(TcaAbatementCalculator.class); + private static final EELFLogger logger = EELFLogFactory.getLogger(TcaAbatementCalculator.class); @Override public TcaExecutionContext calculate(final TcaExecutionContext tcaExecutionContext) { @@ -70,8 +72,8 @@ public class TcaAbatementCalculator implements TcaCalculationFunction { final ClosedLoopEventStatus closedLoopEventStatus = violatedThreshold.getClosedLoopEventStatus(); final String requestId = tcaExecutionContext.getRequestId(); final String lookupKey = createLookupKey(eventListener, violatedMetricsPerEventName); - - + final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId); + final DebugLogSpecImpl debugLogSpec = new DebugLogSpecImpl(requestIdLogInfo); switch (closedLoopEventStatus) { // ONSET - save alert info in database so that next abated event can fetch its request id for abated @@ -80,9 +82,9 @@ public class TcaAbatementCalculator implements TcaCalculationFunction { final TcaAbatementEntity tcaAbatementEntity = abatementContext.create(lookupKey, requestId, false); - logger.debug("Request Id: {}. Alert ClosedLoop Status is ONSET. " + + logger.debugLog().debug("Request Id: {}. Alert ClosedLoop Status is ONSET. " + "Saving abatement Entity to repository with lookupKey: {}", - requestId, tcaAbatementEntity.getLookupKey()); + debugLogSpec, requestId, tcaAbatementEntity.getLookupKey()); abatementPersistenceContext.save(tcaAbatementEntity); return tcaExecutionContext; @@ -99,8 +101,8 @@ public class TcaAbatementCalculator implements TcaCalculationFunction { final TcaAbatementEntity previousTcaAbatementEntity = previousTcaAbatementEntities.get(previousTcaAbatementEntities.size() - 1); - logger.debug("Request Id: {}. Found previous Abatement Entity: {}", requestId, - previousTcaAbatementEntity); + logger.debugLog().debug("Request Id: {}. Found previous Abatement Entity with lookupKey: {}", + debugLogSpec, requestId, previousTcaAbatementEntity.getLookupKey()); // previous abatement entity was found - but it was already sent before - so ignore alert creation if (previousTcaAbatementEntity.isAbatementAlertSent()) { @@ -113,14 +115,14 @@ public class TcaAbatementCalculator implements TcaCalculationFunction { // no previous abatement was sent final String previousRequestId = previousTcaAbatementEntity.getRequestId(); // set abated alert request id to previous ONSET alert request id - logger.debug("Request Id: {}. No previous abated alert was sent. Setting previous request id: {}", - requestId, previousRequestId); + logger.debugLog().debug("Request Id: {}. No previous abated alert was sent. Setting previous request id: {}", + debugLogSpec, requestId, previousRequestId); resultContext.setPreviousRequestId(previousRequestId); // save new entity with alert as sent final TcaAbatementEntity newTcaAbatementEntity = abatementContext.create(lookupKey, previousRequestId, true); - logger.debug("Request Id: {}. Saving new entity with alert as sent: {}", - requestId, newTcaAbatementEntity); + logger.debugLog().debug("Request Id: {}. Saving new entity with alert as sent with lookupKey: {}", + debugLogSpec, requestId, newTcaAbatementEntity.getLookupKey()); abatementPersistenceContext.save(newTcaAbatementEntity); return tcaExecutionContext; diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaCalculationFunction.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaCalculationFunction.java index ec9f7bd..d24bfe1 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaCalculationFunction.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaCalculationFunction.java @@ -21,10 +21,20 @@ package org.onap.dcae.analytics.tca.core.util.function.calculation; import java.util.function.Function; +import org.onap.dcae.analytics.model.TcaModelConstants; +import org.onap.dcae.analytics.model.ecomplogger.AnalyticsErrorType; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; import org.onap.dcae.analytics.tca.core.service.TcaProcessingContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.dcae.analytics.tca.core.util.TcaUtils; +import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; +import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl; +import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl; /** * Functional interface which all TCA calculation functions should implement @@ -34,11 +44,10 @@ import org.slf4j.LoggerFactory; @FunctionalInterface public interface TcaCalculationFunction extends Function<TcaExecutionContext, TcaExecutionContext> { - Logger logger = LoggerFactory.getLogger(TcaCalculationFunction.class); + EELFLogger logger = EELFLogFactory.getLogger(TcaCalculationFunction.class); TcaExecutionContext calculate(TcaExecutionContext tcaExecutionContext); - default TcaExecutionContext preCalculation(TcaExecutionContext tcaExecutionContext) { // do nothing return tcaExecutionContext; @@ -69,12 +78,24 @@ public interface TcaCalculationFunction extends Function<TcaExecutionContext, Tc final TcaExecutionContext tcaExecutionContext, final boolean isErrorMessage) { final TcaProcessingContext tcaProcessingContext = tcaExecutionContext.getTcaProcessingContext(); + + final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(tcaExecutionContext.getRequestId()); + if (isErrorMessage) { - logger.error("Request Id: {}. Error Message: {}", tcaExecutionContext.getRequestId(), terminatingMessage); + final TargetServiceLogInfo targetServiceLogInfo = new TargetServiceLogInfoImpl( + "DCAE-TCA", TcaModelConstants.TCA_SERVICE_NAME, ""); + final ErrorLogInfo errorLogInfo = + new ErrorLogInfoImpl(AnalyticsErrorType.SCHEMA_ERROR.getErrorCode(), + AnalyticsErrorType.SCHEMA_ERROR.getErrorDescription()); + final ErrorLogSpecImpl errorLogSpec = new ErrorLogSpecImpl(requestIdLogInfo, + TcaUtils.TCA_SERVICE_LOG_INFO, targetServiceLogInfo, errorLogInfo); + logger.errorLog().error("Request Id: {}. Error Message: {}", + errorLogSpec, tcaExecutionContext.getRequestId(), terminatingMessage); tcaProcessingContext.setErrorMessage(terminatingMessage); } else { - logger.debug("Request Id: {}. Early Termination Message: {}", tcaExecutionContext.getRequestId(), - terminatingMessage); + final DebugLogSpecImpl debugLogSpec = new DebugLogSpecImpl(requestIdLogInfo); + logger.debugLog().debug("Request Id: {}. Early Termination Message: {}", + debugLogSpec, tcaExecutionContext.getRequestId(), terminatingMessage); tcaProcessingContext.setEarlyTerminationMessage(terminatingMessage); } tcaProcessingContext.setContinueProcessing(false); diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentServiceImpl.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentServiceImpl.java index d38bd23..ccaacba 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentServiceImpl.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/aai/TcaAaiEnrichmentServiceImpl.java @@ -21,8 +21,6 @@ package org.onap.dcae.analytics.tca.web.aai; import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion.TCA_OBJECT_MAPPER; -import com.fasterxml.jackson.databind.JsonNode; - import java.io.IOException; import java.net.URI; import java.util.Collections; @@ -34,11 +32,14 @@ import org.onap.dcae.analytics.model.AnalyticsHttpConstants; import org.onap.dcae.analytics.model.TcaModelConstants; import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentService; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; +import org.onap.dcae.analytics.tca.core.util.LogSpec; import org.onap.dcae.analytics.tca.model.facade.Aai; import org.onap.dcae.analytics.tca.model.facade.TcaAlert; import org.onap.dcae.analytics.tca.web.TcaAppProperties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -47,12 +48,14 @@ import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import com.fasterxml.jackson.databind.JsonNode; + /** * @author Rajiv Singla */ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { - private static final Logger logger = LoggerFactory.getLogger(TcaAaiEnrichmentServiceImpl.class); + private static final EELFLogger logger = EELFLogFactory.getLogger(TcaAaiEnrichmentServiceImpl.class); private final TcaAppProperties tcaAppProperties; private final RestTemplate aaiRestTemplate; @@ -100,7 +103,7 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { // get resource link final String resourceLink = - getVMResourceLink(getAAIRestAPIResponse(aaiRestTemplate, nodeQueryUri, requestId, transactionId)); + getVMResourceLink(requestId, getAAIRestAPIResponse(aaiRestTemplate, nodeQueryUri, requestId, transactionId)); if (resourceLink == null) { return; } @@ -115,7 +118,7 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { getAAIRestAPIResponse(aaiRestTemplate, vServerEnrichmentUri, requestId, transactionId); // do aai enrichment - enrichAAI(vServerEnrichmentDetails, tcaAlert, TcaModelConstants.AAI_VSERVER_KEY_PREFIX); + enrichAAI(requestId, vServerEnrichmentDetails, tcaAlert, TcaModelConstants.AAI_VSERVER_KEY_PREFIX); } private static void doAaiVnfEnrichment(final TcaExecutionContext tcaExecutionContext, @@ -138,7 +141,7 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { final String aaiResponse = getAAIRestAPIResponse(aaiRestTemplate, genericVnfUri, requestId, transactionId); // do AAI enrichment - enrichAAI(aaiResponse, tcaAlert, TcaModelConstants.AAI_VNF_KEY_PREFIX); + enrichAAI(requestId, aaiResponse, tcaAlert, TcaModelConstants.AAI_VNF_KEY_PREFIX); } @@ -162,7 +165,9 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { final HttpEntity<String> httpEntity = new HttpEntity<>(headers); aaiResponseEntity = aaiRestTemplate.exchange(aaiUri, HttpMethod.GET, httpEntity, String.class); } catch (Exception e) { - logger.debug("Request id: " + requestId + ". Unable to get A&AI enrichment details", e); + final ErrorLogSpec errorLogSpec = LogSpec.createErrorLogSpec(requestId); + logger.errorLog().error("Request id: " + requestId + ". Unable to get A&AI enrichment details", + errorLogSpec, e.toString()); } if (aaiResponseEntity != null && aaiResponseEntity.getStatusCode().is2xxSuccessful()) { @@ -182,17 +187,20 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { * * @return true if A&AI enrichment completed successfully */ - private static boolean enrichAAI(final String aaiEnrichmentDetails, final TcaAlert tcaAlert, + private static boolean enrichAAI(final String requestId, final String aaiEnrichmentDetails, final TcaAlert tcaAlert, final String keyPrefix) { final Aai preEnrichmentAAI = tcaAlert.getAai(); + final ErrorLogSpec errorLogSpec = LogSpec.createErrorLogSpec(requestId); + final DebugLogSpec debugLogSpec = LogSpec.createDebugLogSpec(requestId); + if (aaiEnrichmentDetails == null) { - logger.warn("Request id: {}. No A&AI Enrichment possible. A&AI Enrichment details are absent.", - tcaAlert.getRequestId()); + logger.errorLog().error("Request id: {}. No A&AI Enrichment possible. A&AI Enrichment details are absent.", + errorLogSpec, tcaAlert.getRequestId()); return false; } - final Aai enrichedAAI = getNewEnrichedAAI(aaiEnrichmentDetails); + final Aai enrichedAAI = getNewEnrichedAAI(requestId, aaiEnrichmentDetails); if (enrichedAAI != null) { final Set<Map.Entry<String, Object>> enrichedAAIEntrySet = @@ -205,11 +213,12 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { keyPrefix + enrichedAAIEntry.getKey(), enrichedAAIEntry.getValue()); } - logger.debug("Request id: {}. A&AI Enrichment was completed successfully.", tcaAlert.getRequestId()); + logger.debugLog().debug("Request id: {}. A&AI Enrichment was completed successfully.", + debugLogSpec, tcaAlert.getRequestId()); return true; } else { - logger.warn("Request id: {}. No A&AI Enrichment possible. Skipped - Invalid A&AI Response.", - tcaAlert.getRequestId()); + logger.errorLog().error("Request id: {}. No A&AI Enrichment possible. Skipped - Invalid A&AI Response.", + errorLogSpec, tcaAlert.getRequestId()); return false; } @@ -222,7 +231,7 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { * * @return new A&AI with only top level A&AI Enrichment details */ - private static Aai getNewEnrichedAAI(final String aaiEnrichmentDetails) { + private static Aai getNewEnrichedAAI(final String requestId, final String aaiEnrichmentDetails) { try { final JsonNode rootNode = TCA_OBJECT_MAPPER.readTree(aaiEnrichmentDetails); final Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields(); @@ -236,8 +245,10 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { } return TCA_OBJECT_MAPPER.treeToValue(rootNode, Aai.class); } catch (IOException e) { - logger.error( - "Failed to Parse AAI Enrichment Details from JSON: {}, Exception: {}.", aaiEnrichmentDetails, e); + final ErrorLogSpec errorLogSpec = LogSpec.createErrorLogSpec(requestId); + logger.errorLog().error( + "Failed to Parse AAI Enrichment Details from JSON: {}, Exception: {}.", + errorLogSpec, aaiEnrichmentDetails, e.toString()); } return null; } @@ -249,7 +260,7 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { * * @return object resource link String */ - private static String getVMResourceLink(final String vmAAIResourceLinkDetails) { + private static String getVMResourceLink(final String requestId, final String vmAAIResourceLinkDetails) { if (StringUtils.hasText(vmAAIResourceLinkDetails)) { try { final JsonNode jsonNode = TCA_OBJECT_MAPPER.readTree(vmAAIResourceLinkDetails); @@ -258,8 +269,9 @@ public class TcaAaiEnrichmentServiceImpl implements TcaAaiEnrichmentService { return resourceLinkJsonNode.asText(); } } catch (IOException e) { - logger.error("Unable to determine VM Object link inside AAI Resource Link Response JSON: {}", - vmAAIResourceLinkDetails, e); + final ErrorLogSpec errorLogSpec = LogSpec.createErrorLogSpec(requestId); + logger.errorLog().error("Unable to determine VM Object link inside AAI Resource Link Response JSON: {}", + errorLogSpec, vmAAIResourceLinkDetails, e.toString()); } } return null; diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/mongo/MongoAbatementEntity.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/mongo/MongoAbatementEntity.java index 0cc1fcf..82c32ec 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/mongo/MongoAbatementEntity.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/mongo/MongoAbatementEntity.java @@ -37,8 +37,6 @@ import org.springframework.data.mongodb.core.mapping.Document; @Document(collection = "tca_abatement") public class MongoAbatementEntity implements TcaAbatementEntity, TcaModel { - private static final long serialVersionUID = 1L; - @Id private String lookupKey; private String requestId; diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/simple/SimpleAbatementEntity.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/simple/SimpleAbatementEntity.java index 42e3759..e1880ac 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/simple/SimpleAbatementEntity.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/abatement/simple/SimpleAbatementEntity.java @@ -32,8 +32,6 @@ import org.onap.dcae.analytics.tca.model.TcaModel; @Data public class SimpleAbatementEntity implements TcaAbatementEntity, TcaModel { - private static final long serialVersionUID = 1L; - protected String lookupKey; protected String requestId; protected boolean isAbatementAlertSent; diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java index eb9eb13..0d34f90 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java @@ -19,9 +19,6 @@ package org.onap.dcae.analytics.tca.web.controller; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; - import java.time.format.DateTimeFormatter; import java.util.List; import java.util.stream.Collectors; @@ -30,12 +27,12 @@ import org.onap.dcae.analytics.model.TcaModelConstants; import org.onap.dcae.analytics.model.common.ConfigSource; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; import org.onap.dcae.analytics.tca.core.service.TcaResultContext; +import org.onap.dcae.analytics.tca.core.util.TcaUtils; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; import org.onap.dcae.analytics.tca.model.restapi.TcaExecutionRequest; import org.onap.dcae.analytics.tca.model.restapi.TcaExecutionResponse; import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper; import org.onap.dcae.analytics.tca.web.service.TcaProcessingService; -import org.onap.dcae.analytics.tca.web.util.TcaUtils; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -44,6 +41,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + /** * @author Rajiv Singla */ diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java index c54d27c..fcfc3fe 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java @@ -25,10 +25,10 @@ import java.time.ZonedDateTime; import java.util.concurrent.atomic.AtomicInteger; import org.onap.dcae.analytics.model.common.ConfigSource; +import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; import org.onap.dcae.analytics.tca.model.policy.TcaPolicyModel; import org.onap.dcae.analytics.tca.web.TcaAppProperties; -import org.onap.dcae.analytics.web.exception.AnalyticsParsingException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java index 59acd2d..9bade85 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java @@ -29,9 +29,9 @@ import org.onap.dcae.analytics.model.AnalyticsHttpConstants; import org.onap.dcae.analytics.model.TcaModelConstants; import org.onap.dcae.analytics.model.ecomplogger.AnalyticsErrorType; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; +import org.onap.dcae.analytics.tca.core.util.TcaUtils; import org.onap.dcae.analytics.tca.model.facade.TcaAlert; import org.onap.dcae.analytics.tca.web.TcaAppProperties; -import org.onap.dcae.analytics.tca.web.util.TcaUtils; import org.onap.dcae.analytics.web.util.AnalyticsHttpUtils; import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo; import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; @@ -150,10 +150,11 @@ public class TcaAlertTransformer extends AbstractTransformer { final AuditLogSpecImpl auditLogSpec = new AuditLogSpecImpl(requestIdLogInfo, TcaUtils.TCA_SERVICE_LOG_INFO, requestTimingLogInfo, responseLogInfo); logger.auditLog().info("Request Id: {}, Transaction Id: {}, " + - "Message counts - Received: {}, Errors: {}, Terminated Early: {}, Abated: {}, Alerts: {}", + "Message counts - Received: {}, Errors: {}, Terminated Early: {}, Abated: {}, Alerts: {}, Alerts size: {}", auditLogSpec, requestId, transactionId, Integer.toString(tcaExecutionContexts.size()), Integer.toString(errorExecutionContexts.size()), Integer.toString(earlyTerminationExecutionContexts.size()), + tcaAlerts.toString(), Integer.toString(abatedExecutionContexts.size()), Integer.toString(tcaAlerts.size())); } } diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java index 0e81a28..7cd542c 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java @@ -27,8 +27,8 @@ import java.util.Date; import java.util.Map; import org.onap.dcae.analytics.model.ecomplogger.AnalyticsErrorType; +import org.onap.dcae.analytics.tca.core.util.TcaUtils; import org.onap.dcae.analytics.tca.web.TcaAppProperties; -import org.onap.dcae.analytics.tca.web.util.TcaUtils; import org.onap.dcae.analytics.web.util.AnalyticsHttpUtils; import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo; import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java index 3bb742a..f5aec0b 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java @@ -34,9 +34,9 @@ import org.onap.dcae.analytics.tca.core.service.GenericTcaResultContext; import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext; import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; +import org.onap.dcae.analytics.tca.core.util.TcaUtils; import org.onap.dcae.analytics.tca.core.util.function.calculation.TcaCalculator; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; -import org.onap.dcae.analytics.tca.web.util.TcaUtils; /** * @author Rajiv Singla diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/resources/logback.xml b/dcae-analytics/dcae-analytics-tca-web/src/main/resources/logback.xml index 5430f0b..63625a5 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/resources/logback.xml +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/resources/logback.xml @@ -37,7 +37,7 @@ <logger name="com.jayway" level="INFO"/> <logger name="org.springframework.retry" level="INFO"/> - <logger name="org.onap.dcae.analytics" level="INFO"/> + <logger name="org.onap.dcae.analytics" level="DEBUG"/> <root level="DEBUG"> <!-- required appenders --> diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java index 426ae46..9347d53 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java @@ -25,16 +25,12 @@ import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException; import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext; import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; import org.onap.dcae.analytics.tca.model.facade.TcaAlert; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; -import org.onap.dcae.analytics.tca.web.TcaAppProperties; -import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper; -import org.onap.dcae.analytics.web.exception.AnalyticsParsingException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/dcae-analytics/dcae-analytics-web/pom.xml b/dcae-analytics/dcae-analytics-web/pom.xml index d331f45..7744f3f 100644 --- a/dcae-analytics/dcae-analytics-web/pom.xml +++ b/dcae-analytics/dcae-analytics-web/pom.xml @@ -49,6 +49,11 @@ <groupId>${project.groupId}</groupId> <artifactId>dcae-analytics-model</artifactId> </dependency> + <!-- PROJECT DEPENDENCIES --> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>dcae-analytics-tca-core</artifactId> + </dependency> <!-- ECOMP LOGGER --> <dependency> diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java index 97fdcc5..1fe9e51 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java @@ -63,7 +63,7 @@ import org.springframework.web.client.RestTemplate; public class DmaapMrConfig { private static final String[] DMAAP_MAPPED_REQUEST_HEADERS = - DmaapMrConstants.DMAAP_MAPPED_HEADERS.toArray(new String[DmaapMrConstants.DMAAP_MAPPED_HEADERS.size()]); + DmaapMrConstants.getDmaapmappedHeaders().toArray(new String[DmaapMrConstants.getDmaapmappedHeaders().size()]); @Bean(name = DmaapMrConstants.DMAAP_MR_SUBSCRIBER_OUTPUT_CHANNEL_NAME) public QueueChannel mrSubscriberOutputChannel(final BasicMessageGroupStore basicMessageGroupStore) { diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitter.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitter.java index fe8f7ed..0396005 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitter.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitter.java @@ -24,11 +24,9 @@ import static org.apache.commons.text.StringEscapeUtils.unescapeJson; import static org.onap.dcae.analytics.model.AnalyticsHttpConstants.REQUEST_ID_HEADER_KEY; import static org.onap.dcae.analytics.model.AnalyticsModelConstants.ANALYTICS_REQUEST_ID_DELIMITER; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - import java.io.IOException; import java.util.Collections; +import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.stream.IntStream; @@ -36,15 +34,22 @@ import java.util.stream.IntStream; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.onap.dcae.analytics.model.AnalyticsHttpConstants; import org.onap.dcae.analytics.model.DmaapMrConstants; -import org.onap.dcae.analytics.web.exception.AnalyticsParsingException; +import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException; +import org.onap.dcae.analytics.tca.core.util.LogSpec; import org.onap.dcae.analytics.web.util.AnalyticsHttpUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec; +import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec; import org.springframework.integration.splitter.AbstractMessageSplitter; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * DMaaP MR message splitter split the incoming messages into batch of given batch size * @@ -52,7 +57,7 @@ import org.springframework.messaging.Message; */ public class MrMessageSplitter extends AbstractMessageSplitter { - private static final Logger logger = LoggerFactory.getLogger(MrMessageSplitter.class); + private static final EELFLogger eelfLogger = EELFLogFactory.getLogger(MrMessageSplitter.class); private final ObjectMapper objectMapper; private final Integer batchSize; @@ -66,18 +71,23 @@ public class MrMessageSplitter extends AbstractMessageSplitter { @Override protected Object splitMessage(final Message<?> message) { - final List<String> dmaapMessages = convertJsonToStringMessages(String.class.cast(message.getPayload()).trim()); - final String requestId = AnalyticsHttpUtils.getRequestId(message.getHeaders()); + final List<String> dmaapMessages = convertJsonToStringMessages(requestId, String.class.cast(message.getPayload()).trim()); + final String transactionId = AnalyticsHttpUtils.getTransactionId(message.getHeaders()); - logger.info("Request Id: {}, Transaction Id: {}, Received new messages from DMaaP MR. Count: {}", - requestId, transactionId, dmaapMessages.size()); + final Date requestBeginTimestamp = AnalyticsHttpUtils.getTimestampFromHeaders(message.getHeaders(), + AnalyticsHttpConstants.REQUEST_BEGIN_TS_HEADER_KEY); + final AuditLogSpec auditLogSpec = LogSpec.createAuditLogSpec(requestId, requestBeginTimestamp); - final List<List<String>> messagePartitions = partition(dmaapMessages, batchSize); + eelfLogger.auditLog().info("Request Id: {}, Transaction Id: {}, dmaapMessages: {}," + + " Received new messages from DMaaP MR. Count: {}", + auditLogSpec, requestId, transactionId, dmaapMessages.toString(), String.valueOf(dmaapMessages.size())); - logger.debug("Request Id: {}, Transaction Id: {}, Max allowed messages per batch: {}. " + - "No of batches created: {}", requestId, transactionId, batchSize, messagePartitions.size()); + final List<List<String>> messagePartitions = partition(dmaapMessages, batchSize); + eelfLogger.auditLog().info("Request Id: {}, Transaction Id: {}, Max allowed messages per batch: {}. " + + "No of batches created: {}", + auditLogSpec, requestId, transactionId, String.valueOf(batchSize), String.valueOf(messagePartitions.size())); // append batch id to request id header return messagePartitions.isEmpty() ? null : IntStream.range(0, messagePartitions.size()) @@ -100,7 +110,7 @@ public class MrMessageSplitter extends AbstractMessageSplitter { * * @return List containing DMaaP MR Messages */ - private List<String> convertJsonToStringMessages(@Nullable final String messagesJsonString) { + private List<String> convertJsonToStringMessages(String requestId, @Nullable final String messagesJsonString) { final LinkedList<String> messages = new LinkedList<>(); @@ -128,9 +138,11 @@ public class MrMessageSplitter extends AbstractMessageSplitter { } } catch (IOException e) { - final String errorMessage = String.format("Unable to convert subscriber Json String to Messages. " + + ErrorLogSpec errorLogSpec = LogSpec.createErrorLogSpec(requestId); + eelfLogger.errorLog().error("Unable to convert subscriber Json String to Messages. " + + "Subscriber Response String: {}, Json Error: {}", errorLogSpec, messagesJsonString, e.toString()); + String errorMessage = String.format("Unable to convert subscriber Json String to Messages. " + "Subscriber Response String: %s, Json Error: %s", messagesJsonString, e); - logger.error(errorMessage, e); throw new AnalyticsParsingException(errorMessage, e); } @@ -183,6 +195,4 @@ public class MrMessageSplitter extends AbstractMessageSplitter { } return result; } - - } diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java index 33115c5..2ebb38d 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java @@ -24,9 +24,11 @@ import java.util.concurrent.atomic.AtomicInteger; import org.onap.dcae.analytics.model.AnalyticsHttpConstants; import org.onap.dcae.analytics.model.DmaapMrConstants; +import org.onap.dcae.analytics.tca.core.util.LogSpec; import org.onap.dcae.analytics.web.util.AnalyticsHttpUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; import org.springframework.http.HttpStatus; import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice; import org.springframework.integration.support.MessageBuilder; @@ -48,7 +50,7 @@ import org.springframework.messaging.Message; */ public class MrSubscriberPollingAdvice extends AbstractRequestHandlerAdvice { - private static final Logger log = LoggerFactory.getLogger(MrSubscriberPollingAdvice.class); + private static final EELFLogger eelfLogger = EELFLogFactory.getLogger(MrSubscriberPollingAdvice.class); private final DynamicPeriodicTrigger trigger; private final int minPollingInterval; @@ -112,17 +114,17 @@ public class MrSubscriberPollingAdvice extends AbstractRequestHandlerAdvice { final String requestId = AnalyticsHttpUtils.getRequestId(message.getHeaders()); final String transactionId = AnalyticsHttpUtils.getTransactionId(message.getHeaders()); - - log.debug("Request Id: {}, Transaction Id: {}, Messages Present: {}, " + - "Next Polling Interval will be: {}", requestId, transactionId, - areMessagesPresent, nextPollingInterval); + final DebugLogSpec debugLogSpec = LogSpec.createDebugLogSpec(requestId); + eelfLogger.debugLog().debug("Request Id: {}, Transaction Id: {}, Messages Present: {}, " + + "Next Polling Interval will be: {}", debugLogSpec, requestId, transactionId, + String.valueOf(areMessagesPresent), nextPollingInterval.toString()); trigger.setPeriod(nextPollingInterval.get()); // if no messages were found in dmaap poll - terminate further processing if (!areMessagesPresent) { - log.info("Request Id: {}, Transaction Id: {}, No new messages found in DMaaP MR Response. " + - "No further processing required", requestId, transactionId); + eelfLogger.debugLog().debug("Request Id: {}, Transaction Id: {}, No new messages found in DMaaP MR Response. " + + "No further processing required", debugLogSpec, requestId, transactionId); return null; } diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrTriggerMessageProvider.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrTriggerMessageProvider.java index 183957d..b537170 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrTriggerMessageProvider.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrTriggerMessageProvider.java @@ -26,10 +26,12 @@ import java.util.function.Supplier; import org.onap.dcae.analytics.model.AnalyticsHttpConstants; import org.onap.dcae.analytics.model.util.supplier.UnboundedSupplier; +import org.onap.dcae.analytics.tca.core.util.LogSpec; import org.onap.dcae.analytics.web.util.AnalyticsWebUtils; import org.onap.dcae.analytics.web.util.function.MrSubscriberURLFunction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory; +import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger; +import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; @@ -40,7 +42,7 @@ import org.springframework.messaging.Message; */ public class MrTriggerMessageProvider { - private static final Logger logger = LoggerFactory.getLogger(MrTriggerMessageProvider.class); + private static final EELFLogger logger = EELFLogFactory.getLogger(MrTriggerMessageProvider.class); public static final String TRIGGER_METHOD_NAME = "getTriggerMessage"; @@ -60,8 +62,9 @@ public class MrTriggerMessageProvider { final String requestId = AnalyticsWebUtils.REQUEST_ID_SUPPLIER.get(); final String transactionId = AnalyticsWebUtils.RANDOM_ID_SUPPLIER.get(); final String beginTimestamp = AnalyticsWebUtils.CREATION_TIMESTAMP_SUPPLIER.get(); - logger.debug("Request Id: {}. Transaction Id: {}. Begin TS: {}. Starting new DMaaP MR Subscriber poll.", - requestId, transactionId, beginTimestamp); + final DebugLogSpec debugLogSpec = LogSpec.createDebugLogSpec(requestId); + logger.debugLog().debug("Request Id: {}. Transaction Id: {}. Begin TS: {}. Starting new DMaaP MR Subscriber poll.", + debugLogSpec, requestId, transactionId, beginTimestamp); return MessageBuilder .withPayload(subscriberUrlSupplier.get().toString()) .setHeader(AnalyticsHttpConstants.REQUEST_ID_HEADER_KEY, requestId) diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java index d643de2..31c01b0 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessor.java @@ -240,7 +240,7 @@ public class ConfigBindingServiceEnvironmentPostProcessor implements Environment // remove config service key prefix on spring reserved property key prefixes final Set<String> springKeyPrefixes = - ConfigBindingServiceConstants.SPRING_RESERVED_PROPERTIES_KEY_PREFIXES; + ConfigBindingServiceConstants.getSpringReservedPropertiesKeyPrefixes(); final Set<String> springKeys = springKeyPrefixes.stream() .map(springKeyPrefix -> configServicePropertiesKey + "." + springKeyPrefix) .collect(Collectors.toSet()); |