Search in sources :

Example 16 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method deactivateConsistencyGroupSnapshot.

/**
 * Deactivate the specified Consistency Group Snapshot
 *
 * @prereq none
 *
 * @param consistencyGroupId
 *            - Consistency group URI
 * @param snapshotId
 *            - Consistency group snapshot URI
 *
 * @brief Deactivate consistency group snapshot session
 * @return TaskResourceRep
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList deactivateConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
    // Snapshots of RecoverPoint consistency groups is not supported.
    if (isIdEmbeddedInURL(consistencyGroupId) && consistencyGroup.checkForType(Types.RP)) {
        throw APIException.badRequests.snapshotsNotSupportedForRPCGs();
    }
    // check for backend CG
    if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
        _log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
        throw APIException.badRequests.cannotCreateSnapshotOfCG();
    }
    final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
    verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
    // 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);
    ArgValidator.checkReference(BlockSnapshot.class, snapshotId, checkForDelete(snapshot, excludeTypes));
    // Snapshot session linked targets must be unlinked instead.
    BlockSnapshotSession session = BlockSnapshotSessionUtils.getLinkedTargetSnapshotSession(snapshot, _dbClient);
    if (session != null) {
        return deactivateAndUnlinkTargetVolumesForSession(session, snapshot);
    }
    // Generate task id
    final String task = UUID.randomUUID().toString();
    TaskList response = new TaskList();
    // Not an error if the snapshot we try to delete is already deleted
    if (snapshot.getInactive()) {
        Operation op = new Operation();
        op.ready("The consistency group snapshot has already been deactivated");
        op.setResourceType(ResourceOperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT);
        _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
        response.getTaskList().add(toTask(snapshot, task, op));
        return response;
    }
    List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
    snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
    // Get the snapshot parent volume.
    Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
    // Check that there are no pending tasks for these snapshots.
    checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), snapshots);
    for (BlockSnapshot snap : snapshots) {
        Operation snapOp = _dbClient.createTaskOpStatus(BlockSnapshot.class, snap.getId(), task, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_SNAPSHOT);
        response.getTaskList().add(toTask(snap, task, snapOp));
    }
    addConsistencyGroupTask(consistencyGroup, response, task, ResourceOperationTypeEnum.DEACTIVATE_CONSISTENCY_GROUP_SNAPSHOT);
    try {
        BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(parentVolume, _dbClient);
        blockServiceApiImpl.deleteSnapshot(snapshot, snapshots, task, VolumeDeleteTypeEnum.FULL.name());
    } catch (APIException | InternalException e) {
        String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
        _log.error(errorMsg);
        for (TaskResourceRep taskResourceRep : response.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(errorMsg);
            @SuppressWarnings({ "unchecked" }) Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
            _dbClient.error(clazz, taskResourceRep.getResource().getId(), task, e);
        }
        throw e;
    } catch (Exception e) {
        String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
        _log.error(errorMsg);
        APIException apie = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        for (TaskResourceRep taskResourceRep : response.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(apie.getMessage());
            @SuppressWarnings("unchecked") Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
            _dbClient.error(clazz, taskResourceRep.getResource().getId(), task, apie);
        }
        throw apie;
    }
    auditBlockConsistencyGroup(OperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
    return response;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) TaskList(com.emc.storageos.model.TaskList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Volume(com.emc.storageos.db.client.model.Volume) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 17 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method verifyCGForFullCopyRequest.

/**
 * Verifies the CG passe din the request is valid and contains volumes.
 *
 * @param cgURI The URI of a consistency group.
 *
 * @return The volumes in the consistency group.
 */
private List<Volume> verifyCGForFullCopyRequest(URI cgURI) {
    // Query Consistency Group.
    BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(cgURI);
    // defined system types.
    if (!consistencyGroup.created()) {
        throw APIException.badRequests.consistencyGroupNotCreated();
    }
    // Get the block service implementation.
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    // Get the volumes in the consistency group.
    List<Volume> cgVolumes = blockServiceApiImpl.getActiveCGVolumes(consistencyGroup);
    if (cgVolumes.isEmpty()) {
        throw APIException.badRequests.fullCopyOperationNotAllowedOnEmptyCG(consistencyGroup.getLabel());
    }
    return cgVolumes;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 18 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method swap.

/**
 * Request to reverse the replication direction, i.e. R1 and R2 are interchanged.
 *
 * @prereq none
 *
 * @param id the URI of a BlockConsistencyGroup
 * @param param Copy to swap
 *
 * @brief Reverse roles of source and target
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/swap")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList swap(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
    TaskResourceRep taskResp = null;
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    // Query Consistency Group
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
    // system types.
    if (!consistencyGroup.created()) {
        throw APIException.badRequests.consistencyGroupNotCreated();
    }
    List<Copy> copies = param.getCopies();
    if (copies.size() > 1) {
        throw APIException.badRequests.swapCopiesParamCanOnlyBeOne();
    }
    Copy copy = copies.get(0);
    ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
    ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
    if (TechnologyType.RP.name().equalsIgnoreCase(copy.getType())) {
        taskResp = performProtectionAction(id, copy, ProtectionOp.SWAP.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else if (TechnologyType.SRDF.name().equalsIgnoreCase(copy.getType())) {
        taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.SWAP.getRestOp());
        taskList.getTaskList().add(taskResp);
    } else {
        throw APIException.badRequests.invalidCopyType(copy.getType());
    }
    return taskList;
}
Also used : Copy(com.emc.storageos.model.block.Copy) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 19 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method deleteConsistencyGroup.

/**
 * Deletes a consistency group
 *
 * Do not delete if snapshots exist for consistency group
 *
 * @prereq Dependent snapshot resources must be deleted
 *
 * @param id the URN of a ViPR Consistency group
 *
 * @brief Delete consistency group
 * @return TaskResourceRep
 *
 * @throws InternalException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deleteConsistencyGroup(@PathParam("id") final URI id, @DefaultValue("FULL") @QueryParam("type") String type) throws InternalException {
    // Query for the given consistency group and verify it is valid.
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
    ArgValidator.checkReference(BlockConsistencyGroup.class, id, checkForDelete(consistencyGroup));
    // Create a unique task identifier.
    String task = UUID.randomUUID().toString();
    // So, we do need to verify that no volumes reference the CG.
    if (deletingUncreatedConsistencyGroup(consistencyGroup) || VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(type)) {
        markCGForDeletion(consistencyGroup);
        return finishDeactivateTask(consistencyGroup, task);
    }
    // Otherwise, we need to clean up the array consistency groups.
    TaskResourceRep taskRep = null;
    try {
        List<StorageSystem> vplexSystems = BlockConsistencyGroupUtils.getVPlexStorageSystems(consistencyGroup, _dbClient);
        if (!vplexSystems.isEmpty()) {
            // If there is a VPLEX system, then we simply call the VPLEX controller which
            // will delete all VPLEX CGS on all VPLEX systems, and also all local CGs on
            // all local systems.
            BlockServiceApi blockServiceApi = getBlockServiceImpl(DiscoveredDataObject.Type.vplex.name());
            taskRep = blockServiceApi.deleteConsistencyGroup(vplexSystems.get(0), consistencyGroup, task);
        } else {
            // Otherwise, we call the block controller to delete the local CGs on all local systems.
            List<URI> localSystemURIs = BlockConsistencyGroupUtils.getLocalSystems(consistencyGroup, _dbClient);
            if (!localSystemURIs.isEmpty()) {
                boolean foundSystem = false;
                for (URI localSystemURI : localSystemURIs) {
                    StorageSystem localSystem = _dbClient.queryObject(StorageSystem.class, localSystemURI);
                    if (localSystem != null) {
                        foundSystem = true;
                        BlockServiceApi blockServiceApi = getBlockServiceImpl(BLOCKSERVICEAPIIMPL_GROUP);
                        taskRep = blockServiceApi.deleteConsistencyGroup(localSystem, consistencyGroup, task);
                        if (Task.Status.error.name().equals(taskRep.getState())) {
                            break;
                        }
                    } else {
                        _log.warn("Local system {} for consistency group {} does not exist", localSystemURI, consistencyGroup.getLabel());
                    }
                }
                // Check to make sure we found at least one of these local systems.
                if (!foundSystem) {
                    // For some reason we have a CG with local systems, but none of them
                    // are in the database. In this case, we will log a warning and mark
                    // it for deletion.
                    _log.warn("Deleting created consistency group {} where none of the local systems for the group exist", consistencyGroup.getLabel());
                    markCGForDeletion(consistencyGroup);
                    return finishDeactivateTask(consistencyGroup, task);
                }
            } else {
                // For some reason the CG has no VPLEX or local systems but is
                // marked as being active and created. In this case, we will log
                // a warning and mark it for deletion.
                _log.info("Deleting created consistency group {} with no local or VPLEX systems", consistencyGroup.getLabel());
                markCGForDeletion(consistencyGroup);
                return finishDeactivateTask(consistencyGroup, task);
            }
        }
    } catch (APIException | InternalException e) {
        String errorMsg = String.format("Exception attempting to delete consistency group %s: %s", consistencyGroup.getLabel(), e.getMessage());
        _log.error(errorMsg);
        taskRep.setState(Operation.Status.error.name());
        taskRep.setMessage(errorMsg);
        _dbClient.error(BlockConsistencyGroup.class, taskRep.getResource().getId(), task, e);
    } catch (Exception e) {
        String errorMsg = String.format("Exception attempting to delete consistency group %s: %s", consistencyGroup.getLabel(), e.getMessage());
        _log.error(errorMsg);
        APIException apie = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        taskRep.setState(Operation.Status.error.name());
        taskRep.setMessage(apie.getMessage());
        _dbClient.error(BlockConsistencyGroup.class, taskRep.getResource().getId(), task, apie);
    }
    // the request was successful.
    if (Task.Status.ready.name().equals(taskRep.getState())) {
        markCGForDeletion(consistencyGroup);
    }
    return taskRep;
}
Also used : TaskResourceRep(com.emc.storageos.model.TaskResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 20 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method restoreConsistencyGroupSnapshot.

/**
 * Restore the specified consistency group snapshot
 *
 * @prereq Activate consistency group snapshot
 *
 * @param consistencyGroupId
 *            - Consistency group URI
 * @param snapshotId
 *            - Consistency group snapshot URI
 *
 * @brief Restore consistency group snapshot
 * @return TaskResourceRep
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/restore")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep restoreConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
    // Get the consistency group and snapshot and verify the snapshot
    // is actually associated with the consistency group.
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
    final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
    verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
    // check for backend CG
    if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
        _log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
        throw APIException.badRequests.cannotCreateSnapshotOfCG();
    }
    // Get the parent volume.
    final Volume snapshotParentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
    // Get the block implementation
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    // Validate the snapshot restore.
    blockServiceApiImpl.validateRestoreSnapshot(snapshot, snapshotParentVolume);
    // Create the restore operation task for the snapshot.
    final String taskId = UUID.randomUUID().toString();
    final Operation op = _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.RESTORE_CONSISTENCY_GROUP_SNAPSHOT);
    // Restore the snapshot.
    blockServiceApiImpl.restoreSnapshot(snapshot, snapshotParentVolume, null, taskId);
    auditBlockConsistencyGroup(OperationTypeEnum.RESTORE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshotId.toString(), consistencyGroupId.toString(), snapshot.getStorageController().toString());
    return toTask(snapshot, taskId, op);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Operation(com.emc.storageos.db.client.model.Operation) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)253 Volume (com.emc.storageos.db.client.model.Volume)134 URI (java.net.URI)134 ArrayList (java.util.ArrayList)102 NamedURI (com.emc.storageos.db.client.model.NamedURI)88 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)71 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)71 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)49 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)46 StringSet (com.emc.storageos.db.client.model.StringSet)45 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 ControllerException (com.emc.storageos.volumecontroller.ControllerException)43 BlockObject (com.emc.storageos.db.client.model.BlockObject)37 Project (com.emc.storageos.db.client.model.Project)33 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)31 HashMap (java.util.HashMap)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)29 List (java.util.List)29 HashSet (java.util.HashSet)28 Produces (javax.ws.rs.Produces)28