Search in sources :

Example 81 with VolumeRestRep

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

the class BlockProvider method getVPlexVolumesInTargetVArray.

/**
 * Gets all {@link VolumeRestRep}s that are either in the target VArray or use the target VArray for protection
 *
 * @param client the ViPR client instance.
 * @param targetVArrayId the target VArray ID.
 * @param volumes the volumes we are concerned with. (These should be VPlex volumes)
 * @return List of {@link VolumeRestRep}s that are VPlex volumes that are in the target VArray
 */
public static List<BlockObjectRestRep> getVPlexVolumesInTargetVArray(ViPRCoreClient client, URI targetVArrayId, List<VolumeRestRep> volumes) {
    // collect vpools used by these volumes
    Map<URI, BlockVirtualPoolRestRep> vpools = getVpoolsForVolumes(client, volumes);
    // sift through the volumes to find ones with the correct VArray
    List<BlockObjectRestRep> acceptedVolumes = Lists.newArrayList();
    for (VolumeRestRep volume : volumes) {
        if (volume.getVirtualArray().getId().equals(targetVArrayId)) {
            addVolume(acceptedVolumes, volume);
        } else {
            // if this volume's HA type is 'distributed' and its distributed VArray matches the target VArray we can accept the volume
            URI vpoolId = volume.getVirtualPool().getId();
            BlockVirtualPoolRestRep volumeVpool = vpools.get(vpoolId);
            if (volumeVpool != null && isVpoolProtectedByVarray(volumeVpool, targetVArrayId)) {
                addVolume(acceptedVolumes, volume);
            }
        }
    }
    return acceptedVolumes;
}
Also used : BlockVirtualPoolRestRep(com.emc.storageos.model.vpool.BlockVirtualPoolRestRep) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep)

Example 82 with VolumeRestRep

use of com.emc.storageos.model.block.VolumeRestRep 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 83 with VolumeRestRep

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

the class BlockProvider method findVolumesByProject.

/**
 * Find all volumes by a project
 * @param client
 * @param project
 * @return  a list of volume REST representations.
 */
private List<VolumeRestRep> findVolumesByProject(ViPRCoreClient client, URI project) {
    log.info("Finding volumes by project {}", project);
    List<SearchResultResourceRep> volRefs = client.blockVolumes().performSearchBy(SearchConstants.PROJECT_PARAM, project);
    List<URI> ids = new ArrayList<>();
    for (SearchResultResourceRep volRef : volRefs) {
        ids.add(volRef.getId());
    }
    List<VolumeRestRep> volumes = client.blockVolumes().getByIds(ids, null);
    log.info("Got volumes: [{}]", volumes.size());
    return volumes;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) URI(java.net.URI)

Example 84 with VolumeRestRep

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

the class BlockProvider method getCopyNameByConsistencyGroup.

@Asset("journalCopyName")
@AssetDependencies("rpConsistencyGroupByProject")
public List<AssetOption> getCopyNameByConsistencyGroup(AssetOptionsContext ctx, URI consistencyGroupId) {
    ViPRCoreClient client = api(ctx);
    List<RelatedResourceRep> volumes = client.blockConsistencyGroups().get(consistencyGroupId).getVolumes();
    Set<String> copyNames = Sets.newHashSet();
    if (volumes != null && !volumes.isEmpty()) {
        RelatedResourceRep volume = volumes.get(0);
        VolumeRestRep volumeRep = client.blockVolumes().get(volume);
        if (volumeRep.getProtection() != null && volumeRep.getProtection().getRpRep() != null) {
            if (volumeRep.getProtection().getRpRep().getCopyName() != null) {
                String copyName = volumeRep.getProtection().getRpRep().getCopyName();
                copyNames.add(copyName);
            }
            if (volumeRep.getHaVolumes() != null) {
                List<RelatedResourceRep> haVolumes = volumeRep.getHaVolumes();
                List<URI> haVolumeIds = new ArrayList<URI>();
                for (RelatedResourceRep haVolume : haVolumes) {
                    haVolumeIds.add(haVolume.getId());
                }
                List<VolumeRestRep> haVolumeReps = client.blockVolumes().getByIds(haVolumeIds, null);
                for (VolumeRestRep haVolumeRep : haVolumeReps) {
                    if (haVolumeRep.getProtection() != null && haVolumeRep.getProtection().getRpRep() != null && haVolumeRep.getProtection().getRpRep().getCopyName() != null) {
                        String copyName = haVolumeRep.getProtection().getRpRep().getCopyName();
                        copyNames.add(copyName);
                    }
                }
            }
            if (volumeRep.getProtection().getRpRep().getRpTargets() != null) {
                List<VirtualArrayRelatedResourceRep> targetVolumes = volumeRep.getProtection().getRpRep().getRpTargets();
                List<URI> targetVolumeIds = new ArrayList<URI>();
                for (VirtualArrayRelatedResourceRep targetVolume : targetVolumes) {
                    targetVolumeIds.add(targetVolume.getId());
                }
                List<VolumeRestRep> targetVolumeReps = client.blockVolumes().getByIds(targetVolumeIds, null);
                for (VolumeRestRep targetVolumeRep : targetVolumeReps) {
                    String copyName = targetVolumeRep.getProtection().getRpRep().getCopyName();
                    copyNames.add(copyName);
                }
            }
        }
    }
    List<AssetOption> copyNameAssets = Lists.newArrayList();
    for (String copyName : copyNames) {
        copyNameAssets.add(newAssetOption(copyName, copyName));
    }
    AssetOptionsUtils.sortOptionsByLabel(copyNameAssets);
    return copyNameAssets;
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) AssetOption(com.emc.vipr.model.catalog.AssetOption) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) VirtualArrayRelatedResourceRep(com.emc.storageos.model.VirtualArrayRelatedResourceRep) ArrayList(java.util.ArrayList) URI(java.net.URI) VirtualArrayRelatedResourceRep(com.emc.storageos.model.VirtualArrayRelatedResourceRep) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Example 85 with VolumeRestRep

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

the class BlockProvider method getTargetVirtualPoolsForVpool.

@Asset("targetVirtualPool")
@AssetDependencies({ "project", "blockVirtualPool", "virtualPoolChangeOperation", "virtualPoolChangeVolumeWithSourceFilter", "displayJournals" })
public List<AssetOption> getTargetVirtualPoolsForVpool(AssetOptionsContext ctx, URI projectId, URI virtualPoolId, String vpoolChangeOperation, String filteredVolumes, String displayJournals) {
    List<URI> volumeIds = Lists.newArrayList();
    if (filteredVolumes != null && !filteredVolumes.isEmpty()) {
        // Best case we are passed in the volumes selected by the user
        // as comma delimited string so we do not have to load them from
        // the API.
        info("Filtered volumes selected by user: %s", filteredVolumes);
        List<String> parsedVolumeIds = TextUtils.parseCSV(filteredVolumes);
        for (String id : parsedVolumeIds) {
            volumeIds.add(uri(id));
        }
    } else {
        // Worst case we need to get the volumes from the API.
        info("Loading all volumes for vpool: %s", virtualPoolId.toString());
        List<VolumeRestRep> volumes = null;
        if (YES_VALUE.equals(displayJournals)) {
            volumes = listJournalVolumes(api(ctx), projectId, new VirtualPoolFilter(virtualPoolId));
        } else {
            volumes = listSourceVolumes(api(ctx), projectId, new VirtualPoolFilter(virtualPoolId));
        }
        for (VolumeRestRep volume : volumes) {
            volumeIds.add(volume.getId());
        }
    }
    if (CollectionUtils.isNotEmpty(volumeIds)) {
        BulkIdParam input = new BulkIdParam();
        input.setIds(volumeIds);
        List<VirtualPoolChangeRep> vpoolChanges = api(ctx).blockVpools().listVirtualPoolChangeCandidates(virtualPoolId, input);
        return createVpoolChangeOptions(vpoolChangeOperation, vpoolChanges);
    }
    return Collections.emptyList();
}
Also used : BulkIdParam(com.emc.storageos.model.BulkIdParam) VplexVolumeVirtualPoolFilter(com.emc.vipr.client.core.filters.VplexVolumeVirtualPoolFilter) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) URI(java.net.URI) VirtualPoolChangeRep(com.emc.storageos.model.vpool.VirtualPoolChangeRep) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Aggregations

VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)136 URI (java.net.URI)74 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)49 Asset (com.emc.sa.asset.annotation.Asset)35 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)35 ArrayList (java.util.ArrayList)25 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)23 AssetOption (com.emc.vipr.model.catalog.AssetOption)20 BlockSnapshotRestRep (com.emc.storageos.model.block.BlockSnapshotRestRep)13 HashSet (java.util.HashSet)13 UnManagedVolumeRestRep (com.emc.storageos.model.block.UnManagedVolumeRestRep)12 Test (org.junit.Test)12 NamedVolumesList (com.emc.storageos.model.block.NamedVolumesList)11 BlockConsistencyGroupRestRep (com.emc.storageos.model.block.BlockConsistencyGroupRestRep)10 VirtualArrayRelatedResourceRep (com.emc.storageos.model.VirtualArrayRelatedResourceRep)9 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)8 RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)7 VolumeCreate (com.emc.storageos.model.block.VolumeCreate)7 List (java.util.List)7 SnapshotList (com.emc.storageos.model.SnapshotList)6