@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); }
private Scope pickCacheScopeForCopy(DataObject srcData, DataObject destData) { Scope srcScope = srcData.getDataStore().getScope(); Scope destScope = destData.getDataStore().getScope(); Scope selectedScope = null; if (srcScope.getScopeId() != null) { selectedScope = getZoneScope(srcScope); } else if (destScope.getScopeId() != null) { selectedScope = getZoneScope(destScope); } else { LOGGER.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); } return selectedScope; }
@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; }
private Scope pickCacheScopeForCopy(DataObject srcData, DataObject destData) { Scope srcScope = srcData.getDataStore().getScope(); Scope destScope = destData.getDataStore().getScope(); Scope selectedScope = null; if (srcScope.getScopeId() != null) { selectedScope = getZoneScope(srcScope); } else if (destScope.getScopeId() != null) { selectedScope = getZoneScope(destScope); } else { s_logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); } return selectedScope; }
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); } }
@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); }
@Override public void downloadBootstrapSysTemplate(DataStore store) { Set<VMTemplateVO> toBeDownloaded = new HashSet(); List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates(); for (VMTemplateVO rtngTmplt : rtngTmplts) { toBeDownloaded.add(rtngTmplt); } List<HypervisorType> availHypers = _clusterDao.getAvailableHypervisorInZone(store.getScope().getScopeId()); if (availHypers.isEmpty()) { /* * This is for cloudzone, local secondary storage resource started * before cluster created */ availHypers.add(HypervisorType.KVM); } /* Baremetal need not to download any template */ availHypers.remove(HypervisorType.BareMetal); availHypers.add(HypervisorType.None); // bug 9809: resume ISO // download. for (VMTemplateVO template : toBeDownloaded) { if (availHypers.contains(template.getHypervisorType())) { // only download sys template applicable for current hypervisor TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId()); if (tmpltHost == null || tmpltHost.getState() != ObjectInDataStoreStateMachine.State.Ready) { TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image); createTemplateAsync(tmplt, store, null); } } } }
@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; }
Long zoneId = imageStore.getScope().getScopeId(); if (zoneId != null) { DataCenterVO zone = _dcDao.findById(zoneId);
if (dsScope.getScopeId() != null) { UsageEventUtils.publishUsageEvent(etype, template.getAccountId(), dsScope.getScopeId(), template.getId(), template.getName(), null, null, physicalSize, template.getSize(), VirtualMachineTemplate.class.getName(), template.getUuid()); } else {
if (dsScope.getScopeId() != null) { UsageEventUtils.publishUsageEvent(etype, template.getAccountId(), dsScope.getScopeId(), template.getId(), template.getName(), null, null, physicalSize, template.getSize(), VirtualMachineTemplate.class.getName(), template.getUuid()); } else {
Long zoneId_is = imageStore.getScope().getScopeId(); if (zoneId != null) { DataCenterVO zone = _dcDao.findById(zoneId_is);
ImageStoreEntity imageStore = (ImageStoreEntity)dataStoreMgr.getImageStore(destScope.getScopeId()); if (!imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) { s_logger.debug("can't find a nfs (or cifs) image store to satisfy the need for a staging store");
if (dsScope.getScopeId() != null) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_UPLOAD, vo.getAccountId(), dsScope.getScopeId(), vo.getId(), vo.getName(), null, null, physicalSize, vo.getSize(), Volume.class.getName(), vo.getUuid()); } else {
if (storeForNewStoreScope.getScopeId().equals(vmClusterId)) { return false; } else { && (storeForExistingStoreScope.getScopeType() == ScopeType.CLUSTER || storeForExistingStoreScope.getScopeType() == ScopeType.ZONE)) { Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId(); if (storeForNewStoreScope.getScopeId().equals(hostId)) { return false;