From 9db07ee1eccc2be7a78e1d6434bf489e040d8cd1 Mon Sep 17 00:00:00 2001 From: "yong.you" Date: Mon, 16 Sep 2013 16:13:12 +0800 Subject: [PATCH] modify the cat time --- .../cat/hadoop/hdfs/UploaderAndCleaner.java | 63 +++++++++++-------- .../report/page/AbstractReportPayload.java | 2 +- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/cat-hadoop/src/main/java/com/dianping/cat/hadoop/hdfs/UploaderAndCleaner.java b/cat-hadoop/src/main/java/com/dianping/cat/hadoop/hdfs/UploaderAndCleaner.java index 0a4a244d5..bfc97b844 100644 --- a/cat-hadoop/src/main/java/com/dianping/cat/hadoop/hdfs/UploaderAndCleaner.java +++ b/cat-hadoop/src/main/java/com/dianping/cat/hadoop/hdfs/UploaderAndCleaner.java @@ -118,38 +118,47 @@ public class UploaderAndCleaner implements Initializable, Task, LogEnabled { } public void deleteOldReports() { - File reportDir = new File(m_reportBaseDir); - final List toRemovePaths = new ArrayList(); - Date date = new Date(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - final String today = sdf.format(date); - final String yesterday = sdf.format(new Date(date.getTime() - 24 * 60 * 60 * 1000L)); - - Scanners.forDir().scan(reportDir, new FileMatcher() { - @Override - public Direction matches(File base, String path) { - File file = new File(base, path); - if (file.isFile() && shouldDeleteReport(path)) { - toRemovePaths.add(path); + Transaction t = Cat.newTransaction("System", "DeleteReport"); + try { + File reportDir = new File(m_reportBaseDir); + final List toRemovePaths = new ArrayList(); + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + final String today = sdf.format(date); + final String yesterday = sdf.format(new Date(date.getTime() - 24 * 60 * 60 * 1000L)); + + Scanners.forDir().scan(reportDir, new FileMatcher() { + @Override + public Direction matches(File base, String path) { + File file = new File(base, path); + if (file.isFile() && shouldDeleteReport(path)) { + toRemovePaths.add(path); + } + return Direction.DOWN; } - return Direction.DOWN; - } - private boolean shouldDeleteReport(String path) { - if (path.indexOf(today) > -1 || path.indexOf(yesterday) > -1) { - return false; - } else { - return true; + private boolean shouldDeleteReport(String path) { + if (path.indexOf(today) > -1 || path.indexOf(yesterday) > -1) { + return false; + } else { + return true; + } } - } - }); - for (String path : toRemovePaths) { - File file = new File(m_reportBaseDir, path); + }); + for (String path : toRemovePaths) { + File file = new File(m_reportBaseDir, path); - file.delete(); - Cat.logEvent("System", "DeleteReport", Event.SUCCESS, file.getAbsolutePath()); + file.delete(); + Cat.logEvent("System", "DeleteReport", Event.SUCCESS, file.getAbsolutePath()); + } + removeEmptyDir(reportDir); + t.setStatus(Transaction.SUCCESS); + } catch (Exception e) { + Cat.logError(e); + t.setStatus(e); + } finally { + t.complete(); } - removeEmptyDir(reportDir); } private void removeEmptyDir(File baseFile) { diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/AbstractReportPayload.java b/cat-home/src/main/java/com/dianping/cat/report/page/AbstractReportPayload.java index 97d7d778a..59c57fcb4 100755 --- a/cat-home/src/main/java/com/dianping/cat/report/page/AbstractReportPayload.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/AbstractReportPayload.java @@ -162,7 +162,7 @@ public abstract class AbstractReportPayload implements ActionP } else { temp = m_date + (TimeUtil.ONE_HOUR * 24); } - cal.setTimeInMillis(temp-1); + cal.setTimeInMillis(temp); return cal.getTime(); } -- GitLab