@Override public DataStore getImageStore(List<DataStore> imageStores) { if (imageStores.size() > 1) { Collections.shuffle(imageStores); // Randomize image store list. Iterator<DataStore> i = imageStores.iterator(); DataStore imageStore = null; while(i.hasNext()) { imageStore = i.next(); // Return image store if used percentage is less then threshold value i.e. 90%. if (_statsCollector.imageStoreHasEnoughCapacity(imageStore)) { return imageStore; } } } return imageStores.get(0); } }
@Override public DataStore getCacheStore(DataObject data, Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { s_logger.debug("Can only support zone wide cache storage"); return null; } List<DataStore> cacheStores = dataStoreMgr.getImageCacheStores(scope); if (cacheStores.size() <= 0) { s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); return null; } // if there are multiple cache stores, we give priority to the one where data is already there if (cacheStores.size() > 1) { for (DataStore store : cacheStores) { DataObjectInStore obj = objectInStoreMgr.findObject(data, store); if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready && statsCollector.imageStoreHasEnoughCapacity(store)) { s_logger.debug("pick the cache store " + store.getId() + " where data is already there"); return store; } } } return imageStoreMgr.getImageStore(cacheStores); } }
if (!_statsCollector.imageStoreHasEnoughCapacity(imageStore)) { s_logger.info("Image store doesn't have enough capacity. Skip downloading template to this image store " + imageStore.getId()); continue;