use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method rollbackVolumeMigration.
private boolean rollbackVolumeMigration(final String srcVolumeId) {
Preconditions.checkArgument(StringUtils.isNotEmpty(srcVolumeId), "src volume id cannot be null");
Volume volume = getVolume(srcVolumeId);
if (volume == null) {
LOG.warn("Unable to rollback volume migration, couldn't get details for the volume: " + srcVolumeId);
return false;
}
VTreeMigrationInfo.MigrationStatus migrationStatus = getVolumeTreeMigrationStatus(volume.getVtreeId());
if (migrationStatus != null && migrationStatus == VTreeMigrationInfo.MigrationStatus.NotInMigration) {
LOG.debug("Volume: " + srcVolumeId + " is not migrating, no need to rollback");
return true;
}
// Pause forcefully
pauseVolumeMigration(srcVolumeId, true);
// Wait few secs for volume migration to change to Paused state
boolean paused = false;
int retryCount = 3;
while (retryCount > 0) {
try {
// Try after few secs
Thread.sleep(3000);
// Get updated migration status
migrationStatus = getVolumeTreeMigrationStatus(volume.getVtreeId());
if (migrationStatus != null && migrationStatus == VTreeMigrationInfo.MigrationStatus.Paused) {
LOG.debug("Migration for the volume: " + srcVolumeId + " paused");
paused = true;
break;
}
} catch (Exception ex) {
LOG.warn("Exception while checking for migration pause status of the volume: " + srcVolumeId + " - " + ex.getLocalizedMessage());
// don't do anything
} finally {
retryCount--;
}
}
if (paused) {
// Rollback migration to the src pool (should be quick)
Boolean migrateVTreeStatus = post("/instances/Volume::" + srcVolumeId + "/action/migrateVTree", String.format("{\"destSPId\":\"%s\"}", volume.getStoragePoolId()), Boolean.class);
if (migrateVTreeStatus != null) {
return migrateVTreeStatus;
}
} else {
LOG.warn("Migration for the volume: " + srcVolumeId + " didn't pause, couldn't rollback");
}
return false;
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method unmapVolumeFromAllSdcs.
@Override
public boolean unmapVolumeFromAllSdcs(final String volumeId) {
Preconditions.checkArgument(StringUtils.isNotEmpty(volumeId), "Volume id cannot be null");
Volume volume = getVolume(volumeId);
if (volume == null) {
return false;
}
List<SdcMappingInfo> mappedSdcList = volume.getMappedSdcList();
if (mappedSdcList == null || mappedSdcList.isEmpty()) {
return true;
}
Boolean unmapVolumeFromAllSdcsStatus = post("/instances/Volume::" + volumeId + "/action/removeMappedSdc", "{\"allSdcs\": \"\"}", Boolean.class);
if (unmapVolumeFromAllSdcsStatus != null) {
return unmapVolumeFromAllSdcsStatus;
}
return false;
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method createVolume.
// ////////////////////////////////////////////////
// ////////////// Volume APIs /////////////////////
// ////////////////////////////////////////////////
@Override
public Volume createVolume(final String name, final String storagePoolId, final Integer sizeInGb, final Storage.ProvisioningType volumeType) {
Preconditions.checkArgument(StringUtils.isNotEmpty(name), "Volume name cannot be null");
Preconditions.checkArgument(StringUtils.isNotEmpty(storagePoolId), "Storage pool id cannot be null");
Preconditions.checkArgument(sizeInGb != null && sizeInGb > 0, "Size(GB) must be greater than 0");
Volume newVolume = new Volume();
newVolume.setName(name);
newVolume.setStoragePoolId(storagePoolId);
newVolume.setVolumeSizeInGb(sizeInGb);
if (Storage.ProvisioningType.FAT.equals(volumeType)) {
newVolume.setVolumeType(Volume.VolumeType.ThickProvisioned);
} else {
newVolume.setVolumeType(Volume.VolumeType.ThinProvisioned);
}
// The basic allocation granularity is 8GB. The volume size will be rounded up.
Volume newVolumeObject = post("/types/Volume/instances", newVolume, Volume.class);
return getVolume(newVolumeObject.getId());
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method getVolumeStatistics.
@Override
public VolumeStatistics getVolumeStatistics(String volumeId) {
Preconditions.checkArgument(StringUtils.isNotEmpty(volumeId), "Volume id cannot be null");
Volume volume = getVolume(volumeId);
if (volume != null) {
String volumeTreeId = volume.getVtreeId();
if (StringUtils.isNotEmpty(volumeTreeId)) {
VolumeStatistics volumeStatistics = get("/instances/VTree::" + volumeTreeId + "/relationships/Statistics", VolumeStatistics.class);
if (volumeStatistics != null) {
volumeStatistics.setAllocatedSizeInKb(volume.getSizeInKb());
return volumeStatistics;
}
}
}
return null;
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method revertSnapshot.
@Override
public boolean revertSnapshot(final String sourceSnapshotVolumeId, final String destVolumeId) {
Preconditions.checkArgument(StringUtils.isNotEmpty(sourceSnapshotVolumeId), "Source snapshot volume id cannot be null");
Preconditions.checkArgument(StringUtils.isNotEmpty(destVolumeId), "Destination volume id cannot be null");
Volume sourceSnapshotVolume = getVolume(sourceSnapshotVolumeId);
if (sourceSnapshotVolume == null) {
throw new CloudRuntimeException("Source snapshot volume: " + sourceSnapshotVolumeId + " doesn't exists");
}
Volume destVolume = getVolume(destVolumeId);
if (sourceSnapshotVolume == null) {
throw new CloudRuntimeException("Destination volume: " + destVolumeId + " doesn't exists");
}
if (!sourceSnapshotVolume.getVtreeId().equals(destVolume.getVtreeId())) {
throw new CloudRuntimeException("Unable to revert, source snapshot volume and destination volume doesn't belong to same volume tree");
}
Boolean overwriteVolumeContentStatus = post("/instances/Volume::" + destVolumeId + "/action/overwriteVolumeContent", String.format("{\"srcVolumeId\":\"%s\",\"allowOnExtManagedVol\":\"TRUE\"}", sourceSnapshotVolumeId), Boolean.class);
if (overwriteVolumeContentStatus != null) {
return overwriteVolumeContentStatus;
}
return false;
}
Aggregations