<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.dcaegen2.analytics.tca-gen2</groupId>
+ <artifactId>eelf-logger-logback-impl</artifactId>
+ </dependency>
+
</dependencies>
</project>
// ================== 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-";
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());
+ }
}
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 = ".";
private ConfigBindingServiceConstants() {
// private constructor
}
+
+ /**
+ * getSpringReservedPropertiesKeyPrefixes
+ */
+ public static final Set<String> getSpringReservedPropertiesKeyPrefixes() {
+ return Stream.of("spring", "endpoints", "server", "logging", "management").collect(Collectors.toSet());
+ }
}
*
*/
-package org.onap.dcae.analytics.web.exception;
+package org.onap.dcae.analytics.tca.core.exception;
/**
* @author Rajiv Singla
--- /dev/null
+/*
+ * ================================================================================
+ * 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);
+ }
+
+}
*
*/
-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;
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;
/**
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) {
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
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;
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()) {
// 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;
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
@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;
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);
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;
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;
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;
// get resource link
final String resourceLink =
- getVMResourceLink(getAAIRestAPIResponse(aaiRestTemplate, nodeQueryUri, requestId, transactionId));
+ getVMResourceLink(requestId, getAAIRestAPIResponse(aaiRestTemplate, nodeQueryUri, requestId, transactionId));
if (resourceLink == null) {
return;
}
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,
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);
}
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()) {
*
* @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 =
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;
}
*
* @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();
}
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;
}
*
* @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);
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;
@Document(collection = "tca_abatement")
public class MongoAbatementEntity implements TcaAbatementEntity, TcaModel {
- private static final long serialVersionUID = 1L;
-
@Id
private String lookupKey;
private String requestId;
@Data
public class SimpleAbatementEntity implements TcaAbatementEntity, TcaModel {
- private static final long serialVersionUID = 1L;
-
protected String lookupKey;
protected String requestId;
protected boolean isAbatementAlertSent;
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;
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;
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
*/
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;
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;
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()));
}
}
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;
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
<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 -->
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;
<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>
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) {
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;
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
*
*/
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;
@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())
*
* @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<>();
}
} 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);
}
}
return result;
}
-
-
}
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;
*/
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;
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;
}
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;
*/
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";
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)
// 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());