protected boolean hostCanAccessSPool(Host host, StoragePool pool) { boolean hostCanAccessSPool = false; StoragePoolHostVO hostPoolLinkage = _poolHostDao.findByPoolHost(pool.getId(), host.getId()); if (hostPoolLinkage != null) { hostCanAccessSPool = true; } s_logger.debug("Host: " + host.getId() + (hostCanAccessSPool ? " can" : " cannot") + " access pool: " + pool.getId()); return hostCanAccessSPool; }
/** * Retrieves the storage pool tags as a {@link String}. If the storage pool does not have tags we return a null value. */ protected String getStoragePoolTags(StoragePool destPool) { List<StoragePoolDetailVO> storagePoolDetails = storagePoolDetailsDao.listDetails(destPool.getId()); if (CollectionUtils.isEmpty(storagePoolDetails)) { return null; } String storageTags = ""; for (StoragePoolDetailVO storagePoolDetailVO : storagePoolDetails) { storageTags = storageTags + storagePoolDetailVO.getName() + ","; } return storageTags.substring(0, storageTags.length() - 1); }
private void sendModifyStoragePoolCommand(ModifyStoragePoolCommand cmd, StoragePool storagePool, long hostId) { Answer answer = agentMgr.easySend(hostId, cmd); if (answer == null) { throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command (" + storagePool.getId() + ")"); } if (!answer.getResult()) { String msg = "Unable to attach storage pool " + storagePool.getId() + " to host " + hostId; alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, storagePool.getDataCenterId(), storagePool.getPodId(), msg, msg); throw new CloudRuntimeException("Unable to establish a connection from agent to storage pool " + storagePool.getId() + " due to " + answer.getDetails() + " (" + storagePool.getId() + ")"); } assert (answer instanceof ModifyStoragePoolAnswer) : "ModifyStoragePoolAnswer expected ; Pool = " + storagePool.getId() + " Host = " + hostId; LOGGER.info("Connection established between storage pool " + storagePool + " and host + " + hostId); } }
public boolean shouldAvoid(StoragePool pool) { if (_dcIds != null && _dcIds.contains(pool.getDataCenterId())) { return true; } if (_podIds != null && _podIds.contains(pool.getPodId())) { return true; } if (_clusterIds != null && _clusterIds.contains(pool.getClusterId())) { return true; } if (_poolIds != null && _poolIds.contains(pool.getId())) { return true; } return false; }
@Override public boolean storagePoolHasEnoughSpaceForResize(StoragePool pool, long currentSize, long newSiz) { if (!checkUsagedSpace(pool)) { return false; } if (s_logger.isDebugEnabled()) { s_logger.debug("Destination pool id: " + pool.getId()); } long totalAskingSize = newSiz - currentSize; if (totalAskingSize <= 0) { return true; } else { final StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId()); final long allocatedSizeWithTemplate = _capacityMgr.getAllocatedPoolCapacity(poolVO, null); return checkPoolforSpace(pool, allocatedSizeWithTemplate, totalAskingSize); } }
private DataStore getPlannedDataStore(DeployDestination dest, DataStore dataStore) { for (final Volume volume : dest.getStorageForDisks().keySet()) { if (volume.getVolumeType() == Volume.Type.ROOT) { final StoragePool primaryPool = dest.getStorageForDisks().get(volume); dataStore = _dataStoreMgr.getDataStore(primaryPool.getId(), DataStoreRole.Primary); break; } } return dataStore; }
private ModifyStoragePoolAnswer sendModifyStoragePoolCommand(ModifyStoragePoolCommand cmd, StoragePool storagePool, long hostId) { Answer answer = agentMgr.easySend(hostId, cmd); if (answer == null) { throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command for storage pool: " + storagePool.getId()); } if (!answer.getResult()) { String msg = "Unable to attach storage pool " + storagePool.getId() + " to the host " + hostId; alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, storagePool.getDataCenterId(), storagePool.getPodId(), msg, msg); throw new CloudRuntimeException(msg); } assert (answer instanceof ModifyStoragePoolAnswer) : "ModifyStoragePoolAnswer not returned from ModifyStoragePoolCommand; Storage pool = " + storagePool.getId() + "; Host = " + hostId; LOGGER.info("Connection established between storage pool " + storagePool + " and host " + hostId); return (ModifyStoragePoolAnswer)answer; } }
public PrimaryStorageDownloadCommand(final String name, final String url, final ImageFormat format, final long accountId, final StoragePool pool, final int wait) { super(name, url, format, accountId); poolId = pool.getId(); poolUuid = pool.getUuid(); primaryPool = new StorageFilerTO(pool); setWait(wait); }
@Override public List<StoragePoolJoinVO> newStoragePoolView(StoragePool host) { SearchCriteria<StoragePoolJoinVO> sc = spIdSearch.create(); sc.setParameters("id", host.getId()); return searchIncludingRemoved(sc, null, null, false); }
@Override public void updateStoragePool(StoragePool storagePool, Map<String, String> details) { StoragePoolVO storagePoolVo = _storagePoolDao.findById(storagePool.getId()); String strCapacityBytes = details.get(PrimaryDataStoreLifeCycle.CAPACITY_BYTES); Long capacityBytes = strCapacityBytes != null ? Long.parseLong(strCapacityBytes) : null; if (capacityBytes != null) { long usedBytes = _capacityMgr.getUsedBytes(storagePoolVo); if (capacityBytes < usedBytes) { throw new CloudRuntimeException("Cannot reduce the number of bytes for this storage pool as it would lead to an insufficient number of bytes"); } } String strCapacityIops = details.get(PrimaryDataStoreLifeCycle.CAPACITY_IOPS); Long capacityIops = strCapacityIops != null ? Long.parseLong(strCapacityIops) : null; if (capacityIops != null) { long usedIops = _capacityMgr.getUsedIops(storagePoolVo); if (capacityIops < usedIops) { throw new CloudRuntimeException("Cannot reduce the number of IOPS for this storage pool as it would lead to an insufficient number of IOPS"); } } }
@Override public boolean storagePoolHasEnoughIops(List<Volume> requestedVolumes, StoragePool pool) { if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) { return false; } // Only IOPS-guaranteed primary storage like SolidFire is using/setting IOPS. // This check returns true for storage that does not specify IOPS. if (pool.getCapacityIops() == null) { s_logger.info("Storage pool " + pool.getName() + " (" + pool.getId() + ") does not supply IOPS capacity, assuming enough capacity"); return true; } StoragePoolVO storagePoolVo = _storagePoolDao.findById(pool.getId()); long currentIops = _capacityMgr.getUsedIops(storagePoolVo); long requestedIops = 0; for (Volume requestedVolume : requestedVolumes) { Long minIops = requestedVolume.getMinIops(); if (minIops != null && minIops > 0) { requestedIops += minIops; } } long futureIops = currentIops + requestedIops; return futureIops <= pool.getCapacityIops(); }
@Override public void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException { StoragePool pool = (StoragePool)_dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary); assert (pool.isShared()) : "Now, did you actually read the name of this method?"; s_logger.debug("Adding pool " + pool.getName() + " to host " + hostId); DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName()); HypervisorHostListener listener = hostListeners.get(provider.getName()); listener.hostConnect(hostId, pool.getId()); }
@DB protected Volume liveMigrateVolume(Volume volume, StoragePool destPool) throws StorageUnavailableException { VolumeInfo vol = volFactory.getVolume(volume.getId()); DataStore dataStoreTarget = dataStoreMgr.getDataStore(destPool.getId(), DataStoreRole.Primary); AsyncCallFuture<VolumeApiResult> future = volService.migrateVolume(vol, dataStoreTarget); try { VolumeApiResult result = future.get(); if (result.isFailed()) { s_logger.debug("migrate volume failed:" + result.getResult()); throw new StorageUnavailableException("Migrate volume failed: " + result.getResult(), destPool.getId()); } return result.getVolume(); } catch (InterruptedException e) { s_logger.debug("migrate volume failed", e); throw new CloudRuntimeException(e.getMessage()); } catch (ExecutionException e) { s_logger.debug("migrate volume failed", e); throw new CloudRuntimeException(e.getMessage()); } }
@Override public long getUsedIops(StoragePool storagePool) { long usedIops = 0; List<VolumeVO> volumes = volumeDao.findByPoolId(storagePool.getId(), null); if (volumes != null) { for (VolumeVO volume : volumes) { if (!Volume.State.Creating.equals(volume.getState())) { usedIops += volume.getMinIops() != null ? volume.getMinIops() : 0; } } } return usedIops; }
/** * This method is only relevant when storagePool is being used with a compute cluster that supports UUID resigning. */ @Override public long getBytesRequiredForTemplate(TemplateInfo templateInfo, StoragePool storagePool) { List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = tmpltPoolDao.listByPoolId(storagePool.getId()); if (lstTemplatePoolRefs != null) { for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) { if (templatePoolRef.getTemplateId() == templateInfo.getId()) { // This indicates that we already have this template stored on this primary storage, so // we do not require additional space. return 0; } } } // This indicates that we do not have a copy of this template on this primary storage, so // we need to take it into consideration from a space standpoint (ex. when a new VM is spun // up and wants to use this particular template for its root disk). return getDataObjectSizeIncludingHypervisorSnapshotReserve(templateInfo, storagePool); }
public StorageFilerTO(StoragePool pool) { this.id = pool.getId(); this.host = pool.getHostAddress(); this.port = pool.getPort(); this.path = pool.getPath(); this.type = pool.getPoolType(); this.uuid = pool.getUuid(); this.userInfo = pool.getUserInfo(); }
protected VolumeVO duplicateVolumeOnAnotherStorage(Volume volume, StoragePool pool) { Long lastPoolId = volume.getPoolId(); String folder = pool.getPath(); // For SMB, pool credentials are also stored in the uri query string. We trim the query string // part here to make sure the credentials do not get stored in the db unencrypted. if (pool.getPoolType() == StoragePoolType.SMB && folder != null && folder.contains("?")) { folder = folder.substring(0, folder.indexOf("?")); } VolumeVO newVol = new VolumeVO(volume); newVol.setInstanceId(null); newVol.setChainInfo(null); newVol.setPath(null); newVol.setFolder(folder); newVol.setPodId(pool.getPodId()); newVol.setPoolId(pool.getId()); newVol.setLastPoolId(lastPoolId); newVol.setPodId(pool.getPodId()); return volDao.persist(newVol); }
private void checkDestinationForTags(StoragePool destPool, VMInstanceVO vm) { List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId()); // OfflineVmwareMigration: iterate over volumes // OfflineVmwareMigration: get disk offering List<String> storageTags = storageMgr.getStoragePoolTagList(destPool.getId()); for(Volume vol : vols) { DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId()); List<String> volumeTags = StringUtils.csvTagsToList(diskOffering.getTags()); if(! matches(volumeTags, storageTags)) { String msg = String.format("destination pool '%s' with tags '%s', does not support the volume diskoffering for volume '%s' (tags: '%s') ", destPool.getName(), StringUtils.listToCsvTags(storageTags), vol.getName(), StringUtils.listToCsvTags(volumeTags) ); throw new CloudRuntimeException(msg); } } }
private void handleSuccessfulVolumeMigration(VolumeInfo srcVolumeInfo, StoragePool destPool, MigrateVolumeAnswer migrateVolumeAnswer) { VolumeVO volumeVO = _volumeDao.findById(srcVolumeInfo.getId()); volumeVO.setPath(migrateVolumeAnswer.getVolumePath()); String chainInfo = migrateVolumeAnswer.getVolumeChainInfo(); if (chainInfo != null) { volumeVO.setChainInfo(chainInfo); } volumeVO.setPodId(destPool.getPodId()); volumeVO.setPoolId(destPool.getId()); volumeVO.setLastPoolId(srcVolumeInfo.getPoolId()); _volumeDao.update(srcVolumeInfo.getId(), volumeVO); }
@Override public AsyncCallFuture<TemplateApiResult> deleteTemplateOnPrimary(TemplateInfo template, StoragePool pool) { TemplateObject templateObject = (TemplateObject)_templateFactory.getTemplate(template.getId(), (DataStore)pool); templateObject.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested); DataStore dataStore = _storeMgr.getPrimaryDataStore(pool.getId()); AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>(); TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, templateObject, future); AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().deleteTemplateCallback(null, null)).setContext(context); dataStore.getDriver().deleteAsync(dataStore, templateObject, caller); return future; }