X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FDeliveryTask.java;h=eb79b563d37dc75e640ac0f2e7a24c0607626e29;hp=2093d6d40d401cdb4cd549a70aaaec9ef5f1e167;hb=6c78b3e6a0a67c73f931337356a172cc69cee0e8;hpb=52c5c5ab9ba33755e26f06f41de608f825866a53 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 2093d6d4..eb79b563 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 @@ -39,6 +39,7 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.UUID; @@ -79,11 +80,11 @@ public class DeliveryTask implements Runnable, Comparable { /** - * Create a delivery task for a given delivery queue and pub ID + * Create a delivery task for a given delivery queue and pub ID. * * @param deliveryTaskHelper The delivery task helper for the queue this task is in. * @param pubid The publish ID for this file. This is used as the base for the file name in the spool directory and - * is of the form . + * is of the form (milliseconds since 1970).(fqdn of initial data router node) */ DeliveryTask(DeliveryTaskHelper deliveryTaskHelper, String pubid) { this.deliveryTaskHelper = deliveryTaskHelper; @@ -93,9 +94,9 @@ public class DeliveryTask implements Runnable, Comparable { this.followRedirects = destInfo.isFollowRedirects(); feedid = destInfo.getLogData(); spool = destInfo.getSpool(); - String dfn = spool + "/" + pubid; + String dfn = spool + File.separator + pubid; String mfn = dfn + ".M"; - datafile = new File(spool + "/" + pubid); + datafile = new File(spool + File.separator + pubid); metafile = new File(mfn); boolean monly = destInfo.isMetaDataOnly(); date = Long.parseLong(pubid.substring(0, pubid.indexOf('.'))); @@ -221,6 +222,7 @@ public class DeliveryTask implements Runnable, Comparable { byte[] buf = new byte[4096]; if (is != null) { while (is.read(buf) > 0) { + //flush the buffer } is.close(); } @@ -241,7 +243,7 @@ public class DeliveryTask implements Runnable, Comparable { httpURLConnection.setRequestProperty(DECOMPRESSION_STATUS, "SUCCESS"); OutputStream outputStream = getOutputStream(httpURLConnection); if (outputStream != null) { - int bytesRead = 0; + int bytesRead; try (InputStream gzipInputStream = new GZIPInputStream(new FileInputStream(datafile))) { int bufferLength = buffer.length; while ((bytesRead = gzipInputStream.read(buffer, 0, bufferLength)) > 0) { @@ -295,7 +297,7 @@ public class DeliveryTask implements Runnable, Comparable { * @param httpURLConnection connection used to make request * @return AN Outpustream that can be used to send your data. */ - private OutputStream getOutputStream(HttpURLConnection httpURLConnection) throws IOException { + OutputStream getOutputStream(HttpURLConnection httpURLConnection) throws IOException { OutputStream outputStream = null; try { outputStream = httpURLConnection.getOutputStream(); @@ -355,13 +357,28 @@ public class DeliveryTask implements Runnable, Comparable { * Remove meta and data files. */ void clean() { - datafile.delete(); - metafile.delete(); + deleteWithRetry(datafile); + deleteWithRetry(metafile); eelfLogger.info(EelfMsgs.INVOKE, newInvocationId); eelfLogger.info(EelfMsgs.EXIT); hdrs = null; } + private void deleteWithRetry(File file) { + int maxTries = 3; + int tryCount = 1; + while (tryCount <= maxTries) { + try { + Files.deleteIfExists(file.toPath()); + break; + } catch (IOException e) { + eelfLogger.error("IOException : Failed to delete file :" + + file.getName() + " on attempt " + tryCount, e); + } + tryCount++; + } + } + /** * Get the resume time for a delivery task. */ @@ -449,7 +466,7 @@ public class DeliveryTask implements Runnable, Comparable { /** * Get the followRedirects for this delivery task. */ - public boolean getFollowRedirects() { + boolean getFollowRedirects() { return (followRedirects); } }