Search in sources :

Example 21 with BlockSnapshotRestRep

use of com.emc.storageos.model.block.BlockSnapshotRestRep in project coprhd-controller by CoprHD.

the class BlockProvider method findSnapshotsByProject.

private List<BlockSnapshotRestRep> findSnapshotsByProject(ViPRCoreClient client, URI project) {
    log.info("Finding snapshots by project {}", project);
    List<SearchResultResourceRep> snapshotRefs = client.blockSnapshots().performSearchBy(SearchConstants.PROJECT_PARAM, project);
    List<URI> ids = new ArrayList<>();
    for (SearchResultResourceRep ref : snapshotRefs) {
        ids.add(ref.getId());
    }
    List<BlockSnapshotRestRep> snapshots = client.blockSnapshots().getByIds(ids, null);
    log.info("Got snapshots: [{}]", snapshots.size());
    return snapshots;
}
Also used : BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 22 with BlockSnapshotRestRep

use of com.emc.storageos.model.block.BlockSnapshotRestRep in project coprhd-controller by CoprHD.

the class GetBlockResource method executeTask.

@SuppressWarnings("incomplete-switch")
@Override
public BlockObjectRestRep executeTask() throws Exception {
    ViPRCoreClient client = getClient();
    ResourceType volumeType = ResourceType.fromResourceId(resourceId.toString());
    switch(volumeType) {
        case VOLUME:
            VolumeRestRep volume = client.blockVolumes().get(resourceId);
            if (volume != null) {
                return volume;
            }
            break;
        case BLOCK_SNAPSHOT:
            BlockSnapshotRestRep snapshot = client.blockSnapshots().get(resourceId);
            if (snapshot != null) {
                return snapshot;
            }
            break;
    }
    throw stateException("GetBlockResource.illegalState.notFound", resourceId);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) ResourceType(com.emc.sa.util.ResourceType) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep)

Example 23 with BlockSnapshotRestRep

use of com.emc.storageos.model.block.BlockSnapshotRestRep in project coprhd-controller by CoprHD.

the class BlockProvider method getVolumeSnapshotOptionsForProject.

private List<AssetOption> getVolumeSnapshotOptionsForProject(AssetOptionsContext ctx, URI project) {
    final ViPRCoreClient client = api(ctx);
    List<BlockSnapshotRestRep> snapshots = findSnapshotsByProject(client, project);
    List<BlockSnapshotRestRep> filteredSnap = new ArrayList<>();
    for (BlockSnapshotRestRep snapshot : snapshots) {
        if (!isSnapshotRPBookmark(snapshot)) {
            filteredSnap.add(snapshot);
        }
    }
    return constructSnapshotOptions(client, project, filteredSnap);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) ArrayList(java.util.ArrayList)

Example 24 with BlockSnapshotRestRep

use of com.emc.storageos.model.block.BlockSnapshotRestRep in project coprhd-controller by CoprHD.

the class BlockProvider method getApplicationSnapshotCopySetsForRestore.

private Set<String> getApplicationSnapshotCopySetsForRestore(AssetOptionsContext ctx, URI application) {
    Set<String> restoreCopySets = new HashSet<String>();
    Set<String> copySetNames = api(ctx).application().getVolumeGroupSnapshotSets(application).getCopySets();
    boolean isRP = false;
    NamedVolumesList volsInApp = api(ctx).application().getVolumeByApplication(application);
    if (volsInApp != null && volsInApp.getVolumes() != null && !volsInApp.getVolumes().isEmpty()) {
        VolumeRestRep firstVol = api(ctx).blockVolumes().get(volsInApp.getVolumes().get(0).getId());
        isRP = BlockStorageUtils.isRPVolume(firstVol);
    }
    if (isRP) {
        for (String copySetName : copySetNames) {
            VolumeGroupCopySetParam input = new VolumeGroupCopySetParam();
            input.setCopySetName(copySetName);
            SnapshotList snapshots = api(ctx).application().getVolumeGroupSnapshotsForSet(application, input);
            if (snapshots != null && snapshots.getSnapList() != null && !snapshots.getSnapList().isEmpty()) {
                BlockSnapshotRestRep snapRep = api(ctx).blockSnapshots().get(snapshots.getSnapList().get(0));
                if (snapRep != null) {
                    VolumeRestRep parentVol = api(ctx).blockVolumes().get(snapRep.getParent());
                    if (BlockStorageUtils.isRPSourceVolume(parentVol)) {
                        restoreCopySets.add(copySetName);
                    }
                }
            }
        }
    } else {
        restoreCopySets.addAll(copySetNames);
    }
    return restoreCopySets;
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) VolumeGroupCopySetParam(com.emc.storageos.model.application.VolumeGroupCopySetParam) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) HashSet(java.util.HashSet)

Example 25 with BlockSnapshotRestRep

use of com.emc.storageos.model.block.BlockSnapshotRestRep in project coprhd-controller by CoprHD.

the class BlockProvider method addVolume.

/**
 * Add the volume and its snapshots to the 'blockObjects' list.
 *
 * When the method completes the snapshots that have been added to the blockObjects list will be removed from the snapshots list.
 */
protected static void addVolume(List<BlockObjectRestRep> blockObjects, VolumeRestRep volume, List<BlockSnapshotRestRep> snapshots) {
    blockObjects.add(volume);
    if (CollectionUtils.isNotEmpty(snapshots)) {
        // use an iterator so we can do proper removes
        Iterator<BlockSnapshotRestRep> snapshotIter = snapshots.iterator();
        while (snapshotIter.hasNext()) {
            BlockSnapshotRestRep snap = snapshotIter.next();
            if (ResourceUtils.idEquals(snap.getParent(), volume)) {
                blockObjects.add(snap);
                snapshotIter.remove();
            }
        }
    }
}
Also used : BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep)

Aggregations

BlockSnapshotRestRep (com.emc.storageos.model.block.BlockSnapshotRestRep)41 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)20 URI (java.net.URI)17 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)13 ArrayList (java.util.ArrayList)10 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)9 Asset (com.emc.sa.asset.annotation.Asset)8 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)8 RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)5 BlockSnapshotSessionRestRep (com.emc.storageos.model.block.BlockSnapshotSessionRestRep)5 AssetOption (com.emc.vipr.model.catalog.AssetOption)5 VolumeGroupCopySetParam (com.emc.storageos.model.application.VolumeGroupCopySetParam)4 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)4 HashSet (java.util.HashSet)4 VirtualArrayRelatedResourceRep (com.emc.storageos.model.VirtualArrayRelatedResourceRep)3 ExportBlockParam (com.emc.storageos.model.block.export.ExportBlockParam)3 DeactivateBlockSnapshot (com.emc.sa.service.vipr.block.tasks.DeactivateBlockSnapshot)2 ResourceType (com.emc.sa.util.ResourceType)2 SnapshotList (com.emc.storageos.model.SnapshotList)2 BlockConsistencyGroupRestRep (com.emc.storageos.model.block.BlockConsistencyGroupRestRep)2