Search in sources :

Example 1 with Volume

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

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

Example 3 with Volume

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

Example 4 with Volume

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

Example 5 with Volume

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;
}
Also used : Volume(org.apache.cloudstack.storage.datastore.api.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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