Skip to content

Commit 8425df0

Browse files
committed
deal with null return for create deployment plan for maintenance
1 parent b41acf2 commit 8425df0

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -1461,13 +1461,7 @@ private void migrateAwayVmWithVolumes(HostVO host, VMInstanceVO vm) {
14611461
ServiceOfferingVO offeringVO = serviceOfferingDao.findById(vm.getServiceOfferingId());
14621462
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
14631463
plan.setMigrationPlan(true);
1464-
DeployDestination dest = null;
1465-
try {
1466-
dest = deploymentManager.planDeployment(profile, plan, new DeploymentPlanner.ExcludeList(), null);
1467-
} catch (InsufficientServerCapacityException e) {
1468-
throw new CloudRuntimeException(String.format("Maintenance failed, could not find deployment destination for VM [id=%s, name=%s].", vm.getId(), vm.getInstanceName()),
1469-
e);
1470-
}
1464+
DeployDestination dest = getDeployDestination(vm, profile, plan);
14711465
Host destHost = dest.getHost();
14721466

14731467
try {
@@ -1479,6 +1473,20 @@ private void migrateAwayVmWithVolumes(HostVO host, VMInstanceVO vm) {
14791473
}
14801474
}
14811475

1476+
private DeployDestination getDeployDestination(VMInstanceVO vm, VirtualMachineProfile profile, DataCenterDeployment plan) {
1477+
DeployDestination dest = null;
1478+
try {
1479+
dest = deploymentManager.planDeployment(profile, plan, new DeploymentPlanner.ExcludeList(), null);
1480+
} catch (InsufficientServerCapacityException e) {
1481+
throw new CloudRuntimeException(String.format("Maintenance failed, could not find deployment destination for VM [id=%s, name=%s].", vm.getId(), vm.getInstanceName()),
1482+
e);
1483+
}
1484+
if (dest == null) {
1485+
throw new CloudRuntimeException(String.format("Maintenance failed, could not find deployment destination for VM [id=%s, name=%s], using plan: %s.", vm.getId(), vm.getInstanceName(), plan));
1486+
}
1487+
return dest;
1488+
}
1489+
14821490
@Override
14831491
public boolean maintain(final long hostId) throws AgentUnavailableException {
14841492
final Boolean result = propagateResourceEvent(hostId, ResourceState.Event.AdminAskMaintenance);

0 commit comments

Comments
 (0)