diff options
Diffstat (limited to 'common-logging/src/main')
6 files changed, 289 insertions, 300 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/Configuration.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/Configuration.java index 4cbe63af..9d550c35 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/Configuration.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/Configuration.java @@ -21,81 +21,80 @@ package org.onap.policy.common.logging.eelf; -public interface Configuration extends com.att.eelf.configuration.Configuration{ - - /** - * The Date-time of the start of a transaction - */ - public String BEGIN_TIME_STAMP = "BeginTimestamp"; - - /** - * The Date-time of the end of transaction - */ - public String END_TIME_STAMP = "EndTimestamp"; - - /** - * Externally advertised API invoked by clients of this component - */ - public String SERVICE_NAME = "ServiceName"; - - /** - * Client or user invoking the API - */ - public String PARTNER_NAME = "PartnerName"; - - /** - * Target Entity - */ - public String TARGET_ENTITY = "TargetEntity"; - +public interface Configuration extends com.att.eelf.configuration.Configuration { + + /** + * The Date-time of the start of a transaction + */ + String BEGIN_TIME_STAMP = "BeginTimestamp"; + + /** + * The Date-time of the end of transaction + */ + String END_TIME_STAMP = "EndTimestamp"; + + /** + * Externally advertised API invoked by clients of this component + */ + String SERVICE_NAME = "ServiceName"; + + /** + * Client or user invoking the API + */ + String PARTNER_NAME = "PartnerName"; + + /** + * Target Entity + */ + String TARGET_ENTITY = "TargetEntity"; + /** * Target service name */ - public String TARGET_SERVICE_NAME = "TargetServiceName"; - - /** - * High level success or failure (COMPLETE or ERROR) - */ - public String STATUS_CODE = "StatusCode"; - - /** - * Application specific response code - */ - public String RESPONSE_CODE = "ResponseCode"; - - /** - * Human readable description of the application specific response code - */ - public String RESPONSE_DESCRIPTION = "ResponseDescription"; - - /** - * Externally advertised API invoked by clients of this component - */ - public String ELAPSED_TIME = "ElapsedTime"; - - /** - * High level failure (ERROR) - */ - public String ERROR_CATEGORY = "ErrorCategory"; - - /** - * Error Code - */ - public String ERROR_CODE = "ErrorCode"; - - /** - * Error Description - */ - public String ERROR_DESCRIPTION = "ErrorDesciption"; - - /** - * Class name - */ - public String CLASS_NAME = "ClassName"; - - /** - * Server name - */ - public String SERVER_NAME = "ServerName"; - + String TARGET_SERVICE_NAME = "TargetServiceName"; + + /** + * High level success or failure (COMPLETE or ERROR) + */ + String STATUS_CODE = "StatusCode"; + + /** + * Application specific response code + */ + String RESPONSE_CODE = "ResponseCode"; + + /** + * Human readable description of the application specific response code + */ + String RESPONSE_DESCRIPTION = "ResponseDescription"; + + /** + * Externally advertised API invoked by clients of this component + */ + String ELAPSED_TIME = "ElapsedTime"; + + /** + * High level failure (ERROR) + */ + String ERROR_CATEGORY = "ErrorCategory"; + + /** + * Error Code + */ + String ERROR_CODE = "ErrorCode"; + + /** + * Error Description + */ + String ERROR_DESCRIPTION = "ErrorDescription"; + + /** + * Class name + */ + String CLASS_NAME = "ClassName"; + + /** + * Server name + */ + String SERVER_NAME = "ServerName"; } diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java index 7b9bba65..c1e99822 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java @@ -22,32 +22,28 @@ package org.onap.policy.common.logging.eelf; import java.util.concurrent.ConcurrentHashMap; -public class DroolsPDPMDCInfo implements MDCInfo{ +public class DroolsPDPMDCInfo implements MDCInfo { private static ConcurrentHashMap<String, String> mdcMap = new ConcurrentHashMap<>(); static { - - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.MDC_REMOTE_HOST, ""); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.MDC_SERVICE_NAME, "Policy.droolsPdp"); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.MDC_SERVICE_INSTANCE_ID, "Policy.droolsPdp.event"); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.MDC_INSTANCE_UUID, ""); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.MDC_ALERT_SEVERITY, ""); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.PARTNER_NAME, "N/A"); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.STATUS_CODE, "N/A"); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.RESPONSE_CODE, "N/A"); - mdcMap.put(org.onap.policy.common.logging.eelf.Configuration.RESPONSE_DESCRIPTION, "N/A"); - - } - @Override - /** - * @return the instance of ConcurrentHashMap - */ - public ConcurrentHashMap<String, String> getMDCInfo() { + mdcMap.put(Configuration.MDC_REMOTE_HOST, ""); + mdcMap.put(Configuration.MDC_SERVICE_NAME, "Policy.droolsPdp"); + mdcMap.put(Configuration.MDC_SERVICE_INSTANCE_ID, "Policy.droolsPdp.event"); + mdcMap.put(Configuration.MDC_INSTANCE_UUID, ""); + mdcMap.put(Configuration.MDC_ALERT_SEVERITY, ""); + mdcMap.put(Configuration.PARTNER_NAME, "N/A"); + mdcMap.put(Configuration.STATUS_CODE, "N/A"); + mdcMap.put(Configuration.RESPONSE_CODE, "N/A"); + mdcMap.put(Configuration.RESPONSE_DESCRIPTION, "N/A"); + } - return mdcMap; - } - - + /** + * @return the instance of ConcurrentHashMap + */ + @Override + public ConcurrentHashMap<String, String> getMDCInfo() { + return mdcMap; + } } diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java index 2267b909..ce31fbcb 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java @@ -23,88 +23,88 @@ package org.onap.policy.common.logging.eelf; import java.time.Instant; /** - * + * * EventData can be used for logging a rule event. * */ public class EventData { - - private String requestID = null; - private Instant startTime = null; - private Instant endTime = null; - //Default constructor takes no arguments. - //Is empty because instance variables are assigned - //their default values upon declaration. - public EventData() { - - } - - public EventData(String requestID, Instant startTime, Instant endTime) { - - this.requestID = requestID; - this.startTime = startTime; - this.endTime = endTime; - } + private String requestID = null; + private Instant startTime = null; + private Instant endTime = null; + + //Default constructor takes no arguments. + //Is empty because instance variables are assigned + //their default values upon declaration. + public EventData() { + } + + public EventData(String requestID, Instant startTime, Instant endTime) { + this.requestID = requestID; + this.startTime = startTime; + this.endTime = endTime; + } + + public String getRequestID() { + return requestID; + } - public String getRequestID() { - return requestID; - } + public void setRequestID(String requestID) { + this.requestID = requestID; + } - public void setRequestID(String requestID) { - this.requestID = requestID; - } + public Instant getStartTime() { + return startTime; + } - public Instant getStartTime() { - return startTime; - } + public void setStartTime(Instant startTime) { + this.startTime = startTime; + } - public void setStartTime(Instant startTime) { - this.startTime = startTime; - } + public Instant getEndTime() { + return endTime; + } - public Instant getEndTime() { - return endTime; - } + public void setEndTime(Instant endTime) { + this.endTime = endTime; + } - public void setEndTime(Instant endTime) { - this.endTime = endTime; - } - - @Override - public String toString(){ - return requestID + " Starting Time : " + this.startTime + " Ending Time : " + this.endTime; - } + @Override + public String toString() { + return requestID + " Starting Time : " + this.startTime + " Ending Time : " + this.endTime; + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((requestID == null) ? 0 : requestID.hashCode()); - return result; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((requestID == null) ? 0 : requestID.hashCode()); + return result; + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (obj instanceof String) { - String requestId = (String) obj; - if(requestID != null && requestID.equals(requestId)){ - return true; - } - return false; - } - if (getClass() != obj.getClass()) - return false; - EventData other = (EventData) obj; - if (requestID == null) { - if (other.requestID != null) - return false; - } else if (!requestID.equals(other.requestID)) - return false; - return true; - } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (obj instanceof String) { + String requestId = (String) obj; + return requestID != null && requestID.equals(requestId); + } + if (getClass() != obj.getClass()) { + return false; + } + EventData other = (EventData) obj; + if (requestID == null) { + if (other.requestID != null) { + return false; + } + } else if (!requestID.equals(other.requestID)) { + return false; + } + return true; + } } diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java index 58699867..6c31a990 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java @@ -23,62 +23,62 @@ package org.onap.policy.common.logging.eelf; import java.util.concurrent.ConcurrentHashMap; /** - * - * EventTrackInfo contains a ConcurrentHashMap of EventData - * + * EventTrackInfo contains a ConcurrentHashMap of EventData. */ public class EventTrackInfo { - private ConcurrentHashMap<String, EventData> eventInfo = null; - - public EventTrackInfo() { - /* - * An initial capacity of 16 ensures the number of elements before resizing happens - * Load factor of 0,9 ensures a dense packaging inside ConcurrentHashMap which will optimize memory use - * ConcurencyLevel set to 1 will ensure that only one shard is created and maintained - */ - eventInfo = new ConcurrentHashMap<>(16, 0.9f, 1); - } - - /** - * Returns an instance of EventData associated to this requestID - * @param requestID - * @return EventData - */ - public EventData getEventDataByRequestID(String requestID){ - return eventInfo.get(requestID); - } - - /** - * Stores an EventData object in a ConcurrentHashMap using its requestID as key. - * @param event - */ - public void storeEventData(EventData event){ - - if(event == null || event.getRequestID() == null || event.getRequestID().isEmpty()){ - return; - } - //in case override the start time, check the original event was already stored or not - if(!eventInfo.containsKey(event.getRequestID())){ - eventInfo.put(event.getRequestID(), event); - } - } - - /** - * Removes an EventData object from a ConcurrentHashMap using the eventId as key. - * @param eventId - */ - public void remove(String eventId){ - if(eventInfo != null){ - eventInfo.remove(eventId); - } - } - - /** - * Returns a ConcurrentHashMap of EventData - */ - public ConcurrentHashMap<String, EventData> getEventInfo() { - return eventInfo; - } + private ConcurrentHashMap<String, EventData> eventInfo = null; + + public EventTrackInfo() { + /* + * An initial capacity of 16 ensures the number of elements before resizing happens + * Load factor of 0,9 ensures a dense packaging inside ConcurrentHashMap which will optimize memory use + * Concurrency Level set to 1 will ensure that only one shard is created and maintained + */ + eventInfo = new ConcurrentHashMap<>(16, 0.9f, 1); + } + + /** + * Returns an instance of EventData associated to this requestID + * @param requestID request id + * @return EventData + */ + public EventData getEventDataByRequestID(String requestID) { + return eventInfo.get(requestID); + } + + /** + * Stores an EventData object in a ConcurrentHashMap using its requestID as key. + * @param event event data + */ + public void storeEventData(EventData event) { + + if (event != null) { + String id = event.getRequestID(); + if (id == null || id.isEmpty()) { + return; + } + //in case override the start time, check the original event was already stored or not + if (!eventInfo.containsKey(id)) { + eventInfo.put(id, event); + } + } + } + + /** + * Removes an EventData object from a ConcurrentHashMap using the eventId as key. + * @param eventId event id + */ + public void remove(String eventId) { + if (eventInfo != null) { + eventInfo.remove(eventId); + } + } + /** + * Returns a ConcurrentHashMap of EventData + */ + public ConcurrentHashMap<String, EventData> getEventInfo() { + return eventInfo; + } } diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java index 8dc7ecb0..097bc706 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java @@ -7,9 +7,9 @@ * 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. @@ -24,84 +24,75 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; /** - * - * EventTrackInfoHandler is the handler of clean up all expired event objcts + * + * EventTrackInfoHandler is the handler of clean up all expired event objects * */ public class EventTrackInfoHandler extends TimerTask { - String className = this.getClass().getSimpleName(); - - @Override - public void run() { - - PolicyLogger.info(className - + " Release expired event records start..."); - - CleanUp(); - - PolicyLogger.info(className + " Release expired event records done"); - } - - /** - * Removes all expired event objects from the ConcurrentHashMap of EventData - */ - private void CleanUp() { - - if (PolicyLogger.getEventTracker() == null - || PolicyLogger.getEventTracker().getEventInfo() == null - || PolicyLogger.getEventTracker().getEventInfo().isEmpty()) { - return; - } - - Instant startTime; - long ns; - - ArrayList<String> expiredEvents = null; - - for (String key: PolicyLogger.getEventTracker().getEventInfo().keySet()) { - EventData event = PolicyLogger.getEventTracker().getEventInfo().get(key); - startTime = event.getStartTime(); - ns = Duration.between(startTime, Instant.now()).getSeconds(); - - PolicyLogger.info(className - + " duration time : " + ns); - - PolicyLogger.info(className - + " PolicyLogger.EXPIRED_TIME : " + PolicyLogger.EXPIRED_TIME); - - // if longer than EXPIRED_TIME, remove the object - - if (ns > PolicyLogger.EXPIRED_TIME){ - if (expiredEvents == null) { - expiredEvents = new ArrayList<>(); - } - expiredEvents.add(key); - - PolicyLogger.info(className - + " add expired event request ID: " - + event.getRequestID()); - } - } - - synchronized (PolicyLogger.getEventTracker().getEventInfo()) { - if (expiredEvents != null) { - for (String expiredKey : expiredEvents) { - PolicyLogger.getEventTracker().getEventInfo() - .remove(expiredKey); - System.out.println(className - + " removed expired event request ID: " - + expiredKey); - PolicyLogger.info(className - + " removed expired event request ID: " - + expiredKey); - } - } - - } - - } + String className = this.getClass().getSimpleName(); + + @Override + public void run() { + + PolicyLogger.info(className + " Release expired event records start..."); + + cleanUp(); + + PolicyLogger.info(className + " Release expired event records done"); + } + + /** + * Removes all expired event objects from the ConcurrentHashMap of EventData + */ + private void cleanUp() { + + EventTrackInfo eventTrackInfo = PolicyLogger.getEventTracker(); + if (eventTrackInfo == null) { + return; + } + ConcurrentHashMap<String, EventData> eventInfo = eventTrackInfo.getEventInfo(); + if (eventInfo == null || eventInfo.isEmpty()) { + return; + } + + Instant startTime; + long ns; + + ArrayList<String> expiredEvents = null; + + for (ConcurrentHashMap.Entry<String, EventData> entry : eventInfo.entrySet()) { + EventData event = entry.getValue(); + startTime = event.getStartTime(); + ns = Duration.between(startTime, Instant.now()).getSeconds(); + + PolicyLogger.info(className + " duration time : " + ns); + + PolicyLogger.info(className + " PolicyLogger.EXPIRED_TIME : " + PolicyLogger.EXPIRED_TIME); + + // if longer than EXPIRED_TIME, remove the object + + if (ns > PolicyLogger.EXPIRED_TIME) { + if (expiredEvents == null) { + expiredEvents = new ArrayList<>(); + } + expiredEvents.add(entry.getKey()); + + PolicyLogger.info(className + " add expired event request ID: " + event.getRequestID()); + } + } + synchronized (eventInfo) { + if (expiredEvents != null) { + for (String expiredKey : expiredEvents) { + eventInfo.remove(expiredKey); + System.out.println(className + " removed expired event request ID: " + expiredKey); + PolicyLogger.info(className + " removed expired event request ID: " + expiredKey); + } + } + } + } } diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java index d57ed0c4..0d0b5dff 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java @@ -23,13 +23,16 @@ package org.onap.policy.common.logging.eelf; import java.util.concurrent.ConcurrentHashMap; /** - * + * * Interface needs to be implemented by DroolsPDPMDCInfo * */ @FunctionalInterface public interface MDCInfo { - - public ConcurrentHashMap<String, String> getMDCInfo(); - + + /** + * Returns MDC info. + * @return MDC info + */ + ConcurrentHashMap<String, String> getMDCInfo(); } |