Skip to content

Commit 2ef6ed8

Browse files
committed
Bug 11789: The calculation for storage allocated capacity would go through the the common function throught which dashboard calculates the capacity as well.
Reviewed-By: Prachi
1 parent 33857e2 commit 2ef6ed8

1 file changed

Lines changed: 4 additions & 49 deletions

File tree

‎server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java‎

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.apache.log4j.Logger;
3030

31+
import com.cloud.capacity.CapacityManager;
3132
import com.cloud.configuration.Config;
3233
import com.cloud.configuration.dao.ConfigurationDao;
3334
import com.cloud.dc.ClusterVO;
@@ -78,8 +79,8 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
7879
@Inject StoragePoolHostDao _poolHostDao;
7980
@Inject ConfigurationDao _configDao;
8081
@Inject ClusterDao _clusterDao;
81-
@Inject
82-
SwiftManager _swiftMgr;
82+
@Inject SwiftManager _swiftMgr;
83+
@Inject CapacityManager _capacityMgr;
8384
protected BigDecimal _storageOverprovisioningFactor = new BigDecimal(1);
8485
long _extraBytesPerVolume = 0;
8586
Random _rand;
@@ -214,54 +215,8 @@ protected boolean checkPool(ExcludeList avoid, StoragePoolVO pool, DiskProfile d
214215
}
215216
}
216217
}
217-
218-
Pair<Long, Long> sizes = _volumeDao.getCountAndTotalByPool(pool.getId());
219218

220-
long totalAllocatedSize = sizes.second() + sizes.first() * _extraBytesPerVolume;
221-
222-
// Iterate through all templates on this storage pool
223-
boolean tmpinstalled = false;
224-
List<VMTemplateStoragePoolVO> templatePoolVOs;
225-
if (templatesInPool != null) {
226-
templatePoolVOs = templatesInPool;
227-
} else {
228-
templatePoolVOs = _templatePoolDao.listByPoolId(pool.getId());
229-
}
230-
231-
for (VMTemplateStoragePoolVO templatePoolVO : templatePoolVOs) {
232-
if ((template != null) && !tmpinstalled && (templatePoolVO.getTemplateId() == template.getId())) {
233-
tmpinstalled = true;
234-
}
235-
236-
long templateSize = templatePoolVO.getTemplateSize();
237-
totalAllocatedSize += templateSize + _extraBytesPerVolume;
238-
}
239-
240-
if ((template != null) && !tmpinstalled) {
241-
// If the template that was passed into this allocator is not installed in the storage pool,
242-
// add 3 * (template size on secondary storage) to the running total
243-
VMTemplateHostVO templateHostVO = _storageMgr.findVmTemplateHost(template.getId(), pool);
244-
245-
if (templateHostVO == null) {
246-
VMTemplateSwiftVO templateSwiftVO = _swiftMgr.findByTmpltId(template.getId());
247-
if (templateSwiftVO == null) {
248-
s_logger.error("Did not find template downloaded on secondary hosts in zone " + plan.getDataCenterId());
249-
return false;
250-
}
251-
long templateSize = templateSwiftVO.getPhysicalSize();
252-
if (templateSize == 0) {
253-
templateSize = templateSwiftVO.getSize();
254-
}
255-
totalAllocatedSize += (templateSize + _extraBytesPerVolume);
256-
} else {
257-
long templateSize = templateHostVO.getPhysicalSize();
258-
if ( templateSize == 0 ){
259-
templateSize = templateHostVO.getSize();
260-
}
261-
totalAllocatedSize += (templateSize + _extraBytesPerVolume);
262-
}
263-
}
264-
219+
long totalAllocatedSize = _capacityMgr.getAllocatedPoolCapacity(pool, null);
265220
long askingSize = dskCh.getSize();
266221

267222
long totalOverProvCapacity;

0 commit comments

Comments
 (0)