@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 boolean isSameScope(Scope scope) { return this.getScopeType() == scope.getScopeType() && this.getScopeId().equals(scope.getScopeId()); } }
protected EndPoint findEndpointForImageStorage(DataStore store) { Long dcId = null; Scope storeScope = store.getScope(); if (storeScope.getScopeType() == ScopeType.ZONE) { dcId = storeScope.getScopeId(); } // find ssvm that can be used to download data to store. For zone-wide // image store, use SSVM for that zone. For region-wide store, // we can arbitrarily pick one ssvm to do that task List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId); if (ssAHosts == null || ssAHosts.isEmpty()) { return null; } Collections.shuffle(ssAHosts); HostVO host = ssAHosts.get(0); return RemoteHostEndPoint.getHypervisorHostEndPoint(host); }
@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; }
if (scope.getScopeType() == ScopeType.HOST) { sbuilder.append(" and h.id = "); sbuilder.append(scope.getScopeId()); } else if (scope.getScopeType() == ScopeType.CLUSTER) { sbuilder.append(" and h.cluster_id = "); sbuilder.append(scope.getScopeId()); } else if (scope.getScopeType() == ScopeType.ZONE) { sbuilder.append(" and h.data_center_id = "); sbuilder.append(scope.getScopeId());
@Override public boolean isRegionStore(DataStore store) { if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null) return true; else return false; }
@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 (storeForNewStoreScope.getScopeType() == ScopeType.ZONE) { return false; if (storeForExistingStoreScope.getScopeType() != storeForNewStoreScope.getScopeType()) { if (storeForNewStoreScope.getScopeType() == ScopeType.CLUSTER) { Long vmClusterId = null; if (storeForExistingStoreScope.getScopeType() == ScopeType.HOST) { HostScope hs = (HostScope)storeForExistingStoreScope; vmClusterId = hs.getClusterId(); } else if (storeForExistingStoreScope.getScopeType() == ScopeType.ZONE) { Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId(); if (hostId != null) { return true; } else if (storeForNewStoreScope.getScopeType() == ScopeType.HOST && (storeForExistingStoreScope.getScopeType() == ScopeType.CLUSTER || storeForExistingStoreScope.getScopeType() == ScopeType.ZONE)) { Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId(); if (storeForNewStoreScope.getScopeId().equals(hostId)) { throw new InvalidParameterValueException("Can't move volume between scope: " + storeForNewStoreScope.getScopeType() + " and " + storeForExistingStoreScope.getScopeType());
@Override public DataObject createCacheObject(DataObject data, Scope scope) { DataStore cacheStore = getCacheStorage(scope); if (cacheStore == null) { String errMsg = "No cache DataStore in scope id " + scope.getScopeId() + " type " + scope.getScopeType().toString(); throw new CloudRuntimeException(errMsg); } return this.createCacheObject(data, cacheStore); }
protected EndPoint findEndPointForImageMove(DataStore srcStore, DataStore destStore) { // find any xenserver/kvm host in the scope Scope srcScope = srcStore.getScope(); Scope destScope = destStore.getScope(); Scope selectedScope = null; Long poolId = null; // assumption, at least one of scope should be zone, find the least // scope if (srcScope.getScopeType() != ScopeType.ZONE) { selectedScope = srcScope; poolId = srcStore.getId(); } else if (destScope.getScopeType() != ScopeType.ZONE) { selectedScope = destScope; poolId = destStore.getId(); } else { // if both are zone scope if (srcStore.getRole() == DataStoreRole.Primary) { selectedScope = srcScope; poolId = srcStore.getId(); } else if (destStore.getRole() == DataStoreRole.Primary) { selectedScope = destScope; poolId = destStore.getId(); } } return findEndPointInScope(selectedScope, findOneHostOnPrimaryStorage, poolId); }
@Override public List<EndPoint> selectAll(DataStore store) { List<EndPoint> endPoints = new ArrayList<EndPoint>(); if (store.getScope().getScopeType() == ScopeType.HOST) { HostVO host = hostDao.findById(store.getScope().getScopeId()); endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host)); } else if (store.getScope().getScopeType() == ScopeType.CLUSTER) { QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getClusterId(), Op.EQ, store.getScope().getScopeId()); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); List<HostVO> hosts = sc.list(); for (HostVO host : hosts) { endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host)); } } else { throw new CloudRuntimeException("shouldn't use it for other scope"); } return endPoints; } }
@Override public EndPoint select(DataObject object) { DataStore store = object.getDataStore(); EndPoint ep = select(store); if (ep != null) { return ep; } if (object instanceof TemplateInfo) { TemplateInfo tmplInfo = (TemplateInfo)object; if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null && tmplInfo.getTemplateType() == TemplateType.SYSTEM) { return LocalHostEndpoint.getEndpoint(); // for bootstrap system vm template downloading to region image store } } return null; }
} else if (plan.getDataCenterId() == exstPoolDcId) { DataStore dataStore = dataStoreMgr.getPrimaryDataStore(pool.getId()); if (dataStore != null && dataStore.getScope() != null && dataStore.getScope().getScopeType() == ScopeType.ZONE) { canReusePool = true;
if (dsScope.getScopeType() == ScopeType.ZONE) { if (dsScope.getScopeId() != null) { UsageEventUtils.publishUsageEvent(etype, template.getAccountId(), dsScope.getScopeId(), template.getId(), template.getName(), null, null, s_logger.warn("Zone scope image store " + ds.getId() + " has a null scope id"); } else if (dsScope.getScopeType() == ScopeType.REGION) {
if (result.isSuccess()) { if (imageStore.getScope().getScopeType() == ScopeType.REGION) { associateTemplateToZone(templateId, null); } else if (imageStore.getScope().getScopeType() == ScopeType.ZONE) { Long zoneId = ((ImageStoreEntity)imageStore).getDataCenterId(); VMTemplateZoneVO templateZone = new VMTemplateZoneVO(zoneId, templateId, new Date());
if (dsScope.getScopeType() == ScopeType.ZONE) { if (dsScope.getScopeId() != null) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_UPLOAD, vo.getAccountId(), dsScope.getScopeId(), vo.getId(), vo.getName(), null, null, physicalSize, vo.getSize(), s_logger.warn("Zone scope image store " + ds.getId() + " has a null scope id"); } else if (dsScope.getScopeType() == ScopeType.REGION) {
if (store.getScope().getScopeType() == ScopeType.REGION) { if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && volumeHost.getInstallPath() == null) { s_logger.info("Skip sync volume for migration of previous NFS to object store");