Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While starting VM with 'considerlasthost' enabled, don't load host tags/details for the last host when it doesn't exist #9037

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,105 +415,107 @@
s_logger.debug("This VM has last host_id specified, trying to choose the same host: " + vm.getLastHostId());

HostVO host = _hostDao.findById(vm.getLastHostId());
_hostDao.loadHostTags(host);
_hostDao.loadDetails(host);
ServiceOfferingDetailsVO offeringDetails = null;
if (host == null) {
s_logger.debug("The last host of this VM cannot be found");
} else if (avoids.shouldAvoid(host)) {
s_logger.debug("The last host of this VM is in avoid set");
} else if (plan.getClusterId() != null && host.getClusterId() != null
&& !plan.getClusterId().equals(host.getClusterId())) {
s_logger.debug("The last host of this VM cannot be picked as the plan specifies different clusterId: "
+ plan.getClusterId());
} else if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
s_logger.debug("The last Host, hostId: " + host.getId() +
" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
} else if ((offeringDetails = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString());
if(!_resourceMgr.isGPUDeviceAvailable(host.getId(), groupName.getValue(), offeringDetails.getValue())){
s_logger.debug("The last host of this VM does not have required GPU devices available");
}
} else if (volumesRequireEncryption && !Boolean.parseBoolean(host.getDetail(Host.HOST_VOLUME_ENCRYPTION))) {
s_logger.warn(String.format("The last host of this VM %s does not support volume encryption, which is required by this VM.", host));
} else {
if (host.getStatus() == Status.Up) {
if (checkVmProfileAndHost(vmProfile, host)) {
long cluster_id = host.getClusterId();
ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id,
"cpuOvercommitRatio");
ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id,
"memoryOvercommitRatio");
Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());

boolean hostHasCpuCapability, hostHasCapacity = false;
hostHasCpuCapability = _capacityMgr.checkIfHostHasCpuCapability(host.getId(), offering.getCpu(), offering.getSpeed());

if (hostHasCpuCapability) {
// first check from reserved capacity
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOvercommitRatio, memoryOvercommitRatio, true);

// if not reserved, check the free capacity
if (!hostHasCapacity)
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true);
}

boolean displayStorage = getDisplayStorageFromVmProfile(vmProfile);
if (hostHasCapacity
&& hostHasCpuCapability) {
s_logger.debug("The last host of this VM is UP and has enough capacity");
s_logger.debug("Now checking for suitable pools under zone: " + host.getDataCenterId()
+ ", pod: " + host.getPodId() + ", cluster: " + host.getClusterId());

Pod pod = _podDao.findById(host.getPodId());
Cluster cluster = _clusterDao.findById(host.getClusterId());
if (vm.getHypervisorType() == HypervisorType.BareMetal) {
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, new HashMap<Volume, StoragePool>(), displayStorage);
s_logger.debug("Returning Deployment Destination: " + dest);
return dest;
_hostDao.loadHostTags(host);
_hostDao.loadDetails(host);
if (avoids.shouldAvoid(host)) {
s_logger.debug("The last host of this VM is in avoid set");

Check warning on line 425 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L425

Added line #L425 was not covered by tests
} else if (plan.getClusterId() != null && host.getClusterId() != null
&& !plan.getClusterId().equals(host.getClusterId())) {
s_logger.debug("The last host of this VM cannot be picked as the plan specifies different clusterId: "
+ plan.getClusterId());

Check warning on line 429 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L428-L429

Added lines #L428 - L429 were not covered by tests
} else if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
s_logger.debug("The last Host, hostId: " + host.getId() +

Check warning on line 431 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L431

Added line #L431 was not covered by tests
" already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
} else if ((offeringDetails = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString())) != null) {
ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.pciDevice.toString());

Check warning on line 434 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L434

Added line #L434 was not covered by tests
if(!_resourceMgr.isGPUDeviceAvailable(host.getId(), groupName.getValue(), offeringDetails.getValue())){
s_logger.debug("The last host of this VM does not have required GPU devices available");

Check warning on line 436 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L436

Added line #L436 was not covered by tests
}
} else if (volumesRequireEncryption && !Boolean.parseBoolean(host.getDetail(Host.HOST_VOLUME_ENCRYPTION))) {
s_logger.warn(String.format("The last host of this VM %s does not support volume encryption, which is required by this VM.", host));
} else {
shwstppr marked this conversation as resolved.
Show resolved Hide resolved
if (host.getStatus() == Status.Up) {
if (checkVmProfileAndHost(vmProfile, host)) {
long cluster_id = host.getClusterId();
ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id,
"cpuOvercommitRatio");
ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id,
"memoryOvercommitRatio");
Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());

boolean hostHasCpuCapability, hostHasCapacity = false;
hostHasCpuCapability = _capacityMgr.checkIfHostHasCpuCapability(host.getId(), offering.getCpu(), offering.getSpeed());

if (hostHasCpuCapability) {
// first check from reserved capacity
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOvercommitRatio, memoryOvercommitRatio, true);

// if not reserved, check the free capacity
if (!hostHasCapacity)
hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true);

Check warning on line 460 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L460

Added line #L460 was not covered by tests
}

// search for storage under the zone, pod, cluster
// of
// the last host.
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(),
host.getPodId(), host.getClusterId(), host.getId(), plan.getPoolId(), null);
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(
vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
List<Volume> readyAndReusedVolumes = result.second();

// choose the potential pool for this VM for this
// host
if (!suitableVolumeStoragePools.isEmpty()) {
List<Host> suitableHosts = new ArrayList<Host>();
suitableHosts.add(host);
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
suitableHosts, suitableVolumeStoragePools, avoids,
getPlannerUsage(planner, vmProfile, plan, avoids), readyAndReusedVolumes, plan.getPreferredHosts(), vm);
if (potentialResources != null) {
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
// remove the reused vol<->pool from
// destination, since we don't have to
// prepare
// this volume.
for (Volume vol : readyAndReusedVolumes) {
storageVolMap.remove(vol);
}
DeployDestination dest = new DeployDestination(dc, pod, cluster, host,
storageVolMap, displayStorage);
boolean displayStorage = getDisplayStorageFromVmProfile(vmProfile);
if (hostHasCapacity
&& hostHasCpuCapability) {
s_logger.debug("The last host of this VM is UP and has enough capacity");
s_logger.debug("Now checking for suitable pools under zone: " + host.getDataCenterId()
+ ", pod: " + host.getPodId() + ", cluster: " + host.getClusterId());

Pod pod = _podDao.findById(host.getPodId());
Cluster cluster = _clusterDao.findById(host.getClusterId());
if (vm.getHypervisorType() == HypervisorType.BareMetal) {
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, new HashMap<Volume, StoragePool>(), displayStorage);

Check warning on line 473 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L473

Added line #L473 was not covered by tests
s_logger.debug("Returning Deployment Destination: " + dest);
return dest;
}

// search for storage under the zone, pod, cluster
// of
// the last host.
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(),
host.getPodId(), host.getClusterId(), host.getId(), plan.getPoolId(), null);
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(
vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
List<Volume> readyAndReusedVolumes = result.second();

// choose the potential pool for this VM for this
// host
if (!suitableVolumeStoragePools.isEmpty()) {
List<Host> suitableHosts = new ArrayList<Host>();
suitableHosts.add(host);
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
suitableHosts, suitableVolumeStoragePools, avoids,
getPlannerUsage(planner, vmProfile, plan, avoids), readyAndReusedVolumes, plan.getPreferredHosts(), vm);
if (potentialResources != null) {
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
// remove the reused vol<->pool from
// destination, since we don't have to
// prepare
// this volume.
for (Volume vol : readyAndReusedVolumes) {
storageVolMap.remove(vol);
}
DeployDestination dest = new DeployDestination(dc, pod, cluster, host,
storageVolMap, displayStorage);
s_logger.debug("Returning Deployment Destination: " + dest);
return dest;
}
}
} else {
s_logger.debug("The last host of this VM does not have enough capacity");

Check warning on line 512 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L511-L512

Added lines #L511 - L512 were not covered by tests
}
} else {
s_logger.debug("The last host of this VM does not have enough capacity");
}
} else {
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: " +
host.getResourceState());

Check warning on line 517 in server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java#L516-L517

Added lines #L516 - L517 were not covered by tests
}
} else {
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: " +
host.getResourceState());
}
}
s_logger.debug("Cannot choose the last host to deploy this VM ");
Expand Down