use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method migrateVolume.
@Override
public boolean migrateVolume(final String srcVolumeId, final String destPoolId, final int timeoutInSecs) {
Preconditions.checkArgument(StringUtils.isNotEmpty(srcVolumeId), "src volume id cannot be null");
Preconditions.checkArgument(StringUtils.isNotEmpty(destPoolId), "dest pool id cannot be null");
Preconditions.checkArgument(timeoutInSecs > 0, "timeout must be greater than 0");
try {
Volume volume = getVolume(srcVolumeId);
if (volume == null || StringUtils.isEmpty(volume.getVtreeId())) {
LOG.warn("Couldn't find the volume(-tree), can not migrate the volume " + srcVolumeId);
return false;
}
String srcPoolId = volume.getStoragePoolId();
LOG.debug("Migrating the volume: " + srcVolumeId + " on the src pool: " + srcPoolId + " to the dest pool: " + destPoolId + " in the same PowerFlex cluster");
post("/instances/Volume::" + srcVolumeId + "/action/migrateVTree", String.format("{\"destSPId\":\"%s\"}", destPoolId), Boolean.class);
LOG.debug("Wait until the migration is complete for the volume: " + srcVolumeId);
long migrationStartTime = System.currentTimeMillis();
boolean status = waitForVolumeMigrationToComplete(volume.getVtreeId(), timeoutInSecs);
// Check volume storage pool and migration status
// volume, v-tree, snapshot ids remains same after the migration
volume = getVolume(srcVolumeId);
if (volume == null || volume.getStoragePoolId() == null) {
LOG.warn("Couldn't get the volume: " + srcVolumeId + " details after migration");
return status;
} else {
String volumeOnPoolId = volume.getStoragePoolId();
// confirm whether the volume is on the dest storage pool or not
if (status && destPoolId.equalsIgnoreCase(volumeOnPoolId)) {
LOG.debug("Migration success for the volume: " + srcVolumeId);
return true;
} else {
try {
// Check and pause any migration activity on the volume
status = false;
VTreeMigrationInfo.MigrationStatus migrationStatus = getVolumeTreeMigrationStatus(volume.getVtreeId());
if (migrationStatus != null && migrationStatus != VTreeMigrationInfo.MigrationStatus.NotInMigration) {
long timeElapsedInSecs = (System.currentTimeMillis() - migrationStartTime) / 1000;
int timeRemainingInSecs = (int) (timeoutInSecs - timeElapsedInSecs);
if (timeRemainingInSecs > (timeoutInSecs / 2)) {
// Try to pause gracefully (continue the migration) if atleast half of the time is remaining
pauseVolumeMigration(srcVolumeId, false);
status = waitForVolumeMigrationToComplete(volume.getVtreeId(), timeRemainingInSecs);
}
}
if (!status) {
rollbackVolumeMigration(srcVolumeId);
}
return status;
} catch (Exception ex) {
LOG.warn("Exception on pause/rollback migration of the volume: " + srcVolumeId + " - " + ex.getLocalizedMessage());
}
}
}
} catch (final Exception e) {
LOG.error("Failed to migrate PowerFlex volume due to: " + e.getMessage(), e);
throw new CloudRuntimeException("Failed to migrate PowerFlex volume due to: " + e.getMessage());
}
LOG.debug("Migration failed for the volume: " + srcVolumeId);
return false;
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImplTest method testCreateSingleVolume.
@Test
public void testCreateSingleVolume() {
Assert.assertNotNull(client);
wireMockRule.verify(getRequestedFor(urlEqualTo("/api/login")).withBasicAuth(new BasicCredentials(username, password)));
final String volumeName = "testvolume";
final String scaleIOStoragePoolId = "4daaa55e00000000";
final int sizeInGb = 8;
Volume scaleIOVolume = client.createVolume(volumeName, scaleIOStoragePoolId, sizeInGb, Storage.ProvisioningType.THIN);
wireMockRule.verify(postRequestedFor(urlEqualTo("/api/types/Volume/instances")).withBasicAuth(new BasicCredentials(username, sessionKey)).withRequestBody(containing("\"name\":\"" + volumeName + "\"")).withHeader("Content-Type", equalTo("application/json")));
wireMockRule.verify(getRequestedFor(urlEqualTo("/api/instances/Volume::c948d0b10000000a")).withBasicAuth(new BasicCredentials(username, sessionKey)));
Assert.assertNotNull(scaleIOVolume);
Assert.assertEquals(scaleIOVolume.getId(), "c948d0b10000000a");
Assert.assertEquals(scaleIOVolume.getName(), volumeName);
Assert.assertEquals(scaleIOVolume.getStoragePoolId(), scaleIOStoragePoolId);
Assert.assertEquals(scaleIOVolume.getSizeInKb(), Long.valueOf(sizeInGb * 1024 * 1024));
Assert.assertEquals(scaleIOVolume.getVolumeType(), Volume.VolumeType.ThinProvisioned);
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method isVolumeMappedToSdc.
@Override
public boolean isVolumeMappedToSdc(final String volumeId, final String sdcId) {
Preconditions.checkArgument(StringUtils.isNotEmpty(volumeId), "Volume id cannot be null");
Preconditions.checkArgument(StringUtils.isNotEmpty(sdcId), "Sdc Id cannot be null");
if (StringUtils.isAnyEmpty(volumeId, sdcId)) {
return false;
}
Volume volume = getVolume(volumeId);
if (volume == null) {
return false;
}
List<SdcMappingInfo> mappedSdcList = volume.getMappedSdcList();
if (mappedSdcList != null && !mappedSdcList.isEmpty()) {
for (SdcMappingInfo mappedSdc : mappedSdcList) {
if (sdcId.equalsIgnoreCase(mappedSdc.getSdcId())) {
return true;
}
}
}
return false;
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImpl method listSnapshotVolumes.
@Override
public List<Volume> listSnapshotVolumes() {
List<Volume> volumes = listVolumes();
List<Volume> snapshotVolumes = new ArrayList<>();
if (volumes != null && !volumes.isEmpty()) {
for (Volume volume : volumes) {
if (volume != null && volume.getVolumeType() == Volume.VolumeType.Snapshot) {
snapshotVolumes.add(volume);
}
}
}
return snapshotVolumes;
}
use of org.apache.cloudstack.storage.datastore.api.Volume in project cloudstack by apache.
the class ScaleIOGatewayClientImplTest method testCreateMultipleVolumes.
@Test
public void testCreateMultipleVolumes() {
Assert.assertNotNull(client);
wireMockRule.verify(getRequestedFor(urlEqualTo("/api/login")).withBasicAuth(new BasicCredentials(username, password)));
final String volumeNamePrefix = "testvolume_";
final String scaleIOStoragePoolId = "4daaa55e00000000";
final int sizeInGb = 8;
final int volumesCount = 1000;
for (int i = 1; i <= volumesCount; i++) {
String volumeName = volumeNamePrefix + i;
Volume scaleIOVolume = client.createVolume(volumeName, scaleIOStoragePoolId, sizeInGb, Storage.ProvisioningType.THIN);
Assert.assertNotNull(scaleIOVolume);
Assert.assertEquals(scaleIOVolume.getId(), "c948d0b10000000a");
Assert.assertEquals(scaleIOVolume.getStoragePoolId(), scaleIOStoragePoolId);
Assert.assertEquals(scaleIOVolume.getSizeInKb(), Long.valueOf(sizeInGb * 1024 * 1024));
Assert.assertEquals(scaleIOVolume.getVolumeType(), Volume.VolumeType.ThinProvisioned);
}
wireMockRule.verify(volumesCount, postRequestedFor(urlEqualTo("/api/types/Volume/instances")).withBasicAuth(new BasicCredentials(username, sessionKey)).withRequestBody(containing("\"name\":\"" + volumeNamePrefix)).withHeader("Content-Type", equalTo("application/json")));
wireMockRule.verify(volumesCount, getRequestedFor(urlEqualTo("/api/instances/Volume::c948d0b10000000a")).withBasicAuth(new BasicCredentials(username, sessionKey)));
}
Aggregations