use of com.emc.storageos.model.SnapshotList in project coprhd-controller by CoprHD.
the class FileService method getSnapshots.
/**
* Get file system snapshots
*
* @param id
* the URN of a ViPR File system
* @brief List file system snapshots
* @return List of snapshots
*/
@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 getSnapshots(@PathParam("id") URI id) {
List<URI> snapIDList = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id));
_log.debug("getSnapshots: FS {}: {} ", id.toString(), snapIDList.toString());
List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapIDList);
SnapshotList list = new SnapshotList();
for (Snapshot snap : snapList) {
list.getSnapList().add(toNamedRelatedResource(snap));
}
return list;
}
use of com.emc.storageos.model.SnapshotList in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroupSnapshots.
/**
* List snapshots for a volume group
*
* @prereq none
* @param volumeGroupId The URI of the volume group.
* @brief List snapshots for a volume group
* @return SnapshotList
*/
@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 getVolumeGroupSnapshots(@PathParam("id") final URI volumeGroupId) {
// query volume group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
// 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()) {
snapshotList.getSnapList().add(toNamedRelatedResource(snapshot));
}
}
}
return snapshotList;
}
use of com.emc.storageos.model.SnapshotList in project coprhd-controller by CoprHD.
the class VolumeGroupService method validateSnapshotOperation.
/**
* Validates a snapshot operation and throws and exception if the operation cannot be done:
* - checks for pending tasks
* - for deactivate snapshot, check for any exported snapshots
*
* @param volumeGroupId
* @param snapsetToSnapshots
* @param opType
*/
private void validateSnapshotOperation(URI volumeGroupId, Map<String, List<BlockSnapshot>> snapsetToSnapshots, OperationTypeEnum opType) {
// Check for pending tasks
VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, volumeGroupId);
if (opType == OperationTypeEnum.RESTORE_VOLUME_GROUP_SNAPSHOT) {
checkForApplicationPendingTasks(volumeGroup, _dbClient, true);
} else {
checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
if (opType == OperationTypeEnum.DEACTIVATE_VOLUME_GROUP_SNAPSHOT) {
for (Entry<String, List<BlockSnapshot>> entry : snapsetToSnapshots.entrySet()) {
String snapsetName = entry.getKey();
List<BlockSnapshot> snapshotList = entry.getValue();
for (BlockSnapshot snapshot : snapshotList) {
if (snapshot.isSnapshotExported(_dbClient)) {
throw APIException.badRequests.cannotDeleteApplicationSnapshotExportExists(volumeGroup.getLabel(), snapsetName);
}
}
}
}
}
}
use of com.emc.storageos.model.SnapshotList in project coprhd-controller by CoprHD.
the class BlockService method getSnapshots.
/**
* List volume snapshots
*
* @prereq none
*
* @param id
* the URN of a ViPR Volume to list snapshots
*
* @brief List volume snapshots
* @return Volume snapshot response containing list of snapshot identifiers
*/
@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 getSnapshots(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, Volume.class, "id");
Volume requestedVolume = queryVolumeResource(id);
// Get the block service implementation for the volume.
BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(requestedVolume);
// Get and return the snapshots.
List<BlockSnapshot> snapList = blockServiceApiImpl.getSnapshots(requestedVolume);
SnapshotList list = new SnapshotList();
list.setSnapList(new ArrayList<NamedRelatedResourceRep>());
List<NamedRelatedResourceRep> activeSnaps = new ArrayList<NamedRelatedResourceRep>();
List<NamedRelatedResourceRep> inactiveSnaps = new ArrayList<NamedRelatedResourceRep>();
for (BlockSnapshot snap : snapList) {
if (snap.getInactive()) {
inactiveSnaps.add(toNamedRelatedResource(snap));
} else {
activeSnaps.add(toNamedRelatedResource(snap));
}
}
list.getSnapList().addAll(activeSnaps);
list.getSnapList().addAll(inactiveSnaps);
return list;
}
use of com.emc.storageos.model.SnapshotList in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method createConsistencyGroupSnapshot.
/**
* Creates a consistency group snapshot
*
* @prereq none
*
* @param consistencyGroupId
* - Consistency group URI
* @param param
*
* @brief Create consistency group snapshot
* @return TaskList
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ANY })
public TaskList createConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, final BlockConsistencyGroupSnapshotCreate param) {
ArgValidator.checkFieldUriType(consistencyGroupId, BlockConsistencyGroup.class, "id");
// Query Consistency Group
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
// system types.
if (!consistencyGroup.created()) {
throw APIException.badRequests.consistencyGroupNotCreated();
}
// RP CG's must use applications to create snapshots
if (isIdEmbeddedInURL(consistencyGroupId) && consistencyGroup.checkForType(Types.RP)) {
throw APIException.badRequests.snapshotsNotSupportedForRPCGs();
}
// Validate CG information in the request
validateVolumesInReplicationGroups(consistencyGroup, param.getVolumes(), _dbClient);
// Get the block service implementation
BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
Table<URI, String, List<Volume>> storageRgToVolumes = null;
if (!param.getVolumes().isEmpty()) {
// Volume group snapshot
// group volumes by backend storage system and replication group
storageRgToVolumes = BlockServiceUtils.getReplicationGroupVolumes(param.getVolumes(), consistencyGroupId, _dbClient, uriInfo);
} else {
// CG snapshot
storageRgToVolumes = BlockServiceUtils.getReplicationGroupVolumes(blockServiceApiImpl.getActiveCGVolumes(consistencyGroup), _dbClient);
}
// Validation replication group volumes to ensure there aren't mixed meta and non-meta devices
validateReplicationGroupDevices(storageRgToVolumes);
TaskList taskList = new TaskList();
for (Cell<URI, String, List<Volume>> cell : storageRgToVolumes.cellSet()) {
List<Volume> volumeList = cell.getValue();
if (volumeList == null || volumeList.isEmpty()) {
_log.warn(String.format("No volume in replication group %s", cell.getColumnKey()));
continue;
}
// Generate task id
String taskId = UUID.randomUUID().toString();
// Set snapshot type.
String snapshotType = BlockSnapshot.TechnologyType.NATIVE.toString();
// Validate the snapshot request.
String snapshotName = TimeUtils.formatDateForCurrent(param.getName());
// Set the read only flag.
final Boolean readOnly = param.getReadOnly() == null ? Boolean.FALSE : param.getReadOnly();
// Set the create inactive flag.
final Boolean createInactive = param.getCreateInactive() == null ? Boolean.FALSE : param.getCreateInactive();
blockServiceApiImpl.validateCreateSnapshot(volumeList.get(0), volumeList, snapshotType, snapshotName, readOnly, getFullCopyManager());
// Prepare and create the snapshots for the group.
List<URI> snapIdList = new ArrayList<URI>();
List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
snapshotList.addAll(blockServiceApiImpl.prepareSnapshots(volumeList, snapshotType, snapshotName, snapIdList, taskId));
for (BlockSnapshot snapshot : snapshotList) {
taskList.getTaskList().add(toTask(snapshot, taskId));
}
addConsistencyGroupTask(consistencyGroup, taskList, taskId, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT);
try {
blockServiceApiImpl.createSnapshot(volumeList.get(0), snapIdList, snapshotType, createInactive, readOnly, taskId);
auditBlockConsistencyGroup(OperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, param.getName(), consistencyGroup.getId().toString());
} catch (Exception ex) {
_log.error("Unexpected Exception occurred when creating snapshot for replication group {}", cell.getColumnKey(), ex);
}
}
return taskList;
}
Aggregations