Issue #2092 added purge results to plugin dao
Alternative purge methods that return the purge results Former-commit-id:92860b0cd7
[formerly26be5f79d7
] [formerly41f3b7436e
] [formerly4fcaedce46
[formerly41f3b7436e
[formerly 9e95df4e45e23d3283c5804eb71bff97e6e406ea]]] Former-commit-id:4fcaedce46
Former-commit-id: 596bf531686e451ebadb5b06e4ecce0f37d8c85c [formerly4112a4d969
] Former-commit-id:0a7062666e
This commit is contained in:
parent
7f410653ca
commit
355dd0ad43
2 changed files with 135 additions and 9 deletions
|
@ -113,6 +113,7 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
|
||||||
* PluginDataObject.
|
* PluginDataObject.
|
||||||
* May 16, 2013 1869 bsteffen Rewrite dataURI property mappings.
|
* May 16, 2013 1869 bsteffen Rewrite dataURI property mappings.
|
||||||
* Jun 11, 2013 2090 djohnson Separate the hdf5 purge by ref time for reuse.
|
* Jun 11, 2013 2090 djohnson Separate the hdf5 purge by ref time for reuse.
|
||||||
|
* Jun 11, 2013 2092 bclement Added purge results
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -699,6 +700,25 @@ public abstract class PluginDao extends CoreDao {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Result of purge for rule
|
||||||
|
*/
|
||||||
|
protected static class RuleResult {
|
||||||
|
public Set<Date> timesKept;
|
||||||
|
|
||||||
|
public Set<Date> timesPurged;
|
||||||
|
|
||||||
|
public int itemsDeletedForKey;
|
||||||
|
|
||||||
|
public RuleResult(Set<Date> timesKept, Set<Date> timesPurged,
|
||||||
|
int itemsDeletedForKey) {
|
||||||
|
this.timesKept = timesKept;
|
||||||
|
this.timesPurged = timesPurged;
|
||||||
|
this.itemsDeletedForKey = itemsDeletedForKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purges data according to purge criteria specified by the owning plugin
|
* Purges data according to purge criteria specified by the owning plugin
|
||||||
*
|
*
|
||||||
|
@ -706,14 +726,25 @@ public abstract class PluginDao extends CoreDao {
|
||||||
* If problems occur while interacting with data stores
|
* If problems occur while interacting with data stores
|
||||||
*/
|
*/
|
||||||
public void purgeExpiredData() throws PluginException {
|
public void purgeExpiredData() throws PluginException {
|
||||||
|
purgeExpiredDataWithResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purges data according to purge criteria specified by the owning plugin
|
||||||
|
*
|
||||||
|
* @throws PluginException
|
||||||
|
* If problems occur while interacting with data stores
|
||||||
|
*/
|
||||||
|
public PurgeResults purgeExpiredDataWithResults() throws PluginException {
|
||||||
try {
|
try {
|
||||||
PurgeRuleSet ruleSet = getPurgeRulesForPlugin(pluginName);
|
PurgeRuleSet ruleSet = getPurgeRulesForPlugin(pluginName);
|
||||||
|
Map<String, Set<Date>> timesKept = new HashMap<String, Set<Date>>();
|
||||||
|
Map<String, Set<Date>> timesPurged = new HashMap<String, Set<Date>>();
|
||||||
if (ruleSet == null) {
|
if (ruleSet == null) {
|
||||||
PurgeLogger.logInfo(
|
PurgeLogger.logInfo(
|
||||||
"No valid purge rules found. Skipping purge.",
|
"No valid purge rules found. Skipping purge.",
|
||||||
pluginName);
|
pluginName);
|
||||||
return;
|
return new PurgeResults(timesKept, timesPurged);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the database to get all possible product keys for this data
|
// Query the database to get all possible product keys for this data
|
||||||
|
@ -725,11 +756,17 @@ public abstract class PluginDao extends CoreDao {
|
||||||
String[][] distinctKeys = getDistinctProductKeyValues(ruleSet
|
String[][] distinctKeys = getDistinctProductKeyValues(ruleSet
|
||||||
.getKeys());
|
.getKeys());
|
||||||
for (String[] key : distinctKeys) {
|
for (String[] key : distinctKeys) {
|
||||||
totalItems += purgeExpiredKey(ruleSet, key);
|
RuleResult res = purgeExpiredKey(ruleSet, key);
|
||||||
|
timesKept.put(Arrays.toString(key), res.timesKept);
|
||||||
|
timesPurged.put(Arrays.toString(key), res.timesPurged);
|
||||||
|
totalItems += res.itemsDeletedForKey;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no rule keys defined, can only apply default rule
|
// no rule keys defined, can only apply default rule
|
||||||
totalItems += purgeExpiredKey(ruleSet, null);
|
RuleResult res = purgeExpiredKey(ruleSet, null);
|
||||||
|
timesKept.put("default", res.timesKept);
|
||||||
|
timesPurged.put("default", res.timesPurged);
|
||||||
|
totalItems += res.itemsDeletedForKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder messageBuffer = new StringBuilder();
|
StringBuilder messageBuffer = new StringBuilder();
|
||||||
|
@ -740,6 +777,7 @@ public abstract class PluginDao extends CoreDao {
|
||||||
messageBuffer.append(" total.");
|
messageBuffer.append(" total.");
|
||||||
|
|
||||||
PurgeLogger.logInfo(messageBuffer.toString(), pluginName);
|
PurgeLogger.logInfo(messageBuffer.toString(), pluginName);
|
||||||
|
return new PurgeResults(timesKept, timesPurged);
|
||||||
} catch (EdexException e) {
|
} catch (EdexException e) {
|
||||||
throw new PluginException("Error applying purge rule!!", e);
|
throw new PluginException("Error applying purge rule!!", e);
|
||||||
}
|
}
|
||||||
|
@ -751,10 +789,11 @@ public abstract class PluginDao extends CoreDao {
|
||||||
*
|
*
|
||||||
* @param ruleSet
|
* @param ruleSet
|
||||||
* @param purgeKeys
|
* @param purgeKeys
|
||||||
* @return Number of records purged
|
* @return Summary of purge for keys
|
||||||
* @throws DataAccessLayerException
|
* @throws DataAccessLayerException
|
||||||
*/
|
*/
|
||||||
protected int purgeExpiredKey(PurgeRuleSet ruleSet, String[] purgeKeys)
|
protected RuleResult purgeExpiredKey(PurgeRuleSet ruleSet,
|
||||||
|
String[] purgeKeys)
|
||||||
throws DataAccessLayerException {
|
throws DataAccessLayerException {
|
||||||
List<PurgeRule> rules = ruleSet.getRuleForKeys(purgeKeys);
|
List<PurgeRule> rules = ruleSet.getRuleForKeys(purgeKeys);
|
||||||
|
|
||||||
|
@ -762,7 +801,8 @@ public abstract class PluginDao extends CoreDao {
|
||||||
PurgeLogger.logWarn(
|
PurgeLogger.logWarn(
|
||||||
"No rules found for purgeKeys: "
|
"No rules found for purgeKeys: "
|
||||||
+ Arrays.toString(purgeKeys), pluginName);
|
+ Arrays.toString(purgeKeys), pluginName);
|
||||||
return 0;
|
return new RuleResult(Collections.<Date> emptySet(),
|
||||||
|
Collections.<Date> emptySet(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -828,7 +868,8 @@ public abstract class PluginDao extends CoreDao {
|
||||||
if (maxRefTime == null) {
|
if (maxRefTime == null) {
|
||||||
PurgeLogger.logInfo("No data available to purge",
|
PurgeLogger.logInfo("No data available to purge",
|
||||||
pluginName);
|
pluginName);
|
||||||
return 0;
|
return new RuleResult(Collections.<Date> emptySet(),
|
||||||
|
Collections.<Date> emptySet(), 0);
|
||||||
} else {
|
} else {
|
||||||
periodCutoffTime = new Date(maxRefTime.getTime()
|
periodCutoffTime = new Date(maxRefTime.getTime()
|
||||||
- rule.getPeriodInMillis());
|
- rule.getPeriodInMillis());
|
||||||
|
@ -1143,7 +1184,7 @@ public abstract class PluginDao extends CoreDao {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemsDeletedForKey;
|
return new RuleResult(timesKept, timesPurged, itemsDeletedForKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
// header placeholder 2a20 c8e1
|
||||||
|
package com.raytheon.uf.edex.database.plugin;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Summary of purge
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Jun 12, 2013 bclement Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author bclement
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class PurgeResults {
|
||||||
|
|
||||||
|
private Map<String, Set<Date>> timesKept;
|
||||||
|
|
||||||
|
private Map<String, Set<Date>> timesPurged;
|
||||||
|
|
||||||
|
public PurgeResults() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PurgeResults(Map<String, Set<Date>> timesKept,
|
||||||
|
Map<String, Set<Date>> timesPurged) {
|
||||||
|
this.timesKept = timesKept;
|
||||||
|
this.timesPurged = timesPurged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if any times were purged for any rule
|
||||||
|
*/
|
||||||
|
public boolean didPurge() {
|
||||||
|
if (timesPurged == null || timesPurged.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String key : timesPurged.keySet()) {
|
||||||
|
Set<Date> set = timesPurged.get(key);
|
||||||
|
if (!set.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the timesKept
|
||||||
|
*/
|
||||||
|
public Map<String, Set<Date>> getTimesKept() {
|
||||||
|
return timesKept;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param timesKept
|
||||||
|
* the timesKept to set
|
||||||
|
*/
|
||||||
|
public void setTimesKept(Map<String, Set<Date>> timesKept) {
|
||||||
|
this.timesKept = timesKept;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the timesPurged
|
||||||
|
*/
|
||||||
|
public Map<String, Set<Date>> getTimesPurged() {
|
||||||
|
return timesPurged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param timesPurged
|
||||||
|
* the timesPurged to set
|
||||||
|
*/
|
||||||
|
public void setTimesPurged(Map<String, Set<Date>> timesPurged) {
|
||||||
|
this.timesPurged = timesPurged;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue