Skip to content

Commit f9e3936

Browse files
committed
fixes
Check for NPE during nic network validation Filter orphan, removed volumes while list unmanaged VMs from VMware Publish usage and update resource count only after import complete Use disk size when disk offering for disk is of higher size durng import Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent f0aee9b commit f9e3936

File tree

6 files changed

+177
-66
lines changed

6 files changed

+177
-66
lines changed

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,15 +1674,6 @@ public DiskProfile importVolume(Type type, String name, DiskOffering offering, L
16741674
vol.setChainInfo(chainInfo);
16751675
vol.setState(Volume.State.Ready);
16761676
vol = _volsDao.persist(vol);
1677-
1678-
// Save usage event and update resource count for user vm volumes
1679-
if (vm.getType() == VirtualMachine.Type.User) {
1680-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null, size,
1681-
Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
1682-
1683-
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, vol.isDisplayVolume());
1684-
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, vol.isDisplayVolume(), new Long(vol.getSize()));
1685-
}
16861677
return toDiskProfile(vol, offering);
16871678
}
16881679
}

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
9696

9797
List<Long> listZoneWidePoolIdsByVolumeCount(long dcId, long accountId);
9898

99+
List<VolumeVO> findIncludingRemovedByZone(long zoneId);
100+
99101
/**
100102
* Gets the Total Primary Storage space allocated for an account
101103
*

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,13 @@ public List<Long> listZoneWidePoolIdsByVolumeCount(long dcId, long accountId) {
595595
}
596596
}
597597

598+
@Override
599+
public List<VolumeVO> findIncludingRemovedByZone(long zoneId) {
600+
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
601+
sc.setParameters("dcId", zoneId);
602+
return searchIncludingRemoved(sc, null, null, false);
603+
}
604+
598605
@Override
599606
@DB()
600607
public Pair<Long, Long> getNonDestroyedCountAndTotalByPool(long poolId) {

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,16 +3977,18 @@ public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCap
39773977
}
39783978
CallContext.current().setEventDetails("Vm Id: " + vm.getUuid());
39793979

3980-
if (!offering.isDynamic()) {
3981-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), template.getId(),
3982-
hypervisorType.toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
3983-
} else {
3984-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), template.getId(),
3985-
hypervisorType.toString(), VirtualMachine.class.getName(), vm.getUuid(), customParameters, vm.isDisplayVm());
3986-
}
3980+
if (!isImport) {
3981+
if (!offering.isDynamic()) {
3982+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), template.getId(),
3983+
hypervisorType.toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
3984+
} else {
3985+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), template.getId(),
3986+
hypervisorType.toString(), VirtualMachine.class.getName(), vm.getUuid(), customParameters, vm.isDisplayVm());
3987+
}
39873988

3988-
//Update Resource Count for the given account
3989-
resourceCountIncrement(accountId, isDisplayVm, new Long(offering.getCpu()), new Long(offering.getRamSize()));
3989+
//Update Resource Count for the given account
3990+
resourceCountIncrement(accountId, isDisplayVm, new Long(offering.getCpu()), new Long(offering.getRamSize()));
3991+
}
39903992
return vm;
39913993
}
39923994
});

0 commit comments

Comments
 (0)