From aead68e5444dce63453acf06b72786d010ade475 Mon Sep 17 00:00:00 2001 From: Abhinandan Prateek Date: Tue, 18 Oct 2011 14:58:15 +0530 Subject: [PATCH] bug 11701: removed host sync from startup, now only cluster sync happens from master during startup --- .../xen/resource/CitrixResourceBase.java | 81 +++++++++++-------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 042f4a95f5e..d1ed69295ef 100755 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -2509,39 +2509,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe throw new CloudRuntimeException("Com'on no control domain? What the crap?!#@!##$@"); } - protected void fullHostSync(StartupRoutingCommand cmd, Connection conn) { - try { - final HashMap vmStates = new HashMap(); - Host lhost = Host.getByUuid(conn, _host.uuid); - Set vms = lhost.getResidentVMs(conn); - for (VM vm: vms) { - VM.Record record = vm.getRecord(conn); - if (record.isControlDomain || record.isASnapshot || record.isATemplate) { - continue; // Skip DOM0 - } - String vm_name = record.nameLabel; - VmPowerState ps = record.powerState; - final State state = convertToState(ps); - Host host = record.residentOn; - String host_uuid = null; - if( ! isRefNull(host) ) { - host_uuid = host.getUuid(conn); - VmState vm_state = new StartupRoutingCommand.VmState(state, host_uuid); - vmStates.put(vm_name, vm_state); - s_vms.put(_cluster, host_uuid, vm_name, state); - } - if (s_logger.isTraceEnabled()) { - s_logger.trace("VM " + vm_name + ": powerstate = " + ps + "; vm state=" + state.toString()); - } - } - cmd.setChanges(vmStates); - } catch (final Throwable e) { - String msg = "Unable to get vms through host " + _host.uuid + " due to to " + e.toString(); - s_logger.warn(msg, e); - throw new CloudRuntimeException(msg); - } - } - protected ReadyAnswer execute(ReadyCommand cmd) { Connection conn = getConnection(); @@ -3929,7 +3896,19 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe StartupRoutingCommand cmd = new StartupRoutingCommand(); fillHostInfo(conn, cmd); - fullHostSync(cmd, conn); + Pool pool; + try { + pool = Pool.getByUuid(conn, _host.pool); + Pool.Record poolr = pool.getRecord(conn); + + Host.Record hostr = poolr.master.getRecord(conn); + if (_host.uuid.equals(hostr.uuid)) { + s_logger.debug("Doing the initial cluster sync from the pool master " + _host.ip); + fullClusterSync(cmd, conn); + } + } catch (Exception e) { + s_logger.warn("Check for master failed, failing the probbaly initial Cluster sync ", e); + } cmd.setHypervisorType(HypervisorType.XenServer); cmd.setCluster(_cluster); cmd.setPoolSync(false); @@ -6523,6 +6502,40 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } + protected void fullClusterSync(StartupRoutingCommand cmd, Connection conn) { + try { + final HashMap vmStates = new HashMap(); + Host lhost = Host.getByUuid(conn, _host.uuid); + Map vm_map = VM.getAllRecords(conn); + for (VM.Record record: vm_map.values()) { + if (record.isControlDomain || record.isASnapshot || record.isATemplate) { + continue; // Skip DOM0 + } + String vm_name = record.nameLabel; + VmPowerState ps = record.powerState; + final State state = convertToState(ps); + Host host = record.residentOn; + String host_uuid = null; + if( ! isRefNull(host) ) { + host_uuid = host.getUuid(conn); + VmState vm_state = new StartupRoutingCommand.VmState(state, host_uuid); + vmStates.put(vm_name, vm_state); + s_vms.put(_cluster, host_uuid, vm_name, state); + } + if (s_logger.isTraceEnabled()) { + s_logger.trace("VM " + vm_name + ": powerstate = " + ps + "; vm state=" + state.toString()); + } + } + cmd.setChanges(vmStates); + } catch (final Throwable e) { + String msg = "Unable to get vms through host " + _host.uuid + " due to to " + e.toString(); + s_logger.warn(msg, e); + throw new CloudRuntimeException(msg); + } + } + + + protected HashMap> fullClusterSync(Connection conn) { s_vms.clear(_cluster); try {