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 boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.HypervisorType hypervisorType) { dataStoreHelper.attachZone(dataStore); List<HostVO> xenServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.XenServer, scope.getScopeId()); List<HostVO> vmWareServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.VMware, scope.getScopeId()); List<HostVO> kvmHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.KVM, scope.getScopeId()); List<HostVO> hosts = new ArrayList<HostVO>(); hosts.addAll(xenServerHosts); hosts.addAll(vmWareServerHosts); hosts.addAll(kvmHosts); for (HostVO host : hosts) { try { _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); } catch (Exception e) { logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } return true; }
@Override public Scope getScope() { return new ZoneScope(imageDataStoreVO.getDataCenterId()); }
@Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { List<HostVO> xenServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType.XenServer, scope.getScopeId()); List<HostVO> vmWareServerHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType.VMware, scope.getScopeId()); List<HostVO> kvmHosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType.KVM, scope.getScopeId()); List<HostVO> hosts = new ArrayList<>(); hosts.addAll(xenServerHosts); hosts.addAll(vmWareServerHosts); hosts.addAll(kvmHosts); for (HostVO host : hosts) { try { _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); } catch (Exception e) { s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } _dataStoreHelper.attachZone(dataStore); return true; }
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 List<ImageStoreVO> findImageCacheByScope(ZoneScope scope) { SearchCriteria<ImageStoreVO> sc = createSearchCriteria(); sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.ImageCache); if (scope.getScopeId() != null) { sc.addAnd("scope", SearchCriteria.Op.EQ, ScopeType.ZONE); sc.addAnd("dcId", SearchCriteria.Op.EQ, scope.getScopeId()); } return listBy(sc); }
@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 boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); s_logger.debug("In createPool. Attaching the pool to each of the hosts."); List<HostVO> poolHosts = new ArrayList<HostVO>(); for (HostVO host : hosts) { try { storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); poolHosts.add(host); } catch (Exception e) { s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } if (poolHosts.isEmpty()) { s_logger.warn("No host can access storage pool " + dataStore + " in this zone."); primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts."); } dataStoreHelper.attachZone(dataStore, hypervisorType); return true; }
@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 List<ImageStoreVO> findByScope(ZoneScope scope) { SearchCriteria<ImageStoreVO> sc = createSearchCriteria(); sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.Image); if (scope.getScopeId() != null) { SearchCriteria<ImageStoreVO> scc = createSearchCriteria(); scc.addOr("scope", SearchCriteria.Op.EQ, ScopeType.REGION); scc.addOr("dcId", SearchCriteria.Op.EQ, scope.getScopeId()); sc.addAnd("scope", SearchCriteria.Op.SC, scc); } // we should return all image stores if cross-zone scope is passed // (scopeId = null) return listBy(sc); }
@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 boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); s_logger.debug("In createPool. Attaching the pool to each of the hosts."); List<HostVO> poolHosts = new ArrayList<HostVO>(); for (HostVO host : hosts) { try { storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); poolHosts.add(host); } catch (StorageConflictException se) { primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Storage has already been added as local storage to host: " + host.getName()); } catch (Exception e) { s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } if (poolHosts.isEmpty()) { s_logger.warn("No host can access storage pool " + dataStore + " in this zone."); primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts."); } dataStoreHelper.attachZone(dataStore, hypervisorType); return true; }
@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; }
List<DataStore> imageStores = storeMgr.getImageStoresByScope(new ZoneScope(zoneId)); if (imageStores == null || imageStores.size() == 0) { throw new CloudRuntimeException("Unable to find image store to download template " + profile.getTemplate());
@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; } }