Search in sources :

Example 1 with QuotaOfCinder

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

the class QuotaHelper method createProjectDefaultQuota.

/**
 * Get default quota for provided project
 *
 * @prereq none
 *
 * @param project
 * param defaultQuotaMap (comprehensive default quota map)
 * @brief get project default quota
 * @return quota
 */
public QuotaOfCinder createProjectDefaultQuota(Project project, HashMap<String, String> defaultQuotaMap) {
    long maxQuota = 0;
    if (project.getQuotaEnabled()) {
        maxQuota = (long) (project.getQuota().intValue());
    } else {
        maxQuota = Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.GIGABYTES.getResource()));
    }
    QuotaOfCinder quotaObj = new QuotaOfCinder();
    quotaObj.setId(URI.create(UUID.randomUUID().toString()));
    quotaObj.setProject(project.getId());
    quotaObj.setVolumesLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.VOLUMES.getResource())));
    quotaObj.setSnapshotsLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.SNAPSHOTS.getResource())));
    quotaObj.setTotalQuota(maxQuota);
    _log.info("Creating default quota for project");
    _dbClient.createObject(quotaObj);
    return quotaObj;
}
Also used : QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder)

Example 2 with QuotaOfCinder

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

the class QuotaHelper method getVPoolQuota.

/**
 * Get quota for provided vpool
 *
 * @prereq none
 *
 * @param tenantId
 * @param vpool
 *
 * @brief get vpool quota
 * @return quota
 */
public QuotaOfCinder getVPoolQuota(String tenantId, VirtualPool vpool, StorageOSUser user) {
    _log.debug("In getVPoolQuota");
    Project project = getCinderHelper().getProject(tenantId.toString(), user);
    List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
    for (URI quota : quotas) {
        QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
        URI vpoolUri = quotaObj.getVpool();
        if (vpoolUri == null) {
            continue;
        } else if ((quotaObj.getProject() != null) && (quotaObj.getProject().toString().equalsIgnoreCase(project.getId().toString()))) {
            VirtualPool pool = _dbClient.queryObject(VirtualPool.class, vpoolUri);
            if ((pool != null) && (pool.getLabel().equals(vpool.getLabel())) && (vpool.getLabel() != null) && (vpool.getLabel().length() > 0)) {
                return quotaObj;
            }
        }
    }
    HashMap<String, String> qMap = getCompleteDefaultConfiguration(tenantId);
    return createVpoolDefaultQuota(project, vpool, qMap);
}
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)

Example 3 with QuotaOfCinder

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

the class QuotaHelper method getProjectQuota.

/**
 * Get quota for given project/tenant
 *
 * @prereq none
 *
 * @param tenantId
 *
 * @brief get project quota
 * @return quota
 */
public QuotaOfCinder getProjectQuota(String tenantId, StorageOSUser user) {
    Project project = getCinderHelper().getProject(tenantId.toString(), user);
    List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
    for (URI quota : quotas) {
        QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
        URI vpoolUri = quotaObj.getVpool();
        if (vpoolUri != null) {
            continue;
        }
        if ((quotaObj.getProject() != null) && (quotaObj.getProject().toString().equalsIgnoreCase(project.getId().toString()))) {
            return quotaObj;
        }
    }
    HashMap<String, String> qMap = getCompleteDefaultConfiguration(tenantId);
    return createProjectDefaultQuota(project, qMap);
}
Also used : Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) URI(java.net.URI)

Example 4 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 5 with QuotaOfCinder

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

the class MiscService method getLimits.

/**
 * Get Limits
 *
 * @prereq none
 * @param tenant_id the URN of the tenant
 * @brief Get Limits
 * @return limits
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/limits")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getLimits(@PathParam("tenant_id") String openstack_tenant_id, @Context HttpHeaders header) {
    _log.info("START get limits");
    CinderLimits limitsResp = new CinderLimits();
    Project project = getCinderHelper().getProject(openstack_tenant_id.toString(), getUserFromContext());
    if (project == null) {
        throw APIException.badRequests.projectWithTagNonexistent(openstack_tenant_id);
    }
    HashMap<String, String> defaultQuotaMap = getQuotaHelper().loadDefaultsMapFromDb();
    int totalSizeUsed = 0;
    int maxQuota = Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.GIGABYTES.getResource())).intValue();
    int maxTotalVolumes = 0;
    int maxTotalSnapshots = 0;
    int totalVolumesUsed = 0;
    int totalSnapshotsUsed = 0;
    if (project.getQuotaEnabled()) {
        maxQuota = (int) (project.getQuota().intValue());
    }
    UsageStats objUsageStats = new UsageStats();
    objUsageStats = getQuotaHelper().getStorageStats(null, project.getId());
    totalVolumesUsed = (int) objUsageStats.volumes;
    totalSnapshotsUsed = (int) objUsageStats.snapshots;
    totalSizeUsed = (int) objUsageStats.spaceUsed;
    QuotaOfCinder projQuota = getQuotaHelper().getProjectQuota(openstack_tenant_id, getUserFromContext());
    if (projQuota != null) {
        maxTotalVolumes = projQuota.getVolumesLimit().intValue();
        maxTotalSnapshots = (int) projQuota.getSnapshotsLimit().intValue();
    } else {
        QuotaOfCinder quotaObj = new QuotaOfCinder();
        quotaObj.setId(URI.create(UUID.randomUUID().toString()));
        quotaObj.setProject(project.getId());
        quotaObj.setVolumesLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.VOLUMES.getResource())));
        quotaObj.setSnapshotsLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.SNAPSHOTS.getResource())));
        quotaObj.setTotalQuota((long) maxQuota);
        _dbClient.createObject(quotaObj);
        maxTotalSnapshots = quotaObj.getSnapshotsLimit().intValue();
        maxTotalVolumes = quotaObj.getVolumesLimit().intValue();
    }
    Map<String, Integer> absoluteDetailsMap = new HashMap<String, Integer>();
    absoluteDetailsMap.put("totalSnapshotsUsed", totalSnapshotsUsed);
    absoluteDetailsMap.put("maxTotalVolumeGigabytes", maxQuota);
    absoluteDetailsMap.put("totalGigabytesUsed", totalSizeUsed);
    absoluteDetailsMap.put("maxTotalSnapshots", maxTotalSnapshots);
    absoluteDetailsMap.put("totalVolumesUsed", totalVolumesUsed);
    absoluteDetailsMap.put("maxTotalVolumes", maxTotalVolumes);
    limitsResp.absolute = absoluteDetailsMap;
    _log.info("END get limits");
    return CinderApiUtils.getCinderResponse(limitsResp, header, true, CinderConstants.STATUS_OK);
}
Also used : Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) HashMap(java.util.HashMap) UsageStats(com.emc.storageos.cinder.model.UsageStats) CinderLimits(com.emc.storageos.cinder.model.CinderLimits) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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