From 6e72186116c333fae33bf103eb1f4fca692f17c9 Mon Sep 17 00:00:00 2001 From: efiacor Date: Wed, 26 Jun 2019 10:04:13 +0000 Subject: Adding more robust file deletion Change-Id: I39675f77c101e55f6a8eba18cabb5f282081d032 Issue-ID: DMAAP-1212 Signed-off-by: efiacor --- .../org/onap/dmaap/datarouter/node/DeliveryTask.java | 19 +++++++++++++++++-- 1 file 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 { * 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. */ -- cgit 1.2.3-korg