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;
}
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;
}
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);
}
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;
}
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();
}
Aggregations