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
This commit is contained in:
anthony 2011-09-07 12:36:17 -07:00
parent 3dce7ebd03
commit 13ee22d421
4 changed files with 47 additions and 6 deletions

View File

@ -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<String, String> other = new HashMap<String, String>();
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<String, String> other = new HashMap<String, String>();
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");

View File

@ -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);

View File

@ -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),

View File

@ -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 {