Search in sources :

Example 6 with BlockServiceApi

use of com.emc.storageos.api.service.impl.resource.BlockServiceApi in project coprhd-controller by CoprHD.

the class VolumeService method deleteVolume.

/**
 * Delete a specific volume
 *
 * @prereq none
 *
 * @param tenant_id the URN of the tenant
 * @param volume_id the URN of the volume
 * @return
 *
 * @brief Delete volume
 * @return Task result
 */
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{volume_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response deleteVolume(@PathParam("tenant_id") String openstackTenantId, @PathParam("volume_id") String volumeId) {
    _log.info("Delete volume: id = {} tenant: id ={}", volumeId, openstackTenantId);
    if (volumeId == null) {
        _log.debug("Delete volume is failed : Volume id is empty ");
        return CinderApiUtils.createErrorResponse(404, "Not Found : volume id is empty");
    }
    Volume vol = findVolume(volumeId, openstackTenantId);
    if (vol == null) {
        return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid volume id");
    } else if (vol.hasConsistencyGroup()) {
        return CinderApiUtils.createErrorResponse(400, "Invalid volume: Volume belongs to consistency group");
    }
    BlockServiceApi api = BlockService.getBlockServiceImpl(vol, _dbClient);
    if ((api.getSnapshots(vol) != null) && (!api.getSnapshots(vol).isEmpty())) {
        return CinderApiUtils.createErrorResponse(400, "Invalid volume: Volume still has one or more dependent snapshots");
    }
    verifyUserCanModifyVolume(vol);
    // Now delete it
    String task = UUID.randomUUID().toString();
    URI systemUri = vol.getStorageController();
    List<URI> volumeURIs = new ArrayList<URI>();
    volumeURIs.add(vol.getId());
    api.deleteVolumes(systemUri, volumeURIs, "FULL", task);
    if (vol.getExtensions() == null) {
        vol.setExtensions(new StringMap());
    }
    vol.getExtensions().put("status", CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase());
    vol.getExtensions().put(DELETE_TASK_ID, task);
    _dbClient.updateObject(vol);
    return Response.status(202).build();
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) CinderVolume(com.emc.storageos.cinder.model.CinderVolume) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) URI(java.net.URI) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with BlockServiceApi

use of com.emc.storageos.api.service.impl.resource.BlockServiceApi in project coprhd-controller by CoprHD.

the class VolumeService method createVolume.

/**
 * The fundamental abstraction in the Block Store is a
 * volume. A volume is a unit of block storage capacity that has been
 * allocated by a consumer to a project. This API allows the user to
 * create one or more volumes. The volumes are created in the same
 * storage pool.
 *
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param param POST data containing the volume creation information.
 *
 * @brief Create volume
 * @return Details of the newly created volume
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createVolume(@PathParam("tenant_id") String openstackTenantId, @HeaderParam("X-Cinder-V1-Call") String isV1Call, VolumeCreateRequestGen param, @Context HttpHeaders header) throws InternalException {
    // Step 1: Parameter validation
    Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    String snapshotId = param.volume.snapshot_id;
    String sourceVolId = param.volume.source_volid;
    String imageId = param.volume.imageRef;
    String consistencygroup_id = param.volume.consistencygroup_id;
    String volume_type = param.volume.volume_type;
    boolean hasConsistencyGroup = false;
    if (project == null) {
        if (openstackTenantId != null) {
            throw APIException.badRequests.projectWithTagNonexistent(openstackTenantId);
        } else {
            throw APIException.badRequests.parameterIsNullOrEmpty(PROJECT_TENANTID_NULL);
        }
    }
    URI tenantUri = project.getTenantOrg().getURI();
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, tenantUri);
    if (tenant == null)
        throw APIException.notFound.unableToFindUserScopeOfSystem();
    _log.debug("Create volume: project = {}, tenant = {}", project.getLabel(), tenant.getLabel());
    if (param.volume.size <= 0) {
        _log.error("volume size should not be zero or negative ={} ", param.volume.size);
        return CinderApiUtils.createErrorResponse(400, "Bad Request : Invalid Volume size");
    }
    long requestedSize = param.volume.size * GB;
    // convert volume type from name to vpool
    VirtualPool vpool = getVpool(param.volume.volume_type);
    Volume sourceVolume = null;
    if (vpool == null) {
        if (sourceVolId != null) {
            sourceVolume = findVolume(sourceVolId, openstackTenantId);
            if (sourceVolume == null) {
                _log.error("Invalid Source Volume ID ={} ", sourceVolId);
                return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid Source Volume ID " + sourceVolId);
            }
            vpool = _dbClient.queryObject(VirtualPool.class, sourceVolume.getVirtualPool());
        } else {
            _log.error("Invalid Volume Type ={} ", volume_type);
            return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid Volume Type " + volume_type);
        }
    }
    if (!validateVolumeCreate(openstackTenantId, null, requestedSize)) {
        _log.info("The volume can not be created because of insufficient project quota.");
        throw APIException.badRequests.insufficientQuotaForProject(project.getLabel(), "volume");
    } else if (!validateVolumeCreate(openstackTenantId, vpool, requestedSize)) {
        _log.info("The volume can not be created because of insufficient quota for virtual pool.");
        throw APIException.badRequests.insufficientQuotaForVirtualPool(vpool.getLabel(), "virtual pool");
    }
    _log.debug("Create volume: vpool = {}", vpool.getLabel());
    VirtualArray varray = getCinderHelper().getVarray(param.volume.availability_zone, getUserFromContext());
    if ((snapshotId == null) && (sourceVolId == null) && (varray == null)) {
        // otherwise availability_zone exception will be thrown
        throw APIException.badRequests.parameterIsNotValid(param.volume.availability_zone);
    }
    // Validating consistency group
    URI blockConsistencyGroupId = null;
    BlockConsistencyGroup blockConsistencyGroup = null;
    if (consistencygroup_id != null) {
        _log.info("Verifying for consistency group : " + consistencygroup_id);
        blockConsistencyGroup = (BlockConsistencyGroup) getCinderHelper().queryByTag(URI.create(consistencygroup_id), getUserFromContext(), BlockConsistencyGroup.class);
        if (getCinderHelper().verifyConsistencyGroupHasSnapshot(blockConsistencyGroup)) {
            _log.error("Bad Request : Consistency Group has Snapshot ");
            return CinderApiUtils.createErrorResponse(400, "Bad Request : Consistency Group has Snapshot ");
        }
        blockConsistencyGroupId = blockConsistencyGroup.getId();
        if (blockConsistencyGroup.getTag() != null && consistencygroup_id.equals(blockConsistencyGroupId.toString().split(":")[3])) {
            for (ScopedLabel tag : blockConsistencyGroup.getTag()) {
                if (tag.getScope().equals("volume_types")) {
                    if (tag.getLabel().equals(volume_type)) {
                        hasConsistencyGroup = true;
                    } else {
                        return CinderApiUtils.createErrorResponse(404, "Invalid volume: No consistency group exist for volume : " + param.volume.display_name);
                    }
                }
            }
        } else {
            return CinderApiUtils.createErrorResponse(404, "Invalid Consistency Group Id : No Such Consistency group exists");
        }
    }
    BlockSnapshot snapshot = null;
    URI snapUri = null;
    if (snapshotId != null) {
        snapshot = (BlockSnapshot) getCinderHelper().queryByTag(URI.create(snapshotId), getUserFromContext(), BlockSnapshot.class);
        if (snapshot == null) {
            _log.error("Invalid snapshot id ={} ", snapshotId);
            return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid snapshot id" + snapshotId);
        } else {
            snapUri = snapshot.getId();
            URI varrayUri = snapshot.getVirtualArray();
            if (varray == null) {
                varray = _dbClient.queryObject(VirtualArray.class, varrayUri);
            }
        }
    }
    if (varray != null)
        _log.info("Create volume: varray = {}", varray.getLabel());
    String name = null;
    String description = null;
    _log.info("is isV1Call {}", isV1Call);
    _log.info("name = {},  description  = {}", name, description);
    if (isV1Call != null) {
        name = param.volume.display_name;
        description = param.volume.display_description;
    } else {
        name = param.volume.name;
        description = param.volume.description;
    }
    if (name == null) {
        name = "volume-" + RandomStringUtils.random(10);
    }
    _log.info("param.volume.name = {}, param.volume.display_name = {}", param.volume.name, param.volume.display_name);
    _log.info("param.volume.description = {}, param.volume.display_description = {}", param.volume.description, param.volume.display_description);
    if (name == null || (name.length() <= 2))
        throw APIException.badRequests.parameterIsNotValid(name);
    URI projectUri = project.getId();
    checkForDuplicateName(name, Volume.class, projectUri, "project", _dbClient);
    // Step 2: Check if the user has rights for volume create
    verifyUserIsAuthorizedForRequest(project, vpool, varray);
    // Step 3: Check capacity Quotas
    _log.debug(" volume name = {}, size = {} GB", name, param.volume.size);
    int volumeCount = 1;
    VolumeCreate volumeCreate = new VolumeCreate(name, Long.toString(requestedSize), volumeCount, vpool.getId(), varray.getId(), project.getId());
    BlockServiceApi api = getBlockServiceImpl(vpool, _dbClient);
    CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, requestedSize, "volume");
    // Step 4: Call out placementManager to get the recommendation for placement.
    VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
    capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, volumeCount);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, requestedSize);
    // Create a unique task id if one is not passed in the request.
    String task = UUID.randomUUID().toString();
    TaskList tasklist = null;
    BlockFullCopyManager blkFullCpManager = new BlockFullCopyManager(_dbClient, _permissionsHelper, _auditMgr, _coordinator, _placementManager, sc, uriInfo, _request, null);
    if (hasConsistencyGroup && blockConsistencyGroupId != null) {
        try {
            checkForConsistencyGroup(vpool, blockConsistencyGroup, project, api, varray, capabilities, blkFullCpManager);
            volumeCreate.setConsistencyGroup(blockConsistencyGroupId);
        } catch (APIException exp) {
            return CinderApiUtils.createErrorResponse(400, "Bad Request : can't create volume for the consistency group : " + blockConsistencyGroupId);
        }
    }
    if (sourceVolId != null) {
        _log.debug("Creating New Volume from Volume : Source volume ID ={}", sourceVolId);
        if (sourceVolume != null) {
            Volume vol = findVolume(sourceVolId, openstackTenantId);
            if (vol == null) {
                _log.debug("Creating Clone Volume failed : Invalid source volume id ");
                return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid source volume id" + sourceVolId);
            }
            tasklist = volumeClone(name, project, sourceVolId, varray, volumeCount, sourceVolume, blkFullCpManager);
        } else {
            _log.debug("Creating Clone Volume failed : Null Source volume ");
            return CinderApiUtils.createErrorResponse(404, "Not Found : Null source volume ");
        }
    } else if (snapshotId != null) {
        _log.debug("Creating New Volume from Snapshot ID ={}", snapshotId);
        tasklist = volumeFromSnapshot(name, project, snapshotId, varray, param, volumeCount, blkFullCpManager, snapUri, snapshot);
    } else if ((snapshotId == null) && (sourceVolId == null)) {
        _log.debug("Creating New Volume where snapshotId and sourceVolId are null");
        tasklist = newVolume(volumeCreate, project, api, capabilities, varray, task, vpool, param, volumeCount, requestedSize, name);
    }
    if (imageId != null) {
        _log.debug("Creating New Volume from imageid ={}", imageId);
        // will be implemented
        tasklist = volumeFromImage(name, project, varray, param, volumeCount, blkFullCpManager, imageId);
    }
    if (!(tasklist.getTaskList().isEmpty())) {
        for (TaskResourceRep rep : tasklist.getTaskList()) {
            URI volumeUri = rep.getResource().getId();
            Volume vol = _dbClient.queryObject(Volume.class, volumeUri);
            if (vol != null) {
                StringMap extensions = vol.getExtensions();
                if (extensions == null)
                    extensions = new StringMap();
                extensions.put("display_description", (description == null) ? "" : description);
                vol.setExtensions(extensions);
                ScopedLabelSet tagSet = new ScopedLabelSet();
                vol.setTag(tagSet);
                String[] splits = volumeUri.toString().split(":");
                String tagName = splits[3];
                if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
                    throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
                }
                URI tenantOwner = vol.getTenant().getURI();
                ScopedLabel tagLabel = new ScopedLabel(tenantOwner.toString(), tagName);
                tagSet.add(tagLabel);
                _dbClient.updateAndReindexObject(vol);
                if (isV1Call != null) {
                    _log.debug("Inside V1 call");
                    return CinderApiUtils.getCinderResponse(getVolumeDetail(vol, isV1Call, openstackTenantId), header, true, CinderConstants.STATUS_OK);
                } else {
                    return CinderApiUtils.getCinderResponse(getVolumeDetail(vol, isV1Call, openstackTenantId), header, true, CinderConstants.STATUS_ACCEPT);
                }
            } else {
                throw APIException.badRequests.parameterIsNullOrEmpty("Volume");
            }
        }
    }
    return CinderApiUtils.getCinderResponse(new VolumeDetail(), header, true, CinderConstants.STATUS_ACCEPT);
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StringMap(com.emc.storageos.db.client.model.StringMap) TaskList(com.emc.storageos.model.TaskList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) VolumeCreate(com.emc.storageos.model.block.VolumeCreate) BlockFullCopyManager(com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager) Project(com.emc.storageos.db.client.model.Project) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) CinderVolume(com.emc.storageos.cinder.model.CinderVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeDetail(com.emc.storageos.cinder.model.VolumeDetail) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 8 with BlockServiceApi

use of com.emc.storageos.api.service.impl.resource.BlockServiceApi in project coprhd-controller by CoprHD.

the class ExportService method extendExistingVolume.

private TaskResourceRep extendExistingVolume(Volume vol, Long newSize, String openstackTenantId, String volumeId) {
    // Check if the volume is on VMAX V3 which doesn't support expansion yet
    StorageSystem storage = _dbClient.queryObject(StorageSystem.class, vol.getStorageController());
    if (storage.checkIfVmax3()) {
        _log.error("Volume expansion is not supported for VMAX V3 array {}", storage.getSerialNumber());
        throw APIException.badRequests.volumeNotExpandable(vol.getLabel());
    }
    // Verify that the volume is 'expandable'
    VirtualPool virtualPool = _dbClient.queryObject(VirtualPool.class, vol.getVirtualPool());
    if (!virtualPool.getExpandable()) {
        throw APIException.badRequests.volumeNotExpandable(vol.getLabel());
    }
    // Don't operate on VPLEX backend or RP Journal volumes.
    BlockServiceUtils.validateNotAnInternalBlockObject(vol, false);
    // Don't operate on ingested volumes
    VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(vol, ResourceOperationTypeEnum.EXPAND_BLOCK_VOLUME, _dbClient);
    // Get the new size.
    // verify quota in cinder side
    Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    if (!validateVolumeExpand(openstackTenantId, null, vol, newSize, project)) {
        _log.info("The volume can not be expanded because of insufficient project quota.");
        throw APIException.badRequests.insufficientQuotaForProject(project.getLabel(), "volume");
    } else if (!validateVolumeExpand(openstackTenantId, virtualPool, vol, newSize, project)) {
        _log.info("The volume can not be expanded because of insufficient quota for virtual pool.");
        throw APIException.badRequests.insufficientQuotaForVirtualPool(virtualPool.getLabel(), "virtual pool");
    }
    // dangling meta members created for failed expansion
    if (newSize.equals(vol.getCapacity()) && vol.getMetaVolumeMembers() != null && !(vol.getMetaVolumeMembers().isEmpty())) {
        _log.info(String.format("expandVolume --- Zero capacity expansion: allowed as a recovery to cleanup dangling members from previous expand failure.\n" + "VolumeId id: %s, Current size: %d, New size: %d, Dangling volumes: %s ", volumeId, vol.getCapacity(), newSize, vol.getMetaVolumeMembers()));
    }
    _log.info(String.format("expandVolume --- VolumeId id: %s, Current size: %d, New size: %d", volumeId, vol.getCapacity(), newSize));
    // Get the Block service implementation for this volume.
    BlockServiceApi blockServiceApi = BlockService.getBlockServiceImpl(vol, _dbClient);
    // Verify that the volume can be expanded.
    blockServiceApi.verifyVolumeExpansionRequest(vol, newSize);
    // verify quota in vipr side
    if (newSize > vol.getProvisionedCapacity()) {
        long size = newSize - vol.getProvisionedCapacity();
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, vol.getTenant().getURI());
        ArgValidator.checkEntity(tenant, vol.getTenant().getURI(), false);
        ArgValidator.checkEntity(project, vol.getProject().getURI(), false);
        VirtualPool cos = _dbClient.queryObject(VirtualPool.class, vol.getVirtualPool());
        ArgValidator.checkEntity(cos, vol.getVirtualPool(), false);
        CapacityUtils.validateQuotasForProvisioning(_dbClient, cos, project, tenant, size, "volume");
    }
    // Create a task for the volume expansion.
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Volume.class, vol.getId(), taskId, ResourceOperationTypeEnum.EXPAND_BLOCK_VOLUME);
    // Try and expand the volume.
    try {
        blockServiceApi.expandVolume(vol, newSize, taskId);
    } catch (final ControllerException e) {
        _log.error("Controller Error", e);
        String errMsg = String.format("Controller Error: %s", e.getMessage());
        op = new Operation(Operation.Status.error.name(), errMsg);
        _dbClient.updateTaskOpStatus(Volume.class, URI.create(volumeId), taskId, op);
        throw e;
    }
    auditOp(OperationTypeEnum.EXPAND_BLOCK_VOLUME, true, AuditLogManager.AUDITOP_BEGIN, vol.getId().toString(), vol.getCapacity(), newSize);
    StringMap extensions = vol.getExtensions();
    if (extensions == null) {
        extensions = new StringMap();
    }
    extensions.put("status", ComponentStatus.EXTENDING.getStatus().toLowerCase());
    extensions.put("task_id", taskId);
    vol.setExtensions(extensions);
    _log.debug("Volume  Status ={}", vol.getExtensions().get("status"));
    _log.debug("Volume creation task_id ={}", vol.getExtensions().get("task_id"));
    _dbClient.updateObject(vol);
    return toTask(vol, taskId, op);
}
Also used : Project(com.emc.storageos.db.client.model.Project) StringMap(com.emc.storageos.db.client.model.StringMap) ControllerException(com.emc.storageos.volumecontroller.ControllerException) Volume(com.emc.storageos.db.client.model.Volume) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 9 with BlockServiceApi

use of com.emc.storageos.api.service.impl.resource.BlockServiceApi in project coprhd-controller by CoprHD.

the class SnapshotService method updateSnapshot.

/**
 * Update a specific snapshot
 *
 * @prereq none
 *
 * @param tenant_id
 *            the URN of the tenant
 * @param snapshot_id
 *            the URN of the snapshot
 *
 * @brief Update snapshot
 * @return snapshot details
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{snapshot_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response updateSnapshot(@PathParam("tenant_id") String openstack_tenant_id, @PathParam("snapshot_id") String snapshot_id, SnapshotUpdateRequestGen param, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    BlockSnapshot snap = findSnapshot(snapshot_id, openstack_tenant_id);
    if (snap == null) {
        throw APIException.badRequests.parameterIsNotValid(snapshot_id);
    }
    _log.debug("Update snapshot {}: ", snap.getLabel());
    String label = null;
    String description = null;
    if (isV1Call != null) {
        label = param.snapshot.display_name;
        description = param.snapshot.display_description;
    } else {
        label = param.snapshot.name;
        description = param.snapshot.description;
    }
    _log.debug("new name = {}, description = {}", label, description);
    if (label != null && (label.length() > 2)) {
        URI volumeUri = snap.getParent().getURI();
        String snapshotType = TechnologyType.NATIVE.toString();
        Volume volume = queryVolumeResource(URI.create(getCinderHelper().trimId(volumeUri.toString())), openstack_tenant_id);
        URIQueryResultList uris = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume.getId()), uris);
        for (URI snuri : uris) {
            BlockSnapshot snapIter = _dbClient.queryObject(BlockSnapshot.class, snuri);
            if (snapIter != null && !snapIter.getInactive() && snapIter.getLabel().equals(label)) {
                _log.info("Update snapshot: duplicate name");
                throw APIException.badRequests.duplicateLabel(label);
            }
        }
        // ToDo if the backend system is vplex, rp
        // we cannot use the default blockservice implemenation
        // we need to use other APIs(for vplex adn RP), that need to be implemented
        VirtualPool pool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
        if (pool == null) {
            _log.info("Virtual Pool corresponding to the volume does not exist.");
            throw APIException.badRequests.parameterIsNotValid(volume.getVirtualPool().toString());
        }
        BlockServiceApi api = getBlockServiceImpl(pool, _dbClient);
        List<Volume> volumesToSnap = new ArrayList<Volume>();
        volumesToSnap.addAll(api.getVolumesToSnap(volume, snapshotType));
        BlockFullCopyManager fcManager = new BlockFullCopyManager(_dbClient, _permissionsHelper, _auditMgr, _coordinator, _placementManager, sc, uriInfo, _request, _tenantsService);
        api.validateCreateSnapshot(volume, volumesToSnap, snapshotType, label, false, fcManager);
        _log.debug("Update snapshot: not a duplicate name");
        snap.setLabel(label);
    }
    if (description != null && (description.length() > 2)) {
        StringMap extensions = snap.getExtensions();
        if (extensions == null)
            extensions = new StringMap();
        extensions.put("display_description", description);
        _log.debug("Update volume : stored description");
        snap.setExtensions(extensions);
    }
    _dbClient.updateObject(snap);
    return CinderApiUtils.getCinderResponse(getSnapshotDetail(snap, isV1Call, openstack_tenant_id), header, true, CinderConstants.STATUS_OK);
}
Also used : BlockFullCopyManager(com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager) StringMap(com.emc.storageos.db.client.model.StringMap) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

BlockServiceApi (com.emc.storageos.api.service.impl.resource.BlockServiceApi)9 Volume (com.emc.storageos.db.client.model.Volume)9 StringMap (com.emc.storageos.db.client.model.StringMap)8 URI (java.net.URI)8 Produces (javax.ws.rs.Produces)8 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)6 ArrayList (java.util.ArrayList)6 TaskList (com.emc.storageos.model.TaskList)5 Path (javax.ws.rs.Path)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 BlockFullCopyManager (com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager)3 Operation (com.emc.storageos.db.client.model.Operation)3 Project (com.emc.storageos.db.client.model.Project)3