use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class VolumeOrchestrator method cleanupVolumeDuringMigrationFailure.
private void cleanupVolumeDuringMigrationFailure(Long volumeId, Long destPoolId) {
StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destPoolId, DataStoreRole.Primary);
if (destPool == null) {
return;
}
VolumeVO volume = _volsDao.findById(volumeId);
if (volume.getState() == Volume.State.Migrating) {
VolumeVO duplicateVol = _volsDao.findByPoolIdName(destPoolId, volume.getName());
if (duplicateVol != null) {
s_logger.debug("Remove volume " + duplicateVol.getId() + " on storage pool " + destPoolId);
_volsDao.remove(duplicateVol.getId());
}
s_logger.debug("change volume state to ready from migrating in case migration failure for vol: " + volumeId);
volume.setState(Volume.State.Ready);
_volsDao.update(volumeId, volume);
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class StoragePoolJoinDaoImpl method newStoragePoolResponse.
@Override
public StoragePoolResponse newStoragePoolResponse(StoragePoolJoinVO pool) {
StoragePool storagePool = storagePoolDao.findById(pool.getId());
StoragePoolResponse poolResponse = new StoragePoolResponse();
poolResponse.setId(pool.getUuid());
poolResponse.setName(pool.getName());
poolResponse.setState(pool.getStatus());
String path = pool.getPath();
// cifs store may contain password entry, remove the password
path = StringUtils.cleanString(path);
poolResponse.setPath(path);
poolResponse.setIpAddress(pool.getHostAddress());
poolResponse.setZoneId(pool.getZoneUuid());
poolResponse.setZoneName(pool.getZoneName());
poolResponse.setType(pool.getPoolType().toString());
poolResponse.setPodId(pool.getPodUuid());
poolResponse.setPodName(pool.getPodName());
poolResponse.setCreated(pool.getCreated());
if (pool.getScope() != null) {
poolResponse.setScope(pool.getScope().toString());
}
if (pool.getHypervisor() != null) {
poolResponse.setHypervisor(pool.getHypervisor().toString());
}
StoragePoolDetailVO poolType = storagePoolDetailsDao.findDetail(pool.getId(), "pool_type");
if (poolType != null) {
poolResponse.setType(poolType.getValue());
}
long allocatedSize = pool.getUsedCapacity() + pool.getReservedCapacity();
if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
List<StoragePoolVO> childDatastores = storagePoolDao.listChildStoragePoolsInDatastoreCluster(pool.getId());
if (childDatastores != null) {
for (StoragePoolVO childDatastore : childDatastores) {
StoragePoolJoinVO childDSJoinVO = findById(childDatastore.getId());
allocatedSize += (childDSJoinVO.getUsedCapacity() + childDSJoinVO.getReservedCapacity());
}
}
}
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
poolResponse.setDiskSizeAllocated(allocatedSize);
poolResponse.setCapacityIops(pool.getCapacityIops());
if (storagePool.isManaged()) {
DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
PrimaryDataStoreDriver driver = (PrimaryDataStoreDriver) store.getDriver();
long usedIops = driver.getUsedIops(storagePool);
poolResponse.setAllocatedIops(usedIops);
}
// TODO: StatsCollector does not persist data
StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
if (stats != null) {
Long used = stats.getByteUsed();
poolResponse.setDiskSizeUsed(used);
}
poolResponse.setClusterId(pool.getClusterUuid());
poolResponse.setClusterName(pool.getClusterName());
poolResponse.setProvider(pool.getStorageProviderName());
poolResponse.setTags(pool.getTag());
poolResponse.setOverProvisionFactor(Double.toString(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())));
// set async job
if (pool.getJobId() != null) {
poolResponse.setJobId(pool.getJobUuid());
poolResponse.setJobStatus(pool.getJobStatus());
}
poolResponse.setHasAnnotation(annotationDao.hasAnnotations(pool.getUuid(), AnnotationService.EntityType.PRIMARY_STORAGE.name(), accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
poolResponse.setObjectName("storagepool");
return poolResponse;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class AbstractStoragePoolAllocator method reorderPoolsByCapacity.
protected List<StoragePool> reorderPoolsByCapacity(DeploymentPlan plan, List<StoragePool> pools) {
Long zoneId = plan.getDataCenterId();
Long clusterId = plan.getClusterId();
short capacityType;
if (pools != null && pools.size() != 0) {
capacityType = pools.get(0).getPoolType().isShared() ? Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED : Capacity.CAPACITY_TYPE_LOCAL_STORAGE;
} else {
return null;
}
List<Long> poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);
if (s_logger.isDebugEnabled()) {
s_logger.debug("List of pools in descending order of free capacity: " + poolIdsByCapacity);
}
// now filter the given list of Pools by this ordered list
Map<Long, StoragePool> poolMap = new HashMap<>();
for (StoragePool pool : pools) {
poolMap.put(pool.getId(), pool);
}
List<Long> matchingPoolIds = new ArrayList<>(poolMap.keySet());
poolIdsByCapacity.retainAll(matchingPoolIds);
List<StoragePool> reorderedPools = new ArrayList<>();
for (Long id : poolIdsByCapacity) {
reorderedPools.add(poolMap.get(id));
}
return reorderedPools;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class DefaultHostListener method hostConnect.
@Override
public boolean hostConnect(long hostId, long poolId) throws StorageConflictException {
StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
final Answer answer = agentMgr.easySend(hostId, cmd);
if (answer == null) {
throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
}
if (!answer.getResult()) {
String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
}
assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
String datastoreName = mspAnswer.getLocalDatastoreName();
List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
for (StoragePoolVO localStoragePool : localStoragePools) {
if (datastoreName.equals(localStoragePool.getPath())) {
s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
}
}
}
StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
updateStoragePoolHostVOAndDetails(poolVO, hostId, mspAnswer);
if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
storageManager.syncDatastoreClusterStoragePool(poolId, ((ModifyStoragePoolAnswer) answer).getDatastoreClusterChildren(), hostId);
}
storageService.updateStorageCapabilities(poolId, false);
s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
return true;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class VirtualMachineManagerImpl method buildMapUsingUserInformation.
/**
* Builds the map of storage pools and volumes with the information entered by the user. Before creating the an entry we validate if the migration is feasible checking if the migration is allowed and if the target host can access the defined target storage pool.
*/
protected Map<Volume, StoragePool> buildMapUsingUserInformation(VirtualMachineProfile profile, Host targetHost, Map<Long, Long> userDefinedVolumeToStoragePoolMap) {
Map<Volume, StoragePool> volumeToPoolObjectMap = new HashMap<>();
if (MapUtils.isEmpty(userDefinedVolumeToStoragePoolMap)) {
return volumeToPoolObjectMap;
}
for (Long volumeId : userDefinedVolumeToStoragePoolMap.keySet()) {
VolumeVO volume = _volsDao.findById(volumeId);
Long poolId = userDefinedVolumeToStoragePoolMap.get(volumeId);
StoragePoolVO targetPool = _storagePoolDao.findById(poolId);
StoragePoolVO currentPool = _storagePoolDao.findById(volume.getPoolId());
executeManagedStorageChecksWhenTargetStoragePoolProvided(currentPool, volume, targetPool);
if (targetHost != null && _poolHostDao.findByPoolHost(targetPool.getId(), targetHost.getId()) == null) {
throw new CloudRuntimeException(String.format("Cannot migrate the volume [%s] to the storage pool [%s] while migrating VM [%s] to target host [%s]. The host does not have access to the storage pool entered.", volume.getUuid(), targetPool.getUuid(), profile.getUuid(), targetHost.getUuid()));
}
if (currentPool.getId() == targetPool.getId()) {
s_logger.info(String.format("The volume [%s] is already allocated in storage pool [%s].", volume.getUuid(), targetPool.getUuid()));
}
volumeToPoolObjectMap.put(volume, targetPool);
}
return volumeToPoolObjectMap;
}
Aggregations