use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockService method verifyVPlexVolumeForDataMigration.
/**
* Performs verification on the VPLEX volume to ensure it is a candidate for migration.
*
* @param volume VPLEX volume to check
* @param currentVpool The current vpool where the volume is placed
* @param newVpool The target vpool where the volume will be placed after migration
*/
public static void verifyVPlexVolumeForDataMigration(Volume volume, VirtualPool currentVpool, VirtualPool newVpool, DbClient _dbClient) {
_log.info(String.format("Verifying that the VPlex volume[%s](%s) qualifies for Data Migration" + " moving from current vpool [%s](%s) to new vpool [%s](%s).", volume.getLabel(), volume.getId(), currentVpool.getLabel(), currentVpool.getId(), newVpool.getLabel(), newVpool.getId()));
// Determine if source side will be migrated.
boolean migrateSourceVolume = VirtualPoolChangeAnalyzer.vpoolChangeRequiresMigration(currentVpool, newVpool);
// Determine if HA side will be migrated.
boolean migrateHAVolume = false;
VirtualPool currentHaVpool = VirtualPoolChangeAnalyzer.getHaVpool(currentVpool, _dbClient);
if (currentHaVpool != null) {
VirtualPool newHaVpool = VirtualPoolChangeAnalyzer.getNewHaVpool(currentVpool, newVpool, _dbClient);
migrateHAVolume = VirtualPoolChangeAnalyzer.vpoolChangeRequiresMigration(currentHaVpool, newHaVpool);
}
// Verify the VPLEX volume structure. Ingested volumes
// can only be migrated if the component structure of
// the volume is supported by ViPR.
verifyVPlexVolumeStructureForDataMigration(volume, currentVpool, migrateSourceVolume, migrateHAVolume, _dbClient);
// Check for snaps, mirrors, and full copies
if (migrateSourceVolume) {
// The vpool change is a data migration and the source
// side backend volume will be migrated. If the volume
// has snapshots, then the vpool change will not be
// allowed because VPLEX snapshots are just snapshots
// of this backend volume. The user would lose all
// snapshots if we allowed the vpool change. The user
// must explicitly go and delete their snapshots first.
// the same is true for volumes that have full copies
// from which they are not detached and also full copy
// volumes that are not detached from their source. If
// not detached a full copy session still exists between
// this backend volume and some other volume.
//
// Note: We make this validation here instead of in the
// verification VirtualPoolChangeAnalyzer method
// "getSupportedVPlexVolumeVirtualPoolChangeOperation"
// because this method is called from not only the API
// to change the volume virtual pool, but also the API
// that determines the virtual pools to which a volume
// can be changed. The latter API is used by the UI to
// populate the list of volumes. We want volumes with
// snaps to appear in the list, so that the user will
// know that if they remove the snapshots, they can
// perform the vpool change.
Volume srcVolume = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient, false);
if (srcVolume != null) {
// Has a source volume, so not ingested.
List<BlockSnapshot> snapshots = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockSnapshot.class, ContainmentConstraint.Factory.getVolumeSnapshotConstraint(srcVolume.getId()));
if (!snapshots.isEmpty()) {
throw APIException.badRequests.volumeForVpoolChangeHasSnaps(volume.getId().toString());
}
// Check for snapshot sessions for the volume.
if (BlockSnapshotSessionUtils.volumeHasSnapshotSession(srcVolume, _dbClient)) {
throw APIException.badRequests.volumeForVpoolChangeHasSnaps(volume.getLabel());
}
// has full copy sessions.
if (BlockFullCopyUtils.volumeHasFullCopySession(srcVolume, _dbClient)) {
throw APIException.badRequests.volumeForVpoolChangeHasFullCopies(volume.getLabel());
}
}
// If the volume has mirrors then Vpool change will not
// be allowed. User needs to explicitly delete mirrors first.
// This is applicable for both Local and Distributed volumes.
// For distributed volume getMirrors will get mirror if any
// on source or HA side.
StringSet mirrorURIs = volume.getMirrors();
if (mirrorURIs != null && !mirrorURIs.isEmpty()) {
List<VplexMirror> mirrors = _dbClient.queryObject(VplexMirror.class, StringSetUtil.stringSetToUriList(mirrorURIs));
if (mirrors != null && !mirrors.isEmpty()) {
throw APIException.badRequests.volumeForVpoolChangeHasMirrors(volume.getId().toString(), volume.getLabel());
}
}
}
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotService method getSnapshot.
/**
* Get snapshot details
*
* @prereq none
* @param id the URN of a ViPR snapshot
* @brief Show snapshot
* @return Block snapshot
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockSnapshotRestRep getSnapshot(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
BlockSnapshot snap = (BlockSnapshot) queryResource(id);
return map(_dbClient, snap);
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotService method getTenantOwner.
@Override
protected URI getTenantOwner(URI id) {
BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
URI projectUri = snapshot.getProject().getURI();
ArgValidator.checkUri(projectUri);
Project project = _permissionsHelper.getObjectById(projectUri, Project.class);
ArgValidator.checkEntityNotNull(project, projectUri, isIdEmbeddedInURL(projectUri));
return project.getTenantOrg().getURI();
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotService method deactivateSnapshot.
/**
* Deactivate volume snapshot, will result in permanent deletion of the requested snapshot from the storage system it was created on
* and will move the snapshot to a "marked-for-delete" state after the deletion happens on the array side.
* It will be deleted by the garbage collector on a subsequent iteration
* If this snapshot was created from a volume that is part of a consistency group,
* then all the related snapshots will be deactivated, as well.
*
* If "?type=VIPR_ONLY" is added to the path, it will delete snapshot only from ViPR data base and leaves the snapshot on storage array
* as it is.
* Possible value for attribute type : FULL, VIPR_ONLY
* FULL : Deletes the snapshot permanently on array and ViPR data base.
* VIPR_ONLY : Deletes the snapshot only from ViPR data base and leaves the snapshot on array as it is.
*
* @prereq none
* @param id the URN of a ViPR snapshot
* @param type the type of deletion {@link DefaultValue} FULL
* @brief Delete snapshot
* @return Snapshot information
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList deactivateSnapshot(@PathParam("id") URI id, @DefaultValue("FULL") @QueryParam("type") String type) {
_log.info("Executing {} snapshot delete for snapshot {}", type, id);
String opStage = null;
boolean successStatus = true;
String taskId = UUID.randomUUID().toString();
TaskList response = new TaskList();
// Get the snapshot.
BlockSnapshot snap = (BlockSnapshot) queryResource(id);
// We can ignore dependencies on BlockSnapshotSession. In this case
// the BlockSnapshot instance is a linked target for a BlockSnapshotSession
// and we will unlink the snapshot from the session and delete it.
List<Class<? extends DataObject>> excludeTypes = new ArrayList<Class<? extends DataObject>>();
excludeTypes.add(BlockSnapshotSession.class);
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(type)) {
excludeTypes.add(ExportGroup.class);
excludeTypes.add(ExportMask.class);
}
ArgValidator.checkReference(BlockSnapshot.class, id, checkForDelete(snap, excludeTypes));
if (!VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(type)) {
// The audit log message operation stage.
opStage = AuditLogManager.AUDITOP_BEGIN;
// If the BlockSnapshot instance represents a linked target, then
// we need to unlink the target form the snapshot session and then
// delete the target.
URIQueryResultList snapSessionURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(id), snapSessionURIs);
Iterator<URI> snapSessionURIsIter = snapSessionURIs.iterator();
if (snapSessionURIsIter.hasNext()) {
_log.info("Snapshot is linked target for a snapshot session");
SnapshotSessionUnlinkTargetsParam param = new SnapshotSessionUnlinkTargetsParam();
List<SnapshotSessionUnlinkTargetParam> targetInfoList = new ArrayList<SnapshotSessionUnlinkTargetParam>();
SnapshotSessionUnlinkTargetParam targetInfo = new SnapshotSessionUnlinkTargetParam(id, Boolean.TRUE);
targetInfoList.add(targetInfo);
param.setLinkedTargets(targetInfoList);
response.getTaskList().add(getSnapshotSessionManager().unlinkTargetVolumesFromSnapshotSession(snapSessionURIsIter.next(), param, OperationTypeEnum.DELETE_VOLUME_SNAPSHOT));
return response;
}
// Not an error if the snapshot we try to delete is already deleted
if (snap.getInactive()) {
_log.info("Snapshot is already inactive");
Operation op = new Operation();
op.ready("The snapshot has already been deleted");
op.setResourceType(ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT);
_dbClient.createTaskOpStatus(BlockSnapshot.class, snap.getId(), taskId, op);
response.getTaskList().add(toTask(snap, taskId, op));
return response;
}
}
// Get the storage system.
StorageSystem device = _dbClient.queryObject(StorageSystem.class, snap.getStorageController());
// Determine all snapshots to delete.
List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
final URI cgId = snap.getConsistencyGroup();
if (!NullColumnValueGetter.isNullURI(cgId) && !NullColumnValueGetter.isNullValue(snap.getReplicationGroupInstance())) {
// Collect all the BlockSnapshots if part of a CG.
snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snap, _dbClient);
} else {
// Snap is not part of a CG so only delete the snap
snapshots.add(snap);
}
// Get the snapshot parent volume.
Volume parentVolume = _permissionsHelper.getObjectById(snap.getParent(), Volume.class);
// Check that there are no pending tasks for these snapshots.
checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), snapshots);
// Create tasks on the volume.
for (BlockSnapshot snapshot : snapshots) {
Operation snapOp = _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT);
response.getTaskList().add(toTask(snapshot, taskId, snapOp));
}
// should be returned.
try {
BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(parentVolume, _dbClient);
blockServiceApiImpl.deleteSnapshot(snap, snapshots, taskId, type);
} catch (APIException | InternalException e) {
successStatus = false;
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snap.getId(), e.getMessage());
_log.error(errorMsg);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
_dbClient.error(BlockSnapshot.class, taskResourceRep.getResource().getId(), taskId, e);
}
} catch (Exception e) {
successStatus = false;
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snap.getId(), e.getMessage());
_log.error(errorMsg);
ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(sc.getMessage());
_dbClient.error(BlockSnapshot.class, taskResourceRep.getResource().getId(), taskId, sc);
}
}
auditOp(OperationTypeEnum.DELETE_VOLUME_SNAPSHOT, successStatus, opStage, id.toString(), snap.getLabel(), snap.getParent().getName(), device.getId().toString());
return response;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotService method resynchronize.
/**
* Call will resynchronize this snapshot from the volume that it is associated with.
* If this snapshot was created from a volume in a consistency group, then all
* related snapshots will be resynchronized.
*
* @prereq none
* @param id [required] - the URN of a ViPR block snapshot to restore from
* @brief Resynchronize snapshot
* @return TaskResourceRep - Task resource object for tracking this operation
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
@Path("/{id}/resynchronize")
public TaskResourceRep resynchronize(@PathParam("id") URI id) {
// Validate an get the snapshot to be restored.
ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
// Get the block service API implementation for the snapshot parent volume.
Volume volume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Get the storage system for the volume
StorageSystem storage = _permissionsHelper.getObjectById(volume.getStorageController(), StorageSystem.class);
if (storage.checkIfVmax3()) {
if (snapshot.getSettingsInstance() == null) {
throw APIException.badRequests.snapshotNullSettingsInstance(snapshot.getLabel());
}
}
// resync for OpenStack storage system type is not supported
if (Type.openstack.name().equalsIgnoreCase(storage.getSystemType())) {
throw APIException.methodNotAllowed.notSupportedWithReason(String.format("Snapshot resynchronization is not possible on third-party storage systems"));
}
// resync for VNX storage system type is not supported
if (Type.vnxblock.name().equalsIgnoreCase(storage.getSystemType())) {
throw APIException.methodNotAllowed.notSupportedWithReason("Snapshot resynchronization is not supported on VNX storage systems");
}
BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(volume, _dbClient);
// Validate the resync snapshot request.
blockServiceApiImpl.validateResynchronizeSnapshot(snapshot, volume);
// Create the task identifier.
String taskId = UUID.randomUUID().toString();
// Create the operation status entry in the status map for the snapshot.
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT);
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, op);
snapshot.getOpStatus().put(taskId, op);
// Resync the snapshot.
blockServiceApiImpl.resynchronizeSnapshot(snapshot, volume, taskId);
// Create the audit log entry.
auditOp(OperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, id.toString(), volume.getId().toString(), snapshot.getStorageController().toString());
return toTask(snapshot, taskId, op);
}
Aggregations