@Override public long getDataCenterId() { return pdsv.getDataCenterId(); }
public void prepareTemplateInAllStoragePools(final VMTemplateVO template, long zoneId) { List<StoragePoolVO> pools = _poolDao.listByStatus(StoragePoolStatus.Up); for (final StoragePoolVO pool : pools) { if (pool.getDataCenterId() == zoneId) { prepareTemplateInOneStoragePool(template, pool); } else { s_logger.info("Skip loading template " + template.getId() + " into primary storage " + pool.getId() + " as pool zone " + pool.getDataCenterId() + " is different from the requested zone " + zoneId); } } }
@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; }
private static boolean isStorageApplicableToZoneOrCluster(StoragePoolVO storagePoolVO, long clusterId, ClusterDao clusterDao) { if (storagePoolVO.getClusterId() != null) { if (storagePoolVO.getClusterId() == clusterId) { return true; } } else { List<ClusterVO> clustersInZone = clusterDao.listByZoneId(storagePoolVO.getDataCenterId()); if (clustersInZone != null) { for (ClusterVO clusterInZone : clustersInZone) { if (clusterInZone.getId() == clusterId) { return true; } } } } return false; }
@Override public VirtualMachineTemplate prepareTemplate(long templateId, long zoneId, Long storageId) { VMTemplateVO vmTemplate = _tmpltDao.findById(templateId); if (vmTemplate == null) { throw new InvalidParameterValueException("Unable to find template id=" + templateId); } _accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.OperateEntry, true, vmTemplate); if (storageId != null) { StoragePoolVO pool = _poolDao.findById(storageId); if (pool != null) { if (pool.getStatus() == StoragePoolStatus.Up && pool.getDataCenterId() == zoneId) { prepareTemplateInOneStoragePool(vmTemplate, pool); } else { s_logger.warn("Skip loading template " + vmTemplate.getId() + " into primary storage " + pool.getId() + " as either the pool zone " + pool.getDataCenterId() + " is different from the requested zone " + zoneId + " or the pool is currently not available."); } } } else { prepareTemplateInAllStoragePools(vmTemplate, zoneId); } return vmTemplate; }
if (pool.getScope() == ScopeType.ZONE) { volumeStatsByUuid = new HashMap<>(); for (final Cluster cluster : _clusterDao.listByZoneId(pool.getDataCenterId())) { final Map<String, VolumeStatsEntry> volumeStatsForCluster = _userVmMgr.getVolumeStatistics(cluster.getId(), pool.getUuid(), pool.getPoolType(), volumeLocators, StatsTimeout.value());
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria(); capacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, storagePool.getId()); capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, storagePool.getDataCenterId()); capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType); CapacityState capacityState = CapacityState.Enabled; if (storagePool.getScope() == ScopeType.ZONE) { DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId()); AllocationState allocationState = dc.getAllocationState(); capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled; CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType); capacity.setCapacityState(capacityState); s_logger.debug("Successfully set Capacity - " + totalOverProvCapacity + " for capacity type - " + capacityType + " , DataCenterId - " + storagePool.getDataCenterId() + ", HostOrPoolId - " + storagePool.getId() + ", PodId " + storagePool.getPodId());
hostDao.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, storagePool.getClusterId(), storagePool.getPodId(), storagePool.getDataCenterId(), null); if (listHost == null || listHost.size() == 0) { throw new InvalidParameterValueException("no host in up state is found");
@Override public List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType) { QueryBuilder<StoragePoolVO> sc = QueryBuilder.create(StoragePoolVO.class); sc.and(sc.entity().getDataCenterId(), Op.EQ, dataCenterId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); sc.and(sc.entity().getScope(), Op.EQ, ScopeType.ZONE); sc.and(sc.entity().getHypervisor(), Op.EQ, hypervisorType); return sc.list(); }
@Override public List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags) { if (tags == null || tags.length == 0) { QueryBuilder<StoragePoolVO> sc = QueryBuilder.create(StoragePoolVO.class); sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); sc.and(sc.entity().getScope(), Op.EQ, ScopeType.ZONE); return sc.list(); } else { String sqlValues = getSqlValuesFromStorageTags(tags); String sql = getSqlPreparedStatement(ZoneWideTagsSqlPrefix, ZoneWideTagsSqlSuffix, sqlValues, null); return searchStoragePoolsPreparedStatement(sql, dcId, null, null, ScopeType.ZONE, tags.length); } }
private HypervisorType getHypervisorType(VMInstanceVO vm, StoragePool srcVolumePool, VirtualMachineProfile profile) { HypervisorType type = null; if (vm == null) { StoragePoolVO poolVo = _poolDao.findById(srcVolumePool.getId()); if (ScopeType.CLUSTER.equals(poolVo.getScope())) { Long clusterId = poolVo.getClusterId(); if (clusterId != null) { ClusterVO cluster = _clusterDao.findById(clusterId); type = cluster.getHypervisorType(); } } else if (ScopeType.ZONE.equals(poolVo.getScope())) { Long zoneId = poolVo.getDataCenterId(); if (zoneId != null) { DataCenterVO dc = _dcDao.findById(zoneId); } } if (null == type) { type = srcVolumePool.getHypervisor(); } } else { type = profile.getHypervisorType(); } return type; }
@Override public List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long snapshotId, Long volumeId, boolean readyOnly) { Long zoneId = null; if (snapshotId != null) { Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId); VolumeVO volume = findVolumeById(snapshot.getVolumeId()); // it seems that the volume can actually be removed from the DB at some point if it's deleted // if volume comes back null, use another technique to try to discover the zone if (volume == null) { SnapshotDataStoreVO snapshotStore = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary); if (snapshotStore != null) { long storagePoolId = snapshotStore.getDataStoreId(); StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId); if (storagePool != null) { zoneId = storagePool.getDataCenterId(); } } } else { zoneId = volume.getDataCenterId(); } } else { VolumeVO volume = findVolumeById(volumeId); zoneId = volume.getDataCenterId(); } if (zoneId == null) { throw new CloudRuntimeException("Unable to determine the zone ID"); } return createTemplateResponses(view, templateId, zoneId, readyOnly); }
int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue())); StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId()); DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId()); DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
newVolumeOnPrimaryStorage = _volumeMgr.moveVolume(newVolumeOnPrimaryStorage, vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), volumeToAttachHyperType); } catch (ConcurrentOperationException e) {
spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), null, null, ScopeType.ZONE); } else { spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), pool.getPodId(), pool.getClusterId(), ScopeType.CLUSTER); hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId()); hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor(), pool.getDataCenterId()); List<StoragePoolVO> upPools = primaryDataStoreDao.listByStatusInZone(pool.getDataCenterId(), StoragePoolStatus.Up); boolean restart = true; if (upPools == null || upPools.size() == 0) {
AllFieldSearch.and("name", AllFieldSearch.entity().getName(), SearchCriteria.Op.EQ); AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ); AllFieldSearch.and("datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllFieldSearch.and("hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ); AllFieldSearch.and("status", AllFieldSearch.entity().getStatus(), SearchCriteria.Op.EQ); DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); DcPodSearch.and("status", DcPodSearch.entity().getStatus(), SearchCriteria.Op.EQ); DcPodSearch.and("scope", DcPodSearch.entity().getScope(), SearchCriteria.Op.EQ); DcPodAnyClusterSearch.and("datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); DcPodAnyClusterSearch.and("status", DcPodAnyClusterSearch.entity().getStatus(), SearchCriteria.Op.EQ); DcPodAnyClusterSearch.and("scope", DcPodAnyClusterSearch.entity().getScope(), SearchCriteria.Op.EQ); DcLocalStorageSearch.and("datacenterId", DcLocalStorageSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); DcLocalStorageSearch.and("path", DcLocalStorageSearch.entity().getPath(), SearchCriteria.Op.EQ); DcLocalStorageSearch.and("scope", DcLocalStorageSearch.entity().getScope(), SearchCriteria.Op.EQ);