mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
HA: set correct hostId of HA work for vm migration (#10591)
This commit is contained in:
parent
8db248e4b4
commit
7b68615bd9
@ -5248,10 +5248,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||||||
workJob = newVmWorkJobAndInfo.first();
|
workJob = newVmWorkJobAndInfo.first();
|
||||||
VmWorkMigrateAway workInfo = new VmWorkMigrateAway(newVmWorkJobAndInfo.second(), srcHostId);
|
VmWorkMigrateAway workInfo = new VmWorkMigrateAway(newVmWorkJobAndInfo.second(), srcHostId);
|
||||||
|
|
||||||
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
|
setCmdInfoAndSubmitAsyncJob(workJob, workInfo, vmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vmId);
|
|
||||||
|
|
||||||
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
|
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
|
||||||
|
|
||||||
|
|||||||
@ -502,7 +502,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("VM instance %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "instanceName", "uuid", "type"));
|
return String.format("VM instance %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "instanceName", "uuid", "type", "state"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -342,7 +342,8 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements Configur
|
|||||||
@Override
|
@Override
|
||||||
public boolean scheduleMigration(final VMInstanceVO vm) {
|
public boolean scheduleMigration(final VMInstanceVO vm) {
|
||||||
if (vm.getHostId() != null) {
|
if (vm.getHostId() != null) {
|
||||||
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.Migration, Step.Scheduled, vm.getHostId(), vm.getState(), 0, vm.getUpdated());
|
Long hostId = VirtualMachine.State.Migrating.equals(vm.getState()) ? vm.getLastHostId() : vm.getHostId();
|
||||||
|
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.Migration, Step.Scheduled, hostId, vm.getState(), 0, vm.getUpdated());
|
||||||
_haDao.persist(work);
|
_haDao.persist(work);
|
||||||
s_logger.info("Scheduled migration work of VM " + vm.getUuid() + " from host " + _hostDao.findById(vm.getHostId()) + " with HAWork " + work);
|
s_logger.info("Scheduled migration work of VM " + vm.getUuid() + " from host " + _hostDao.findById(vm.getHostId()) + " with HAWork " + work);
|
||||||
wakeupWorkers();
|
wakeupWorkers();
|
||||||
@ -716,6 +717,14 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements Configur
|
|||||||
s_logger.info("Unable to find vm: " + vmId + ", skipping migrate.");
|
s_logger.info("Unable to find vm: " + vmId + ", skipping migrate.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (VirtualMachine.State.Stopped.equals(vm.getState())) {
|
||||||
|
s_logger.info(String.format("vm %s is Stopped, skipping migrate.", vm));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (VirtualMachine.State.Running.equals(vm.getState()) && srcHostId != vm.getHostId()) {
|
||||||
|
s_logger.info(String.format("VM %s is running on a different host %s, skipping migration", vm, vm.getHostId()));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
s_logger.info("Migration attempt: for VM " + vm.getUuid() + "from host id " + srcHostId +
|
s_logger.info("Migration attempt: for VM " + vm.getUuid() + "from host id " + srcHostId +
|
||||||
". Starting attempt: " + (1 + work.getTimesTried()) + "/" + _maxRetries + " times.");
|
". Starting attempt: " + (1 + work.getTimesTried()) + "/" + _maxRetries + " times.");
|
||||||
try {
|
try {
|
||||||
@ -1022,6 +1031,13 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements Configur
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
|
synchronized (this) {
|
||||||
|
wait(_timeToSleep);
|
||||||
|
}
|
||||||
|
} catch (final InterruptedException e) {
|
||||||
|
s_logger.info("Interrupted");
|
||||||
|
}
|
||||||
s_logger.info("Starting work");
|
s_logger.info("Starting work");
|
||||||
while (!_stopped) {
|
while (!_stopped) {
|
||||||
_managedContext.runWithContext(new Runnable() {
|
_managedContext.runWithContext(new Runnable() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user