diff --git a/api/src/com/cloud/agent/api/ClusterSyncAnswer.java b/api/src/com/cloud/agent/api/ClusterSyncAnswer.java index d3ea9452016..d82701edcda 100644 --- a/api/src/com/cloud/agent/api/ClusterSyncAnswer.java +++ b/api/src/com/cloud/agent/api/ClusterSyncAnswer.java @@ -25,8 +25,9 @@ import com.cloud.vm.VirtualMachine.State; public class ClusterSyncAnswer extends Answer { private long _clusterId; private HashMap> _newStates; + private HashMap> _allStates; private int _type = -1; // 0 for full, 1 for delta - private boolean isExecuted=false; // this is to avoidf double execution first time, due to framework ??? + private boolean isExecuted=false; // this is to avoid double execution first time, due to framework ??? public static final int FULL_SYNC=0; @@ -39,10 +40,19 @@ public class ClusterSyncAnswer extends Answer { _type = -1; } - public ClusterSyncAnswer(long clusterId, HashMap> newStates, int type){ + + public ClusterSyncAnswer(long clusterId, HashMap> newStates){ _clusterId = clusterId; _newStates = newStates; - _type = type; + _type = DELTA_SYNC; + result = true; + } + + public ClusterSyncAnswer(long clusterId, HashMap> newStates, HashMap> allStates){ + _clusterId = clusterId; + _newStates = newStates; + _allStates = allStates; + _type = FULL_SYNC; result = true; } @@ -53,6 +63,10 @@ public class ClusterSyncAnswer extends Answer { public HashMap> getNewStates() { return _newStates; } + + public HashMap> getAllStates() { + return _allStates; + } public boolean isFull(){ return _type==0; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 1d87cda09db..18e837564ec 100755 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -6451,6 +6451,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } + protected Answer execute(final ClusterSyncCommand cmd) { Connection conn = getConnection(); //check if this is master @@ -6461,32 +6462,26 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe Host.Record hostr = poolr.master.getRecord(conn); if (!_host.uuid.equals(hostr.uuid)) { - s_logger.debug("Not the master node so just return ok: " + _host.ip); return new ClusterSyncAnswer(cmd.getClusterId()); } } catch (Exception e) { s_logger.warn("Check for master failed, failing the Cluster sync command"); return new ClusterSyncAnswer(cmd.getClusterId()); } - HashMap> newStates; - int sync_type=-1; + HashMap> newStates = deltaClusterSync(conn); if (cmd.isRightStep()){ // do full sync - newStates=fullClusterSync(conn); - sync_type = ClusterSyncAnswer.FULL_SYNC; + HashMap> allStates=fullClusterSync(conn); + cmd.incrStep(); + return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates); } else { - // do delta sync - newStates = deltaClusterSync(conn); - if (newStates == null) { - s_logger.warn("Unable to get current status from sync"); - } - sync_type = ClusterSyncAnswer.DELTA_SYNC; + cmd.incrStep(); + return new ClusterSyncAnswer(cmd.getClusterId(), newStates); } - cmd.incrStep(); - return new ClusterSyncAnswer(cmd.getClusterId(), newStates, sync_type); } + protected HashMap> fullClusterSync(Connection conn) { s_vms.clear(_cluster); try { diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index d8238bad541..17d38193591 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -148,7 +148,7 @@ public enum Config { MigrateRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "migrate.retry.interval", "120", "Time (in seconds) between migration retries", null), PingInterval("Advanced", AgentManager.class, Integer.class, "ping.interval", "60", "Ping interval in seconds", null), ClusterDeltaSyncInterval("Advanced", AgentManager.class, Integer.class, "sync.interval", "60", "Cluster Delta sync interval in seconds", null), - ClusterFullSyncSkipSteps("Advanced", AgentManager.class, Integer.class, "skip.steps", "30", "Cluster full sync skip steps count", null), + ClusterFullSyncSkipSteps("Advanced", AgentManager.class, Integer.class, "skip.steps", "60", "Cluster full sync skip steps count", null), PingTimeout("Advanced", AgentManager.class, Float.class, "ping.timeout", "2.5", "Multiplier to ping.interval before announcing an agent has timed out", null), Port("Advanced", AgentManager.class, Integer.class, "port", "8250", "Port to listen on for agent connection.", null), RouterCpuMHz("Advanced", NetworkManager.class, Integer.class, "router.cpu.mhz", String.valueOf(VirtualNetworkApplianceManager.DEFAULT_ROUTER_CPU_MHZ), "Default CPU speed (MHz) for router VM.", null), diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index fac4ff2f376..0d8f9e77275 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1641,34 +1641,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene public Commands fullSync(final long clusterId, Map> newStates) { Commands commands = new Commands(OnError.Continue); Map infos = convertToInfos(newStates); - long hId = 0; final List vms = _vmDao.listByClusterId(clusterId); for (VMInstanceVO vm : vms) { - AgentVmInfo info = infos.remove(vm.getId()); - VMInstanceVO castedVm = null; - if (info == null) { - // the vm is not there on cluster, check the vm status in DB - if (vm.getState() == State.Starting && (DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime()) < 10*60*1000){ - continue; // ignoring this VM as it is still settling - } - info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped); - castedVm = info.guru.findById(vm.getId()); - hId = vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId(); - } else { - castedVm = info.vm; - String host_guid = info.getHostUuid(); - Host host = _hostDao.findByGuid(host_guid); - if (host == null) { - infos.put(vm.getId(), info); - continue; - } - hId = host.getId(); - } - HypervisorGuru hvGuru = _hvGuruMgr.getGuru(castedVm.getHypervisorType()); - Command command = compareState(hId, castedVm, info, false, hvGuru.trackVmHostChange()); - if (command != null) { - commands.addCommand(command); - } + infos.remove(vm.getId()); } for (final AgentVmInfo left : infos.values()) { s_logger.warn("Stopping a VM that we have no record of: " + left.name); @@ -1985,7 +1960,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene ClusterSyncAnswer hs = (ClusterSyncAnswer) answer; if (hs.execute()){ if (hs.isFull()) { - fullSync(hs.getClusterId(), hs.getNewStates()); + deltaSync(hs.getNewStates()); + fullSync(hs.getClusterId(), hs.getAllStates()); } else if (hs.isDelta()) { deltaSync(hs.getNewStates()); }