move interval to listener -- allows it to be configurable if needed

This commit is contained in:
Chiradeep Vittal 2011-09-07 11:08:07 -07:00
parent 22c1e66a6c
commit fbfb1b8f5b
2 changed files with 8 additions and 7 deletions

View File

@ -17,12 +17,9 @@
*/
package com.cloud.agent.api;
import java.util.Random;
public class CleanupNetworkRulesCmd extends Command implements CronCommand {
static private Random random = new Random();
private int interval = 10*60;
@Override
@ -31,9 +28,9 @@ public class CleanupNetworkRulesCmd extends Command implements CronCommand {
}
public CleanupNetworkRulesCmd() {
public CleanupNetworkRulesCmd(int intervalSecs) {
super();
interval = 8*60 + random.nextInt(120);
interval = intervalSecs;
}

View File

@ -20,6 +20,7 @@ package com.cloud.network.security;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.log4j.Logger;
@ -51,6 +52,8 @@ public class SecurityGroupListener implements Listener {
public static final Logger s_logger = Logger.getLogger(SecurityGroupListener.class.getName());
private static final int MAX_RETRIES_ON_FAILURE = 3;
private static final int MIN_TIME_BETWEEN_CLEANUPS = 30*60;//30 minutes
private final Random _cleanupRandom = new Random();
SecurityGroupManagerImpl _securityGroupManager;
AgentManager _agentMgr;
@ -158,14 +161,15 @@ public class SecurityGroupListener implements Listener {
if (cmd instanceof StartupRoutingCommand) {
//if (Boolean.toString(true).equals(host.getDetail("can_bridge_firewall"))) {
try {
CleanupNetworkRulesCmd cleanupCmd = new CleanupNetworkRulesCmd();
int interval = MIN_TIME_BETWEEN_CLEANUPS + _cleanupRandom.nextInt(MIN_TIME_BETWEEN_CLEANUPS/2);
CleanupNetworkRulesCmd cleanupCmd = new CleanupNetworkRulesCmd(interval);
Commands c = new Commands(cleanupCmd);
_agentMgr.send(host.getId(), c, this);
if(s_logger.isInfoEnabled())
s_logger.info("Scheduled network rules cleanup, interval=" + cleanupCmd.getInterval());
} catch (AgentUnavailableException e) {
//usually hypervisors that do not understand sec group rules.
s_logger.info("Unable to schedule network rules cleanup for host " + host.getId(), e);
s_logger.debug("Unable to schedule network rules cleanup for host " + host.getId(), e);
}
}
}