summaryrefslogtreecommitdiffstats
path: root/common-logging/src/main/java
diff options
context:
space:
mode:
authorRalph Straubs <rs8887@att.com>2017-04-20 05:26:49 -0500
committerRalph Straubs <rs8887@att.com>2017-04-20 05:34:06 -0500
commitd5d7dd40f8b29a7a4921829bd6ccf9b670613af2 (patch)
treec93b970c711255a5468d82426ca1eb90ecdc8811 /common-logging/src/main/java
parentc2aad6527c903cc3359ef9673d0706f37d4b89ec (diff)
Batch submit
[ECOMPD2TD-1073 1707] Removal of extra flush statements and addition of rollbacks in catch blocks instead of commits. [ECOMPD2TD-1073 1707] Adding some needed synchronized statements to IntegrityMonitor. [ECOMPD2TD-1159] - Loggers should be Serializable By making loggers Serializable, they can be included in Drools persistent data. 'EelfLogger' and 'SystemOutLogger' can do this trivially, but 'Logger4J' needed some additional work, because it has a non-serializable field 'log'. [ECOMPD2TD-000] Fix versioning of org.openecomp.policy.* dependencies [US866186 1707] First cut of stateCheck mod and non-working JUnit [US866186 1707] Completed the coding for the task TA1998344 which adds a check of forward progress for dependencies. [US866186 1707] Completed updates to IntegrityMonitor.stateCheck and IntegrityMonitorTest which includes addition of a JUnit for stateCheck and control of the order of JUnit execution. [US865296] ECOMP Policy Logging Compliance, add TargetEntity and TargetServiceName, remove unit from ElapsedTime [US865296] ECOMP Policy Logging Compliance, set audit log statuscode to 'COMPLETE' instead of N/A [US865296] ECOMP Policy Logging Compliance, remove time unit (seconds and milliseconds) from ElapsedTime for logging compliance [US866186 1707] Cleaned up IntegrityAudit JUnit tests. [US866186 1707] IntegrityMonitor JUnit clean up [US866186 1707] Re-added missing classes that were erroneously deleted. [US865296] - add get/setters and inits for required log fields Change-Id: I76ef4606ed6832ed48eaca68e72839a05c8bc3a8 Signed-off-by: Ralph Straubs <rs8887@att.com>
Diffstat (limited to 'common-logging/src/main/java')
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java113
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java10
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java104
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java3
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java32
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java3
6 files changed, 193 insertions, 72 deletions
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
index 71e75a11..e6e2b1ca 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
@@ -75,6 +75,10 @@ public class ECOMPLoggingContext {
private static final String THREAD_ID = "threadId";
private static final String SERVER_NAME = "serverName";
private static final String SERVICE_NAME = "serviceName";
+ private static final String PARTNER_NAME = "partnerName";
+ private static final String STATUS_CODE = "statusCode";
+ private static final String TARGET_ENTITY = "targetEntity";
+ private static final String TARGET_SERVICE_NAME = "targetServiceName";
private static final String INSTANCE_UUID = "instanceUuid";
private static final String SEVERITY = "severity";
private static final String SERVER_IP_ADDRESS = "serverIpAddress";
@@ -123,6 +127,11 @@ public class ECOMPLoggingContext {
MDC.clear();
baseContext.context.transferTo(context);
transactionStartTime = baseContext.transactionStartTime;
+ setServiceName("POLICY");
+ setPartnerName("USER");
+ setStatusCode("COMPLETE");
+ setTargetEntity("POLICY");
+ setTargetServiceName("PE Process");
}
/**
@@ -253,6 +262,70 @@ public class ECOMPLoggingContext {
}
/**
+ * Set the value for the data item with key "partnerName"
+ *
+ * @param id
+ */
+ public void setPartnerName(String name) {
+ context.put(PARTNER_NAME, name);
+ }
+ /**
+ * Get the value for the data item with key "partnerName"
+ * @return current value, or empty string if not set
+ */
+ public String getPartnerName() {
+ return context.get(PARTNER_NAME, "");
+ }
+
+ /**
+ * Set the value for the data item with key "statusCode"
+ *
+ * @param id
+ */
+ public void setStatusCode(String name) {
+ context.put(STATUS_CODE, name);
+ }
+ /**
+ * Get the value for the data item with key "statusCode"
+ * @return current value, or empty string if not set
+ */
+ public String getStatusCode() {
+ return context.get(STATUS_CODE, "");
+ }
+
+ /**
+ * Set the value for the data item with key "targetEntity"
+ *
+ * @param id
+ */
+ public void setTargetEntity(String name) {
+ context.put(TARGET_ENTITY, name);
+ }
+ /**
+ * Get the value for the data item with key "targetEntity"
+ * @return current value, or empty string if not set
+ */
+ public String getTargetEntity() {
+ return context.get(TARGET_ENTITY, "");
+ }
+
+ /**
+ * Set the value for the data item with key "targetServiceName"
+ *
+ * @param id
+ */
+ public void setTargetServiceName(String name) {
+ context.put(TARGET_SERVICE_NAME, name);
+ }
+ /**
+ * Get the value for the data item with key "targetServiceName"
+ * @return current value, or empty string if not set
+ */
+ public String getTargetServiceName() {
+ return context.get(TARGET_SERVICE_NAME, "");
+ }
+
+ /**
* Set the value for the data item with key "instanceUuid"
*
* @param id
@@ -433,17 +506,17 @@ public class ECOMPLoggingContext {
*/
public void setTransactionElapsedTime(Instant transactionEndTime) {
- long ns = Duration.between(transactionStartTime, transactionEndTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
- unit = " milliseconds";
- }
- context.put(TRANSACTION_ELAPSED_TIME, ns + unit);
+ //if(ns < 1){
+ //ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
+ //unit = " milliseconds";
+ //}
+ context.put(TRANSACTION_ELAPSED_TIME, ns); // + unit);
}
/**
@@ -506,17 +579,17 @@ public class ECOMPLoggingContext {
*/
public void setMetricElapsedTime(Instant metricEndTime) {
- long ns = Duration.between(metricStartTime, metricEndTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(metricStartTime, metricEndTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(metricStartTime, metricEndTime).toMillis();
- unit = " milliseconds";
- }
- context.put(METRIC_ELAPSED_TIME, ns + unit);
+ //if(ns < 1){
+ //ns = Duration.between(metricStartTime, metricEndTime).toMillis();
+ //unit = " milliseconds";
+ //}
+ context.put(METRIC_ELAPSED_TIME, ns); // + unit);
}
/**
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
index a2a0b783..a839ea16 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
@@ -43,6 +43,16 @@ public interface Configuration extends com.att.eelf.configuration.Configuration
*/
public String PARTNER_NAME = "PartnerName";
+ /**
+ * Target Entity
+ */
+ public String TARGET_ENTITY = "TargetEntity";
+
+ /**
+ * Target service name
+ */
+ public String TARGET_SERVICE_NAME = "TargetServiceName";
+
/**
* High level success or failure (COMPLETE or ERROR)
*/
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
index 624ba580..ed03f9a9 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
@@ -125,7 +125,13 @@ public class PolicyLogger {
}
if(component != null && component.equalsIgnoreCase("DROOLS")){
+ MDC.put(TARGET_ENTITY, "POLICY");
+ MDC.put(TARGET_SERVICE_NAME, "drools evaluate rule");
return postMDCInfoForEvent(transId, new DroolsPDPMDCInfo());
+ } else {
+ // For Xacml
+ MDC.put(TARGET_ENTITY, "POLICY");
+ MDC.put(TARGET_SERVICE_NAME, "PE Process");
}
MDC.put(MDC_REMOTE_HOST, "");
@@ -140,16 +146,16 @@ public class PolicyLogger {
}
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
-
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
+
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -161,11 +167,11 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
MDC.put(PARTNER_NAME, "N/A");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
@@ -203,16 +209,16 @@ public class PolicyLogger {
}
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
@@ -222,7 +228,7 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
return transId;
}
@@ -234,16 +240,16 @@ public class PolicyLogger {
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
-
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ long ns = Duration.between(startTime, endTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
+
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -255,11 +261,11 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
MDC.put(PARTNER_NAME, "N/A");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
@@ -315,7 +321,7 @@ public class PolicyLogger {
}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
return transId;
@@ -634,7 +640,7 @@ public class PolicyLogger {
* @param arg0
*/
public static void audit(String className, Object arg0) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(CLASS_NAME, className);
auditLogger.info("" + arg0);
}
@@ -644,7 +650,7 @@ public class PolicyLogger {
* @param arg0
*/
public static void audit(Object arg0) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(CLASS_NAME, "");
auditLogger.info("" + arg0);
}
@@ -748,7 +754,7 @@ public class PolicyLogger {
*/
public static void recordAuditEventStart(String eventId) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
postMDCInfoForEvent(eventId);
if(eventTracker == null){
@@ -955,21 +961,21 @@ public class PolicyLogger {
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(startTime, endTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
auditLogger.info(MessageCodes.RULE_AUDIT_START_END_INFO,
- serviceName, rule, startTime.toString(), endTime.toString(), ns+unit, policyVersion);
+ serviceName, rule, startTime.toString(), endTime.toString(), Long.toString(ns), policyVersion);
//--- remove the record from the concurrentHashMap
if(eventTracker != null){
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
index 6e74b94c..31c17554 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
@@ -20,6 +20,7 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.Serializable;
import java.util.UUID;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
@@ -33,7 +34,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
*
*/
-public class EelfLogger implements Logger {
+public class EelfLogger implements Logger, Serializable {
private String className = "";
private String transId = UUID.randomUUID().toString();
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
index 02f95cf2..23cafb41 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
@@ -20,6 +20,10 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.UUID;
import org.apache.log4j.Logger;
@@ -34,7 +38,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
* Logger4J implements all the methods of interface Logger by calling org.apache.log4j.Logger
*
*/
-public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.Logger {
+public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.Logger, Serializable {
private Logger log = null;
private String methodName = "";
@@ -451,4 +455,30 @@ public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.
public void postMDCInfoForEvent(Object o){
log.info(o);
}
+
+ /* ============================================================ */
+
+ /*
+ * Support for 'Serializable' --
+ * the default rules don't work for the 'log' field
+ */
+
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // write out 'methodName', 'className', 'transId' strings
+ out.writeObject(methodName);
+ out.writeObject(className);
+ out.writeObject(transId);
+ }
+
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+
+ // read in 'methodName', 'className', 'transId' strings
+ methodName = (String)(in.readObject());
+ className = (String)(in.readObject());
+ transId = (String)(in.readObject());
+
+ // look up associated logger
+ log = Logger.getLogger(className);
+ }
}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
index 26f06640..91e16b97 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
@@ -20,6 +20,7 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.Serializable;
import java.util.UUID;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
@@ -31,7 +32,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
* SystemOutLogger implements all the methods of interface Logger by calling System.out.println
*
*/
-public class SystemOutLogger implements Logger {
+public class SystemOutLogger implements Logger, Serializable {
private String className = "";
private boolean isDebugEnabled = true;