@@ -378,31 +378,11 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
378378 planner = getDeploymentPlannerByName (plannerName );
379379 }
380380
381- Host lastHost = null ;
382-
383- String considerLastHostStr = (String )vmProfile .getParameter (VirtualMachineProfile .Param .ConsiderLastHost );
384- boolean considerLastHost = vm .getLastHostId () != null && haVmTag == null &&
385- (considerLastHostStr == null || Boolean .TRUE .toString ().equalsIgnoreCase (considerLastHostStr ));
386- if (considerLastHost ) {
387- logger .debug ("This VM has last host_id: {}" , vm .getLastHostId ());
388- HostVO host = _hostDao .findById (vm .getLastHostId ());
389- if (host == null ) {
390- if (Boolean .TRUE .toString ().equalsIgnoreCase (considerLastHostStr )) {
391- throw new CloudRuntimeException (String .format ("Failed to deploy VM %s, last host doesn't exist" , vm .getName ()));
392- }
393- } else {
394- logger .debug ("VM's last host is {}, trying to choose the same host if it is not in maintenance state" , host );
395- if (host .isInMaintenanceStates ()) {
396- if (Boolean .TRUE .toString ().equalsIgnoreCase (considerLastHostStr )) {
397- throw new CloudRuntimeException (String .format ("Failed to deploy VM %s, last host %s is in maintenance state" , vm .getName (), host .getName ()));
398- }
399- } else {
400- lastHost = host ;
401- DeployDestination deployDestination = deployInVmLastHost (vmProfile , plan , avoids , planner , vm , dc , offering , cpuRequested , ramRequested , volumesRequireEncryption );
402- if (deployDestination != null ) {
403- return deployDestination ;
404- }
405- }
381+ Host lastHost = checkDeployInVmLastHost (vmProfile , vm );
382+ if (lastHost != null ) {
383+ DeployDestination deployDestination = deployInVmLastHost (vmProfile , plan , avoids , planner , vm , dc , offering , cpuRequested , ramRequested , volumesRequireEncryption );
384+ if (deployDestination != null ) {
385+ return deployDestination ;
406386 }
407387 }
408388
@@ -468,6 +448,31 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
468448 return dest ;
469449 }
470450
451+ private Host checkDeployInVmLastHost (VirtualMachineProfile vmProfile , VirtualMachine vm ) {
452+ String considerLastHostStr = (String )vmProfile .getParameter (VirtualMachineProfile .Param .ConsiderLastHost );
453+ String haVmTag = (String )vmProfile .getParameter (VirtualMachineProfile .Param .HaTag );
454+ boolean considerLastHost = vm .getLastHostId () != null && haVmTag == null &&
455+ (considerLastHostStr == null || Boolean .TRUE .toString ().equalsIgnoreCase (considerLastHostStr ));
456+ if (!considerLastHost ) {
457+ return null ;
458+ }
459+
460+ logger .debug ("This VM has last host_id: {}" , vm .getLastHostId ());
461+ HostVO lastHost = _hostDao .findById (vm .getLastHostId ());
462+ if (lastHost == null ) {
463+ logger .debug ("Unable to deploy VM {} in the last host, last host doesn't exist" , vm .getName ());
464+ return null ;
465+ }
466+
467+ logger .debug ("VM's last host is {}, trying to choose the same host if it is not in maintenance state" , lastHost );
468+ if (lastHost .isInMaintenanceStates ()) {
469+ logger .debug ("Unable to deploy VM {} in the last host, last host {} is in maintenance state" , vm .getName (), lastHost .getName ());
470+ return null ;
471+ }
472+
473+ return lastHost ;
474+ }
475+
471476 private void avoidDifferentArchResources (VirtualMachineProfile vmProfile , DataCenter dc , ExcludeList avoids ) {
472477 VirtualMachineTemplate template = vmProfile .getTemplate ();
473478 for (CPU .CPUArch arch : clusterArchTypes ) {
0 commit comments