Add RequestId and InvocationId to DR
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / DeliveryTask.java
index 7e10d5a..4d570b5 100644 (file)
@@ -28,7 +28,13 @@ import java.io.*;
 import java.net.*;
 import java.util.*;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import org.apache.log4j.Logger;
+import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
+import org.slf4j.MDC;
+
+import static com.att.eelf.configuration.Configuration.*;
 
 /**
  * A file to be delivered to a destination.
@@ -39,6 +45,8 @@ import org.apache.log4j.Logger;
  */
 public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
     private static Logger loggerDeliveryTask = Logger.getLogger("org.onap.dmaap.datarouter.node.DeliveryTask");
+    private static EELFLogger eelflogger = EELFManager.getInstance()
+            .getLogger(DeliveryTask.class);
     private DeliveryTaskHelper dth;
     private String pubid;
     private DestInfo di;
@@ -55,6 +63,7 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
     private String subid;
     private int attempts;
     private String[][] hdrs;
+    private String newInvocationId;
 
 
     /**
@@ -84,6 +93,7 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
             String s = br.readLine();
             int i = s.indexOf('\t');
             method = s.substring(0, i);
+            NodeUtils.setIpAndFqdnForEelf(method);
             if (!"DELETE".equals(method) && !monly) {
                 length = datafile.length();
             }
@@ -102,6 +112,14 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
                 if (h.equalsIgnoreCase("content-type")) {
                     ctype = v;
                 }
+                if (h.equalsIgnoreCase("x-onap-requestid")) {
+                    MDC.put(MDC_KEY_REQUEST_ID, v);
+                }
+                if (h.equalsIgnoreCase("x-invocationid")) {
+                    MDC.put("InvocationId", v);
+                    v = UUID.randomUUID().toString();
+                    newInvocationId = v;
+                }
                 hdrv.add(new String[]{h, v});
             }
         } catch (Exception e) {
@@ -252,6 +270,8 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
     public void clean() {
         datafile.delete();
         metafile.delete();
+        eelflogger.info(EelfMsgs.INVOKE, newInvocationId);
+        eelflogger.info(EelfMsgs.EXIT);
         hdrs = null;
     }