|
28 | 28 |
|
29 | 29 | import org.apache.log4j.Logger; |
30 | 30 |
|
| 31 | +import com.cloud.capacity.CapacityManager; |
31 | 32 | import com.cloud.configuration.Config; |
32 | 33 | import com.cloud.configuration.dao.ConfigurationDao; |
33 | 34 | import com.cloud.dc.ClusterVO; |
@@ -78,8 +79,8 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement |
78 | 79 | @Inject StoragePoolHostDao _poolHostDao; |
79 | 80 | @Inject ConfigurationDao _configDao; |
80 | 81 | @Inject ClusterDao _clusterDao; |
81 | | - @Inject |
82 | | - SwiftManager _swiftMgr; |
| 82 | + @Inject SwiftManager _swiftMgr; |
| 83 | + @Inject CapacityManager _capacityMgr; |
83 | 84 | protected BigDecimal _storageOverprovisioningFactor = new BigDecimal(1); |
84 | 85 | long _extraBytesPerVolume = 0; |
85 | 86 | Random _rand; |
@@ -214,54 +215,8 @@ protected boolean checkPool(ExcludeList avoid, StoragePoolVO pool, DiskProfile d |
214 | 215 | } |
215 | 216 | } |
216 | 217 | } |
217 | | - |
218 | | - Pair<Long, Long> sizes = _volumeDao.getCountAndTotalByPool(pool.getId()); |
219 | 218 |
|
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); |
265 | 220 | long askingSize = dskCh.getSize(); |
266 | 221 |
|
267 | 222 | long totalOverProvCapacity; |
|
0 commit comments