Search in sources :

Example 21 with Project

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

the class FileSnapshotService method getTenantOwner.

@Override
protected URI getTenantOwner(URI id) {
    Snapshot snapshot = queryResource(id);
    URI projectUri = snapshot.getProject().getURI();
    ArgValidator.checkUri(projectUri);
    Project project = _permissionsHelper.getObjectById(projectUri, Project.class);
    ArgValidator.checkEntityNotNull(project, projectUri, isIdEmbeddedInURL(projectUri));
    return project.getTenantOrg().getURI();
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 22 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)

Example 23 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 24 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 25 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)

Aggregations

Project (com.emc.storageos.db.client.model.Project)190 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)65 Volume (com.emc.storageos.db.client.model.Volume)57 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)54 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)34 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)33 Test (org.junit.Test)31 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)27 Operation (com.emc.storageos.db.client.model.Operation)26 Consumes (javax.ws.rs.Consumes)26