Search in sources :

Example 61 with Project

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

the class BlockFullCopyService method getTenantOwner.

/**
 * {@inheritDoc}
 */
@Override
protected URI getTenantOwner(URI id) {
    Volume fullCopy = (Volume) queryResource(id);
    URI projectURI = fullCopy.getProject().getURI();
    ArgValidator.checkUri(projectURI);
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    ArgValidator.checkEntityNotNull(project, projectURI, isIdEmbeddedInURL(projectURI));
    return project.getTenantOrg().getURI();
}
Also used : Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) URI(java.net.URI)

Example 62 with Project

use of com.emc.storageos.db.client.model.Project 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 63 with Project

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

the class BlockSnapshotService method expandBlockSnapshot.

/**
 * Request to expand blocksnapshot capacity to the specified size.
 * Currently This API is supported only for XtremIO.
 *
 * @prereq snapshot should exist before this operation and
 *                   newSize should be greater than current size.
 *
 * @param id
 *            the URN of a ViPR BlockSnapshot.
 * @param param
 *            Specifies requested size for BlockSnapshot expansion.
 *
 * @brief Expand blocksnapshot capacity
 * @return Task resource representation
 *
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/expand")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep expandBlockSnapshot(@PathParam("id") URI id, BlockSnapshotExpandParam param) throws InternalException {
    // Get the volume.
    ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
    BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.EXPAND_BLOCK_SNAPSHOT);
    Volume volume = (Volume) queryResource(snapshot.getParent().getURI());
    // Get the new size.
    Long newSize = SizeUtil.translateSize(param.getNewSize());
    // Check whether snapshot belongs to a XIO or not as only XIO supports snapshot expansion.
    if (!Type.isXtremIOStorageSystem(Type.valueOf(snapshot.getSystemType()))) {
        _log.error("Snapshot {} expansion is supported only for xtremio systems.", snapshot.getLabel());
        throw APIException.badRequests.snapshotExpansionNotSupported(snapshot.getLabel(), snapshot.getSystemType());
    }
    if (newSize.equals(snapshot.getProvisionedCapacity())) {
        _log.error("Snapshot newSize specified is same as current size {}GB", SizeUtil.translateSize(snapshot.getProvisionedCapacity(), SIZE_GB));
        throw APIException.badRequests.snapshotNewSizeSameAsCurrentSize();
    }
    // Verify that the source volume is 'expandable'
    VirtualPool virtualPool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
    if (!virtualPool.getExpandable()) {
        _log.error("Expand feature is not enabled for VPool {}", virtualPool.getLabel());
        throw APIException.badRequests.snapshotNotExpandable(virtualPool.getLabel(), snapshot.getLabel());
    }
    // Check if the snapshot new size is same as source volume size. if not throw exception
    if (!newSize.equals(volume.getProvisionedCapacity())) {
        Double sourVolSizeInGB = SizeUtil.translateSize(volume.getProvisionedCapacity(), SIZE_GB);
        _log.error("Snapshot {} newSize {} is not matching with source volume size {}GB", snapshot.getLabel(), newSize, sourVolSizeInGB);
        throw APIException.badRequests.snapshotSourceVolumeSizeMismatch(snapshot.getLabel(), volume.getLabel(), sourVolSizeInGB);
    }
    // verify quota
    if (newSize > snapshot.getProvisionedCapacity()) {
        long size = newSize - snapshot.getProvisionedCapacity();
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, volume.getTenant().getURI());
        ArgValidator.checkEntity(tenant, volume.getTenant().getURI(), false);
        Project project = _dbClient.queryObject(Project.class, volume.getProject().getURI());
        ArgValidator.checkEntity(project, volume.getProject().getURI(), false);
        VirtualPool vPool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
        ArgValidator.checkEntity(vPool, volume.getVirtualPool(), false);
        CapacityUtils.validateQuotasForProvisioning(_dbClient, vPool, project, tenant, size, "snapshot");
    }
    // Make sure that we don't have some pending operation against the volume
    checkForPendingTasks(Arrays.asList(volume.getTenant().getURI()), Arrays.asList(snapshot));
    BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(volume, _dbClient);
    _log.info("expandBlockSnapshot --- Snapshot id: {}, Current size: {}, New size: {}", id, snapshot.getProvisionedCapacity(), newSize);
    String taskId = UUID.randomUUID().toString();
    _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, op);
    // Expand the snapshot.
    blockServiceApiImpl.expandBlockSnapshot(snapshot, newSize, taskId);
    auditOp(OperationTypeEnum.EXPAND_VOLUME_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
    return toTask(snapshot, taskId, op);
}
Also used : Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) MapBlockSnapshot(com.emc.storageos.api.mapper.functions.MapBlockSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) 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 64 with Project

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

the class BlockConsistencyGroupService method verifyAddReplicaToCG.

/**
 * Validates the replicas to be added to Consistency group.
 * - verifies that the replicas are not internal objects,
 * - checks if the given CG is its source volume's CG,
 * - validates that the replica is not in any other CG,
 * - verifies the project for the replicas to be added is same
 * as the project for the consistency group.
 */
private void verifyAddReplicaToCG(URI blockURI, BlockConsistencyGroup cg, StorageSystem cgStorageSystem) {
    BlockObject blockObject = BlockObject.fetch(_dbClient, blockURI);
    // Don't allow partially ingested object to be added to CG.
    BlockServiceUtils.validateNotAnInternalBlockObject(blockObject, false);
    URI sourceVolumeURI = null;
    URI blockProjectURI = null;
    if (blockObject instanceof BlockSnapshot) {
        BlockSnapshot snapshot = (BlockSnapshot) blockObject;
        blockProjectURI = snapshot.getProject().getURI();
        sourceVolumeURI = snapshot.getParent().getURI();
    } else if (blockObject instanceof BlockMirror) {
        BlockMirror mirror = (BlockMirror) blockObject;
        blockProjectURI = mirror.getProject().getURI();
        sourceVolumeURI = mirror.getSource().getURI();
    } else if (blockObject instanceof Volume) {
        Volume volume = (Volume) blockObject;
        blockProjectURI = volume.getProject().getURI();
        sourceVolumeURI = volume.getAssociatedSourceVolume();
    }
    // check if the given CG is its source volume's CG
    Volume sourceVolume = null;
    if (!NullColumnValueGetter.isNullURI(sourceVolumeURI)) {
        sourceVolume = _dbClient.queryObject(Volume.class, sourceVolumeURI);
    }
    if (sourceVolume == null || !cg.getId().equals(sourceVolume.getConsistencyGroup())) {
        throw APIException.badRequests.invalidParameterSourceVolumeNotInGivenConsistencyGroup(sourceVolumeURI, cg.getId());
    }
    // Validate that the replica is not in any other CG.
    if (!NullColumnValueGetter.isNullURI(blockObject.getConsistencyGroup()) && !cg.getId().equals(blockObject.getConsistencyGroup())) {
        throw APIException.badRequests.invalidParameterVolumeAlreadyInAConsistencyGroup(cg.getId(), blockObject.getConsistencyGroup());
    }
    // Verify the project for the replicas to be added is same
    // as the project for the consistency group.
    URI cgProjectURI = cg.getProject().getURI();
    if (!blockProjectURI.equals(cgProjectURI)) {
        List<Project> projects = _dbClient.queryObjectField(Project.class, "label", Arrays.asList(cgProjectURI, blockProjectURI));
        throw APIException.badRequests.consistencyGroupAddVolumeThatIsInDifferentProject(blockObject.getLabel(), projects.get(0).getLabel(), projects.get(1).getLabel());
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 65 with Project

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

the class BlockConsistencyGroupService method createConsistencyGroup.

/**
 * Create a new consistency group
 *
 * You can create a consistency group, but adding volumes into it will be done using in the
 * volume create operations:
 *
 * 1. Create CG object in Bourne 2. Operation will be synchronous
 *
 * @prereq none
 *
 * @param param
 *
 * @brief Create consistency group
 * @return Consistency Group created
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public BlockConsistencyGroupRestRep createConsistencyGroup(final BlockConsistencyGroupCreate param) {
    checkForDuplicateName(param.getName(), BlockConsistencyGroup.class);
    ArgValidator.checkIsAlphaNumeric(param.getName());
    // Validate name
    ArgValidator.checkFieldNotEmpty(param.getName(), "name");
    // Validate name not greater than 64 characters
    ArgValidator.checkFieldLengthMaximum(param.getName(), CG_MAX_LIMIT, "name");
    // Validate project
    ArgValidator.checkFieldUriType(param.getProject(), Project.class, "project");
    final Project project = _dbClient.queryObject(Project.class, param.getProject());
    ArgValidator.checkEntity(project, param.getProject(), isIdEmbeddedInURL(param.getProject()));
    // Verify the user is authorized.
    verifyUserIsAuthorizedForRequest(project);
    // Create Consistency Group in db
    final BlockConsistencyGroup consistencyGroup = new BlockConsistencyGroup();
    consistencyGroup.setId(URIUtil.createId(BlockConsistencyGroup.class));
    consistencyGroup.setLabel(param.getName());
    consistencyGroup.setProject(new NamedURI(project.getId(), project.getLabel()));
    consistencyGroup.setTenant(project.getTenantOrg());
    // disable array consistency if user has selected not to create backend replication group
    consistencyGroup.setArrayConsistency(param.getArrayConsistency());
    _dbClient.createObject(consistencyGroup);
    return map(consistencyGroup, null, _dbClient);
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Project (com.emc.storageos.db.client.model.Project)191 URI (java.net.URI)98 NamedURI (com.emc.storageos.db.client.model.NamedURI)93 ArrayList (java.util.ArrayList)67 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)66 Volume (com.emc.storageos.db.client.model.Volume)58 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)55 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)50 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)47 StringSet (com.emc.storageos.db.client.model.StringSet)43 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)40 List (java.util.List)37 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)36 Produces (javax.ws.rs.Produces)35 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)33 Test (org.junit.Test)31 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)28 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 Operation (com.emc.storageos.db.client.model.Operation)27 Consumes (javax.ws.rs.Consumes)27