X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=appc-oam%2Fappc-oam-bundle%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fappc%2Foam%2Fprocessor%2FBaseCommon.java;h=ccb57305af844e8c50b123cffdec419a4476affc;hb=6b4baf891625c8b5f7635c8c2a1d9f599f57950c;hp=cc725e7b91956e7ed19fd4eea7b7364d89e8f2a8;hpb=db75c0a0b305c86429a6940de4d56870d3daf5bf;p=appc.git diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java index cc725e7b9..ccb57305a 100644 --- a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java +++ b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java @@ -43,7 +43,11 @@ import org.openecomp.appc.oam.util.StateHelper; import org.slf4j.MDC; import java.net.InetAddress; +import java.util.Arrays; import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID; import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; @@ -69,6 +73,18 @@ abstract class BaseCommon { AppcOam.RPC rpc; CommonHeader commonHeader; + private final List MDC_KEYS = Arrays.asList( + LoggingConstants.MDCKeys.PARTNER_NAME, + LoggingConstants.MDCKeys.SERVER_NAME, + MDC_INSTANCE_UUID, + MDC_KEY_REQUEST_ID, + MDC_SERVER_FQDN, + MDC_SERVER_IP_ADDRESS, + MDC_SERVICE_NAME + ); + + private Map oldMdcContent = new HashMap<>(); + /** * Constructor * @@ -137,6 +153,32 @@ abstract class BaseCommon { } } + /** + * Reset MDC log properties based on passed in condition. does:
+ * - persist existing MDC setting and set my MDC log properties
+ * - or re-apply persisted MDC log properties + * @param useMdcMap boolean to indicate whether to persist the existing MDC setting and set my MDC log properties, + * or to re-apply the persisted MDC log properties. + */ + void resetLogProperties(boolean useMdcMap) { + if (useMdcMap) { + for (Map.Entry aEntry : oldMdcContent.entrySet()) { + MDC.put(aEntry.getKey(), aEntry.getValue()); + } + return; + } + + // persist existing log properties and set my log properties + oldMdcContent.clear(); + for (String key : MDC_KEYS) { + String value = MDC.get(key); + if (value != null) { + oldMdcContent.put(key, value); + } + } + setInitialLogProperties(); + } + /** * Set class status by calling setStatus(OAMCommandStatus, Params) with null paramter. * @see #setStatus(OAMCommandStatus, String) @@ -170,9 +212,11 @@ abstract class BaseCommon { /** * Set class status with error status calculated from the passed in paremeter * and audit log the error message. - * @param t of the erro Throwable. + * @param t of the error Throwable. */ void setErrorStatus(Throwable t) { + resetLogProperties(false); + final String appName = configurationHelper.getAppcName(); String exceptionMessage = t.getMessage() != null ? t.getMessage() : t.toString(); @@ -201,6 +245,8 @@ abstract class BaseCommon { LoggingConstants.TargetNames.APPC_OAM_PROVIDER, errorMessage, AppcOam.class.getCanonicalName()); + + resetLogProperties(true); } /**