From 13ee22d421579ce321a69a9b7420e34852da4793 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 7 Sep 2011 12:36:17 -0700 Subject: [PATCH] bug 10078: 1. introduce migratewait in global configuration, the default value is 1 hour 2. use async xapi VM migration API status 10078: resolved fixed --- .../xen/resource/CitrixResourceBase.java | 42 +++++++++++++++++-- .../cloud/agent/manager/AgentManagerImpl.java | 3 +- .../src/com/cloud/configuration/Config.java | 1 + .../xen/discoverer/XcpServerDiscoverer.java | 7 +++- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index eda1917e626..1bc43eb41c6 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -262,6 +262,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected String _storageNetworkName2; protected String _guestNetworkName; protected int _wait; + protected int _migratewait; protected String _instance; //instance name (default is usually "VM") static final Random _rand = new Random(System.currentTimeMillis()); @@ -2450,9 +2451,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe break; } } - Map other = new HashMap(); - other.put("live", "true"); - vm.poolMigrate(conn, dsthost, other); + migrateVM(conn, dsthost, vm, vmName); vm.setAffinity(conn, dsthost); state = State.Stopping; } @@ -2990,6 +2989,40 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } } + + private + void migrateVM(Connection conn, Host destHost, VM vm, String vmName) throws XmlRpcException { + Task task = null; + try { + Map other = new HashMap(); + other.put("live", "true"); + task = vm.poolMigrateAsync(conn, destHost, other); + try { + // poll every 1 seconds + long timeout = (long)(_migratewait) * 1000L; + waitForTask(conn, task, 1000, timeout); + checkForSuccess(conn, task); + } catch (Types.HandleInvalid e) { + if (vm.getResidentOn(conn).equals(destHost)) { + task = null; + return; + } + throw new CloudRuntimeException("migrate VM catch HandleInvalid and VM is not running on dest host"); + } + } catch (XenAPIException e) { + String msg = "Unable to migrate VM(" + vmName + ") from host(" + _host.uuid +") due to " + e.toString(); + s_logger.warn(msg, e); + throw new CloudRuntimeException(msg); + }finally { + if( task != null) { + try { + task.destroy(conn); + } catch (Exception e1) { + s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.uuid +") due to " + e1.toString()); + } + } + } + } protected VDI cloudVDIcopy(Connection conn, VDI vdi, SR sr) throws XenAPIException, XmlRpcException { Task task = null; @@ -4975,6 +5008,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe String value = (String) params.get("wait"); _wait = NumbersUtil.parseInt(value, 600); + + value = (String) params.get("migratewait"); + _migratewait = NumbersUtil.parseInt(value, 3600); if (_pod == null) { throw new ConfigurationException("Unable to get the pod"); diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 02d86f57443..a230b345d46 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -1250,7 +1250,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager { params.put("ipaddress", host.getPrivateIpAddress()); params.put("secondary.storage.vm", "false"); - params.put("max.template.iso.size", _configDao.getValue("max.template.iso.size")); + params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString())); + params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString())); try { resource.configure(host.getName(), params); diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index d9cec7ccef0..3afab7e2a69 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -152,6 +152,7 @@ public enum Config { UpdateWait("Advanced", AgentManager.class, Integer.class, "update.wait", "600", "Time to wait (in seconds) before alerting on a updating agent", null), Wait("Advanced", AgentManager.class, Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return", null), XapiWait("Advanced", AgentManager.class, Integer.class, "xapiwait", "600", "Time (in seconds) to wait for XAPI to return", null), + MigrateWait("Advanced", AgentManager.class, Integer.class, "migratewait", "3600", "Time (in seconds) to wait for VM migrate finish", null), CmdsWait("Advanced", AgentManager.class, Integer.class, "cmd.wait", "7200", "Time (in seconds) to wait for some heavy time-consuming commands", null), Workers("Advanced", AgentManager.class, Integer.class, "workers", "5", "Number of worker threads.", null), MountParent("Advanced", ManagementServer.class, String.class, "mount.parent", "/var/lib/cloud/mnt", "The mount point on the Management Server for Secondary Storage.", null), diff --git a/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index a5d3a0ad528..d916bb51265 100755 --- a/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -45,6 +45,7 @@ import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.alert.AlertManager; import com.cloud.configuration.Config; +import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.dao.ClusterDao; import com.cloud.exception.AgentUnavailableException; @@ -106,6 +107,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L @Inject VMTemplateDao _tmpltDao; @Inject VMTemplateHostDao _vmTemplateHostDao; @Inject ClusterDao _clusterDao; + @Inject protected ConfigurationDao _configDao; protected XcpServerDiscoverer() { } @@ -277,8 +279,9 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L params.put("storage.network.device2", _storageNic2); details.put("storage.network.device2", _storageNic2); } - params.put(Config.Wait.toString().toLowerCase(), Integer.toString(_wait)); - details.put(Config.Wait.toString().toLowerCase(), Integer.toString(_wait)); + params.put("wait", Integer.toString(_wait)); + details.put("wait", Integer.toString(_wait)); + params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString())); params.put(Config.InstanceName.toString().toLowerCase(), _instance); details.put(Config.InstanceName.toString().toLowerCase(), _instance); try {