Bug 11789: Created a function for calculation of allocated primary storage. The dashboard calculation would go through this.

Reviewed-By: Kishan
This commit is contained in:
Nitin Mehta 2012-01-31 12:31:18 +05:30
parent 73aa18eac9
commit 33857e21e3
3 changed files with 78 additions and 4 deletions

View File

@ -300,9 +300,7 @@ public class AlertManagerImpl implements AlertManager {
// Calculate storage pool capacity
List<StoragePoolVO> storagePools = _storagePoolDao.listAll();
for (StoragePoolVO pool : storagePools) {
long disk = 0l;
Pair<Long, Long> sizes = _volumeDao.getCountAndTotalByPool(pool.getId());
disk = sizes.second();
long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
if (pool.isShared()){
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
}else {
@ -312,7 +310,7 @@ public class AlertManagerImpl implements AlertManager {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Done executing storage capacity update");
s_logger.debug("Executing capacity updates public ip and Vlans");
s_logger.debug("Executing capacity updates for public ip and Vlans");
}
List<DataCenterVO> datacenters = _dcDao.listAll();

View File

@ -19,6 +19,8 @@
package com.cloud.capacity;
import com.cloud.host.HostVO;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.utils.component.Manager;
import com.cloud.vm.VirtualMachine;
@ -43,4 +45,12 @@ public interface CapacityManager extends Manager {
boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor, boolean considerReservedCapacity);
void updateCapacityForHost(HostVO host);
/**
* Returns the allocated capacity for the storage pool. If template is passed in it will include its size if its not already present on the pool
* @param pool storage pool
* @param templateForVmCreation template that will be used for vm creation
* @return total allocated capacity for the storage pool
*/
long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation);
}

View File

@ -50,6 +50,15 @@ import com.cloud.resource.ResourceManager;
import com.cloud.resource.ServerResource;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStoragePoolVO;
import com.cloud.storage.VMTemplateSwiftVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.VMTemplatePoolDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.swift.SwiftManager;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
@ -79,14 +88,23 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
HostDao _hostDao;
@Inject
VMInstanceDao _vmDao;
@Inject
VolumeDao _volumeDao;
@Inject
VMTemplatePoolDao _templatePoolDao;
@Inject
AgentManager _agentManager;
@Inject
ResourceManager _resourceMgr;
@Inject
StorageManager _storageMgr;
@Inject
SwiftManager _swiftMgr;
private int _vmCapacityReleaseInterval;
private ScheduledExecutorService _executor;
private boolean _stopped;
long _extraBytesPerVolume = 0;
private float _storageOverProvisioningFactor = 1.0f;
private float _cpuOverProvisioningFactor = 1.0f;
@ -415,6 +433,54 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
}
@Override
public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation){
// Get size for all the volumes
Pair<Long, Long> sizes = _volumeDao.getCountAndTotalByPool(pool.getId());
long totalAllocatedSize = sizes.second() + sizes.first() * _extraBytesPerVolume;
// Iterate through all templates on this storage pool
boolean tmpinstalled = false;
List<VMTemplateStoragePoolVO> templatePoolVOs;
templatePoolVOs = _templatePoolDao.listByPoolId(pool.getId());
for (VMTemplateStoragePoolVO templatePoolVO : templatePoolVOs) {
if ((templateForVmCreation != null) && !tmpinstalled && (templatePoolVO.getTemplateId() == templateForVmCreation.getId())) {
tmpinstalled = true;
}
long templateSize = templatePoolVO.getTemplateSize();
totalAllocatedSize += templateSize + _extraBytesPerVolume;
}
// Add the size for the templateForVmCreation if its not already present
if ((templateForVmCreation != null) && !tmpinstalled) {
// If the template that was passed into this allocator is not installed in the storage pool,
// add 3 * (template size on secondary storage) to the running total
VMTemplateHostVO templateHostVO = _storageMgr.findVmTemplateHost(templateForVmCreation.getId(), pool);
if (templateHostVO == null) {
VMTemplateSwiftVO templateSwiftVO = _swiftMgr.findByTmpltId(templateForVmCreation.getId());
if (templateSwiftVO != null) {
long templateSize = templateSwiftVO.getPhysicalSize();
if (templateSize == 0) {
templateSize = templateSwiftVO.getSize();
}
totalAllocatedSize += (templateSize + _extraBytesPerVolume);
}
} else {
long templateSize = templateHostVO.getPhysicalSize();
if ( templateSize == 0 ){
templateSize = templateHostVO.getSize();
}
totalAllocatedSize += (templateSize + _extraBytesPerVolume);
}
}
return totalAllocatedSize;
}
@DB
@Override
public void updateCapacityForHost(HostVO host){