Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2016-07-21 15:56:22 +0000
committerRyan D. Brooks2016-08-31 16:17:46 +0000
commitefd216d8a8b59d075f1d754edf1c482adc228dfc (patch)
tree9fff54e5914f21dfd4a096b37e70895316e9c7b8
parentefae4306117421e2aa3231d57583e55bb8c16f28 (diff)
downloadorg.eclipse.osee-efd216d8a8b59d075f1d754edf1c482adc228dfc.tar.gz
org.eclipse.osee-efd216d8a8b59d075f1d754edf1c482adc228dfc.tar.xz
org.eclipse.osee-efd216d8a8b59d075f1d754edf1c482adc228dfc.zip
feature[ats_ATS289001]: Create evicting strategy for ActivityLog data
-rw-r--r--plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityConstants.java3
-rw-r--r--plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityStorage.java2
-rw-r--r--plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/ActivityLogImpl.java40
-rw-r--r--plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/DatabaseActivityStorage.java13
4 files changed, 58 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityConstants.java b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityConstants.java
index 4c39959fa1..1b72e88566 100644
--- a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityConstants.java
+++ b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityConstants.java
@@ -26,15 +26,18 @@ public final class ActivityConstants {
}
public static String ACTIVITY_LOGGER__EXECUTOR_ID = qualify("executor");
+ public static String ACTIVITY_LOGGER__CLEANER_EXECUTOR_ID = qualify("cleaner");
public static String ACTIVITY_LOGGER__WRITE_RATE_IN_MILLIS = qualify("write.rate.millis");
public static String ACTIVITY_LOGGER__STACKTRACE_LINE_COUNT = qualify("stacktrace.line.count");
public static String ACTIVITY_LOGGER__EXECUTOR_POOL_SIZE = qualify("executor.pool.size");
+ public static String ACTIVITY_LOGGER__CLEANER_KEEP_DAYS = qualify("cleaner.keep.days");
public static String ACTIVITY_LOGGER__ENABLED = qualify("enabled");
public static long DEFAULT_ACTIVITY_LOGGER__WRITE_RATE_IN_MILLIS = 3000L;
public static int DEFAULT_ACTIVITY_LOGGER__STACKTRACE_LINE_COUNT = 5;
public static int DEFAULT_ACTIVITY_LOGGER__EXECUTOR_POOL_SIZE = 1;
+ public static int DEFAULT_ACTIVITY_LOGGER__CLEANER_KEEP_DAYS = 30;
public static boolean DEFAULT_ACTIVITY_LOGGER__ENABLED = true;
public static final String HTTP_HEADER__ACTIVITY_ENTRY_ID = "X-osee-activity-log-entryId";
diff --git a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityStorage.java b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityStorage.java
index 495c2557ee..051576faba 100644
--- a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityStorage.java
+++ b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/ActivityStorage.java
@@ -35,4 +35,6 @@ public interface ActivityStorage {
boolean typeExists(Long typeId);
+ void cleanEntries(int daysToKeep);
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/ActivityLogImpl.java b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/ActivityLogImpl.java
index 781842f6dc..70742343a8 100644
--- a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/ActivityLogImpl.java
+++ b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/ActivityLogImpl.java
@@ -10,20 +10,26 @@
*******************************************************************************/
package org.eclipse.osee.activity.internal;
+import static org.eclipse.osee.activity.ActivityConstants.ACTIVITY_LOGGER__CLEANER_EXECUTOR_ID;
+import static org.eclipse.osee.activity.ActivityConstants.ACTIVITY_LOGGER__CLEANER_KEEP_DAYS;
import static org.eclipse.osee.activity.ActivityConstants.ACTIVITY_LOGGER__ENABLED;
import static org.eclipse.osee.activity.ActivityConstants.ACTIVITY_LOGGER__EXECUTOR_ID;
import static org.eclipse.osee.activity.ActivityConstants.ACTIVITY_LOGGER__EXECUTOR_POOL_SIZE;
import static org.eclipse.osee.activity.ActivityConstants.ACTIVITY_LOGGER__STACKTRACE_LINE_COUNT;
import static org.eclipse.osee.activity.ActivityConstants.ACTIVITY_LOGGER__WRITE_RATE_IN_MILLIS;
+import static org.eclipse.osee.activity.ActivityConstants.DEFAULT_ACTIVITY_LOGGER__CLEANER_KEEP_DAYS;
import static org.eclipse.osee.activity.ActivityConstants.DEFAULT_ACTIVITY_LOGGER__EXECUTOR_POOL_SIZE;
import static org.eclipse.osee.activity.ActivityConstants.DEFAULT_ACTIVITY_LOGGER__STACKTRACE_LINE_COUNT;
import static org.eclipse.osee.activity.ActivityConstants.DEFAULT_ACTIVITY_LOGGER__WRITE_RATE_IN_MILLIS;
import static org.eclipse.osee.activity.internal.ActivityUtil.captureStackTrace;
import static org.eclipse.osee.activity.internal.ActivityUtil.get;
+import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
+import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.osee.activity.ActivityConstants;
import org.eclipse.osee.activity.ActivityStorage;
@@ -79,6 +85,7 @@ public class ActivityLogImpl implements ActivityLog, Callable<Void> {
private volatile int exceptionLineCount;
private volatile int executorPoolSize;
private volatile long lastFlushTime;
+ private volatile int cleanerKeepDays;
private volatile boolean enabled = ActivityConstants.DEFAULT_ACTIVITY_LOGGER__ENABLED;
public void setLogger(Log logger) {
@@ -118,6 +125,7 @@ public class ActivityLogImpl implements ActivityLog, Callable<Void> {
exceptionLineCount = get(properties, ACTIVITY_LOGGER__STACKTRACE_LINE_COUNT, DEFAULT_ACTIVITY_LOGGER__STACKTRACE_LINE_COUNT);
int newExecutorPoolSize = get(properties, ACTIVITY_LOGGER__EXECUTOR_POOL_SIZE, DEFAULT_ACTIVITY_LOGGER__EXECUTOR_POOL_SIZE);
String value = (String)properties.get(ACTIVITY_LOGGER__ENABLED);
+ int newCleanerKeepDays = get(properties, ACTIVITY_LOGGER__CLEANER_KEEP_DAYS, DEFAULT_ACTIVITY_LOGGER__CLEANER_KEEP_DAYS);
if (Strings.isValid(value)) {
enabled = Boolean.valueOf(value);
}
@@ -137,6 +145,38 @@ public class ActivityLogImpl implements ActivityLog, Callable<Void> {
}
}
}
+ if (newCleanerKeepDays != cleanerKeepDays) {
+ cleanerKeepDays = newCleanerKeepDays;
+ setupCleaner();
+ }
+ }
+
+ private void setupCleaner() {
+ Callable<Void> cleaner = new Callable<Void>() {
+
+ @Override
+ public Void call() throws Exception {
+ storage.cleanEntries(cleanerKeepDays);
+ return null;
+ }
+ };
+
+ // randomly pick a start time around midnight
+ Random random = new Random();
+ Calendar start = Calendar.getInstance();
+ start.set(Calendar.HOUR_OF_DAY, random.nextInt(4));
+ start.set(Calendar.MINUTE, random.nextInt(180));
+ int day = start.get(Calendar.DAY_OF_YEAR);
+ start.set(Calendar.DAY_OF_YEAR, day + 1);
+
+ long startMil = start.getTimeInMillis();
+ long curMil = System.currentTimeMillis();
+ long startAfter = TimeUnit.MILLISECONDS.toMinutes(startMil - curMil);
+
+ // run once a day
+ executorAdmin.shutdown(ACTIVITY_LOGGER__CLEANER_EXECUTOR_ID);
+ executorAdmin.scheduleAtFixedRate(ACTIVITY_LOGGER__CLEANER_EXECUTOR_ID, cleaner, startAfter, 60 * 24,
+ TimeUnit.MINUTES);
}
@Override
diff --git a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/DatabaseActivityStorage.java b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/DatabaseActivityStorage.java
index 52522d205d..d9575015e5 100644
--- a/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/DatabaseActivityStorage.java
+++ b/plugins/org.eclipse.osee.activity/src/org/eclipse/osee/activity/internal/DatabaseActivityStorage.java
@@ -11,6 +11,7 @@
package org.eclipse.osee.activity.internal;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.function.Consumer;
import org.eclipse.osee.activity.ActivityStorage;
import org.eclipse.osee.activity.api.ActivityLog.ActivityDataHandler;
@@ -41,6 +42,8 @@ public class DatabaseActivityStorage implements ActivityStorage {
private static final String COUNT_TYPE = "SELECT count(1) FROM osee_activity_type WHERE type_id = ?";
+ private static final String DELETE_ENTRIES = "DELETE FROM osee_activity WHERE start_time <= ?";
+
private static class ActivityEntryProcessor implements Consumer<JdbcStatement> {
private final ActivityDataHandler handler;
@@ -146,4 +149,14 @@ public class DatabaseActivityStorage implements ActivityStorage {
return getJdbcClient().fetch(-1L, COUNT_TYPE, typeId) > 0;
}
+ @Override
+ public void cleanEntries(int daysToKeep) {
+ Calendar cal = Calendar.getInstance();
+ if (daysToKeep > 0) {
+ daysToKeep = -daysToKeep;
+ }
+ cal.add(Calendar.DATE, daysToKeep);
+ getJdbcClient().runPreparedUpdate(DELETE_ENTRIES, cal.getTimeInMillis());
+ }
+
} \ No newline at end of file

Back to the top