Search in sources :

Example 6 with QuotaOfCinder

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

the class QuotaService method getTenantOwner.

/**
 * returns tenant owner
 */
@Override
protected URI getTenantOwner(URI id) {
    QuotaOfCinder objQuota = (QuotaOfCinder) queryResource(id);
    Project objProj = _dbClient.queryObject(Project.class, objQuota.getProject());
    return objProj.getTenantOrg().getURI();
}
Also used : Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder)

Example 7 with QuotaOfCinder

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

the class QuotaService method updateQuota.

/**
 * Update a quota
 *
 * @prereq none
 *
 * @param tenant_id the URN of the tenant
 * @param target_tenant_id the URN of the target tenant
 *            for which quota is being modified
 *
 * @brief Update Quota
 * @return Quota details of target_tenant_id
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{target_tenant_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response updateQuota(@PathParam("tenant_id") String openstack_tenant_id, @PathParam("target_tenant_id") String openstackTargetTenantId, CinderQuotaDetails quotaUpdates, @Context HttpHeaders header) {
    _log.info("Updating Quota");
    Project project = getCinderHelper().getProject(openstackTargetTenantId.toString(), getUserFromContext());
    HashMap<String, String> defaultQuotaMap = getQuotaHelper().getCompleteDefaultConfiguration(openstackTargetTenantId);
    if (project == null) {
        throw APIException.badRequests.projectWithTagNonexistent(openstackTargetTenantId);
    }
    long maxQuota = 0L;
    if (project.getQuotaEnabled()) {
        maxQuota = (long) (project.getQuota().intValue());
    } else {
        maxQuota = Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.GIGABYTES.getResource()));
    }
    // bVpoolQuotaUpdate will be set to true if the user is updating the quota of a vpool w.r.t a project
    // bVpoolQuotaUpdate will be set to false if the user is updating the quota of the project
    boolean bVpoolQuotaUpdate = isVpoolQuotaUpdate(quotaUpdates.quota_set);
    String vpoolName = null;
    VirtualPool objVpool = null;
    if (bVpoolQuotaUpdate) {
        vpoolName = getVpoolName(quotaUpdates.quota_set);
        _log.info("Vpool for which quota is being updated is {}", vpoolName);
        objVpool = getCinderHelper().getVpool(vpoolName);
        if (objVpool == null) {
            _log.error("vpool with the given name doesnt exist");
            throw APIException.badRequests.parameterIsNotValid(vpoolName);
        }
        if (!_permissionsHelper.tenantHasUsageACL(URI.create(openstackTargetTenantId), objVpool)) {
            _log.error("tenant {} does not have access to vpool with the given name {}", openstackTargetTenantId, vpoolName);
            throw APIException.badRequests.parameterIsNotValid(vpoolName);
        }
        _log.info("objVpool.getLabel() is {}", objVpool.getLabel());
    }
    List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
    boolean noEntriesInDB = true;
    for (URI quota : quotas) {
        QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
        if ((quotaObj.getProject() != null) && (quotaObj.getProject().toString().equalsIgnoreCase(project.getId().toString()))) {
            _log.info("QuotaObj being updated is {}", quotaObj.toString());
            URI vpoolUri = quotaObj.getVpool();
            if ((!bVpoolQuotaUpdate) && (vpoolUri != null)) {
                // Hence just skip the db entry as this is not our concern.
                continue;
            }
            if ((bVpoolQuotaUpdate) && (vpoolUri != null)) {
                // The user requested quota update for a vpool w.r.t a project.
                // The current db entry that we looking into has vpool entry.
                // Hence we should further check if the vpool value is same as the vpool for which the user wants to set quota
                VirtualPool pool = _dbClient.queryObject(VirtualPool.class, vpoolUri);
                if ((pool != null) && (pool.getLabel().equals(vpoolName)) && (vpoolName != null) && (vpoolName.length() > 0)) {
                    if (quotaUpdates.quota_set.containsKey("gigabytes_" + vpoolName))
                        quotaObj.setTotalQuota(new Long(quotaUpdates.quota_set.get("gigabytes_" + vpoolName)));
                    if (quotaUpdates.quota_set.containsKey("volumes_" + vpoolName))
                        quotaObj.setVolumesLimit(new Long(quotaUpdates.quota_set.get("volumes_" + vpoolName)));
                    if (quotaUpdates.quota_set.containsKey("snapshots_" + vpoolName))
                        quotaObj.setSnapshotsLimit(new Long(quotaUpdates.quota_set.get("snapshots_" + vpoolName)));
                    noEntriesInDB = false;
                    _dbClient.updateObject(quotaObj);
                    return getQuotaDetailFormat(header, quotaUpdates);
                }
            } else if (!bVpoolQuotaUpdate) {
                // The current db entry is a project quota entity.(because to reach here vpoolUri should be Null.
                if (quotaUpdates.quota_set.containsKey("gigabytes"))
                    quotaObj.setTotalQuota(new Long(quotaUpdates.quota_set.get("gigabytes")));
                if (quotaUpdates.quota_set.containsKey("volumes"))
                    quotaObj.setVolumesLimit(new Long(quotaUpdates.quota_set.get("volumes")));
                if (quotaUpdates.quota_set.containsKey("snapshots"))
                    quotaObj.setSnapshotsLimit(new Long(quotaUpdates.quota_set.get("snapshots")));
                noEntriesInDB = false;
                _dbClient.updateObject(quotaObj);
                return getQuotaDetailFormat(header, quotaUpdates);
            }
        }
    }
    if (noEntriesInDB) {
        _log.info("No entries in the QuotaOfCinder column family");
        QuotaOfCinder objQuotaOfCinder = new QuotaOfCinder();
        objQuotaOfCinder.setProject(project.getId());
        if (bVpoolQuotaUpdate) {
            objQuotaOfCinder.setVpool(objVpool.getId());
            _log.info("Updating Quota of Vpool");
            if (quotaUpdates.quota_set.containsKey("gigabytes_" + vpoolName))
                objQuotaOfCinder.setTotalQuota(new Long(quotaUpdates.quota_set.get("gigabytes_" + vpoolName)));
            else
                objQuotaOfCinder.setTotalQuota(Long.valueOf(defaultQuotaMap.get("gigabytes_" + vpoolName)));
            if (quotaUpdates.quota_set.containsKey("volumes_" + vpoolName))
                objQuotaOfCinder.setVolumesLimit(new Long(quotaUpdates.quota_set.get("volumes_" + vpoolName)));
            else
                objQuotaOfCinder.setVolumesLimit(Long.valueOf(defaultQuotaMap.get("volumes_" + vpoolName)));
            if (quotaUpdates.quota_set.containsKey("snapshots_" + vpoolName))
                objQuotaOfCinder.setSnapshotsLimit(new Long(quotaUpdates.quota_set.get("snapshots_" + vpoolName)));
            else
                objQuotaOfCinder.setSnapshotsLimit(Long.valueOf(defaultQuotaMap.get("snapshots_" + vpoolName)));
        } else {
            if (quotaUpdates.quota_set.containsKey("gigabytes"))
                objQuotaOfCinder.setTotalQuota(new Long(quotaUpdates.quota_set.get("gigabytes")));
            else
                objQuotaOfCinder.setTotalQuota(maxQuota);
            if (quotaUpdates.quota_set.containsKey("volumes"))
                objQuotaOfCinder.setVolumesLimit(new Long(quotaUpdates.quota_set.get("volumes")));
            else
                objQuotaOfCinder.setVolumesLimit(Long.valueOf(defaultQuotaMap.get("volumes")));
            if (quotaUpdates.quota_set.containsKey("snapshots"))
                objQuotaOfCinder.setSnapshotsLimit(new Long(quotaUpdates.quota_set.get("snapshots")));
            else
                objQuotaOfCinder.setSnapshotsLimit(Long.valueOf(defaultQuotaMap.get("snapshots")));
        }
        objQuotaOfCinder.setId(URI.create(UUID.randomUUID().toString()));
        _dbClient.createObject(objQuotaOfCinder);
        return getQuotaDetailFormat(header, quotaUpdates);
    }
    return getQuotaDetailFormat(header, quotaUpdates);
}
Also used : Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with QuotaOfCinder

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

the class VolumeService method validateVolumeCreate.

private boolean validateVolumeCreate(String openstackTenantId, VirtualPool pool, long requestedSize) {
    QuotaOfCinder objQuota = null;
    boolean isValidVolume = false;
    if (pool == null)
        objQuota = getQuotaHelper().getProjectQuota(openstackTenantId, getUserFromContext());
    else
        objQuota = getQuotaHelper().getVPoolQuota(openstackTenantId, pool, getUserFromContext());
    if (objQuota == null) {
        _log.info("Unable to retrive the Quota information");
        return false;
    }
    Project proj = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    long totalVolumesUsed = 0;
    long totalSizeUsed = 0;
    UsageStats stats = null;
    if (pool != null)
        stats = getQuotaHelper().getStorageStats(pool.getId(), proj.getId());
    else
        stats = getQuotaHelper().getStorageStats(null, proj.getId());
    totalVolumesUsed = stats.volumes;
    totalSizeUsed = stats.spaceUsed;
    _log.info(String.format("VolumesLimit():%s ,TotalQuota:%s , TotalSizeUsed:%s, TotalVolumesUsed:%s, RequestedConsumption:%s", objQuota.getVolumesLimit(), objQuota.getTotalQuota(), totalSizeUsed, totalVolumesUsed, (totalSizeUsed + requestedSize / GB)));
    if ((objQuota.getVolumesLimit() != QuotaService.DEFAULT_VOLUME_TYPE_VOLUMES_QUOTA) && (objQuota.getVolumesLimit() <= totalVolumesUsed)) {
        return isValidVolume;
    } else if ((objQuota.getTotalQuota() != QuotaService.DEFAULT_VOLUME_TYPE_TOTALGB_QUOTA) && (objQuota.getTotalQuota() <= (totalSizeUsed + requestedSize / GB))) {
        return isValidVolume;
    } else {
        isValidVolume = true;
        return isValidVolume;
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) UsageStats(com.emc.storageos.cinder.model.UsageStats)

Example 9 with QuotaOfCinder

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

the class ProjectService method deactivateProject.

/**
 * Deactivates the project.
 * When a project is deleted it will move to a "marked for deletion" state. Once in this state,
 * new resources or child projects may no longer be created in the project.
 * The project will be permanently deleted once all its references of type
 * ExportGroup, FileSystem, KeyPool, KeyPoolInfo, Volume are deleted.
 *
 * @prereq none
 * @param id the URN of a ViPR Project
 * @brief Deactivate project
 * @return No data returned in response body
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN })
public Response deactivateProject(@PathParam("id") URI id) {
    Project project = getProjectById(id, true);
    // check if any filepolicies are assigned to project
    if ((project.getFilePolicies() != null) && !(project.getFilePolicies().isEmpty())) {
        _log.error("Failed to deactivate the project as a policy is assigned");
        throw APIException.badRequests.cannotDeleteProjectAssignedFilePolicy(project.getLabel());
    }
    // for block service cinder if there is QuotaOfCinder entries
    // we need to remove before the project removal
    List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
    for (URI quota : quotas) {
        QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
        if ((quotaObj.getProject() != null) && (quotaObj.getProject().toString().equalsIgnoreCase(project.getId().toString()))) {
            _log.debug("Deleting related Quota object {}.", quotaObj.getId());
            _dbClient.removeObject(quotaObj);
        }
    }
    ArgValidator.checkReference(Project.class, id, checkForDelete(project));
    // Check the project has been assigned with vNAS servers!!!
    if (isProjectAssignedWithVNasServers(project)) {
        _log.error("Delete porject failed due to, One or more vnas servers are assigned to project.");
        throw APIException.badRequests.failedToDeleteVNasAssignedProject();
    }
    _dbClient.markForDeletion(project);
    recordOperation(OperationTypeEnum.DELETE_PROJECT, true, project);
    return Response.ok().build();
}
Also used : MapProject(com.emc.storageos.api.mapper.functions.MapProject) Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with QuotaOfCinder

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

the class VirtualPoolService method deleteVirtualPool.

protected Response deleteVirtualPool(VirtualPool.Type type, URI id) {
    ArgValidator.checkUri(id);
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, id);
    ArgValidator.checkEntityNotNull(vpool, id, isIdEmbeddedInURL(id));
    // we need to remove before the virtual pool removal
    if (vpool.getType().equalsIgnoreCase(Type.block.name())) {
        List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
        for (URI quota : quotas) {
            QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
            if ((quotaObj.getVpool() != null) && (quotaObj.getVpool().toString().equalsIgnoreCase(vpool.getId().toString()))) {
                _log.debug("Deleting related Vpool for quota object {}.", vpool.getId().toString());
                _dbClient.removeObject(quotaObj);
            }
        }
    }
    if (vpool.getType().equalsIgnoreCase(Type.file.name())) {
        // check if any file policies are assigned to the vpool
        if ((vpool.getFilePolicies() != null) && !(vpool.getFilePolicies().isEmpty())) {
            _log.error("Failed to update the name of virtual pool as a policy is assigned");
            throw APIException.badRequests.cannotDeleteVpoolAssignedFilePolicy(vpool.getLabel());
        }
        // if file policy is assigned to project level then also it has file vpool associated with it.
        // In this scenario association is only way.so need to iterate through all the policy to get vpool reference.
        List<URI> filePolicyList = _dbClient.queryByType(FilePolicy.class, true);
        for (URI filePolicy : filePolicyList) {
            FilePolicy policyObj = _dbClient.queryObject(FilePolicy.class, filePolicy);
            if ((policyObj.getAssignedResources() != null) && (policyObj.getFilePolicyVpool() != null) && (policyObj.getFilePolicyVpool().toString().equalsIgnoreCase(vpool.getId().toString()))) {
                _log.error("Failed to update the name of virtual pool as a policy is assigned at higher level");
                throw APIException.badRequests.cannotDeleteVpoolAssignedFilePolicy(vpool.getLabel());
            }
        }
    }
    if (!vpool.getType().equals(type.name())) {
        throw APIException.badRequests.providedVirtualPoolNotCorrectType();
    }
    QosSpecification qosSpecification = null;
    // Check if Virtual Pool type equals block type
    if (vpool.getType().equalsIgnoreCase(Type.block.name())) {
        // Get the QoS for the VirtualPool, otherwise throw exception
        qosSpecification = QosService.getQos(vpool.getId(), _dbClient);
    }
    // make sure vpool is unused by volumes/fileshares
    ArgValidator.checkReference(VirtualPool.class, id, checkForDelete(vpool));
    // Check if vpool is set as a continuous copies vpool
    checkIfVpoolIsSetAsContinuousCopiesVpool(vpool);
    // Additional check for VirtualPool that may be hidden in another VirtualPool via the
    // protection settings
    URIQueryResultList settingsResultList = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolProtectionVarraySettingsConstraint(id.toString()), settingsResultList);
    Iterator<URI> settingsListItr = settingsResultList.iterator();
    while (settingsListItr.hasNext()) {
        final URI settingId = settingsListItr.next();
        VpoolProtectionVarraySettings setting = _dbClient.queryObject(VpoolProtectionVarraySettings.class, settingId);
        ArgValidator.checkEntity(setting, settingId, isIdEmbeddedInURL(settingId));
    }
    if (vpool.getProtectionVarraySettings() != null) {
        // Delete all settings associated with the protection settings
        deleteVPoolProtectionVArraySettings(vpool);
    }
    if (vpool.getFileRemoteCopySettings() != null) {
        // Delete all settings associated with the protection settings
        deleteFileVPoolRemoteCopyProtectionSettings(vpool);
    }
    // We also check to see if this virtual pool is specified as the HA virtual pool
    // for some other virtual pool that specifies VPLEX distributed high availability.
    // If this is the case, we disallow the deletion.
    List<URI> vpoolURIs = _dbClient.queryByType(VirtualPool.class, true);
    Iterator<VirtualPool> vpoolsIter = _dbClient.queryIterativeObjects(VirtualPool.class, vpoolURIs);
    while (vpoolsIter.hasNext()) {
        VirtualPool activeVPool = vpoolsIter.next();
        if (!activeVPool.getId().equals(id)) {
            StringMap haMap = activeVPool.getHaVarrayVpoolMap();
            if ((haMap != null) && (!haMap.isEmpty()) && (haMap.values().contains(id.toString()))) {
                // is not allowed.
                throw APIException.badRequests.cantDeleteVPlexHaVPool(activeVPool.getLabel());
            }
        }
    }
    if (vpool.getType().equalsIgnoreCase(Type.block.name()) && qosSpecification != null) {
        // Remove Qos associated to this Virtual Pool
        _dbClient.removeObject(qosSpecification);
    }
    _dbClient.markForDeletion(vpool);
    recordOperation(OperationTypeEnum.DELETE_VPOOL, VPOOL_DELETED_DESCRIPTION, vpool);
    return Response.ok().build();
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) VpoolProtectionVarraySettings(com.emc.storageos.db.client.model.VpoolProtectionVarraySettings) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) QosSpecification(com.emc.storageos.db.client.model.QosSpecification) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

QuotaOfCinder (com.emc.storageos.db.client.model.QuotaOfCinder)14 Project (com.emc.storageos.db.client.model.Project)10 URI (java.net.URI)6 UsageStats (com.emc.storageos.cinder.model.UsageStats)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 MapProject (com.emc.storageos.api.mapper.functions.MapProject)1 CinderLimits (com.emc.storageos.cinder.model.CinderLimits)1 CinderQuotaDetails (com.emc.storageos.cinder.model.CinderQuotaDetails)1 CinderUsage (com.emc.storageos.cinder.model.CinderUsage)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 QosSpecification (com.emc.storageos.db.client.model.QosSpecification)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 VpoolProtectionVarraySettings (com.emc.storageos.db.client.model.VpoolProtectionVarraySettings)1