@@ -415,105 +415,107 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
415415 s_logger .debug ("This VM has last host_id specified, trying to choose the same host: " + vm .getLastHostId ());
416416
417417 HostVO host = _hostDao .findById (vm .getLastHostId ());
418- _hostDao .loadHostTags (host );
419- _hostDao .loadDetails (host );
420418 ServiceOfferingDetailsVO offeringDetails = null ;
421419 if (host == null ) {
422420 s_logger .debug ("The last host of this VM cannot be found" );
423- } else if (avoids .shouldAvoid (host )) {
424- s_logger .debug ("The last host of this VM is in avoid set" );
425- } else if (plan .getClusterId () != null && host .getClusterId () != null
426- && !plan .getClusterId ().equals (host .getClusterId ())) {
427- s_logger .debug ("The last host of this VM cannot be picked as the plan specifies different clusterId: "
428- + plan .getClusterId ());
429- } else if (_capacityMgr .checkIfHostReachMaxGuestLimit (host )) {
430- s_logger .debug ("The last Host, hostId: " + host .getId () +
431- " already has max Running VMs(count includes system VMs), skipping this and trying other available hosts" );
432- } else if ((offeringDetails = _serviceOfferingDetailsDao .findDetail (offering .getId (), GPU .Keys .vgpuType .toString ())) != null ) {
433- ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao .findDetail (offering .getId (), GPU .Keys .pciDevice .toString ());
434- if (!_resourceMgr .isGPUDeviceAvailable (host .getId (), groupName .getValue (), offeringDetails .getValue ())){
435- s_logger .debug ("The last host of this VM does not have required GPU devices available" );
436- }
437- } else if (volumesRequireEncryption && !Boolean .parseBoolean (host .getDetail (Host .HOST_VOLUME_ENCRYPTION ))) {
438- s_logger .warn (String .format ("The last host of this VM %s does not support volume encryption, which is required by this VM." , host ));
439421 } else {
440- if (host .getStatus () == Status .Up ) {
441- if (checkVmProfileAndHost (vmProfile , host )) {
442- long cluster_id = host .getClusterId ();
443- ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao .findDetail (cluster_id ,
444- "cpuOvercommitRatio" );
445- ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao .findDetail (cluster_id ,
446- "memoryOvercommitRatio" );
447- Float cpuOvercommitRatio = Float .parseFloat (cluster_detail_cpu .getValue ());
448- Float memoryOvercommitRatio = Float .parseFloat (cluster_detail_ram .getValue ());
449-
450- boolean hostHasCpuCapability , hostHasCapacity = false ;
451- hostHasCpuCapability = _capacityMgr .checkIfHostHasCpuCapability (host .getId (), offering .getCpu (), offering .getSpeed ());
452-
453- if (hostHasCpuCapability ) {
454- // first check from reserved capacity
455- hostHasCapacity = _capacityMgr .checkIfHostHasCapacity (host .getId (), cpu_requested , ram_requested , true , cpuOvercommitRatio , memoryOvercommitRatio , true );
456-
457- // if not reserved, check the free capacity
458- if (!hostHasCapacity )
459- hostHasCapacity = _capacityMgr .checkIfHostHasCapacity (host .getId (), cpu_requested , ram_requested , false , cpuOvercommitRatio , memoryOvercommitRatio , true );
460- }
461-
462- boolean displayStorage = getDisplayStorageFromVmProfile (vmProfile );
463- if (hostHasCapacity
464- && hostHasCpuCapability ) {
465- s_logger .debug ("The last host of this VM is UP and has enough capacity" );
466- s_logger .debug ("Now checking for suitable pools under zone: " + host .getDataCenterId ()
467- + ", pod: " + host .getPodId () + ", cluster: " + host .getClusterId ());
468-
469- Pod pod = _podDao .findById (host .getPodId ());
470- Cluster cluster = _clusterDao .findById (host .getClusterId ());
471- if (vm .getHypervisorType () == HypervisorType .BareMetal ) {
472- DeployDestination dest = new DeployDestination (dc , pod , cluster , host , new HashMap <Volume , StoragePool >(), displayStorage );
473- s_logger .debug ("Returning Deployment Destination: " + dest );
474- return dest ;
422+ _hostDao .loadHostTags (host );
423+ _hostDao .loadDetails (host );
424+ if (avoids .shouldAvoid (host )) {
425+ s_logger .debug ("The last host of this VM is in avoid set" );
426+ } else if (plan .getClusterId () != null && host .getClusterId () != null
427+ && !plan .getClusterId ().equals (host .getClusterId ())) {
428+ s_logger .debug ("The last host of this VM cannot be picked as the plan specifies different clusterId: "
429+ + plan .getClusterId ());
430+ } else if (_capacityMgr .checkIfHostReachMaxGuestLimit (host )) {
431+ s_logger .debug ("The last Host, hostId: " + host .getId () +
432+ " already has max Running VMs(count includes system VMs), skipping this and trying other available hosts" );
433+ } else if ((offeringDetails = _serviceOfferingDetailsDao .findDetail (offering .getId (), GPU .Keys .vgpuType .toString ())) != null ) {
434+ ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao .findDetail (offering .getId (), GPU .Keys .pciDevice .toString ());
435+ if (!_resourceMgr .isGPUDeviceAvailable (host .getId (), groupName .getValue (), offeringDetails .getValue ())){
436+ s_logger .debug ("The last host of this VM does not have required GPU devices available" );
437+ }
438+ } else if (volumesRequireEncryption && !Boolean .parseBoolean (host .getDetail (Host .HOST_VOLUME_ENCRYPTION ))) {
439+ s_logger .warn (String .format ("The last host of this VM %s does not support volume encryption, which is required by this VM." , host ));
440+ } else {
441+ if (host .getStatus () == Status .Up ) {
442+ if (checkVmProfileAndHost (vmProfile , host )) {
443+ long cluster_id = host .getClusterId ();
444+ ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao .findDetail (cluster_id ,
445+ "cpuOvercommitRatio" );
446+ ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao .findDetail (cluster_id ,
447+ "memoryOvercommitRatio" );
448+ Float cpuOvercommitRatio = Float .parseFloat (cluster_detail_cpu .getValue ());
449+ Float memoryOvercommitRatio = Float .parseFloat (cluster_detail_ram .getValue ());
450+
451+ boolean hostHasCpuCapability , hostHasCapacity = false ;
452+ hostHasCpuCapability = _capacityMgr .checkIfHostHasCpuCapability (host .getId (), offering .getCpu (), offering .getSpeed ());
453+
454+ if (hostHasCpuCapability ) {
455+ // first check from reserved capacity
456+ hostHasCapacity = _capacityMgr .checkIfHostHasCapacity (host .getId (), cpu_requested , ram_requested , true , cpuOvercommitRatio , memoryOvercommitRatio , true );
457+
458+ // if not reserved, check the free capacity
459+ if (!hostHasCapacity )
460+ hostHasCapacity = _capacityMgr .checkIfHostHasCapacity (host .getId (), cpu_requested , ram_requested , false , cpuOvercommitRatio , memoryOvercommitRatio , true );
475461 }
476462
477- // search for storage under the zone, pod, cluster
478- // of
479- // the last host.
480- DataCenterDeployment lastPlan = new DataCenterDeployment (host .getDataCenterId (),
481- host .getPodId (), host .getClusterId (), host .getId (), plan .getPoolId (), null );
482- Pair <Map <Volume , List <StoragePool >>, List <Volume >> result = findSuitablePoolsForVolumes (
483- vmProfile , lastPlan , avoids , HostAllocator .RETURN_UPTO_ALL );
484- Map <Volume , List <StoragePool >> suitableVolumeStoragePools = result .first ();
485- List <Volume > readyAndReusedVolumes = result .second ();
486-
487- // choose the potential pool for this VM for this
488- // host
489- if (!suitableVolumeStoragePools .isEmpty ()) {
490- List <Host > suitableHosts = new ArrayList <Host >();
491- suitableHosts .add (host );
492- Pair <Host , Map <Volume , StoragePool >> potentialResources = findPotentialDeploymentResources (
493- suitableHosts , suitableVolumeStoragePools , avoids ,
494- getPlannerUsage (planner , vmProfile , plan , avoids ), readyAndReusedVolumes , plan .getPreferredHosts (), vm );
495- if (potentialResources != null ) {
496- Map <Volume , StoragePool > storageVolMap = potentialResources .second ();
497- // remove the reused vol<->pool from
498- // destination, since we don't have to
499- // prepare
500- // this volume.
501- for (Volume vol : readyAndReusedVolumes ) {
502- storageVolMap .remove (vol );
503- }
504- DeployDestination dest = new DeployDestination (dc , pod , cluster , host ,
505- storageVolMap , displayStorage );
463+ boolean displayStorage = getDisplayStorageFromVmProfile (vmProfile );
464+ if (hostHasCapacity
465+ && hostHasCpuCapability ) {
466+ s_logger .debug ("The last host of this VM is UP and has enough capacity" );
467+ s_logger .debug ("Now checking for suitable pools under zone: " + host .getDataCenterId ()
468+ + ", pod: " + host .getPodId () + ", cluster: " + host .getClusterId ());
469+
470+ Pod pod = _podDao .findById (host .getPodId ());
471+ Cluster cluster = _clusterDao .findById (host .getClusterId ());
472+ if (vm .getHypervisorType () == HypervisorType .BareMetal ) {
473+ DeployDestination dest = new DeployDestination (dc , pod , cluster , host , new HashMap <Volume , StoragePool >(), displayStorage );
506474 s_logger .debug ("Returning Deployment Destination: " + dest );
507475 return dest ;
508476 }
477+
478+ // search for storage under the zone, pod, cluster
479+ // of
480+ // the last host.
481+ DataCenterDeployment lastPlan = new DataCenterDeployment (host .getDataCenterId (),
482+ host .getPodId (), host .getClusterId (), host .getId (), plan .getPoolId (), null );
483+ Pair <Map <Volume , List <StoragePool >>, List <Volume >> result = findSuitablePoolsForVolumes (
484+ vmProfile , lastPlan , avoids , HostAllocator .RETURN_UPTO_ALL );
485+ Map <Volume , List <StoragePool >> suitableVolumeStoragePools = result .first ();
486+ List <Volume > readyAndReusedVolumes = result .second ();
487+
488+ // choose the potential pool for this VM for this
489+ // host
490+ if (!suitableVolumeStoragePools .isEmpty ()) {
491+ List <Host > suitableHosts = new ArrayList <Host >();
492+ suitableHosts .add (host );
493+ Pair <Host , Map <Volume , StoragePool >> potentialResources = findPotentialDeploymentResources (
494+ suitableHosts , suitableVolumeStoragePools , avoids ,
495+ getPlannerUsage (planner , vmProfile , plan , avoids ), readyAndReusedVolumes , plan .getPreferredHosts (), vm );
496+ if (potentialResources != null ) {
497+ Map <Volume , StoragePool > storageVolMap = potentialResources .second ();
498+ // remove the reused vol<->pool from
499+ // destination, since we don't have to
500+ // prepare
501+ // this volume.
502+ for (Volume vol : readyAndReusedVolumes ) {
503+ storageVolMap .remove (vol );
504+ }
505+ DeployDestination dest = new DeployDestination (dc , pod , cluster , host ,
506+ storageVolMap , displayStorage );
507+ s_logger .debug ("Returning Deployment Destination: " + dest );
508+ return dest ;
509+ }
510+ }
511+ } else {
512+ s_logger .debug ("The last host of this VM does not have enough capacity" );
509513 }
510- } else {
511- s_logger .debug ("The last host of this VM does not have enough capacity" );
512514 }
515+ } else {
516+ s_logger .debug ("The last host of this VM is not UP or is not enabled, host status is: " + host .getStatus ().name () + ", host resource state is: " +
517+ host .getResourceState ());
513518 }
514- } else {
515- s_logger .debug ("The last host of this VM is not UP or is not enabled, host status is: " + host .getStatus ().name () + ", host resource state is: " +
516- host .getResourceState ());
517519 }
518520 }
519521 s_logger .debug ("Cannot choose the last host to deploy this VM " );
0 commit comments