From 107103a6e1f874baf6f423d834207b2de783e790 Mon Sep 17 00:00:00 2001 From: kishan Date: Sun, 13 Mar 2011 23:30:38 +0530 Subject: [PATCH] bug 7877: sync domR private Ip map independent of start/stop/migrate of router --- .../xen/resource/CitrixResourceBase.java | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 64b7a87ac23..a9513116b54 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -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 _domrIPMap = new ConcurrentHashMap(); + 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(); } + if (_domrSyncCount++ == 100) { + //Sync domr Ip Map, after every 100 calls + _domrSyncCount = 0; + _domrIPMap.clear(); + for (final Map.Entry 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 allVms= getAllVms(); - if (allVms != null) { - for (final Map.Entry 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;