Search in sources :

Example 56 with Project

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

the class FileService method expand.

/**
 * Expand file system.
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param param
 *            File system expansion parameters
 * @param id
 *            the URN of a ViPR File system
 * @brief Expand file system
 * @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 expand(@PathParam("id") URI id, FileSystemExpandParam param) throws InternalException {
    _log.info(String.format("FileShareExpand --- FileShare id: %1$s, New Size: %2$s", id, param.getNewSize()));
    // check file System
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    Long newFSsize = SizeUtil.translateSize(param.getNewSize());
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    if (newFSsize <= 0) {
        throw APIException.badRequests.parameterMustBeGreaterThan("new_size", 0);
    }
    // checkQuota
    long expand = newFSsize - fs.getCapacity();
    final long MIN_EXPAND_SIZE = SizeUtil.translateSize("1MB") + 1;
    if (expand < MIN_EXPAND_SIZE) {
        throw APIException.badRequests.invalidParameterBelowMinimum("new_size", newFSsize, fs.getCapacity() + MIN_EXPAND_SIZE, "bytes");
    }
    Project project = _dbClient.queryObject(Project.class, fs.getProject().getURI());
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, fs.getTenant().getURI());
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, expand, "filesystem");
    String task = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.EXPAND_FILE_SYSTEM);
    op.setDescription("Filesystem expand");
    FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
    try {
        fileServiceApi.expandFileShare(fs, newFSsize, task);
    } catch (InternalException e) {
        if (_log.isErrorEnabled()) {
            _log.error("Expand File Size error", e);
        }
        FileShare fileShare = _dbClient.queryObject(FileShare.class, fs.getId());
        op = fs.getOpStatus().get(task);
        op.error(e);
        fileShare.getOpStatus().updateTaskStatus(task, op);
        _dbClient.updateObject(fs);
        throw e;
    }
    return toTask(fs, task, op);
}
Also used : Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) 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 57 with Project

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

the class ExportGroupService method validateInitiatorsData.

/**
 * Validates that the host belongs to same tenant org and/or project as the export group.
 * Also validates that the host has connectivity to all the storage systems that the
 * export group has block objects in.
 *
 * @param host the host being validated
 * @param exportGroup the export group where the host will be added
 * @param storageSystems the storage systems the export group has block objects in.
 * @param project the export group project
 * @param initiators the list of initiators to be updated with the host initiators.
 */
private void validateInitiatorsData(List<Initiator> initiators, Set<URI> initiatorsHosts, ExportGroup exportGroup) {
    if (initiatorsHosts.size() != 1) {
        throw APIException.badRequests.initiatorExportGroupInitiatorsBelongToSameHost();
    }
    Host host = queryObject(Host.class, initiatorsHosts.iterator().next(), true);
    // if the host is in a project
    if (!NullColumnValueGetter.isNullURI(host.getProject())) {
        // validate it is in the same project as the as the export group,
        if (!host.getProject().equals(exportGroup.getProject().getURI())) {
            throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentProject(host.getHostName(), exportGroup.getProject().getName());
        }
    } else {
        // validate the host is in the same tenant Org as the as the export group,
        Project project = queryObject(Project.class, exportGroup.getProject().getURI(), true);
        if (!host.getTenant().equals(project.getTenantOrg().getURI())) {
            throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentTenant(host.getHostName(), project.getLabel());
        }
    }
    validatePortConnectivity(exportGroup, initiators);
    _log.info("The initiators were validated successfully.");
}
Also used : Project(com.emc.storageos.db.client.model.Project) Host(com.emc.storageos.db.client.model.Host)

Example 58 with Project

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

the class BlockSnapshotService method getTenantOwner.

@Override
protected URI getTenantOwner(URI id) {
    BlockSnapshot snapshot = (BlockSnapshot) 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 : Project(com.emc.storageos.db.client.model.Project) MapBlockSnapshot(com.emc.storageos.api.mapper.functions.MapBlockSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 59 with Project

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

the class BucketService method createBucket.

/**
 * Creates bucket.
 *
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param param Bucket parameters
 * @param id the URN of a ViPR Project
 * @brief Create bucket
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createBucket(BucketParam param, @QueryParam("project") URI id) throws InternalException {
    // check project
    ArgValidator.checkFieldUriType(id, Project.class, "project");
    // Check for all mandatory field
    ArgValidator.checkFieldNotNull(param.getLabel(), "name");
    Project project = _permissionsHelper.getObjectById(id, Project.class);
    ArgValidator.checkEntity(project, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldNotNull(project.getTenantOrg(), "project");
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
    final String namespace = tenant.getNamespace();
    if (null == namespace || namespace.isEmpty()) {
        throw APIException.badRequests.objNoNamespaceForTenant(tenant.getId());
    }
    // Check if there already exist a bucket with same name in a Project.
    checkForDuplicateName(param.getLabel().replaceAll(SPECIAL_CHAR_REGEX, ""), Bucket.class, id, "project", _dbClient);
    return initiateBucketCreation(param, project, tenant, null);
}
Also used : Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 60 with Project

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

the class BlockService method getVolumesForVirtualArrayChange.

/**
 * Get Volumes For Virtual Array Change
 *
 * @param projectURI
 * 			the URI of a ViPR project
 *
 * @param varrayURI
 * 			the URI of a ViPR vArray
 *
 * @brief Show potential volumes for virtual array change
 *
 * @return Get Volume for Virtual Array Change
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/varray-change")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public NamedVolumesList getVolumesForVirtualArrayChange(@QueryParam("project") URI projectURI, @QueryParam("targetVarray") URI varrayURI) {
    NamedVolumesList volumeList = new NamedVolumesList();
    // Get the project.
    ArgValidator.checkFieldUriType(projectURI, Project.class, "project");
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    ArgValidator.checkEntity(project, projectURI, false);
    _log.info("Found project {}:{}", projectURI);
    // Verify the user is authorized for the project.
    BlockServiceUtils.verifyUserIsAuthorizedForRequest(project, getUserFromContext(), _permissionsHelper);
    _log.info("User is authorized for project");
    // Get the target virtual array.
    ArgValidator.checkFieldUriType(varrayURI, VirtualArray.class, "targetVarray");
    VirtualArray tgtVarray = _permissionsHelper.getObjectById(varrayURI, VirtualArray.class);
    ArgValidator.checkEntity(tgtVarray, varrayURI, false);
    _log.info("Found target virtual array {}:{}", tgtVarray.getLabel(), varrayURI);
    // Determine all volumes in the project that could potentially
    // be moved to the target virtual array.
    URIQueryResultList volumeIds = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(projectURI), volumeIds);
    Iterator<Volume> volumeItr = _dbClient.queryIterativeObjects(Volume.class, volumeIds);
    while (volumeItr.hasNext()) {
        Volume volume = volumeItr.next();
        try {
            // Don't operate on VPLEX backend, RP Journal volumes,
            // or other internal volumes.
            BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
            // Don't operate on ingested volumes.
            VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VARRAY, _dbClient);
            // Can't change to the same varray.
            if (volume.getVirtualArray().equals(varrayURI)) {
                _log.info("Virtual array change not supported for volume {} already in the target varray", volume.getId());
                continue;
            }
            // Get the appropriate block service implementation.
            BlockServiceApi blockServiceAPI = getBlockServiceImpl(volume);
            // Verify that the virtual array change is allowed for the
            // volume and target virtual array.
            blockServiceAPI.verifyVarrayChangeSupportedForVolumeAndVarray(volume, tgtVarray);
            // If so, add it to the list.
            volumeList.getVolumes().add(toNamedRelatedResource(volume));
        } catch (Exception e) {
            _log.info("Virtual array change not supported for volume {}:{}", volume.getId(), e.getMessage());
        }
    }
    return volumeList;
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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