aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-node/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-node/src/main')
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java138
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java11
2 files changed, 80 insertions, 69 deletions
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 76bf04e2..c28827a0 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
@@ -38,7 +38,7 @@ import org.apache.log4j.Logger;
* the file and its delivery data as well as to attempt delivery.
*/
public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
- private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.DeliveryTask");
+ private static Logger loggerDeliveryTask = Logger.getLogger("org.onap.dmaap.datarouter.node.DeliveryTask");
private DeliveryTaskHelper dth;
private String pubid;
private DestInfo di;
@@ -56,36 +56,6 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
private int attempts;
private String[][] hdrs;
- /**
- * Is the object a DeliveryTask with the same publication ID?
- */
- public boolean equals(Object o) {
- if (!(o instanceof DeliveryTask)) {
- return (false);
- }
- return (pubid.equals(((DeliveryTask) o).pubid));
- }
-
- /**
- * Compare the publication IDs.
- */
- public int compareTo(DeliveryTask o) {
- return (pubid.compareTo(o.pubid));
- }
-
- /**
- * Get the hash code of the publication ID.
- */
- public int hashCode() {
- return (pubid.hashCode());
- }
-
- /**
- * Return the publication ID.
- */
- public String toString() {
- return (pubid);
- }
/**
* Create a delivery task for a given delivery queue and pub ID
@@ -110,38 +80,69 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
date = Long.parseLong(pubid.substring(0, pubid.indexOf('.')));
Vector<String[]> hdrv = new Vector<String[]>();
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();
- }
- 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(" .*", ""));
+ 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();
}
- if (length == 0 && h.toLowerCase().startsWith("content-")) {
- continue;
- }
- if (h.equalsIgnoreCase("content-type")) {
- ctype = v;
+ 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});
}
- hdrv.add(new String[]{h, v});
}
- br.close();
+
} catch (Exception e) {
+ loggerDeliveryTask.error("Exception "+e.getStackTrace(),e);
}
hdrs = hdrv.toArray(new String[hdrv.size()][]);
url = dth.getDestURL(fileid);
}
+ /**
+ * Is the object a DeliveryTask with the same publication ID?
+ */
+ public boolean equals(Object o) {
+ if (!(o instanceof DeliveryTask)) {
+ return (false);
+ }
+ return (pubid.equals(((DeliveryTask) o).pubid));
+ }
/**
+ * Compare the publication IDs.
+ */
+ public int compareTo(DeliveryTask o) {
+ return (pubid.compareTo(o.pubid));
+ }
+
+ /**
+ * Get the hash code of the publication ID.
+ */
+ public int hashCode() {
+ return (pubid.hashCode());
+ }
+
+ /**
+ * Return the publication ID.
+ */
+ public String toString() {
+ return (pubid);
+ }
+ /**
* Get the publish ID
*/
public String getPublishId() {
@@ -186,29 +187,33 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
} catch (ProtocolException pe) {
dth.reportDeliveryExtra(this, -1L);
// Rcvd error instead of 100-continue
+ loggerDeliveryTask.error("Exception "+pe.getStackTrace(),pe);
}
if (os != null) {
long sofar = 0;
try {
byte[] buf = new byte[1024 * 1024];
- 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);
+ 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);
}
- sofar += i;
- os.write(buf, 0, i);
+ is.close();
+ os.close();
}
- is.close();
- os.close();
+
} catch (IOException ioe) {
dth.reportDeliveryExtra(this, sofar);
throw ioe;
+
}
}
}
@@ -243,6 +248,7 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
}
dth.reportStatus(this, rc, xpubid, rmsg);
} catch (Exception e) {
+ loggerDeliveryTask.error("Exception "+e.getStackTrace(),e);
dth.reportException(this, e);
}
}
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java
index 7e3b4bff..35ba0951 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java
@@ -24,6 +24,8 @@
package org.onap.dmaap.datarouter.node;
+import org.apache.log4j.Logger;
+
import java.util.*;
import java.net.*;
@@ -34,6 +36,7 @@ public class IsFrom {
private long nextcheck;
private String[] ips;
private String fqdn;
+ private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.IsFrom");
/**
* Configure the JVM DNS cache to have a 10 second TTL. This needs to be called very very early or it won't have any effect.
@@ -59,18 +62,20 @@ public class IsFrom {
long now = System.currentTimeMillis();
if (now > nextcheck) {
nextcheck = now + 10000;
- Vector<String> v = new Vector<String>();
+ Vector<String> v = new Vector<>();
try {
InetAddress[] addrs = InetAddress.getAllByName(fqdn);
for (InetAddress a : addrs) {
v.add(a.getHostAddress());
}
- } catch (Exception e) {
+ } catch (UnknownHostException e) {
+ logger.debug("IsFrom: UnknownHostEx: " + e.toString(), e);
}
ips = v.toArray(new String[v.size()]);
+ logger.info("IsFrom: DNS ENTRIES FOR FQDN " + fqdn + " : " + Arrays.toString(ips));
}
for (String s : ips) {
- if (s.equals(ip)) {
+ if (s.equals(ip) || s.equals(System.getenv("DMAAP_DR_PROV_SERVICE_HOST"))) {
return (true);
}
}