Search in sources :

Example 1 with SnapshotSessionUnlinkTargetsParam

use of com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam 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;
}
Also used : TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) SnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) MapBlockSnapshot(com.emc.storageos.api.mapper.functions.MapBlockSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with SnapshotSessionUnlinkTargetsParam

use of com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam 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);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) BlockSnapshotSessionRestRep(com.emc.storageos.model.block.BlockSnapshotSessionRestRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) SnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam)

Example 3 with SnapshotSessionUnlinkTargetsParam

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

the class BlockSnapshotSessions method unlinkTarget.

public static void unlinkTarget(String snapshotId, String snapshotSessionId, Boolean deleteOption) {
    ViPRCoreClient client = BourneUtil.getViprClient();
    SnapshotSessionUnlinkTargetsParam unlinkTarget = new SnapshotSessionUnlinkTargetsParam();
    List<SnapshotSessionUnlinkTargetParam> unlinkSessions = Lists.newArrayList();
    SnapshotSessionUnlinkTargetParam unlink = new SnapshotSessionUnlinkTargetParam();
    unlink.setDeleteTarget(deleteOption);
    unlink.setId(uri(snapshotId));
    unlinkSessions.add(unlink);
    unlinkTarget.setLinkedTargets(unlinkSessions);
    client.blockSnapshotSessions().unlinkTargets(uri(snapshotSessionId), unlinkTarget);
    flash.put("info", MessagesUtils.get("resources.snapshot.session.unlink.success", snapshotId));
    snapshotSessionDetails(snapshotSessionId);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) SnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam)

Example 4 with SnapshotSessionUnlinkTargetsParam

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

the class VolumeGroupService method performVolumeGroupSnapshotSessionOperation.

/*
     * Wrapper of BlockConsistencyGroupService methods for snapshot session operations
     * 
     * @param volumeGroupId
     * 
     * @param param
     * 
     * @return a TaskList
     */
private TaskList performVolumeGroupSnapshotSessionOperation(final URI volumeGroupId, final VolumeGroupSnapshotSessionOperationParam param, OperationTypeEnum opType) {
    List<BlockSnapshotSession> snapSessions = getSnapshotSessionsGroupedBySnapSessionset(volumeGroupId, param);
    // Check for pending tasks
    VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, volumeGroupId);
    if (opType == OperationTypeEnum.RESTORE_VOLUME_GROUP_SNAPSHOT_SESSION) {
        checkForApplicationPendingTasks(volumeGroup, _dbClient, true);
    } else {
        checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
    }
    auditOp(opType, true, AuditLogManager.AUDITOP_BEGIN, volumeGroupId.toString(), param.getSnapshotSessions());
    TaskList taskList = new TaskList();
    Table<URI, String, BlockSnapshotSession> storageRgToSnapshot = ControllerUtils.getSnapshotSessionForStorageReplicationGroup(snapSessions, _dbClient);
    for (Cell<URI, String, BlockSnapshotSession> cell : storageRgToSnapshot.cellSet()) {
        BlockSnapshotSession session = cell.getValue();
        log.info("{} for replication group {}", opType.getDescription(), cell.getColumnKey());
        ResourceOperationTypeEnum oprEnum = null;
        try {
            // should not be null
            URI cgUri = session.getConsistencyGroup();
            URI sessionUri = session.getId();
            log.info("CG: {}, Session: {}", cgUri, session.getLabel());
            switch(opType) {
                case RESTORE_VOLUME_GROUP_SNAPSHOT_SESSION:
                    oprEnum = ResourceOperationTypeEnum.RESTORE_SNAPSHOT_SESSION;
                    taskList.addTask(_blockConsistencyGroupService.restoreConsistencyGroupSnapshotSession(cgUri, sessionUri));
                    break;
                case DELETE_VOLUME_GROUP_SNAPSHOT_SESSION:
                    oprEnum = ResourceOperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT_SESSION;
                    taskList.getTaskList().addAll(_blockConsistencyGroupService.deactivateConsistencyGroupSnapshotSession(cgUri, sessionUri).getTaskList());
                    break;
                case LINK_VOLUME_GROUP_SNAPSHOT_SESSION_TARGET:
                    oprEnum = ResourceOperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGETS;
                    SnapshotSessionLinkTargetsParam linkParam = new SnapshotSessionLinkTargetsParam(((VolumeGroupSnapshotSessionLinkTargetsParam) param).getNewLinkedTargets());
                    taskList.getTaskList().addAll(_blockConsistencyGroupService.linkTargetVolumes(cgUri, sessionUri, linkParam).getTaskList());
                    break;
                case RELINK_VOLUME_GROUP_SNAPSHOT_SESSION_TARGET:
                    oprEnum = ResourceOperationTypeEnum.RELINK_CONSISTENCY_GROUP_SNAPSHOT_SESSION_TARGETS;
                    SnapshotSessionRelinkTargetsParam relinkParam = new SnapshotSessionRelinkTargetsParam(getRelinkTargetIdsForSession((VolumeGroupSnapshotSessionRelinkTargetsParam) param, session, snapSessions.size()));
                    taskList.getTaskList().addAll(_blockConsistencyGroupService.relinkTargetVolumes(cgUri, sessionUri, relinkParam).getTaskList());
                    break;
                case UNLINK_VOLUME_GROUP_SNAPSHOT_SESSION_TARGET:
                    oprEnum = ResourceOperationTypeEnum.UNLINK_SNAPSHOT_SESSION_TARGETS;
                    SnapshotSessionUnlinkTargetsParam unlinkParam = new SnapshotSessionUnlinkTargetsParam(getUnlinkTargetIdsForSession((VolumeGroupSnapshotSessionUnlinkTargetsParam) param, session));
                    taskList.addTask(_blockConsistencyGroupService.unlinkTargetVolumesForSession(cgUri, sessionUri, unlinkParam));
                    break;
                default:
                    log.error("Unsupported operation {}", opType.getDescription());
                    break;
            }
        } catch (InternalException | APIException e) {
            String errMsg = String.format("Exception occurred while performing %s on Replication group %s", opType.getDescription(), cell.getColumnKey());
            log.error(errMsg, e);
            TaskResourceRep task = BlockServiceUtils.createFailedTaskOnSnapshotSession(_dbClient, session, oprEnum, e);
            taskList.addTask(task);
        } catch (Exception ex) {
            String errMsg = String.format("Unexpected Exception occurred while performing %s on Replication group %s", opType.getDescription(), cell.getColumnKey());
            log.error(errMsg, ex);
        }
    }
    auditOp(opType, true, AuditLogManager.AUDITOP_END, volumeGroupId.toString(), param.getSnapshotSessions());
    return taskList;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VolumeGroupSnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionUnlinkTargetsParam) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) SnapshotSessionLinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionLinkTargetsParam) VolumeGroupSnapshotSessionLinkTargetsParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionLinkTargetsParam) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) VolumeGroupSnapshotSessionRelinkTargetsParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionRelinkTargetsParam) SnapshotSessionRelinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionRelinkTargetsParam) VolumeGroupSnapshotSessionRelinkTargetsParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionRelinkTargetsParam) ResourceOperationTypeEnum(com.emc.storageos.model.ResourceOperationTypeEnum) SnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam) VolumeGroupSnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.application.VolumeGroupSnapshotSessionUnlinkTargetsParam)

Example 5 with SnapshotSessionUnlinkTargetsParam

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

the class BlockConsistencyGroupService method deactivateAndUnlinkTargetVolumesForSession.

/**
 * This method is called when a linked BlockSnapshot for a BlockSnapshotSession is passed to
 * {@link #deactivateConsistencyGroupSnapshot(URI, URI)} and we must instead unlink&delete it.
 *
 * @param session The BlockSnapshotSession.
 * @param snapshot The BlockSnapshot.
 * @return TaskList wrapping the single TaskResourceRep.
 */
private TaskList deactivateAndUnlinkTargetVolumesForSession(BlockSnapshotSession session, BlockSnapshot snapshot) {
    SnapshotSessionUnlinkTargetParam unlink = new SnapshotSessionUnlinkTargetParam(snapshot.getId(), true);
    SnapshotSessionUnlinkTargetsParam param = new SnapshotSessionUnlinkTargetsParam(newArrayList(unlink));
    TaskResourceRep task = unlinkTargetVolumesFromSnapshotSession(session.getId(), param, OperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT);
    return new TaskList(newArrayList(task));
}
Also used : SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) SnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam)

Aggregations

SnapshotSessionUnlinkTargetsParam (com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam)5 SnapshotSessionUnlinkTargetParam (com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam)4 TaskList (com.emc.storageos.model.TaskList)3 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)2 URI (java.net.URI)2 MapBlockSnapshot (com.emc.storageos.api.mapper.functions.MapBlockSnapshot)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Operation (com.emc.storageos.db.client.model.Operation)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 Volume (com.emc.storageos.db.client.model.Volume)1 VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)1 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1