Populate diskofferingid in usage events only if the offering is of type disk

This commit is contained in:
kishan 2011-01-20 13:38:29 +05:30
parent 8563322993
commit c685c77d74
2 changed files with 24 additions and 4 deletions

View File

@ -670,7 +670,15 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
long sizeMB = createdVolume.getSize()/(1024*1024);
if (createdVolume.getPath() != null) {
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, templateId , sizeMB);
Long offeringId = null;
if(diskOfferingId != null){
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
if(offering!=null && (offering.getType() == DiskOfferingVO.Type.Disk)){
offeringId = offering.getId();
}
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), offeringId, templateId , sizeMB);
_usageEventDao.persist(usageEvent);
}
txn.commit();
@ -2541,7 +2549,13 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
EventUtils.saveEvent(userId, vol.getAccountId(), EventTypes.EVENT_VOLUME_CREATE, "Created volume: "+ vol.getName() +" with size: " + sizeMB + " MB");
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), template.getId() , sizeMB);
Long offeringId = null;
if(offering.getType() == DiskOfferingVO.Type.Disk){
offeringId = offering.getId();
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offeringId, template.getId() , sizeMB);
_usageEventDao.persist(usageEvent);
_accountMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume);

View File

@ -1015,8 +1015,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
Long diskOfferingId = volume.getDiskOfferingId();
long sizeMB = volume.getSize()/(1024*1024);
StoragePoolVO pool = _storagePoolDao.findById(volume.getPoolId());
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, templateId , sizeMB);
Long offeringId = null;
if(diskOfferingId != null){
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
if(offering!=null && (offering.getType() == DiskOfferingVO.Type.Disk)){
offeringId = offering.getId();
}
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), offeringId, templateId , sizeMB);
_usageEventDao.persist(usageEvent);
}