X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FDeliveryTask.java;h=4d570b555a60b3bb4fc88b902ca1ce6ea78ea445;hb=14b8d9552808063686e0c22760cec6e35b960b59;hp=c28827a0dd51fd8ab8dc8a7f23bbc91f32ffd88a;hpb=7b241efd903a927456c0d04b71887225e3755844;p=dmaap%2Fdatarouter.git diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java index c28827a0..4d570b55 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java @@ -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 { 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 { private String subid; private int attempts; private String[][] hdrs; + private String newInvocationId; /** @@ -79,33 +88,40 @@ public class DeliveryTask implements Runnable, Comparable { boolean monly = di.isMetaDataOnly(); date = Long.parseLong(pubid.substring(0, pubid.indexOf('.'))); Vector hdrv = new Vector(); - try { - try(BufferedReader br = new BufferedReader(new FileReader(metafile))){ - String s = br.readLine(); - int i = s.indexOf('\t'); - method = s.substring(0, i); - if (!"DELETE".equals(method) && !monly) { - length = datafile.length(); + + try (BufferedReader br = new BufferedReader(new FileReader(metafile))) { + 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(); + } + fileid = s.substring(i + 1); + while ((s = br.readLine()) != null) { + i = s.indexOf('\t'); + String h = s.substring(0, i); + String v = s.substring(i + 1); + if ("x-att-dr-routing".equalsIgnoreCase(h)) { + subid = v.replaceAll("[^ ]*/", ""); + feedid = dth.getFeedId(subid.replaceAll(" .*", "")); } - fileid = s.substring(i + 1); - while ((s = br.readLine()) != null) { - i = s.indexOf('\t'); - String h = s.substring(0, i); - String v = s.substring(i + 1); - if ("x-att-dr-routing".equalsIgnoreCase(h)) { - subid = v.replaceAll("[^ ]*/", ""); - feedid = dth.getFeedId(subid.replaceAll(" .*", "")); - } - if (length == 0 && h.toLowerCase().startsWith("content-")) { - continue; - } - if (h.equalsIgnoreCase("content-type")) { - ctype = v; - } - hdrv.add(new String[]{h, v}); + if (length == 0 && h.toLowerCase().startsWith("content-")) { + continue; + } + 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) { loggerDeliveryTask.error("Exception "+e.getStackTrace(),e); } @@ -191,29 +207,24 @@ public class DeliveryTask implements Runnable, Comparable { } if (os != null) { long sofar = 0; - try { + try (InputStream is = new FileInputStream(datafile)) { byte[] buf = new byte[1024 * 1024]; - try(InputStream is = new FileInputStream(datafile)){ - while (sofar < length) { - int i = buf.length; - if (sofar + i > length) { - i = (int) (length - sofar); - } - i = is.read(buf, 0, i); - if (i <= 0) { - throw new IOException("Unexpected problem reading data file " + datafile); - } - sofar += i; - os.write(buf, 0, i); + while (sofar < length) { + int i = buf.length; + if (sofar + i > length) { + i = (int) (length - sofar); + } + i = is.read(buf, 0, i); + if (i <= 0) { + throw new IOException("Unexpected problem reading data file " + datafile); } - is.close(); - os.close(); + sofar += i; + os.write(buf, 0, i); } - + os.close(); } catch (IOException ioe) { dth.reportDeliveryExtra(this, sofar); throw ioe; - } } } @@ -259,6 +270,8 @@ public class DeliveryTask implements Runnable, Comparable { public void clean() { datafile.delete(); metafile.delete(); + eelflogger.info(EelfMsgs.INVOKE, newInvocationId); + eelflogger.info(EelfMsgs.EXIT); hdrs = null; }