From 4527424fce0510cbeab6412faa23ee21838b07f1 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Wed, 5 Aug 2020 10:19:03 +0200 Subject: [PATCH 1/3] vm: Reset deviceId to fix missing nic with vm (#4000) Co-authored-by: Wei Zhou <57355700+weizhouapache@users.noreply.github.com> --- .../cloud/vm/VirtualMachineManagerImpl.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index 8d7e4a515af..f312752fc5d 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1124,6 +1124,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } try { + resetVmNicsDeviceId(vm.getId()); _networkMgr.prepare(vmProfile, new DeployDestination(dest.getDataCenter(), dest.getPod(), null, null, dest.getStorageForDisks()), ctx); if (vm.getHypervisorType() != HypervisorType.BareMetal) { volumeMgr.prepare(vmProfile, dest); @@ -1317,6 +1318,26 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } + private void resetVmNicsDeviceId(Long vmId) { + final List nics = _nicsDao.listByVmId(vmId); + Collections.sort(nics, new Comparator() { + @Override + public int compare(NicVO nic1, NicVO nic2) { + Long nicDevId1 = Long.valueOf(nic1.getDeviceId()); + Long nicDevId2 = Long.valueOf(nic2.getDeviceId()); + return nicDevId1.compareTo(nicDevId2); + } + }); + int deviceId = 0; + for (final NicVO nic : nics) { + if (nic.getDeviceId() != deviceId) { + nic.setDeviceId(deviceId); + _nicsDao.update(nic.getId(),nic); + } + deviceId ++; + } + } + // Add extra config data to the vmTO as a Map private void addExtraConfig(VirtualMachineTO vmTO) { Map details = vmTO.getDetails(); From 2fce8b733e19f37af990a6d21450c1a43a4c5bbd Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 5 Aug 2020 14:01:16 +0530 Subject: [PATCH 2/3] vmware: volume utilisation is always zero (#4225) This fixes issues of virtual size to be twice in case the disk is a linked-clone root disk. The virtual size of root disk (first in chain) must be used. Signed-off-by: Rohit Yadav --- .../com/cloud/hypervisor/vmware/resource/VmwareResource.java | 1 - .../src/main/java/com/cloud/api/query/ViewResponseHelper.java | 2 +- .../main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index fab6f0ad938..341e18cdc5d 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -3766,7 +3766,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VolumeStatsEntry vse = statEntry.get(chainInfo); if (vse != null) { vse.setPhysicalSize(vse.getPhysicalSize() + physicalsize); - vse.setVirtualSize(vse.getVirtualSize() + virtualsize); } } else { VolumeStatsEntry vse = new VolumeStatsEntry(chainInfo, physicalsize, virtualsize); diff --git a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java index ced81a6e06c..4baf25cfca3 100644 --- a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java +++ b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java @@ -268,7 +268,7 @@ public class ViewResponseHelper { public static List createVolumeResponse(ResponseView view, VolumeJoinVO... volumes) { Hashtable vrDataList = new Hashtable(); - DecimalFormat df = new DecimalFormat("0.00"); + DecimalFormat df = new DecimalFormat("0.0%"); for (VolumeJoinVO vr : volumes) { VolumeResponse vrData = vrDataList.get(vr.getId()); if (vrData == null) { diff --git a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java index fa0c380eb06..fd9a374bef0 100644 --- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java +++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java @@ -356,6 +356,7 @@ public class DatastoreMO extends BaseMO { FileQueryFlags fqf = new FileQueryFlags(); fqf.setFileSize(true); fqf.setFileOwner(true); + fqf.setFileType(true); fqf.setModification(true); searchSpec.setDetails(fqf); searchSpec.setSearchCaseInsensitive(false); From a529470b16642b77a39a42da6bbc827a3bf08951 Mon Sep 17 00:00:00 2001 From: Rakesh Date: Wed, 5 Aug 2020 10:32:09 +0200 Subject: [PATCH 3/3] server: Fix cpuallocated value in findHostsForMIgration api (#4220) The findHostsForMigration api displays 0% always for cpuallocated field which is wrong. Fixes #4221 --- .../cloud/api/query/dao/HostJoinDaoImpl.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java index 6f16462f4f3..597cc1ca446 100644 --- a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java +++ b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java @@ -190,10 +190,9 @@ public class HostJoinDaoImpl extends GenericDaoBase implements hostResponse.setHypervisorVersion(host.getHypervisorVersion()); - Float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()); - String cpuAlloc = decimalFormat.format(((float)cpu / cpuWithOverprovisioning * 100f)) + "%"; - hostResponse.setCpuAllocated(cpuAlloc); - hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString()); + float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()); + hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); + hostResponse.setCpuWithOverprovisioning(Float.toString(cpuWithOverprovisioning)); } if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) { @@ -317,7 +316,7 @@ public class HostJoinDaoImpl extends GenericDaoBase implements if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) { // set allocated capacities Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity(); - Long cpu = host.getCpuReservedCapacity() + host.getCpuReservedCapacity(); + Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity(); hostResponse.setMemoryTotal(host.getTotalMemory()); Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId()); @@ -340,10 +339,9 @@ public class HostJoinDaoImpl extends GenericDaoBase implements hostResponse.setHypervisorVersion(host.getHypervisorVersion()); - Float cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId())); - String cpuAlloc = decimalFormat.format(((float)cpu / cpuWithOverprovisioning * 100f)).toString() + "%"; - hostResponse.setCpuAllocated(cpuAlloc); - hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString()); + float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()); + hostResponse.setCpuAllocated(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning)); + hostResponse.setCpuWithOverprovisioning(Float.toString(cpuWithOverprovisioning)); } if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) { @@ -471,4 +469,9 @@ public class HostJoinDaoImpl extends GenericDaoBase implements return listBy(sc); } + private String calculateResourceAllocatedPercentage(float resource, float resourceWithOverProvision) { + DecimalFormat decimalFormat = new DecimalFormat("#.##"); + return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%"; + } + }