aboutsummaryrefslogtreecommitdiffstats
path: root/appc-common
diff options
context:
space:
mode:
authorGary Wu <gary.i.wu@huawei.com>2017-05-08 12:59:44 -0700
committerPatrick Brady <pb071s@att.com>2017-05-16 18:13:41 +0000
commit753cb638fcb58f355f2c979e9e0a43cba2832984 (patch)
tree55526dce196663d6c5c4265e504882e3deec2cc2 /appc-common
parentf16391cacb2e91063bbe9ad66cb2310855c93695 (diff)
Migrate to Java 8 Time API
Migrate the uses of the old Date class in CommonHeader, RuntimeContext, QueueMessage, and TransactionRecord to Java 8 Time API. Change-Id: I3b0c18b2e63cdab06e37587d2010cb7f626a0396 Signed-off-by: Gary Wu <gary.i.wu@huawei.com>
Diffstat (limited to 'appc-common')
-rw-r--r--appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java31
1 files changed, 17 insertions, 14 deletions
diff --git a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java
index 901ff3272..c186a4afa 100644
--- a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java
+++ b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java
@@ -21,20 +21,23 @@
package org.openecomp.appc.logging;
-import org.openecomp.appc.i18n.Msg;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.i18n.EELFResourceManager;
-import org.slf4j.MDC;
-
import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.TimeZone;
+import org.openecomp.appc.i18n.Msg;
+import org.slf4j.MDC;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+
public class LoggingUtils {
@@ -61,7 +64,7 @@ public class LoggingUtils {
cleanErrorLogContext();
}
- public static void logAuditMessage(Date beginTimeStamp, Date endTimeStamp, String code, String responseDescription, String className) {
+ public static void logAuditMessage(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className) {
populateAuditLogContext(beginTimeStamp, endTimeStamp, code, responseDescription, className);
auditLogger.info(EELFResourceManager.format(Msg.APPC_AUDIT_MSG,
MDC.get(MDC_SERVICE_NAME),
@@ -74,7 +77,7 @@ public class LoggingUtils {
cleanAuditErrorContext();
}
- public static void logMetricsMessage(Date beginTimeStamp, Date endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) {
+ public static void logMetricsMessage(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) {
populateMetricLogContext(beginTimeStamp, endTimeStamp, targetEntity, targetServiceName, statusCode, responseCode, responseDescription, className);
metricLogger.info(EELFResourceManager.format(Msg.APPC_METRIC_MSG,
MDC.get(MDC_SERVICE_NAME),
@@ -88,7 +91,7 @@ public class LoggingUtils {
cleanMetricContext();
}
- private static void populateAuditLogContext(Date beginTimeStamp, Date endTimeStamp, String code, String responseDescription, String className) {
+ private static void populateAuditLogContext(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className) {
populateTimeContext(beginTimeStamp, endTimeStamp);
MDC.put(LoggingConstants.MDCKeys.RESPONSE_CODE, code);
MDC.put(LoggingConstants.MDCKeys.STATUS_CODE, code.equals("100") || code.equals("400") ?
@@ -118,7 +121,7 @@ public class LoggingUtils {
MDC.remove(LoggingConstants.MDCKeys.CLASS_NAME);
}
- private static void populateMetricLogContext(Date beginTimeStamp, Date endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) {
+ private static void populateMetricLogContext(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) {
populateTimeContext(beginTimeStamp, endTimeStamp);
populateTargetContext(targetEntity, targetServiceName);
populateResponseContext(statusCode, responseCode, responseDescription);
@@ -142,13 +145,13 @@ public class LoggingUtils {
MDC.remove(LoggingConstants.MDCKeys.TARGET_SERVICE_NAME);
}
- private static void populateTimeContext(Date beginTimeStamp, Date endTimeStamp) {
+ private static void populateTimeContext(Instant beginTimeStamp, Instant endTimeStamp) {
String beginTime = "";
String endTime = "";
String elapsedTime = "";
if (beginTimeStamp != null && endTimeStamp != null) {
- elapsedTime = String.valueOf(endTimeStamp.getTime() - beginTimeStamp.getTime());
+ elapsedTime = String.valueOf(ChronoUnit.MILLIS.between(beginTimeStamp, endTimeStamp));
beginTime = generateTimestampStr(beginTimeStamp);
endTime = generateTimestampStr(endTimeStamp);
}
@@ -158,11 +161,11 @@ public class LoggingUtils {
MDC.put(LoggingConstants.MDCKeys.ELAPSED_TIME, elapsedTime);
}
- private static String generateTimestampStr(Date timeStamp) {
+ private static String generateTimestampStr(Instant timeStamp) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
TimeZone tz = TimeZone.getTimeZone("UTC");
df.setTimeZone(tz);
- return df.format(timeStamp);
+ return df.format(Date.from(timeStamp));
}
private static void cleanTimeContext() {