diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2021-02-10 16:20:35 -0600 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2021-02-11 19:21:40 -0600 |
commit | ef4198b40ee5108cf8c549c09a0a04b09e3f959a (patch) | |
tree | 3250ab0d9c327dacefc39551544e4113386d2908 /policy-utils/src/main/java | |
parent | c3c83896d877602ead85c32215761b3d3555facb (diff) |
support transaction reports in engine
Issue-ID: POLICY-3033
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Id1f02c86be491d5145e74725f76953e294e2975c
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-utils/src/main/java')
3 files changed, 27 insertions, 33 deletions
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java b/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java index 189371e5..01ff58f5 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/metrics/Metric.java @@ -48,9 +48,20 @@ public class Metric { */ protected static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS+00:00"; - protected static final String HOSTNAME = NetworkUtil.getHostname(); - protected static final String HOSTIP = NetworkUtil.getHostIp(); - protected static final String HOST_TYPE = "PDP-D"; + /** + * Host name. + */ + public static final String HOSTNAME = NetworkUtil.getHostname(); + + /** + * Host IP address. + */ + public static final String HOSTIP = NetworkUtil.getHostIp(); + + /** + * Host Type. + */ + public static final String HOST_TYPE = "PDP-D"; /* transaction inheritable fields */ @@ -88,6 +99,8 @@ public class Metric { private String customField3; private String customField4; + private boolean success = false; + /** * converts time to timestamp with format yyyy-MM-dd'T'HH:mm:ss.SSS+00:00. */ diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionConstants.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionConstants.java index 936449c8..1c98eacd 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionConstants.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionConstants.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-utils * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. 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. @@ -19,8 +19,6 @@ package org.onap.policy.drools.utils.logging; -import org.onap.policy.common.utils.network.NetworkUtil; - public class MdcTransactionConstants { /* * The fields must match the naming given at @@ -164,21 +162,6 @@ public class MdcTransactionConstants { public static final String CUSTOM_FIELD4 = "CustomField4"; /** - * Default Service Name. - */ - public static final String DEFAULT_SERVICE_NAME = "PDP-D"; - - /** - * Default Host Name. - */ - public static final String DEFAULT_HOSTNAME = NetworkUtil.getHostname(); - - /** - * Default Host IP. - */ - public static final String DEFAULT_HOSTIP = NetworkUtil.getHostIp(); - - /** * Status Code Complete. */ public static final String STATUS_CODE_COMPLETE = "COMPLETE"; diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java index fa3c0a58..f4f39edd 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/logging/MdcTransactionImpl.java @@ -26,9 +26,6 @@ import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.CUSTO import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.CUSTOM_FIELD2; import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.CUSTOM_FIELD3; import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.CUSTOM_FIELD4; -import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.DEFAULT_HOSTIP; -import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.DEFAULT_HOSTNAME; -import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.DEFAULT_SERVICE_NAME; import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.ELAPSED_TIME; import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.END_TIMESTAMP; import static org.onap.policy.drools.utils.logging.MdcTransactionConstants.INSTANCE_UUID; @@ -89,11 +86,11 @@ class MdcTransactionImpl implements MdcTransaction { setRequestId(requestId); setPartner(partner); - setServiceName(DEFAULT_SERVICE_NAME); - setServer(DEFAULT_HOSTNAME); - setServerIpAddress(DEFAULT_HOSTIP); - setServerFqdn(DEFAULT_HOSTNAME); - setVirtualServerName(DEFAULT_HOSTNAME); + setServiceName(Metric.HOST_TYPE); + setServer(Metric.HOSTNAME); + setServerIpAddress(Metric.HOSTIP); + setServerFqdn(Metric.HOSTNAME); + setVirtualServerName(Metric.HOSTNAME); setStartTime(Instant.now()); } @@ -203,12 +200,10 @@ class MdcTransactionImpl implements MdcTransaction { setMdc(BEGIN_TIMESTAMP, Metric.toTimestamp(execItem.getStartTime())); setMdc(END_TIMESTAMP, Metric.toTimestamp(execItem.getEndTime())); - if (execItem.getElapsedTime() != null) { - MDC.put(ELAPSED_TIME, String.valueOf(execItem.getElapsedTime())); - } else { + if (execItem.getElapsedTime() == null) { execItem.setElapsedTime(null); // this computes elapsed time appropriately with start and end times - MDC.put(ELAPSED_TIME, String.valueOf(execItem.getElapsedTime())); } + MDC.put(ELAPSED_TIME, String.valueOf(execItem.getElapsedTime())); setMdc(SERVICE_INSTANCE_ID, execItem.getServiceInstanceId()); setMdc(INSTANCE_UUID, execItem.getInstanceUuid()); @@ -377,11 +372,14 @@ class MdcTransactionImpl implements MdcTransaction { @Override public MdcTransaction setStatusCode(String statusCode) { execItem.setStatusCode(statusCode); + execItem.setSuccess(STATUS_CODE_COMPLETE.equals(execItem.getStatusCode())); return this; } @Override public MdcTransaction setStatusCode(boolean success) { + execItem.setSuccess(success); + if (success) { execItem.setStatusCode(STATUS_CODE_COMPLETE); } else { |