diff options
Diffstat (limited to 'UniversalVesAdapter/src/main/java/org/onap/universalvesadapter')
14 files changed, 127 insertions, 109 deletions
diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java index cd47619..b922b45 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java @@ -54,7 +54,9 @@ import com.google.gson.JsonSyntaxException; @Component public class UniversalEventAdapter implements GenericAdapter { - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private String enterpriseId; @Value("${defaultEnterpriseId}") @@ -88,37 +90,37 @@ public class UniversalEventAdapter implements GenericAdapter { if (VESAdapterInitializer.getMappingFiles().containsKey(enterpriseId)) { configFileData = VESAdapterInitializer.getMappingFiles().get(enterpriseId); - LOGGER.debug("Using Mapping file as Mapping file is available for Enterprise Id:{}",enterpriseId); + debugLogger.debug("Using Mapping file as Mapping file is available for Enterprise Id:{}",enterpriseId); } else { configFileData = VESAdapterInitializer.getMappingFiles().get(defaultEnterpriseId); - LOGGER.debug("Using Default Mapping file as Mapping file is not available for Enterprise Id:{}",enterpriseId); + debugLogger.debug("Using Default Mapping file as Mapping file is not available for Enterprise Id:{}",enterpriseId); } Smooks smooksTemp = new Smooks(new ByteArrayInputStream(configFileData.getBytes(StandardCharsets.UTF_8))); eventToSmooksMapping.put(eventType, smooksTemp); VesEvent vesEvent = SmooksUtils.getTransformedObjectForInput(smooksTemp,incomingJsonString); - LOGGER.debug("Incoming json transformed to VES format successfully"); + debugLogger.info("Incoming json transformed to VES format successfully"); ObjectMapper objectMapper = new ObjectMapper(); result = objectMapper.writeValueAsString(vesEvent); - LOGGER.debug("Serialized VES json"); + debugLogger.info("Serialized VES json"); } catch (JsonProcessingException exception) { throw new VesException("Unable to convert pojo to VES format, Reason :{}", exception); } catch (SAXException | IOException exception) { //Invalid Mapping file - LOGGER.error("Dropping this Trap :{},due to error Occured :Reason:", incomingJsonString, exception); + errorLogger.error("Dropping this Trap :{},Reason:{}", incomingJsonString, exception); } catch (JsonSyntaxException exception) { // Invalid Trap - LOGGER.error("Dropping this Invalid json Trap :{}, Reason:", incomingJsonString, exception); + errorLogger.error("Dropping this Invalid json Trap :{}, Reason:{}", incomingJsonString, exception); }catch (JsonParseException exception) { // Invalid Trap - LOGGER.error("Dropping this Invalid json Trap :{}, Reason:", incomingJsonString, exception); + errorLogger.error("Dropping this Invalid json Trap :{}, Reason:{}", incomingJsonString, exception); } catch (RuntimeException exception) { - LOGGER.error("Dropping this Trap :{},Reason:", incomingJsonString, exception); + errorLogger.error("Dropping this Trap :{},Reason:{}", incomingJsonString, exception); } return result; @@ -131,7 +133,7 @@ public class UniversalEventAdapter implements GenericAdapter { public void destroy() { for (Smooks smooks : eventToSmooksMapping.values()) smooks.close(); - LOGGER.debug("All Smooks objects closed"); + debugLogger.warn("All Smooks objects closed"); } } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfig.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfig.java index fd4185b..eb3d59d 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfig.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfig.java @@ -42,7 +42,8 @@ import com.google.common.base.Objects; @Component public abstract class DMaaPMRBaseConfig { - protected static final Logger LOG = LoggerFactory.getLogger(DMaaPMRBaseConfig.class); + + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); protected String hostName; protected Integer portNumber; @@ -133,7 +134,7 @@ public abstract class DMaaPMRBaseConfig { final String errorMessage = "Unsupported protocol selection. Only HTTPS and HTTPS are currently supported for DMaaP MR"; - throw new DMaapException(errorMessage, LOG, new IllegalArgumentException(errorMessage)); + throw new DMaapException(errorMessage, errorLogger, new IllegalArgumentException(errorMessage)); } return normalizedProtocolString; } @@ -155,7 +156,7 @@ public abstract class DMaaPMRBaseConfig { final String errorMessage = "Unsupported content type selection. Only application/json is currently supported for DMaaP MR"; - throw new DMaapException(errorMessage, LOG, new IllegalArgumentException(errorMessage)); + throw new DMaapException(errorMessage, errorLogger, new IllegalArgumentException(errorMessage)); } return normalizedContentType; } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/VesController.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/VesController.java index be49587..602857f 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/VesController.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/VesController.java @@ -38,7 +38,9 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class VesController { - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); @Autowired private VesService vesService; @@ -52,28 +54,28 @@ public class VesController { @RequestMapping("/start") public String start() { - LOGGER.info("UniversalVesAdapter Application starting..."); + metricsLogger.info("UniversalVesAdapter Application starting..."); try { vesService.start(); } catch (MapperConfigException e) { - LOGGER.error("Config error:{}",e.getMessage(),e.getCause()); + errorLogger.error("Config error:{}",e.getMessage(),e.getCause()); } return "Application started"; } @RequestMapping("/reload") public void reloadMappingFileFromDB() { - LOGGER.debug("Reload of Mapping File is started"); + debugLogger.debug("Reload of Mapping File is started"); vESAdapterInitializer.fetchMappingFile(); - LOGGER.debug("Reload of Mapping File is completed"); + debugLogger.debug("Reload of Mapping File is completed"); } @RequestMapping("/healthcheck") public String healthcheck() { - LOGGER.debug("UniversalVesAdapter Application is up & running..."); + metricsLogger.info("UniversalVesAdapter Application is up & running..."); return "UniversalVesAdapter Application is up & running..."; } @@ -84,7 +86,7 @@ public class VesController { public String stop() { vesService.stop(); - LOGGER.debug("UniversalVesAdapter Application is stopping..."); + metricsLogger.info("UniversalVesAdapter Application is stopping..."); return "Application will be stopped soon"; } } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/BaseDMaaPMRComponent.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/BaseDMaaPMRComponent.java index 0638574..6c94533 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/BaseDMaaPMRComponent.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/BaseDMaaPMRComponent.java @@ -64,7 +64,8 @@ import com.google.common.base.Optional; @ComponentScan public abstract class BaseDMaaPMRComponent { - private static final Logger LOG = LoggerFactory.getLogger(BaseDMaaPMRComponent.class); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private static final ObjectMapper objectMapper = new ObjectMapper(); public BaseDMaaPMRComponent() {} @@ -109,9 +110,9 @@ public abstract class BaseDMaaPMRComponent { .setPath(dmaapUriPathPrefix + topicName).build(); } catch (URISyntaxException e) { final String errorMessage = format("Error while creating publisher URI: %s", e); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } - LOG.info("Created DMaaP MR Publisher URI: {}", publisherURI); + debugLogger.info("Created DMaaP MR Publisher URI: {}", publisherURI); return publisherURI; } @@ -152,10 +153,10 @@ public abstract class BaseDMaaPMRComponent { } catch (URISyntaxException e) { final String errorMessage = format("Error while creating subscriber URI: %s", e); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } - LOG.info("Created DMaaP MR Subscriber URI: {}", subscriberURI); + debugLogger.info("Created DMaaP MR Subscriber URI: {}", subscriberURI); return subscriberURI; } @@ -267,14 +268,14 @@ public abstract class BaseDMaaPMRComponent { try { publisherQueue.addRecoverableMessages(messages); - LOG.debug("Messages Added to Recovery Queue. Messages Size: {}, Recovery Queue Remaining Size: {}", + debugLogger.debug("Messages Added to Recovery Queue. Messages Size: {}, Recovery Queue Remaining Size: {}", messages.size(), publisherQueue.getBatchQueueRemainingSize()); } catch (IllegalStateException e) { final String errorMessage = format("Unable to put messages in recovery queue. Messages will be lost. " + "Recovery Queue might be full. Message Size: %d, Recovery Queue Remaining Capacity: %d", messages.size(), publisherQueue.getRecoveryQueueRemainingSize()); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } } @@ -307,13 +308,13 @@ public abstract class BaseDMaaPMRComponent { final String errorMessage = format("Unable to convert publisher messages to Json. Messages: %s, Json Error: %s", messages, e); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } catch (IOException e) { final String errorMessage = format("IO Exception while converting publisher messages to Json. Messages: %s, Json Error: %s", messages, e); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } } @@ -357,7 +358,7 @@ public abstract class BaseDMaaPMRComponent { final String errorMessage = format("Unable to convert subscriber Json String to Messages. Subscriber Response String: %s," + " Json Error: %s", messagesJsonString, e); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/Creator.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/Creator.java index bfd3c6d..98191f7 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/Creator.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/Creator.java @@ -34,7 +34,8 @@ import org.springframework.stereotype.Component; @Component public class Creator { - private final Logger LOGGER = LoggerFactory.getLogger(Creator.class); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private DMaaPMRFactory dMaaPMRFactoryInstance; private String dmaaphost; private String publisherTopic; @@ -63,7 +64,7 @@ public class Creator { this.publisherTopic = dmaapConfig.getPublisherTopic(); this.subcriberTopic = dmaapConfig.getSubscriberTopic(); this.dMaaPMRFactoryInstance = DMaaPMRFactory.create(); - LOGGER.info("The Hostname of DMaap is :" + dmaaphost); + debugLogger.info("The Hostname of DMaap is :" + dmaaphost); } @@ -75,7 +76,7 @@ public class Creator { try { dMaaPMRPublisherConfig = new DMaaPMRPublisherConfig.Builder(dmaaphost, publisherTopic,dmaapConfig).build(); } catch (IOException e) { - LOGGER.error("failed or interrupted I/O operations while creating publisher config:{}",e.getCause()); + errorLogger.error("failed or interrupted I/O operations while creating publisher config:{}",e.getCause()); } return dMaaPMRFactoryInstance.createPublisher(dMaaPMRPublisherConfig); } @@ -88,7 +89,7 @@ public class Creator { dMaaPMRSubscriberConfig = new DMaaPMRSubscriberConfig.Builder(dmaaphost, subcriberTopic, dmaapConfig).build(); } catch (IOException e) { - LOGGER.error("failed or interrupted I/O operations while creating subcriber config:{}",e.getCause()); + errorLogger.error("failed or interrupted I/O operations while creating subcriber config:{}",e.getCause()); } return dMaaPMRFactoryInstance.createSubscriber(dMaaPMRSubscriberConfig); diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/DMaaPMRFactory.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/DMaaPMRFactory.java index 50f214c..0dacb0d 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/DMaaPMRFactory.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/DMaaPMRFactory.java @@ -62,8 +62,9 @@ import com.google.inject.Key; public class DMaaPMRFactory { - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRFactory.class); - + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); + private final Injector injector; public DMaaPMRFactory(AbstractModule guiceModule) { @@ -78,10 +79,10 @@ public class DMaaPMRFactory { */ public DMaaPMRPublisher createPublisher(@Nonnull DMaaPMRPublisherConfig publisherConfig) { final DMaaPMRPublisherFactory publisherFactory = injector.getInstance(Key.get(DMaaPMRPublisherFactory.class)); - LOG.debug("Creating new DMaaP MR Publisher Instance with configuration: {}", publisherConfig); + debugLogger.debug("Creating new DMaaP MR Publisher Instance with configuration: {}", publisherConfig); final DMaaPMRPublisher dMaaPMRPublisher = publisherFactory.create(publisherConfig); - LOG.info("Created new DMaaP MR Publisher Instance. Publisher creation time: {}", + debugLogger.info("Created new DMaaP MR Publisher Instance. Publisher creation time: {}", dMaaPMRPublisher.getPublisherCreationTime()); return dMaaPMRPublisher; } @@ -94,9 +95,9 @@ public class DMaaPMRFactory { */ public DMaaPMRSubscriber createSubscriber(@Nonnull DMaaPMRSubscriberConfig subscriberConfig) { final DMaaPMRSubscriberFactory subscriberFactory = injector.getInstance(DMaaPMRSubscriberFactory.class); - LOG.debug("Creating new DMaaP MR Subscriber Instance with configuration: {}", subscriberConfig); + debugLogger.debug("Creating new DMaaP MR Subscriber Instance with configuration: {}", subscriberConfig); final DMaaPMRSubscriber dMaaPMRSubscriber = subscriberFactory.create(subscriberConfig); - LOG.info("Created new DMaaP MR Subscriber Instance. Subscriber creation time: {}", + debugLogger.info("Created new DMaaP MR Subscriber Instance. Subscriber creation time: {}", dMaaPMRSubscriber.getSubscriberCreationTime()); return dMaaPMRSubscriber; } @@ -108,7 +109,7 @@ public class DMaaPMRFactory { */ public static DMaaPMRFactory create() { final DMaaPMRFactory dMaaPMRFactory = new DMaaPMRFactory(new AnalyticsDMaaPModule()); - LOG.info("Created new instance of DMaaP MR Factory"); + debugLogger.info("Created new instance of DMaaP MR Factory"); return dMaaPMRFactory; } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherImpl.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherImpl.java index 5930f41..abcd9e3 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherImpl.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherImpl.java @@ -64,7 +64,9 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM private int publisherMaxFlushRetries; - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRPublisherImpl.class); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); + static public int a =2; private final DMaaPMRPublisherConfig publisherConfig; @@ -95,7 +97,7 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM // if messages size is less than batch queue size - just queue them for batch publishing if (batchQueueRemainingSize > messages.size()) { - LOG.debug("Adding messages to batch Queue. No flushing required. Messages Size:{}. Batch Queue Size:{}", + debugLogger.debug("Adding messages to batch Queue. No flushing required. Messages Size:{}. Batch Queue Size:{}", messages.size(), batchQueueRemainingSize); final int batchQueueSize = publisherQueue.addBatchMessages(messages); return createPublisherAcceptedResponse(batchQueueSize); @@ -104,7 +106,7 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM // grab all already queued messages, append current messages and force publish them to DMaaP MR topic final List<String> queueMessages = publisherQueue.getMessageForPublishing(); - LOG.debug("Batch Queue capacity exceeds messages size. Flushing of all pending messages to DMaaP MR " + + debugLogger.debug("Batch Queue capacity exceeds messages size. Flushing of all pending messages to DMaaP MR " + "Publisher Topic."); return forcePublish(Lists.newLinkedList(Iterables.concat(queueMessages, messages))); } @@ -114,7 +116,7 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM @Override public DMaaPMRPublisherResponse forcePublish(List<String> messages) { - LOG.debug("Force publishing messages to DMaaP MR Topic. Messages Size: {}", messages.size()); + debugLogger.debug("Force publishing messages to DMaaP MR Topic. Messages Size: {}", messages.size()); final String contentType = publisherConfig.getContentType(); final String userName =(publisherConfig.getUserName().equals("null")) ? null : publisherConfig.getUserName(); @@ -126,7 +128,7 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM if (authHeader.isPresent()) { postRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader.get()); } else { - LOG.debug("DMaaP MR Publisher Authentication is disabled as username or password is not present."); + debugLogger.debug("DMaaP MR Publisher Authentication is disabled as username or password is not present."); } // Create post string entity @@ -141,12 +143,12 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM final String responseBody = responsePair.getRight(); // if messages were published successfully, return successful response if (HTTPUtils.isSuccessfulResponseCode(responseCode)) { - LOG.debug("DMaaP MR Messages published successfully. DMaaP Response Code: {}. DMaaP Response " + + debugLogger.debug("DMaaP MR Messages published successfully. DMaaP Response Code: {}. DMaaP Response " + "Body: {}, Number of Messages published: {}", responseCode, responseBody, messages.size()); } else { - LOG.warn("Unable to publish messages to DMaaP MR Topic. DMaaP Response Code: {}, DMaaP Response " + + debugLogger.warn("Unable to publish messages to DMaaP MR Topic. DMaaP Response Code: {}, DMaaP Response " + "Body: {}. Messages will be queued in recovery queue", responseCode, responseBody); addMessagesToRecoveryQueue(publisherQueue, messages); } @@ -160,7 +162,7 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM final String errorMessage = format("IO Exception while publishing messages to DMaaP Topic. " + "Messages will be queued in recovery queue. Messages Size: %d", messages.size()); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } } @@ -171,7 +173,7 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM final List<String> queueMessages = publisherQueue.getMessageForPublishing(); // If there are no message return 204 (No Content) response code if (queueMessages.isEmpty()) { - LOG.debug("No messages to publish to batch queue. Returning 204 status code"); + debugLogger.debug("No messages to publish to batch queue. Returning 204 status code"); return createPublisherNoContentResponse(); } else { // force publish messages in queue @@ -198,7 +200,7 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM flushResponseCode = flushResponse.getResponseCode(); if (!HTTPUtils.isSuccessfulResponseCode(flushResponseCode)) { - LOG.warn("Unable to flush batch messages to publisher due to DMaaP MR invalid Response: {}. " + + debugLogger.warn("Unable to flush batch messages to publisher due to DMaaP MR invalid Response: {}. " + "Retrial No: {} of Max {} Retries", flushResponseCode, retrialNumber, publisherMaxFlushRetries); @@ -208,9 +210,9 @@ public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPM !HTTPUtils.isSuccessfulResponseCode(flushResponseCode)); if (!HTTPUtils.isSuccessfulResponseCode(flushResponseCode)) { - LOG.error("Unable to flush batch messages to publisher. Messages loss cannot be prevented"); + errorLogger.error("Unable to flush batch messages to publisher. Messages loss cannot be prevented"); } else { - LOG.info("Successfully published all batched messages to publisher."); + debugLogger.info("Successfully published all batched messages to publisher."); } // close http client diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherQueueImpl.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherQueueImpl.java index fc240d6..b2f9689 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherQueueImpl.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRPublisher/DMaaPMRPublisherQueueImpl.java @@ -44,7 +44,8 @@ import static java.util.Collections.unmodifiableList; */ public class DMaaPMRPublisherQueueImpl implements DMaaPMRPublisherQueue { - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRPublisherQueueImpl.class); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private final LinkedBlockingDeque<String> batchQueue; private final LinkedBlockingDeque<String> recoveryQueue; @@ -54,7 +55,7 @@ public class DMaaPMRPublisherQueueImpl implements DMaaPMRPublisherQueue { @Assisted("recoveryQueueSize") int recoveryQueueSize) { batchQueue = new LinkedBlockingDeque<>(batchQueueSize); recoveryQueue = new LinkedBlockingDeque<>(recoveryQueueSize); - LOG.debug("Creating Instance of DMaaP Publisher Queue. BatchQueueSize: {}, RecoveryQueueSize: {}", + debugLogger.debug("Creating Instance of DMaaP Publisher Queue. BatchQueueSize: {}, RecoveryQueueSize: {}", batchQueueSize, recoveryQueueSize); } @@ -101,13 +102,13 @@ public class DMaaPMRPublisherQueueImpl implements DMaaPMRPublisherQueue { // get messages from recovery queue if present if (!recoveryQueue.isEmpty()) { final int recoveryQueueSize = recoveryQueue.drainTo(recoveryMessageList); - LOG.debug("Drained Recovery Queue elements for flushing: {}", recoveryQueueSize); + debugLogger.debug("Drained Recovery Queue elements for flushing: {}", recoveryQueueSize); } // get messages from batch queue if present if (!batchQueue.isEmpty()) { final int batchQueueSize = batchQueue.drainTo(batchMessagesList); - LOG.debug("Drained Batch Queue elements for flushing: {}", batchQueueSize); + debugLogger.debug("Drained Batch Queue elements for flushing: {}", batchQueueSize); } // concat recovery and batch queue elements diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRSubcriber/DMaaPMRSubscriberImpl.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRSubcriber/DMaaPMRSubscriberImpl.java index 2e7aac9..bfb5706 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRSubcriber/DMaaPMRSubscriberImpl.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/dmaap/MRSubcriber/DMaaPMRSubscriberImpl.java @@ -51,7 +51,8 @@ import static java.lang.String.format; */ public class DMaaPMRSubscriberImpl extends BaseDMaaPMRComponent implements DMaaPMRSubscriber { - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRSubscriberImpl.class); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private final DMaaPMRSubscriberConfig subscriberConfig; private final CloseableHttpClient closeableHttpClient; @@ -80,7 +81,7 @@ public class DMaaPMRSubscriberImpl extends BaseDMaaPMRComponent implements DMaaP if (authHeader.isPresent()) { getRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader.get()); } else { - LOG.debug("DMaaP MR Subscriber Authentication is disabled as username or password is not present."); + debugLogger.debug("DMaaP MR Subscriber Authentication is disabled as username or password is not present."); } try { @@ -101,7 +102,7 @@ public class DMaaPMRSubscriberImpl extends BaseDMaaPMRComponent implements DMaaP responseMessage = "DMaaP Response Body had no messages"; } } else { - LOG.error("Unable to fetch messages to DMaaP MR Topic. DMaaP MR unsuccessful Response Code: {}, " + errorLogger.error("Unable to fetch messages to DMaaP MR Topic. DMaaP MR unsuccessful Response Code: {}, " + "DMaaP Response Body: {}", responseCode, responseBody); } @@ -111,7 +112,7 @@ public class DMaaPMRSubscriberImpl extends BaseDMaaPMRComponent implements DMaaP final String errorMessage = format("IO Exception while fetching messages from DMaaP Topic. Exception %s", e); - throw new DMaapException(errorMessage, LOG, e); + throw new DMaapException(errorMessage, errorLogger, e); } } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java index 49d68be..26aad94 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java @@ -33,13 +33,14 @@ import org.onap.universalvesadapter.utils.DmaapConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class DMaapService { - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private static List<String> list = new LinkedList<String>(); @Autowired private UniversalEventAdapter eventAdapter; @@ -55,10 +56,9 @@ public class DMaapService { */ public void fetchAndPublishInDMaaP(DMaaPMRSubscriber dMaaPMRSubscriber, DMaaPMRPublisher publisher, Creator creater) throws InterruptedException { - LOGGER.info("fetch and publish from and to Dmaap started"); - + metricsLogger.info("fetch and publish from and to Dmaap started"); int pollingInternalInt=dmaapConfig.getPollingInterval(); - LOGGER.info("The Polling Interval in Milli Second is :" +pollingInternalInt); + debugLogger.info("The Polling Interval in Milli Second is :{}" +pollingInternalInt); while (true) { synchronized (this) { for (String incomingJsonString : dMaaPMRSubscriber.fetchMessages().getFetchedMessages()) { @@ -69,7 +69,7 @@ public class DMaapService { if (list.isEmpty()) { Thread.sleep(pollingInternalInt); } - LOGGER.debug("number of messages to be converted :{}", list.size()); + debugLogger.debug("number of messages to be converted :{}", list.size()); if (!list.isEmpty()) { String val = ((LinkedList<String>) list).removeFirst(); @@ -78,7 +78,7 @@ public class DMaapService { if (vesEvent!=null && (!(vesEvent.isEmpty() || vesEvent.equals("")))) { messages.add(vesEvent); publisher.publish(messages); - LOGGER.info("Message successfully published to DMaaP Topic"); + metricsLogger.info("Message successfully published to DMaaP Topic"); } } @@ -108,10 +108,10 @@ public class DMaapService { outgoingJsonString = eventAdapter.transform(incomingJsonString, "snmp"); } catch (VesException exception) { - LOGGER.error("Received exception : " + exception.getMessage(), exception); - LOGGER.error("APPLICATION WILL BE SHUTDOWN UNTIL ABOVE ISSUE IS RESOLVED."); + errorLogger.error("Received exception : {},{}" + exception.getMessage(), exception); + debugLogger.warn("APPLICATION WILL BE SHUTDOWN UNTIL ABOVE ISSUE IS RESOLVED."); } catch (DMaapException e) { - LOGGER.error("Received exception : ", e.getMessage()); + errorLogger.error("Received exception : {}", e.getMessage()); } } return outgoingJsonString; diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java index 3895421..dbf451d 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java @@ -48,7 +48,9 @@ import org.springframework.stereotype.Component; //AdapterInitializer @Component public class VESAdapterInitializer implements CommandLineRunner, Ordered { - private static final Logger LOGGER = LoggerFactory.getLogger(VESAdapterInitializer.class); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); @Autowired private Creator creator; @@ -82,13 +84,13 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { public void run(String... args) throws Exception { env = System.getenv(); for (Map.Entry<String, String> entry : env.entrySet()) { - LOGGER.info(entry.getKey() + ":" + entry.getValue()); + debugLogger.debug(entry.getKey() + ":" + entry.getValue()); } if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE") && env.containsKey("HOSTNAME")) { //TODO - Add logic to talk to Consul and CBS to get the configuration. For now, we will refer to configuration coming from docker env parameters - LOGGER.info(">>>Dynamic configuration to be used"); + debugLogger.info(">>>Dynamic configuration to be used"); if( (env.get("DMAAPHOST")==null || (env.get("MR_DEFAULT_PORT_NUMBER")==null || @@ -97,8 +99,8 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { (env.get("JDBC_PASSWORD")==null )))))) { - LOGGER.error("Some docker environment parameter is missing. Sample Usage is -\n sudo docker run -d -p 8085:8085/tcp --env URL_JDBC=jdbc:postgresql://10.53.172.129:5432/dummy --env JDBC_USERNAME=ngpuser --env JDBC_PASSWORD=root --env MR_DMAAPHOST=10.10.10.10 --env MR_DEFAULT_PORT_NUMBER=3904 --env CONSUL_HOST=10.53.172.109 --env HOSTNAME=mvp-dcaegen2-collectors-ves --env CONFIG_BINDING_SERVICE=config_binding_service -e DMAAPHOST='10.53.172.156' onap/org.onap.dcaegen2.services.mapper.vesadapter.universalvesadaptor:latest"); - System.exit(SpringApplication.exit(applicationContext, () -> {LOGGER.error("Application stoped due to missing default mapping file");return-1;})); + errorLogger.error("Some docker environment parameter is missing. Sample Usage is -\n sudo docker run -d -p 8085:8085/tcp --env URL_JDBC=jdbc:postgresql://10.53.172.129:5432/dummy --env JDBC_USERNAME=ngpuser --env JDBC_PASSWORD=root --env MR_DMAAPHOST=10.10.10.10 --env MR_DEFAULT_PORT_NUMBER=3904 --env CONSUL_HOST=10.53.172.109 --env HOSTNAME=mvp-dcaegen2-collectors-ves --env CONFIG_BINDING_SERVICE=config_binding_service -e DMAAPHOST='10.53.172.156' onap/org.onap.dcaegen2.services.mapper.vesadapter.universalvesadaptor:latest"); + System.exit(SpringApplication.exit(applicationContext, () -> {errorLogger.error("Application stoped due to missing default mapping file");return-1;})); }else { @@ -116,12 +118,12 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { } else { - LOGGER.info(">>>Static configuration to be used"); + debugLogger.info(">>>Static configuration to be used"); } prepareDatabase(); fetchMappingFile(); - LOGGER.info("Triggering controller's start url "); + debugLogger.info("Triggering controller's start url "); executecurl("http://localhost:"+serverPort+"/start"); } @@ -145,7 +147,7 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { private static String executecurl(String url) { - LOGGER.info("Running curl command for url:"+url); + debugLogger.info("Running curl command for url:{}",url); String[] command = { "curl", "-v", url }; ProcessBuilder process = new ProcessBuilder(command); Process p; @@ -161,10 +163,10 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { builder.append(line); } result = builder.toString(); - LOGGER.info(result); + debugLogger.debug(result); } } catch (IOException e) { - LOGGER.error("error", e); + errorLogger.error("error", e); } return result; @@ -173,7 +175,7 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { public void fetchMappingFile() { try (Connection con = DriverManager.getConnection(dBurl, user, pwd);PreparedStatement pstmt = con.prepareStatement("SELECT * FROM mapping_file");ResultSet rs = pstmt.executeQuery()) { - LOGGER.info("Retrieving data from DB"); + debugLogger.info("Retrieving data from DB"); // parsing the column each time is a linear search int column1Pos = rs.findColumn("enterpriseid"); int column2Pos = rs.findColumn("mappingfilecontents"); @@ -186,9 +188,9 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { String data = new String(bytes, "UTF-8"); mappingFiles.put(column1, data); } - LOGGER.info("DB Initialization Completed, Total # Mappingfiles are" + mappingFiles.size()); + debugLogger.info("DB Initialization Completed, Total # Mappingfiles are:{}" , mappingFiles.size()); } catch (Exception e) { - LOGGER.error("Error occured due to :" + e.getMessage()); + errorLogger.error("Error occured due to :{}", e.getMessage()); } } @@ -197,13 +199,13 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { private void prepareDatabase() throws IOException { - LOGGER.info("The Default Mapping file Location:" + defaultMappingFileLocation.trim()); + debugLogger.info("The Default Mapping file Location:" + defaultMappingFileLocation.trim()); if (ClassLoader.getSystemResource(defaultMappingFileLocation.trim()) == null) { - LOGGER.error( + errorLogger.error( "Default mapping file " + defaultMappingFileLocation.trim() + " is missing"); System.exit(SpringApplication.exit(applicationContext, () -> { - LOGGER.error("Application stoped due to missing default mapping file"); + errorLogger.error("Application stoped due to missing default mapping file"); return -1; })); } @@ -216,11 +218,11 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { fileInputStream.read(bytesArray); } catch (IOException e1) { - LOGGER.error("Exception Occured while reading the default mapping file ,Cause: " + errorLogger.error("Exception Occured while reading the default mapping file ,Cause: " + e1.getMessage(), e1); // exit on missing default mapping file System.exit(SpringApplication.exit(applicationContext, () -> { - LOGGER.error("Application stoped due to missing default mapping file"); + errorLogger.error("Application stoped due to missing default mapping file"); return -1; })); } @@ -238,14 +240,14 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { + ")\r\n" + "WITH (\r\n" + " OIDS = FALSE\r\n" + ")\r\n" + "TABLESPACE pg_default;")) { - LOGGER.info("Postgresql Connection successful..."); - LOGGER.debug("Connection object:" + con.toString()); + metricsLogger.info("Postgresql Connection successful..."); + debugLogger.debug("Connection object:{}" , con.toString()); pstmt11.executeUpdate(); - LOGGER.info("CREATE TABLE IF NOT EXISTS executed successfully...."); + debugLogger.info("CREATE TABLE IF NOT EXISTS executed successfully...."); if ((bytesArray.length > 0) && (!Arrays.toString(bytesArray).equals(""))) { - LOGGER.debug("2Connection object:" + con.toString()); + try (PreparedStatement pstmt = con.prepareStatement("INSERT INTO " + MappingFileTableName + "(enterpriseid, mappingfilecontents, mimetype, File_Name) VALUES (?, ?, ?, ?) ON CONFLICT (enterpriseid) DO NOTHING;")) { @@ -255,22 +257,22 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { pstmt.setString(4, file.getName()); pstmt.executeUpdate(); - LOGGER.info("Made sure that default mapping file is present in table"); + debugLogger.info("Made sure that default mapping file is present in table"); } } else { - LOGGER.error(file.getName() + " is empty"); + errorLogger.error(file.getName() + " is empty"); // exit on empty mapping file System.exit(SpringApplication.exit(applicationContext, () -> { - LOGGER.error("Application stoped beacuase default mapping file is empty.."); + errorLogger.error("Application stoped beacuase default mapping file is empty.."); return -1; })); } } catch (SQLException e) { - LOGGER.error("Received exception : " + e.getMessage(), e); + errorLogger.error("Received exception : " + e.getMessage(), e); // exit on SqlException System.exit(SpringApplication.exit(applicationContext, () -> { - LOGGER.error("Application Stoped due to ", e.getCause()); + errorLogger.error("Application Stoped due to ", e.getCause()); return -1; })); } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java index e9e2023..06ef080 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java @@ -37,7 +37,9 @@ import org.springframework.stereotype.Component; @Component public class VesService { - private final Logger LOGGER = LoggerFactory.getLogger(VesService.class); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private boolean isRunning = true; @@ -52,7 +54,7 @@ public class VesService { * method triggers universal VES adapter module. */ public void start() throws MapperConfigException { - LOGGER.debug("Creating Subcriber and Publisher with creator............."); + debugLogger.info("Creating Subcriber and Publisher with creator............."); DMaaPMRSubscriber subcriber = creator.getDMaaPMRSubscriber(); DMaaPMRPublisher publisher = creator.getDMaaPMRPublisher(); @@ -62,10 +64,10 @@ public class VesService { @Override public void run() { try { - LOGGER.debug("starting subscriber & publisher thread:{}", Thread.currentThread().getName()); + debugLogger.info("starting subscriber & publisher thread:{}", Thread.currentThread().getName()); dmaapService.fetchAndPublishInDMaaP(subcriber, publisher, creator); } catch (InterruptedException e) { - LOGGER.error("Exception in starting of subscriber & publisher thread:{}",e); + errorLogger.error("Exception in starting of subscriber & publisher thread:{}",e); Thread.currentThread().interrupt(); } } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java index 2161497..fb7ed26 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java @@ -43,7 +43,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; */ public class MapperConfigUtils { - private static final Logger LOGGER = LoggerFactory.getLogger(MapperConfigUtils.class); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private static Set<Entry> entries = new TreeSet<>((o1, o2) -> o1.getPriority().compareTo(o2.getPriority())); private enum JoinOperator { @@ -163,7 +164,7 @@ public class MapperConfigUtils { readMapperConfigFile(mappingFile); checkIncomingJsonForMatchingDomain(incomingJsonString); } catch (MapperConfigException e) { - LOGGER.error("Exception in mapperConfigFile reading:{}",e); + errorLogger.error("Exception in mapperConfigFile reading:{}",e); } } @@ -215,7 +216,7 @@ public class MapperConfigUtils { throw new MapperConfigException("Unable to read config file for reason...\n " + exception.getMessage(), exception); } - LOGGER.debug("Read config file content into :{}",config); + debugLogger.debug("Read config file content into :{}",config); if (null != config) { entries.addAll(config.getEntries()); diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/SmooksUtils.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/SmooksUtils.java index 1c38783..e77c965 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/SmooksUtils.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/SmooksUtils.java @@ -43,7 +43,8 @@ import org.slf4j.LoggerFactory; public class SmooksUtils { - private final static Logger LOGGER = LoggerFactory.getLogger(SmooksUtils.class); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); /** * converts the incoming json using passed smooks instance and return the pojo representation of VES event @@ -55,9 +56,9 @@ public class SmooksUtils { */ public static VesEvent getTransformedObjectForInput(Smooks smooks, String incomingJsonString) { - LOGGER.info("Transforming incoming json " ); + debugLogger.info("Transforming incoming json " ); ExecutionContext executionContext = smooks.createExecutionContext(); - LOGGER.info("Context created"); + debugLogger.info("Context created"); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(new Locale("en", "IE")); @@ -67,7 +68,7 @@ public class SmooksUtils { Locale.setDefault(defaultLocale); VesEvent vesEvent = (VesEvent) executionContext.getBeanContext().getBean("vesEvent"); - LOGGER.debug("consversion successful to VES Event"); + debugLogger.debug("consversion successful to VES Event"); return vesEvent; } |