@Override public DataStore getCacheStore(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 == null) || (cacheStores.size() <= 0)) { s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); return null; } return imageStoreMgr.getImageStore(cacheStores); }
@Override public TemplateDataStoreVO findByTemplateZoneStagingDownloadStatus(long templateId, Long zoneId, Status... status) { // get all elgible image stores List<DataStore> cacheStores = _storeMgr.getImageCacheStores(new ZoneScope(zoneId)); if (cacheStores != null) { for (DataStore store : cacheStores) { List<TemplateDataStoreVO> sRes = listByTemplateStoreDownloadStatus(templateId, store.getId(), status); if (sRes != null && sRes.size() > 0) { Collections.shuffle(sRes); return sRes.get(0); } } } return null; }
@Override public TemplateDataStoreVO findByTemplateZone(long templateId, Long zoneId, DataStoreRole role) { // get all elgible image stores List<DataStore> imgStores = null; if (role == DataStoreRole.Image) { imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId)); } else if (role == DataStoreRole.ImageCache) { imgStores = _storeMgr.getImageCacheStores(new ZoneScope(zoneId)); } if (imgStores != null) { for (DataStore store : imgStores) { List<TemplateDataStoreVO> sRes = listByTemplateStore(templateId, store.getId()); if (sRes != null && sRes.size() > 0) { return sRes.get(0); } } } return null; }
@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); } }