From 12e22752c214d383569077863fd23b21f49f8e69 Mon Sep 17 00:00:00 2001 From: Brad Gonzales Date: Thu, 20 Feb 2014 14:22:44 -0600 Subject: [PATCH] Issue #2828 Added purge cron to Central SBN Simulator. Amend: Removed comment accidentally merged from other branch. Moved logging to outer loop and log count of purged files for each dir. Change-Id: I7038e7f76d09576903d35a54e733cd6986a4d1c6 Former-commit-id: 6a42f4162ace5a799df4df0e24bf0199905dcf89 --- .../res/spring/sbn-simulator-ncf.xml | 24 +++++++++++- .../resources/sbnSimulator.properties | 6 ++- .../bandwidth/sbn/SbnSimulator.java | 38 ++++++++++++++++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/res/spring/sbn-simulator-ncf.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/res/spring/sbn-simulator-ncf.xml index 2697d372c8..29bacf1dec 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/res/spring/sbn-simulator-ncf.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/res/spring/sbn-simulator-ncf.xml @@ -3,8 +3,10 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> - + + + @@ -12,6 +14,9 @@ + + @@ -25,6 +30,21 @@ + + + + + + + + + java.lang.Throwable + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/resources/sbnSimulator.properties b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/resources/sbnSimulator.properties index aa40f2458d..d1e16cb9b8 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/resources/sbnSimulator.properties +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/resources/sbnSimulator.properties @@ -1,2 +1,6 @@ # How often to check for dropped off SBN data -sbnSimulator-checkForSbnData.cron=0+*+*+*+*+? \ No newline at end of file +sbnSimulator-checkForSbnData.cron=0+*+*+*+*+? +# cron to Purge old SBN data files +sbnSimulator-sbnDataPurge.cron=0+0+0/2+*+*+? +# age in milliseconds that sbn data files should be removed +sbnSimulator-fileExpirationInMilliseconds=7200000 \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/sbn/SbnSimulator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/sbn/SbnSimulator.java index f01563cf23..2d4980ef02 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/sbn/SbnSimulator.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth.ncf/src/com/raytheon/uf/edex/datadelivery/bandwidth/sbn/SbnSimulator.java @@ -43,6 +43,7 @@ import com.raytheon.uf.edex.core.EDEXUtil; * ------------ ---------- ----------- -------------------------- * Mar 14, 2013 1648 djohnson Initial creation * Oct 18, 2013 2267 bgonzale Added distribution to and check in site specific directories. + * Feb 13, 2014 2828 bgonzale Add purge method. * * * @@ -94,6 +95,8 @@ public class SbnSimulator { private String site; + private long fileExpirationInMilliseconds; + /** * Private constructor. */ @@ -151,8 +154,7 @@ public class SbnSimulator { */ public void distributeToSiteDirs() throws IOException { final List undistributedFiles = FileUtil.listFiles( - directoryToScan, - FilenameFilters.ACCEPT_FILES, false); + directoryToScan, FilenameFilters.ACCEPT_FILES, false); // get list of site dirs final List sites = FileUtil.listFiles(sitesDirectory, FilenameFilters.ACCEPT_DIRECTORIES, false); @@ -178,6 +180,38 @@ public class SbnSimulator { } } + /** + * Purge Sbn simulator data files that are older than the given expiration + * time. + */ + public void purgeSbnSimulatorFiles() { + final List siteDirectories = FileUtil.listFiles(sitesDirectory, + FilenameFilters.ACCEPT_DIRECTORIES, false); + + for (File siteDir : siteDirectories) { + final List filesInDir = FileUtil.listFiles(siteDir, + FilenameFilters.ACCEPT_FILES, false); + int fileCount = 0; + + for (File file : filesInDir) { + if (System.currentTimeMillis() - file.lastModified() > fileExpirationInMilliseconds) { + if (file.delete()) { + ++fileCount; + } + } + } + statusHandler.info("purged " + fileCount + + " sbn simulation data file(s) in " + siteDir); + } + } + + /** + * @param fileExpirationInMilliseconds the fileExpirationInMilliseconds to set + */ + public void setFileExpirationInMilliseconds(long fileExpirationInMilliseconds) { + this.fileExpirationInMilliseconds = fileExpirationInMilliseconds; + } + // TODO Java 1.7 version of the distributeToSiteDirs() method // /** // * Distribute to the site directories. Enables all site client registries