use of com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam 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.model.block.SnapshotSessionUnlinkTargetParam in project coprhd-controller by CoprHD.
the class VolumeGroupService method getUnlinkTargetIdsForSession.
/**
* Gets the unlink target ids for the given session.
*
* @param param the VolumeGroupSnapshotSessionUnlinkTargetsParam
* @param session the snap session
* @return the unlink target id params for session
*/
private List<SnapshotSessionUnlinkTargetParam> getUnlinkTargetIdsForSession(final VolumeGroupSnapshotSessionUnlinkTargetsParam param, BlockSnapshotSession session) {
List<SnapshotSessionUnlinkTargetParam> targetIds = new ArrayList<SnapshotSessionUnlinkTargetParam>();
List<URI> selectedURIs = new ArrayList<URI>();
StringSet sessionTargets = session.getLinkedTargets();
if (param.getLinkedTargets() != null && !param.getLinkedTargets().isEmpty()) {
for (SnapshotSessionUnlinkTargetParam unlinkTarget : param.getLinkedTargets()) {
URI snapURI = unlinkTarget.getId();
// Snapshot session targets are represented by BlockSnapshot instances in ViPR.
ArgValidator.checkFieldUriType(snapURI, BlockSnapshot.class, "id");
BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
ArgValidator.checkEntityNotNull(snap, snapURI, isIdEmbeddedInURL(snapURI));
if (sessionTargets != null && sessionTargets.contains(snapURI.toString())) {
targetIds.add(unlinkTarget);
selectedURIs.add(snapURI);
}
}
} else {
ArgValidator.checkFieldNotEmpty(param.getTargetName(), "target_name");
for (String linkedTgtId : session.getLinkedTargets()) {
URI snapURI = URI.create(linkedTgtId);
BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
if (StringUtils.equals(param.getTargetName(), snap.getSnapsetLabel())) {
SnapshotSessionUnlinkTargetParam unlinkTarget = new SnapshotSessionUnlinkTargetParam();
unlinkTarget.setId(snap.getId());
unlinkTarget.setDeleteTarget(param.getDeleteTarget() == null ? false : param.getDeleteTarget());
targetIds.add(unlinkTarget);
selectedURIs.add(snapURI);
}
}
}
log.info(String.format("Target ids for snapshot session %s : %s", session.getLabel(), Joiner.on(',').join(selectedURIs)));
if (targetIds.isEmpty()) {
// None of the provided target belong to this snapshot session.
throw APIException.badRequests.snapshotSessionDoesNotHaveAnyTargets(session.getId().toString());
}
return targetIds;
}
use of com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method unlinkTargetVolumesFromSnapshotSession.
/**
* Implements a request to unlink the passed targets from the
* BlockSnapshotSession instance with the passed URI.
*
* @param snapSessionURI The URI of a BlockSnapshotSession instance.
* @param param The linked target information.
* @param opType The operation type for the audit and event logs.
*
* @return A TaskResourceRep.
*/
public TaskResourceRep unlinkTargetVolumesFromSnapshotSession(URI snapSessionURI, SnapshotSessionUnlinkTargetsParam param, OperationTypeEnum opType) {
s_logger.info("START unlink targets from snapshot session {}", snapSessionURI);
// Get the snapshot session.
BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
BlockObject snapSessionSourceObj = null;
List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
snapSessionSourceObj = snapSessionSourceObjs.get(0);
// Get the project for the snapshot session source object.
Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
// Get the target information.
Map<URI, Boolean> targetMap = new HashMap<>();
for (SnapshotSessionUnlinkTargetParam targetInfo : param.getLinkedTargets()) {
URI targetURI = targetInfo.getId();
Boolean deleteTarget = targetInfo.getDeleteTarget();
if (deleteTarget == null) {
deleteTarget = Boolean.FALSE;
}
targetMap.put(targetURI, deleteTarget);
}
// Validate that the requested targets can be unlinked from the snapshot session.
snapSessionApiImpl.validateUnlinkSnapshotSessionTargets(snapSession, snapSessionSourceObj, project, targetMap, _uriInfo);
// Create a unique task identifier.
String taskId = UUID.randomUUID().toString();
// Create a task for the snapshot session.
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UNLINK_SNAPSHOT_SESSION_TARGETS);
_dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
snapSession.getOpStatus().put(taskId, op);
TaskResourceRep response = toTask(snapSession, taskId);
// Unlink the targets from the snapshot session.
try {
snapSessionApiImpl.unlinkTargetVolumesFromSnapshotSession(snapSessionSourceObj, snapSession, targetMap, opType, taskId);
} catch (Exception e) {
String errorMsg = format("Failed to unlink targets from snapshot session %s: %s", snapSessionURI, e.getMessage());
ServiceCoded sc = null;
if (e instanceof ServiceCoded) {
sc = (ServiceCoded) e;
} else {
sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
}
cleanupFailure(Arrays.asList(response), new ArrayList<DataObject>(), errorMsg, taskId, sc);
throw e;
}
// Create the audit log entry.
auditOp(opType, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
s_logger.info("FINISH unlink targets from snapshot session {}", snapSessionURI);
return response;
}
use of com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam in project coprhd-controller by CoprHD.
the class BlockVolumes method unlinkTargetSnapshot.
public static void unlinkTargetSnapshot(String sessionId, String volumeId, Boolean deleteOption) {
ViPRCoreClient client = BourneUtil.getViprClient();
SnapshotSessionUnlinkTargetsParam sessionTargets = new SnapshotSessionUnlinkTargetsParam();
List<SnapshotSessionUnlinkTargetParam> targetLists = Lists.newArrayList();
List<RelatedResourceRep> targets = client.blockSnapshotSessions().get(uri(sessionId)).getLinkedTarget();
List<BlockSnapshotRestRep> snapshots = client.blockSnapshots().getByRefs(targets);
for (BlockSnapshotRestRep snap : snapshots) {
SnapshotSessionUnlinkTargetParam targetList = new SnapshotSessionUnlinkTargetParam();
targetList.setId(snap.getId());
targetList.setDeleteTarget(deleteOption);
targetLists.add(targetList);
}
if (!targetLists.isEmpty()) {
sessionTargets.setLinkedTargets(targetLists);
Task<BlockSnapshotSessionRestRep> tasks = client.blockSnapshotSessions().unlinkTargets(uri(sessionId), sessionTargets);
flash.put("info", MessagesUtils.get("resources.snapshot.session.unlink.success", sessionId));
} else {
flash.error(MessagesUtils.get(NOTARGET, sessionId));
}
volume(volumeId, null);
}
use of com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam in project coprhd-controller by CoprHD.
the class UnlinkSnapshotSessionForApplication method doExecute.
@Override
protected Tasks<TaskResourceRep> doExecute() throws Exception {
VolumeGroupSnapshotSessionUnlinkTargetsParam input = new VolumeGroupSnapshotSessionUnlinkTargetsParam();
input.setSnapshotSessions(snapshotSessions);
input.setPartial(true);
List<SnapshotSessionUnlinkTargetParam> linkedTargets = Lists.newArrayList();
if (existingLinkedSnapshotIds != null) {
for (String linkedSnapshot : existingLinkedSnapshotIds) {
SnapshotSessionUnlinkTargetParam param = new SnapshotSessionUnlinkTargetParam();
param.setId(uri(linkedSnapshot));
if (deleteTarget != null) {
param.setDeleteTarget(deleteTarget);
}
linkedTargets.add(param);
}
}
input.setLinkedTargets(linkedTargets);
TaskList taskList = getClient().application().unlinkApplicationSnapshotSession(applicationId, input);
return new Tasks<TaskResourceRep>(getClient().auth().getClient(), taskList.getTaskList(), TaskResourceRep.class);
}
Aggregations