Search in sources :

Example 6 with Volume

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;
}
Also used : Volume(org.apache.cloudstack.storage.datastore.api.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VTreeMigrationInfo(org.apache.cloudstack.storage.datastore.api.VTreeMigrationInfo) URISyntaxException(java.net.URISyntaxException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ServerApiException(org.apache.cloudstack.api.ServerApiException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 7 with Volume

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);
}
Also used : Volume(org.apache.cloudstack.storage.datastore.api.Volume) BasicCredentials(com.github.tomakehurst.wiremock.client.BasicCredentials) Test(org.junit.Test)

Example 8 with Volume

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;
}
Also used : Volume(org.apache.cloudstack.storage.datastore.api.Volume) SdcMappingInfo(org.apache.cloudstack.storage.datastore.api.SdcMappingInfo)

Example 9 with Volume

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;
}
Also used : Volume(org.apache.cloudstack.storage.datastore.api.Volume) ArrayList(java.util.ArrayList)

Example 10 with Volume

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)));
}
Also used : Volume(org.apache.cloudstack.storage.datastore.api.Volume) BasicCredentials(com.github.tomakehurst.wiremock.client.BasicCredentials) Test(org.junit.Test)

Aggregations

Volume (org.apache.cloudstack.storage.datastore.api.Volume)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 BasicCredentials (com.github.tomakehurst.wiremock.client.BasicCredentials)2 IOException (java.io.IOException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 URISyntaxException (java.net.URISyntaxException)2 KeyManagementException (java.security.KeyManagementException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 SdcMappingInfo (org.apache.cloudstack.storage.datastore.api.SdcMappingInfo)2 VTreeMigrationInfo (org.apache.cloudstack.storage.datastore.api.VTreeMigrationInfo)2 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 VolumeStatistics (org.apache.cloudstack.storage.datastore.api.VolumeStatistics)1