Search in sources :

Example 1 with QuotaAction

use of com.github.ambry.quota.QuotaAction in project ambry by linkedin.

the class StorageQuotaEnforcer method recommendBasedOnQuotaAndUsage.

/**
 * Return a {@link QuotaRecommendation} based on the given pair of quota and current usage.
 * @param pair The {@link Pair} of quota and current usage.
 * @return A {@link QuotaRecommendation}.
 */
private QuotaRecommendation recommendBasedOnQuotaAndUsage(Pair<Long, Long> pair) {
    long quotaValue = pair.getFirst();
    long currentUsage = pair.getSecond();
    if (quotaValue == -1L) {
        // There is no quota set for the given account/container
        return NO_QUOTA_VALUE_RECOMMENDATION;
    }
    QuotaAction quotaAction = (currentUsage >= quotaValue) ? QuotaAction.REJECT : QuotaAction.ALLOW;
    float usagePercentage = currentUsage >= quotaValue ? 100f : ((float) currentUsage) / quotaValue * 100f;
    return new QuotaRecommendation(quotaAction, usagePercentage, QuotaName.STORAGE_IN_GB, NO_RETRY);
}
Also used : QuotaAction(com.github.ambry.quota.QuotaAction) QuotaRecommendation(com.github.ambry.quota.QuotaRecommendation)

Aggregations

QuotaAction (com.github.ambry.quota.QuotaAction)1 QuotaRecommendation (com.github.ambry.quota.QuotaRecommendation)1