Search in sources :

Example 1 with SnapshotList

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

the class BlockConsistencyGroupService method getConsistencyGroupSnapshots.

/**
 * List snapshots in the consistency group
 *
 * @prereq none
 *
 * @param consistencyGroupId
 *            - Consistency group URI
 *
 * @brief List snapshots in the consistency group
 * @return The list of snapshots in the consistency group
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getConsistencyGroupSnapshots(@PathParam("id") final URI consistencyGroupId) {
    ArgValidator.checkUri(consistencyGroupId);
    final Class<? extends DataObject> clazz = URIUtil.isType(consistencyGroupId, BlockSnapshot.class) ? BlockSnapshot.class : BlockConsistencyGroup.class;
    final DataObject consistencyGroup = _permissionsHelper.getObjectById(consistencyGroupId, clazz);
    ArgValidator.checkEntityNotNull(consistencyGroup, consistencyGroupId, isIdEmbeddedInURL(consistencyGroupId));
    List<Volume> volumes = ControllerUtils.getVolumesPartOfCG(consistencyGroupId, _dbClient);
    // if any of the source volumes are in an application, replica management must be done via the application
    for (Volume srcVol : volumes) {
        if (srcVol.getApplication(_dbClient) != null) {
            return new SnapshotList();
        }
    }
    SnapshotList list = new SnapshotList();
    List<URI> snapshotsURIs = new ArrayList<URI>();
    // Find all volumes assigned to the group
    final URIQueryResultList cgSnapshotsResults = new URIQueryResultList();
    _dbClient.queryByConstraint(getBlockSnapshotByConsistencyGroup(consistencyGroupId), cgSnapshotsResults);
    if (!cgSnapshotsResults.iterator().hasNext()) {
        return list;
    }
    while (cgSnapshotsResults.iterator().hasNext()) {
        URI snapshot = cgSnapshotsResults.iterator().next();
        snapshotsURIs.add(snapshot);
    }
    List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotsURIs);
    List<NamedRelatedResourceRep> activeSnapshots = new ArrayList<NamedRelatedResourceRep>();
    List<NamedRelatedResourceRep> inactiveSnapshots = new ArrayList<NamedRelatedResourceRep>();
    for (BlockSnapshot snapshot : snapshots) {
        if (snapshot.getInactive()) {
            inactiveSnapshots.add(toNamedRelatedResource(snapshot));
        } else {
            activeSnapshots.add(toNamedRelatedResource(snapshot));
        }
    }
    list.getSnapList().addAll(inactiveSnapshots);
    list.getSnapList().addAll(activeSnapshots);
    return list;
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Volume(com.emc.storageos.db.client.model.Volume) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with SnapshotList

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

the class VolumeGroupService method getVolumeGroupSnapshotsForSet.

/**
 * List snapshots in a snapshot set for a volume group
 *
 * @prereq none
 * @param volumeGroupId The URI of the volume group
 * @brief List snapshots in snapshot set for a volume group
 * @return SnapshotList
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/copy-sets")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getVolumeGroupSnapshotsForSet(@PathParam("id") final URI volumeGroupId, final VolumeGroupCopySetParam param) {
    // query volume group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
    // validate copy set name
    String copySetName = param.getCopySetName();
    ArgValidator.checkFieldNotEmpty(copySetName, COPY_SET_NAME_FIELD);
    // get all volumes
    List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
    // get the snapshots for each volume in the group
    SnapshotList snapshotList = new SnapshotList();
    for (Volume volume : volumes) {
        if (volume.isVPlexVolume(_dbClient)) {
            volume = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient);
            if (volume == null || volume.getInactive()) {
                log.warn("Cannot find backend volume for VPLEX volume {}", volume.getLabel());
            }
        }
        URIQueryResultList snapshotURIs = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume.getId()), snapshotURIs);
        if (!snapshotURIs.iterator().hasNext()) {
            continue;
        }
        List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotURIs);
        for (BlockSnapshot snapshot : snapshots) {
            if (snapshot != null && !snapshot.getInactive()) {
                if (copySetName.equals(snapshot.getSnapsetLabel())) {
                    snapshotList.getSnapList().add(toNamedRelatedResource(snapshot));
                }
            }
        }
    }
    return snapshotList;
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with SnapshotList

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

the class BlockProvider method getReplicationGroupsForApplicationSnapshot.

protected Set<String> getReplicationGroupsForApplicationSnapshot(ViPRCoreClient client, URI applicationId, String copySet) {
    Set<String> options = Sets.newHashSet();
    VolumeGroupCopySetParam input = new VolumeGroupCopySetParam();
    input.setCopySetName(copySet);
    SnapshotList sessions = client.application().getVolumeGroupSnapshotsForSet(applicationId, input);
    for (NamedRelatedResourceRep snap : sessions.getSnapList()) {
        BlockSnapshotRestRep snapRep = client.blockSnapshots().get(snap);
        // TODO get replication group from parent. should the snapshot already contain this?
        VolumeRestRep parentVolume = client.blockVolumes().get(snapRep.getParent());
        if (parentVolume != null && parentVolume.getReplicationGroupInstance() != null) {
            options.add(parentVolume.getReplicationGroupInstance());
        }
    }
    return BlockStorageUtils.stripRPTargetFromReplicationGroup(options);
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) VolumeGroupCopySetParam(com.emc.storageos.model.application.VolumeGroupCopySetParam) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep)

Example 4 with SnapshotList

use of com.emc.storageos.model.SnapshotList 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 5 with SnapshotList

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

the class BlockConsistencyGroups method getSnapshots.

/**
 * List snapshots in the consistency group
 * <p>
 * API Call: <tt>GET /block/consistency-groups/{id}/protection/snapshots</tt>
 *
 * @param consistencyGroupId
 *            the ID of the consistency group
 * @return The list of snapshots in the consistency group
 */
public List<NamedRelatedResourceRep> getSnapshots(URI consistencyGroupId) {
    final String url = getIdUrl() + "/protection/snapshots";
    SnapshotList response = client.get(SnapshotList.class, url, consistencyGroupId);
    return response.getSnapList();
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList)

Aggregations

SnapshotList (com.emc.storageos.model.SnapshotList)10 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 Volume (com.emc.storageos.db.client.model.Volume)5 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)3 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)3 NamedVolumesList (com.emc.storageos.model.block.NamedVolumesList)3 URI (java.net.URI)3 TaskList (com.emc.storageos.model.TaskList)2 VolumeGroupCopySetParam (com.emc.storageos.model.application.VolumeGroupCopySetParam)2 BlockSnapshotRestRep (com.emc.storageos.model.block.BlockSnapshotRestRep)2 BlockSnapshotSessionList (com.emc.storageos.model.block.BlockSnapshotSessionList)2 SOURCE_TO_TARGET (com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET)2 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)2