diff options
author | efiacor <fiachra.corcoran@est.tech> | 2019-06-26 10:04:13 +0000 |
---|---|---|
committer | Fiachra Corcoran <fiachra.corcoran@est.tech> | 2019-06-26 10:32:34 +0000 |
commit | 6e72186116c333fae33bf103eb1f4fca692f17c9 (patch) | |
tree | f200299cb30e38252627473904d991943874884a /datarouter-node/src | |
parent | cf55456bbe6ce4da723f9dfa64b573f02908ab24 (diff) |
Adding more robust file deletion
Change-Id: I39675f77c101e55f6a8eba18cabb5f282081d032
Issue-ID: DMAAP-1212
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Diffstat (limited to 'datarouter-node/src')
-rw-r--r-- | datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java | 19 |
1 files changed, 17 insertions, 2 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 bbd13912..91bd716b 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; @@ -355,13 +356,27 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> { * 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. */ |