use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class CloudStackPrimaryDataStoreDriverImpl method resize.
@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
VolumeObject vol = (VolumeObject) data;
StoragePool pool = (StoragePool) data.getDataStore();
ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName, vol.getChainInfo());
if (pool.getParent() != 0) {
resizeCmd.setContextParam(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
}
CreateCmdResult result = new CreateCmdResult(null, null);
try {
ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd);
if (answer != null && answer.getResult()) {
long finalSize = answer.getNewSize();
s_logger.debug("Resize: volume started at size: " + toHumanReadableSize(vol.getSize()) + " and ended at size: " + toHumanReadableSize(finalSize));
vol.setSize(finalSize);
vol.update();
updateVolumePathDetails(vol, answer);
} else if (answer != null) {
result.setResult(answer.getDetails());
} else {
s_logger.debug("return a null answer, mark it as failed for unknown reason");
result.setResult("return a null answer, mark it as failed for unknown reason");
}
} catch (Exception e) {
s_logger.debug("sending resize command failed", e);
result.setResult(e.toString());
}
callback.complete(result);
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class LinstorPrimaryDataStoreDriverImpl method revertSnapshot.
@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
s_logger.debug("Linstor: revertSnapshot");
final VolumeInfo volumeInfo = snapshot.getBaseVolume();
VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
if (volumeVO == null || volumeVO.getRemoved() != null) {
CommandResult commandResult = new CommandResult();
commandResult.setResult("The volume that the snapshot belongs to no longer exists.");
callback.complete(commandResult);
return;
}
String resultMsg;
try {
final StoragePool pool = (StoragePool) snapshot.getDataStore();
final String rscName = LinstorUtil.RSC_PREFIX + volumeInfo.getUuid();
final String snapName = LinstorUtil.RSC_PREFIX + snapshot.getUuid();
final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(pool.getHostAddress());
ApiCallRcList answers = linstorApi.resourceSnapshotRollback(rscName, snapName);
resultMsg = checkLinstorAnswers(answers);
} catch (ApiException apiEx) {
s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
resultMsg = apiEx.getBestMessage();
}
if (callback != null) {
CommandResult result = new CommandResult();
result.setResult(resultMsg);
callback.complete(result);
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class ElastistorPrimaryDataStoreDriver method resize.
@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
s_logger.debug("Resize elastistor volume started");
Boolean status = false;
VolumeObject vol = (VolumeObject) data;
StoragePool pool = (StoragePool) data.getDataStore();
ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
CreateCmdResult result = new CreateCmdResult(null, null);
StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
if (!(poolVO.isManaged())) {
super.resize(data, callback);
return;
}
try {
status = ElastistorUtil.updateElastistorVolumeSize(vol.getUuid(), resizeParameter.newSize);
} catch (Throwable e) {
s_logger.error("Resize elastistor volume failed, please contact elastistor admin.", e);
result.setResult(e.toString());
callback.complete(result);
}
if (status) {
// now updating the cloudstack storagepool usedbytes and volume
Long usedBytes = poolVO.getUsedBytes();
Long currentVolumeSize = vol.getSize();
Long newUsedBytes;
if (currentVolumeSize < resizeParameter.newSize) {
newUsedBytes = usedBytes + (resizeParameter.newSize - currentVolumeSize);
poolVO.setUsedBytes(newUsedBytes);
} else {
newUsedBytes = usedBytes - (currentVolumeSize - resizeParameter.newSize);
poolVO.setUsedBytes(newUsedBytes);
}
_storagePoolDao.update(pool.getId(), poolVO);
vol.getVolume().setSize(resizeParameter.newSize);
vol.update();
callback.complete(result);
} else {
callback.complete(result);
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class ManagementServerImpl method findAllSuitableStoragePoolsForVm.
/**
* Looks for all suitable storage pools to allocate the given volume.
* We take into account the service offering of the VM and volume to find suitable storage pools. It is also excluded from the search the current storage pool used by the volume.
* We use {@link StoragePoolAllocator} to look for possible storage pools to allocate the given volume. We will look for possible local storage poosl even if the volume is using a shared storage disk offering.
*
* Side note: the idea behind this method is to provide power for administrators of manually overriding deployments defined by CloudStack.
*/
private List<StoragePool> findAllSuitableStoragePoolsForVm(final VolumeVO volume, Long diskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, VMInstanceVO vm, Host vmHost, ExcludeList avoid, Cluster srcCluster, HypervisorType hypervisorType) {
List<StoragePool> suitablePools = new ArrayList<>();
Long clusterId = null;
Long podId = null;
if (srcCluster != null) {
clusterId = srcCluster.getId();
podId = srcCluster.getPodId();
}
DataCenterDeployment plan = new DataCenterDeployment(volume.getDataCenterId(), podId, clusterId, null, null, null, null);
VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
// OfflineVmwareMigration: vm might be null here; deal!
DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
DiskProfile diskProfile = new DiskProfile(volume, diskOffering, hypervisorType);
if (!Objects.equals(volume.getDiskOfferingId(), diskOfferingId)) {
diskProfile.setSize(newSize);
diskProfile.setMinIops(newMinIops);
diskProfile.setMaxIops(newMaxIops);
}
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL, true);
if (CollectionUtils.isEmpty(pools)) {
continue;
}
for (StoragePool pool : pools) {
boolean isLocalPoolSameHostAsVmHost = pool.isLocal() && (vmHost == null || StringUtils.equals(vmHost.getPrivateIpAddress(), pool.getHostAddress()));
if (isLocalPoolSameHostAsVmHost || pool.isShared()) {
suitablePools.add(pool);
}
}
}
return suitablePools;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class ManagementServerImpl method removeDataStoreClusterParents.
private void removeDataStoreClusterParents(List<StoragePool> storagePools) {
Predicate<StoragePool> childDatastorePredicate = pool -> (pool.getParent() != 0);
List<StoragePool> childDatastores = storagePools.stream().filter(childDatastorePredicate).collect(Collectors.toList());
if (!childDatastores.isEmpty()) {
Set<Long> parentStoragePoolIds = childDatastores.stream().map(mo -> mo.getParent()).collect(Collectors.toSet());
for (Long parentStoragePoolId : parentStoragePoolIds) {
StoragePool parentPool = _poolDao.findById(parentStoragePoolId);
storagePools.remove(parentPool);
}
}
}
Aggregations