private Scope getZoneScope(Scope scope) { ZoneScope zoneScope; if (scope instanceof ClusterScope) { ClusterScope clusterScope = (ClusterScope)scope; zoneScope = new ZoneScope(clusterScope.getZoneId()); } else if (scope instanceof HostScope) { HostScope hostScope = (HostScope)scope; zoneScope = new ZoneScope(hostScope.getZoneId()); } else { zoneScope = (ZoneScope)scope; } return zoneScope; }
@Override public Scope getScope() { return new ZoneScope(imageDataStoreVO.getDataCenterId()); }
private Scope getZoneScope(Scope destScope) { ZoneScope zoneScope = null; if (destScope instanceof ClusterScope) { ClusterScope clusterScope = (ClusterScope)destScope; zoneScope = new ZoneScope(clusterScope.getZoneId()); } else if (destScope instanceof HostScope) { HostScope hostScope = (HostScope)destScope; zoneScope = new ZoneScope(hostScope.getZoneId()); } else { zoneScope = (ZoneScope)destScope; } return zoneScope; }
@Override public DataStore getImageStore(long zoneId) { List<DataStore> stores = getImageStoresByScope(new ZoneScope(zoneId)); if (stores == null || stores.size() == 0) { return null; } return imageDataStoreMgr.getImageStore(stores); }
@Override public DataStore getImageCacheStore(long zoneId) { List<DataStore> stores = getImageCacheStores(new ZoneScope(zoneId)); if (stores == null || stores.size() == 0) { return null; } return imageDataStoreMgr.getImageStore(stores); }
@Override public TemplateDataStoreVO findByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) { // get all elgible image stores List<DataStore> imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId)); if (imgStores != null) { for (DataStore store : imgStores) { 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 List<DataStore> getImageStoreByTemplate(long templateId, Long zoneId) { // find all eligible image stores for this zone scope List<DataStore> imageStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId)); if (imageStores == null || imageStores.size() == 0) { return null; } List<DataStore> stores = new ArrayList<DataStore>(); for (DataStore store : imageStores) { // check if the template is stored there List<TemplateDataStoreVO> storeTmpl = _tmplStoreDao.listByTemplateStore(templateId, store.getId()); if (storeTmpl != null && storeTmpl.size() > 0) { stores.add(store); } } return stores; }
@Override public TemplateDataStoreVO findByTemplateZoneReady(long templateId, Long zoneId) { List<DataStore> imgStores = null; imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId)); if (imgStores != null) { Collections.shuffle(imgStores); for (DataStore store : imgStores) { List<TemplateDataStoreVO> sRes = listByTemplateStoreStatus(templateId, store.getId(), State.Ready); if (sRes != null && sRes.size() > 0) { return sRes.get(0); } } } return null; }
@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 List<TemplateDataStoreVO> listByTemplateZoneDownloadStatus(long templateId, Long zoneId, Status... status) { // get all elgible image stores List<DataStore> imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId)); if (imgStores != null) { List<TemplateDataStoreVO> result = new ArrayList<TemplateDataStoreVO>(); for (DataStore store : imgStores) { List<TemplateDataStoreVO> sRes = listByTemplateStoreDownloadStatus(templateId, store.getId(), status); if (sRes != null && sRes.size() > 0) { result.addAll(sRes); } } return result; } 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 List<DataStore> listImageCacheStores(Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { s_logger.debug("only support zone wide image cache stores"); return null; } List<ImageStoreVO> stores = dataStoreDao.findImageCacheByScope(new ZoneScope(scope.getScopeId())); List<DataStore> imageStores = new ArrayList<DataStore>(); for (ImageStoreVO store : stores) { imageStores.add(getImageStore(store.getId())); } return imageStores; }
@Override public TemplateInfo prepareIso(long isoId, long dcId, Long hostId, Long poolId) { TemplateInfo tmplt; boolean bypassed = false; if (_tmplFactory.isTemplateMarkedForDirectDownload(isoId)) { tmplt = _tmplFactory.getReadyBypassedTemplateOnPrimaryStore(isoId, poolId, hostId); bypassed = true; } else { tmplt = _tmplFactory.getTemplate(isoId, DataStoreRole.Image, dcId); } if (tmplt == null || tmplt.getFormat() != ImageFormat.ISO) { s_logger.warn("ISO: " + isoId + " does not exist in vm_template table"); return null; } if (!bypassed && tmplt.getDataStore() != null && !(tmplt.getDataStore().getTO() instanceof NfsTO)) { // if it is s3, need to download into cache storage first Scope destScope = new ZoneScope(dcId); TemplateInfo cacheData = (TemplateInfo)cacheMgr.createCacheObject(tmplt, destScope); if (cacheData == null) { s_logger.error("Failed in copy iso from S3 to cache storage"); return null; } return cacheData; } else { return tmplt; } }
@Override public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) { Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>(); List<DataStore> stores = _storeMgr.getImageStoresByScope(new ZoneScope(dcId)); if (stores == null || stores.isEmpty()) { return;
private void addStorageMetrics(final List<Item> metricsList, final long dcId, final String zoneName, final String zoneUuid) { for (final StoragePoolJoinVO pool: storagePoolJoinDao.listAll()) { if (pool == null || pool.getZoneId() != dcId) { continue; } final String poolName = pool.getName(); final String poolPath = pool.getHostAddress() + ":" + pool.getPath(); long usedCapacity = 0L; long allocatedCapacity = pool.getUsedCapacity() + pool.getReservedCapacity(); final long totalCapacity = pool.getCapacityBytes(); final StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId()); if (stats != null) { usedCapacity = stats.getByteUsed(); } final BigDecimal poolOverProvisioningFactor = BigDecimal.valueOf(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())); final String poolFactor = poolOverProvisioningFactor.toString(); metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, USED, usedCapacity)); metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, ALLOCATED, allocatedCapacity)); metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, UNALLOCATED, poolOverProvisioningFactor.multiply(BigDecimal.valueOf(totalCapacity)).longValue() - allocatedCapacity)); metricsList.add(new ItemPool(zoneName, zoneUuid, poolName, poolPath, "primary", poolFactor, TOTAL, totalCapacity)); } for (final ImageStore imageStore : imageStoreDao.findByScope(new ZoneScope(dcId))) { final StorageStats stats = ApiDBUtils.getSecondaryStorageStatistics(imageStore.getId()); metricsList.add(new ItemPool(zoneName, zoneUuid, imageStore.getName(), imageStore.getUrl(), "secondary", null, USED, stats != null ? stats.getByteUsed() : 0)); metricsList.add(new ItemPool(zoneName, zoneUuid, imageStore.getName(), imageStore.getUrl(), "secondary", null, TOTAL, stats != null ? stats.getCapacityBytes() : 0)); } }
@Override public CapacityVO getSecondaryStorageUsedStats(Long hostId, Long zoneId) { SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria(); if (zoneId != null) { sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); } List<Long> hosts = new ArrayList<Long>(); if (hostId != null) { hosts.add(hostId); } else { List<DataStore> stores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId)); if (stores != null) { for (DataStore store : stores) { hosts.add(store.getId()); } } } CapacityVO capacity = new CapacityVO(hostId, zoneId, null, null, 0, 0, Capacity.CAPACITY_TYPE_SECONDARY_STORAGE); for (Long id : hosts) { StorageStats stats = ApiDBUtils.getSecondaryStorageStatistics(id); if (stats == null) { continue; } capacity.setUsedCapacity(stats.getByteUsed() + capacity.getUsedCapacity()); capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity()); } return capacity; }
if(!_imageStoreDao.findByScope(new ZoneScope(zoneId)).isEmpty()) { throw new CloudRuntimeException(errorMsg + "there are Secondary storages in this zone");
@Override public Scope getScope() { StoragePoolVO vo = dataStoreDao.findById(pdsv.getId()); if (vo.getScope() == ScopeType.CLUSTER) { return new ClusterScope(vo.getClusterId(), vo.getPodId(), vo.getDataCenterId()); } else if (vo.getScope() == ScopeType.ZONE) { return new ZoneScope(vo.getDataCenterId()); } else if (vo.getScope() == ScopeType.HOST) { List<StoragePoolHostVO> poolHosts = poolHostDao.listByPoolId(vo.getId()); if (poolHosts.size() > 0) { return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId()); } s_logger.debug("can't find a local storage in pool host table: " + vo.getId()); } return null; }
List<DataStore> imageStores = _storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId())); for (DataStore store : imageStores) { _volumeSrv.handleVolumeSync(store);
if (!(storTO instanceof NfsTO)) { srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));