6565import com .cloud .service .ServiceOfferingVO ;
6666import com .cloud .service .dao .ServiceOfferingDao ;
6767import com .cloud .utils .Pair ;
68+ import com .cloud .utils .StringUtils ;
6869import com .cloud .utils .Ternary ;
6970import com .cloud .utils .component .ManagerBase ;
7071import com .cloud .utils .exception .CloudRuntimeException ;
72+ import com .cloud .vm .UserVmDetailVO ;
7173import com .cloud .vm .VMInstanceVO ;
7274import com .cloud .vm .VirtualMachine .State ;
7375import com .cloud .vm .VirtualMachineProfileImpl ;
76+ import com .cloud .vm .VmDetailConstants ;
77+ import com .cloud .vm .dao .UserVmDetailsDao ;
7478import com .cloud .vm .dao .VMInstanceDao ;
7579
7680public class RollingMaintenanceManagerImpl extends ManagerBase implements RollingMaintenanceManager {
@@ -86,6 +90,8 @@ public class RollingMaintenanceManagerImpl extends ManagerBase implements Rollin
8690 @ Inject
8791 private VMInstanceDao vmInstanceDao ;
8892 @ Inject
93+ protected UserVmDetailsDao userVmDetailsDao ;
94+ @ Inject
8995 private ServiceOfferingDao serviceOfferingDao ;
9096 @ Inject
9197 private ClusterDetailsDao clusterDetailsDao ;
@@ -622,9 +628,35 @@ private Pair<Boolean, String> performCapacityChecksBeforeHostInMaintenance(Host
622628 for (VMInstanceVO runningVM : vmsRunning ) {
623629 boolean canMigrateVm = false ;
624630 ServiceOfferingVO serviceOffering = serviceOfferingDao .findById (runningVM .getServiceOfferingId ());
631+ Integer cpu = serviceOffering .getCpu ();
632+ Integer speed = serviceOffering .getSpeed ();
633+ Integer ramSize = serviceOffering .getRamSize ();
634+ if (serviceOffering .isDynamic ()) {
635+ List <UserVmDetailVO > vmDetails = userVmDetailsDao .listDetails (runningVM .getId ());
636+ if (CollectionUtils .isNotEmpty (vmDetails )) {
637+ for (UserVmDetailVO vmDetail : vmDetails ) {
638+ if (vmDetail .getName () != null &&vmDetail .getValue () != null ) {
639+ if (cpu == null && VmDetailConstants .CPU_NUMBER .equals (vmDetail .getName ())) {
640+ cpu = Integer .valueOf (vmDetail .getValue ());
641+ }
642+ if (speed == null && VmDetailConstants .CPU_SPEED .equals (vmDetail .getName ())) {
643+ speed = Integer .valueOf (vmDetail .getValue ());
644+ }
645+ if (ramSize == null && VmDetailConstants .MEMORY .equals (vmDetail .getName ())) {
646+ ramSize = Integer .valueOf (vmDetail .getValue ());
647+ }
648+ }
649+ }
650+ }
651+ }
652+ if (cpu == null || speed == null || ramSize == null ) {
653+ s_logger .warn (String .format ("Cannot fetch compute resources for the VM %s, skipping it from the capacity check" , runningVM ));
654+ continue ;
655+ }
656+
625657 for (Host hostInCluster : hostsInCluster ) {
626658 if (!checkHostTags (hostTags , hostTagsDao .getHostTags (hostInCluster .getId ()), serviceOffering .getHostTag ())) {
627- s_logger .debug (String .format ("Host tags mismatch between %s and %s Skipping it from the capacity check" , host , hostInCluster ));
659+ s_logger .warn (String .format ("Host tags mismatch between %s and %s, skipping it from the capacity check" , host , hostInCluster ));
628660 continue ;
629661 }
630662 DeployDestination deployDestination = new DeployDestination (null , null , null , host );
@@ -634,13 +666,13 @@ private Pair<Boolean, String> performCapacityChecksBeforeHostInMaintenance(Host
634666 affinityChecks = affinityChecks && affinityProcessor .check (vmProfile , deployDestination );
635667 }
636668 if (!affinityChecks ) {
637- s_logger .debug (String .format ("Affinity check failed between %s and %s Skipping it from the capacity check" , host , hostInCluster ));
669+ s_logger .warn (String .format ("Affinity check failed between %s and %s, skipping it from the capacity check" , host , hostInCluster ));
638670 continue ;
639671 }
640672 boolean maxGuestLimit = capacityManager .checkIfHostReachMaxGuestLimit (host );
641- boolean hostHasCPUCapacity = capacityManager .checkIfHostHasCpuCapability (hostInCluster .getId (), serviceOffering . getCpu (), serviceOffering . getSpeed () );
642- int cpuRequested = serviceOffering . getCpu () * serviceOffering . getSpeed () ;
643- long ramRequested = serviceOffering . getRamSize () * 1024L * 1024L ;
673+ boolean hostHasCPUCapacity = capacityManager .checkIfHostHasCpuCapability (hostInCluster .getId (), cpu , speed );
674+ int cpuRequested = cpu * speed ;
675+ long ramRequested = ramSize * 1024L * 1024L ;
644676 ClusterDetailsVO clusterDetailsCpuOvercommit = clusterDetailsDao .findDetail (cluster .getId (), "cpuOvercommitRatio" );
645677 ClusterDetailsVO clusterDetailsRamOvercommmt = clusterDetailsDao .findDetail (cluster .getId (), "memoryOvercommitRatio" );
646678 Float cpuOvercommitRatio = Float .parseFloat (clusterDetailsCpuOvercommit .getValue ());
@@ -670,7 +702,7 @@ private Pair<Boolean, String> performCapacityChecksBeforeHostInMaintenance(Host
670702 * Check hosts tags
671703 */
672704 private boolean checkHostTags (List <HostTagVO > hostTags , List <HostTagVO > hostInClusterTags , String offeringTag ) {
673- if (CollectionUtils .isEmpty (hostTags ) && CollectionUtils .isEmpty (hostInClusterTags )) {
705+ if (( CollectionUtils .isEmpty (hostTags ) && CollectionUtils .isEmpty (hostInClusterTags )) || StringUtils . isBlank ( offeringTag )) {
674706 return true ;
675707 } else if ((CollectionUtils .isNotEmpty (hostTags ) && CollectionUtils .isEmpty (hostInClusterTags )) ||
676708 (CollectionUtils .isEmpty (hostTags ) && CollectionUtils .isNotEmpty (hostInClusterTags ))) {
0 commit comments