Search in sources :

Example 16 with TenantOrg

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

the class InternalFileResource method releaseFileSystemInternal.

/**
 * Release a file system from its current tenant & project for internal object usage
 *
 * @param id the URN of a ViPR file system to be released
 * @return the updated file system
 * @throws InternalException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/release")
public FileShareRestRep releaseFileSystemInternal(@PathParam("id") URI id) throws InternalException {
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = _fileService.queryResource(id);
    // and just return success down at the bottom
    if (!fs.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
        URI tenantURI = fs.getTenant().getURI();
        if (!_permissionsHelper.userHasGivenRole(getUserFromContext(), tenantURI, Role.TENANT_ADMIN)) {
            throw APIException.forbidden.onlyAdminsCanReleaseFileSystems(Role.TENANT_ADMIN.toString());
        }
        // we can't release a fs that has exports
        FSExportMap exports = fs.getFsExports();
        if ((exports != null) && (!exports.isEmpty())) {
            throw APIException.badRequests.cannotReleaseFileSystemExportExists(exports.keySet().toString());
        }
        // we can't release a fs that has shares
        SMBShareMap shares = fs.getSMBFileShares();
        if ((shares != null) && (!shares.isEmpty())) {
            throw APIException.badRequests.cannotReleaseFileSystemSharesExists(shares.keySet().toString());
        }
        // files systems with pending operations can't be released
        if (fs.getOpStatus() != null) {
            for (String opId : fs.getOpStatus().keySet()) {
                Operation op = fs.getOpStatus().get(opId);
                if (Operation.Status.pending.name().equals(op.getStatus())) {
                    throw APIException.badRequests.cannotReleaseFileSystemWithTasksPending();
                }
            }
        }
        // file systems with snapshots can't be released
        Integer snapCount = _fileService.getNumSnapshots(fs);
        if (snapCount > 0) {
            throw APIException.badRequests.cannotReleaseFileSystemSnapshotExists(snapCount);
        }
        TenantOrg rootTenant = _permissionsHelper.getRootTenant();
        // we can't release the file system to the root tenant if the root tenant has no access
        // to the filesystem's virtual pool
        ArgValidator.checkFieldNotNull(fs.getVirtualPool(), "virtualPool");
        VirtualPool virtualPool = _permissionsHelper.getObjectById(fs.getVirtualPool(), VirtualPool.class);
        ArgValidator.checkEntity(virtualPool, fs.getVirtualPool(), false);
        if (!_permissionsHelper.tenantHasUsageACL(rootTenant.getId(), virtualPool)) {
            throw APIException.badRequests.cannotReleaseFileSystemRootTenantLacksVPoolACL(virtualPool.getId().toString());
        }
        fs.setOriginalProject(fs.getProject().getURI());
        fs.setTenant(new NamedURI(rootTenant.getId(), fs.getLabel()));
        fs.setProject(new NamedURI(_internalProject.getId(), fs.getLabel()));
        fs.addInternalFlags(INTERNAL_FILESHARE_FLAGS);
        _dbClient.updateAndReindexObject(fs);
        // audit against the source project, not the new dummy internal project
        auditOp(OperationTypeEnum.RELEASE_FILE_SYSTEM, true, null, fs.getId().toString(), fs.getOriginalProject().toString());
    }
    return map(fs);
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 17 with TenantOrg

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

the class ProjectService method updateQuota.

/**
 * Updates quota and available capacity before quota is exhausted
 *
 * @param id the URN of a ViPR Project.
 * @param param new values for the quota
 * @prereq none
 * @brief Update quota and available capacity
 * @return QuotaInfo Quota metrics.
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/quota")
public QuotaInfo updateQuota(@PathParam("id") URI id, QuotaUpdateParam param) throws DatabaseException {
    Project project = getProjectById(id, true);
    project.setQuotaEnabled(param.getEnable());
    if (param.getEnable()) {
        long quota_gb = (param.getQuotaInGb() != null) ? param.getQuotaInGb() : project.getQuota();
        ArgValidator.checkFieldMinimum(quota_gb, 0, "quota_gb", "GB");
        // Verify that the quota of this project does not exit quota for its tenant
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
        if (tenant.getQuotaEnabled()) {
            long totalProjects = CapacityUtils.totalProjectQuota(_dbClient, tenant.getId()) - project.getQuota() + quota_gb;
            if (totalProjects > tenant.getQuota()) {
                throw APIException.badRequests.invalidParameterProjectQuotaInvalidatesTenantQuota(tenant.getQuota());
            }
        }
        project.setQuota(quota_gb);
    }
    _dbClient.persistObject(project);
    return getQuota(project);
}
Also used : MapProject(com.emc.storageos.api.mapper.functions.MapProject) Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 18 with TenantOrg

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

the class ResourceService method checkForDuplicateNamespace.

/**
 * Check if a tenant with the same namespace exists
 * @param namespace     namespace of the tenant
 */
public void checkForDuplicateNamespace(String namespace) {
    TenantOrgList list = new TenantOrgList();
    // Verify with root tenant if current is not root
    TenantOrg rootTenant = _permissionsHelper.getRootTenant();
    if (rootTenant.getNamespace() != null && rootTenant.getNamespace().equalsIgnoreCase(namespace)) {
        throw APIException.badRequests.duplicateNamespace(namespace);
    }
    NamedElementQueryResultList subtenants = new NamedElementQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(rootTenant.getId()), subtenants);
    for (NamedElementQueryResultList.NamedElement el : subtenants) {
        TenantOrg currTenant = _dbClient.queryObject(TenantOrg.class, el.getId());
        if (currTenant.getNamespace() != null && currTenant.getNamespace().equalsIgnoreCase(namespace)) {
            throw APIException.badRequests.duplicateNamespace(namespace);
        }
    }
}
Also used : TenantOrg(com.emc.storageos.db.client.model.TenantOrg) TenantOrgList(com.emc.storageos.model.tenant.TenantOrgList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 19 with TenantOrg

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

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

the class FileService method createFileSystem.

/**
 * Creates file system.
 *
 * The VNX File array does not allow 'root' as the beginning of a file system name. If the generated file system
 * name begins with 'root', then the VNX File array will return an error.
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param param
 *            File system parameters
 * @param id
 *            the URN of a ViPR Project
 * @brief Create file system
 * @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 createFileSystem(FileSystemParam param, @QueryParam("project") URI id) throws InternalException {
    // check project
    ArgValidator.checkFieldUriType(id, Project.class, "project");
    // Make label as mandatory field
    ArgValidator.checkFieldNotNull(param.getLabel(), "label");
    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());
    // Check for duplicate file system in this project
    if (param.getLabel() != null && !param.getLabel().isEmpty()) {
        checkForDuplicateName(param.getLabel(), FileShare.class, id, "project", _dbClient);
    }
    return createFSInternal(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)

Aggregations

TenantOrg (com.emc.storageos.db.client.model.TenantOrg)138 URI (java.net.URI)64 NamedURI (com.emc.storageos.db.client.model.NamedURI)57 Project (com.emc.storageos.db.client.model.Project)54 Volume (com.emc.storageos.db.client.model.Volume)41 ArrayList (java.util.ArrayList)40 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)37 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)33 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)29 StringSet (com.emc.storageos.db.client.model.StringSet)29 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)28 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)26 Produces (javax.ws.rs.Produces)26 StoragePool (com.emc.storageos.db.client.model.StoragePool)25 List (java.util.List)23 Test (org.junit.Test)23 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)22 StringMap (com.emc.storageos.db.client.model.StringMap)21 Consumes (javax.ws.rs.Consumes)21