bug 7877: sync domR private Ip map independent of start/stop/migrate of router

This commit is contained in:
kishan 2011-03-13 23:30:38 +05:30
parent f7dd5f9216
commit 107103a6e1
1 changed files with 14 additions and 24 deletions

View File

@ -41,9 +41,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
@ -174,7 +171,6 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.Script;
@ -241,8 +237,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
protected String _instance; //instance name (default is usually "VM")
protected IAgentControl _agentControl;
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterIpSync"));
protected Map<String, String> _domrIPMap = new ConcurrentHashMap<String, String>();
protected int _domrSyncCount = 0;
protected final XenServerHost _host = new XenServerHost();
@ -2847,6 +2843,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
networkUsage(router.getPrivateIpAddress(), "create", null);
return new StartRouterAnswer(cmd);
}
_domrIPMap.put(cmd.getVmName(), router.getPrivateIpAddress());
return new StartRouterAnswer(cmd, result);
} catch (Exception e) {
@ -3504,6 +3501,18 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
if (newStates == null) {
newStates = new HashMap<String, State>();
}
if (_domrSyncCount++ == 100) {
//Sync domr Ip Map, after every 100 calls
_domrSyncCount = 0;
_domrIPMap.clear();
for (final Map.Entry<String, State> entry : newStates.entrySet()) {
final String vm = entry.getKey();
State state = entry.getValue();
if (VirtualMachineName.isValidRouterName(vm) && (state == State.Running)) {
addDomRIpToMap(vm);
}
}
}
if (!_canBridgeFirewall) {
return new PingRoutingCommand(getType(), id, newStates);
} else {
@ -3842,7 +3851,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
cmd.setHypervisorType(Hypervisor.Type.XenServer);
cmd.setChanges(changes);
cmd.setCluster(_cluster);
_executor.scheduleAtFixedRate(new RouterIpSyncTask(), 60, 60, TimeUnit.MINUTES);
StartupStorageCommand sscmd = initializeLocalSR();
if (sscmd != null) {
@ -6158,24 +6166,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
}
protected class RouterIpSyncTask implements Runnable {
@Override
public void run() {
_domrIPMap.clear();
HashMap<String, State> allVms= getAllVms();
if (allVms != null) {
for (final Map.Entry<String, State> entry : allVms.entrySet()) {
final String vm = entry.getKey();
State state = entry.getValue();
if (VirtualMachineName.isValidRouterName(vm) && (state == State.Running)) {
addDomRIpToMap(vm);
}
}
}
}
}
protected class Nic {
public Network n;
public Network.Record nr;