Search in sources :

Example 41 with InternalException

use of com.emc.storageos.svcs.errorhandling.resources.InternalException 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 42 with InternalException

use of com.emc.storageos.svcs.errorhandling.resources.InternalException 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 43 with InternalException

use of com.emc.storageos.svcs.errorhandling.resources.InternalException in project coprhd-controller by CoprHD.

the class BlockService method changeVolumeVirtualPool.

/**
 * Allows the caller to change the virtual pool for the volume identified in
 * the request. Currently, the only virtual pool changes that are supported
 * are as follows:
 *
 * Change the virtual pool for a VPLEX virtual volume. This virtual pool
 * change would allow the caller to change the types of drives, for example,
 * used for the backend volume(s) that are used by the virtual volume.
 *
 * Change the virtual pool for a VPLEX virtual volume, such that a local
 * VPLEX virtual volumes becomes a distributed VPLEX virtual volume.
 *
 * Change the virtual pool of a VMAX or VNX Block volume to make the volume
 * a local or distributed VPLEX virtual volume. Essentially, the volume
 * becomes the backend volume for a VPLEX virtual volume. Similar to
 * creating a virtual volume, but instead of creating a new backend volume,
 * using the volume identified in the request. The VMAX or VNX volume cannot
 * currently be exported for this change.
 *
 * Change the virtual pool of a VMAX or VNX Block volume to make the volume
 * a RecoverPoint protected volume. The volume must be able to stay put, and
 * ViPR will build a protection around it.
 *
 * Change the virtual pool of a VMAX or VNX Block volume to allow native
 * continuous copies to be created for it.
 *
 * Change the virtual pool of a volume to increase the export path parameter max_paths.
 * The number of paths will be upgraded if possible for all Export Groups / Export Masks
 * containing this volume. If the volume is not currently exported, max_paths can be
 * decreased or paths_per_initiator can be changed. Note that changing max_paths does
 * not have any effect on the export of BlockSnapshots that were created from this volume.
 *
 * Change the virtual pool of a VMAX and VNX volume to allow change of Auto-tiering policy
 * associated with it.
 * <p>
 * Since this method has been deprecated use POST /block/volumes/vpool-change
 *
 * @brief Change the virtual pool for a volume.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR volume.
 * @param param
 *            The parameter specifying the new virtual pool.
 * @return A TaskResourceRep representing the virtual pool change for the
 *         volume.
 * @throws InternalException,
 *             APIException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/vpool")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
@Deprecated
public TaskResourceRep changeVolumeVirtualPool(@PathParam("id") URI id, VirtualPoolChangeParam param) throws InternalException, APIException {
    _log.info("Request to change VirtualPool for volume {}", id);
    // Get the volume.
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    Volume volume = queryVolumeResource(id);
    _log.info("Found volume");
    // Don't operate on VPLEX backend or RP Journal volumes.
    BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
    // Don't operate on ingested volumes.
    VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VPOOL, _dbClient);
    // Get the project.
    URI projectURI = volume.getProject().getURI();
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    ArgValidator.checkEntity(project, projectURI, false);
    _log.info("Found volume project {}", projectURI);
    // Verify the user is authorized for the volume's project.
    BlockServiceUtils.verifyUserIsAuthorizedForRequest(project, getUserFromContext(), _permissionsHelper);
    _log.info("User is authorized for volume's project");
    // Get the VirtualPool for the request and verify that the
    // project's tenant has access to the VirtualPool.
    VirtualPool vpool = getVirtualPoolForRequest(project, param.getVirtualPool(), _dbClient, _permissionsHelper);
    _log.info("Found new VirtualPool {}", vpool.getId());
    // Verify that the VirtualPool change is allowed for the
    // requested volume and VirtualPool.
    verifyVirtualPoolChangeSupportedForVolumeAndVirtualPool(volume, vpool);
    _log.info("VirtualPool change is supported for requested volume and VirtualPool");
    verifyAllVolumesInCGRequirement(Arrays.asList(volume), vpool);
    // verify quota
    if (!CapacityUtils.validateVirtualPoolQuota(_dbClient, vpool, volume.getProvisionedCapacity())) {
        throw APIException.badRequests.insufficientQuotaForVirtualPool(vpool.getLabel(), "volume");
    }
    // Create a unique task id.
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Volume.class, id, taskId, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VPOOL);
    // execute the VirtualPool update on the volume.
    try {
        BlockServiceApi blockServiceAPI = getBlockServiceImplForVirtualPoolChange(volume, vpool);
        _log.info("Got block service implementation for VirtualPool change request");
        blockServiceAPI.changeVolumeVirtualPool(Arrays.asList(volume), vpool, param, taskId);
        _log.info("Executed VirtualPool change for volume.");
    } catch (InternalException | APIException e) {
        String errorMsg = String.format("Volume VirtualPool change error: %s", e.getMessage());
        op = new Operation(Operation.Status.error.name(), errorMsg);
        _dbClient.updateTaskOpStatus(Volume.class, id, taskId, op);
        throw e;
    }
    auditOp(OperationTypeEnum.CHANGE_VOLUME_VPOOL, true, AuditLogManager.AUDITOP_BEGIN, volume.getLabel(), 1, volume.getVirtualArray().toString(), volume.getProject().toString());
    return toTask(volume, taskId, op);
}
Also used : Project(com.emc.storageos.db.client.model.Project) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 44 with InternalException

use of com.emc.storageos.svcs.errorhandling.resources.InternalException 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 45 with InternalException

use of com.emc.storageos.svcs.errorhandling.resources.InternalException in project coprhd-controller by CoprHD.

the class FileMirrorServiceApiImpl method createTargetsForExistingSource.

@Override
public TaskResourceRep createTargetsForExistingSource(FileShare fs, Project project, VirtualPool vpool, VirtualArray varray, TaskList taskList, String task, List<Recommendation> recommendations, VirtualPoolCapabilityValuesWrapper vpoolCapabilities) throws InternalException {
    List<FileShare> fileList = null;
    List<FileShare> fileShares = new ArrayList<FileShare>();
    FileSystemParam fsParams = new FileSystemParam();
    fsParams.setFsId(fs.getId().toString());
    fsParams.setLabel(fs.getLabel());
    fsParams.setVarray(fs.getVirtualArray());
    fsParams.setVpool(fs.getVirtualPool());
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
    // Prepare the FileShares
    fileList = prepareFileSystems(fsParams, task, taskList, project, tenant, null, varray, vpool, recommendations, vpoolCapabilities, false);
    fileShares.addAll(fileList);
    // prepare the file descriptors
    final List<FileDescriptor> fileDescriptors = prepareFileDescriptors(fileShares, vpoolCapabilities, null);
    final FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
    try {
        // Execute the create mirror copies of fileshare!!!
        controller.createTargetsForExistingSource(fs.getId().toString(), fileDescriptors, task);
    } catch (InternalException e) {
        _log.error("Controller error when creating mirror filesystems", e);
        failFileShareCreateRequest(task, taskList, fileShares, e.getMessage());
        throw e;
    } catch (Exception e) {
        _log.error("Controller error when creating mirror filesystems", e);
        failFileShareCreateRequest(task, taskList, fileShares, e.getMessage());
        throw e;
    }
    return taskList.getTaskList().get(0);
}
Also used : FileSystemParam(com.emc.storageos.model.file.FileSystemParam) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) ArrayList(java.util.ArrayList) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileShare(com.emc.storageos.db.client.model.FileShare) FileDescriptor(com.emc.storageos.fileorchestrationcontroller.FileDescriptor) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Aggregations

InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)209 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)112 URI (java.net.URI)106 ControllerException (com.emc.storageos.volumecontroller.ControllerException)100 Volume (com.emc.storageos.db.client.model.Volume)91 ArrayList (java.util.ArrayList)86 WorkflowException (com.emc.storageos.workflow.WorkflowException)84 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)83 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)77 NamedURI (com.emc.storageos.db.client.model.NamedURI)63 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)60 URISyntaxException (java.net.URISyntaxException)58 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)55 Operation (com.emc.storageos.db.client.model.Operation)51 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)45 Workflow (com.emc.storageos.workflow.Workflow)41 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)40 Path (javax.ws.rs.Path)39 Produces (javax.ws.rs.Produces)39 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)37