mirror of https://github.com/apache/cloudstack.git
quota: fix stuff
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
8df0a53bf8
commit
fdfcd953d5
|
|
@ -36,13 +36,13 @@ public interface QuotaConfig {
|
|||
"true means all the emails sent out will be stored in local DB, by default it is false", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaEnableEnforcement = new ConfigKey<String>("Advanced", String.class, "quota.enable.enforcement", "true",
|
||||
"Enable the usage quota enforcement, i.e. on true exceeding quota the respective account will be locked.", true);
|
||||
"Enable the usage quota enforcement, i.e. on true when exceeding quota the respective account will be locked.", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaCurrencySymbol = new ConfigKey<String>("Advanced", String.class, "quota.currency.symbol", "R",
|
||||
"The symbol for the currency in use to measure usage.", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaLimitCritical = new ConfigKey<String>("Advanced", String.class, "quota.limit.critical", "80",
|
||||
"A percentage limit for quota when it is reached user is sent and alert.", true);
|
||||
"The quota amount when reached, the account users are sent low quota email alerts.", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaLimitIncremental = new ConfigKey<String>("Advanced", String.class, "quota.limit.increment", "5",
|
||||
"Quota limit incremental", true);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.cloudstack.quota.job;
|
|||
import com.cloud.configuration.Config;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.usage.UsageVO;
|
||||
|
|
@ -48,6 +49,8 @@ import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
|
|||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaUsageVO;
|
||||
import org.apache.cloudstack.region.RegionManager;
|
||||
import org.apache.cloudstack.region.RegionService;
|
||||
import org.apache.cloudstack.utils.usage.UsageUtils;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -99,6 +102,8 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
|||
private QuotaBalanceDao _quotaBalanceDao;
|
||||
@Inject
|
||||
private ConfigurationDao _configDao;
|
||||
@Inject
|
||||
private RegionManager _regionMgr;
|
||||
|
||||
private TimeZone _usageTimezone;
|
||||
private int _aggregationDuration = 0;
|
||||
|
|
@ -266,24 +271,30 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
|||
List <DeferredQuotaEmail> deferredQuotaEmailList = new ArrayList<DeferredQuotaEmail>();
|
||||
final Date currentDate = new Date();
|
||||
final BigDecimal zeroBalance = new BigDecimal(0);
|
||||
final BigDecimal thresholdBalance = new BigDecimal(1000); // FIXME: get value from threshold
|
||||
final BigDecimal thresholdBalance = new BigDecimal(QuotaConfig.QuotaLimitCritical.value());
|
||||
final boolean lockAccountEnforcement = QuotaConfig.QuotaEnableEnforcement.value().equalsIgnoreCase("true");
|
||||
for (final AccountVO account : _accountDao.listAll()) {
|
||||
QuotaBalanceVO accountBalanceVO = _quotaBalanceDao.findLastBalanceEntry(account.getId(), account.getDomainId(), currentDate);
|
||||
//FIXME: Abhi we need to find the current/actual accountBalance?
|
||||
if (accountBalanceVO != null && accountBalanceVO.getCreditBalance() != null) {
|
||||
BigDecimal accountBalance = accountBalanceVO.getCreditBalance();
|
||||
s_logger.debug("Checking and sending email to account: " + accountBalance.toString() + " account=" + account.getAccountName());
|
||||
if (accountBalance.compareTo(zeroBalance) <= 0) {
|
||||
if (lockAccountEnforcement) {
|
||||
try {
|
||||
_regionMgr.disableAccount(account.getAccountName(), account.getDomainId(), account.getId(), true);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.error(String.format("Unable to lock account %s which has exhausted its allocated quota", account.getAccountName()));
|
||||
}
|
||||
}
|
||||
deferredQuotaEmailList.add(new DeferredQuotaEmail(account, accountBalanceVO, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY));
|
||||
// FIXME: lock account?
|
||||
} else if (accountBalance.compareTo(thresholdBalance) <= 0) {
|
||||
deferredQuotaEmailList.add(new DeferredQuotaEmail(account, accountBalanceVO, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this could be enqueued in DB and sent later on in a bg thread?
|
||||
for (DeferredQuotaEmail emailToBeSent: deferredQuotaEmailList) {
|
||||
s_logger.debug("Attempting to send email to user: " + emailToBeSent.getAccount().getAccountName());
|
||||
s_logger.debug("Attempting to send quota alert email to users of account: " + emailToBeSent.getAccount().getAccountName());
|
||||
sendQuotaAlert(emailToBeSent);
|
||||
}
|
||||
}
|
||||
|
|
@ -473,10 +484,10 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
|||
try {
|
||||
_emailQuotaAlert.sendQuotaAlert(emailRecipients, subject, body);
|
||||
} catch (Exception e) {
|
||||
s_logger.error(String.format("Unable to send quota alert email to account %s (%s) due to error: %s", account.getAccountName(), account.getUuid(), e));
|
||||
s_logger.error(String.format("Unable to send quota alert email (subject=%s; body=%s) to account %s (%s) recipients (%s) due to error (%s)", subject, body, account.getAccountName(), account.getUuid(), emailRecipients, e));
|
||||
}
|
||||
} else {
|
||||
s_logger.error(String.format("No quota email template found for type %s, cannot send quota alert email to account %s(%s) ", emailType, account.getAccountName(), account.getUuid()));
|
||||
s_logger.error(String.format("No quota email template found for type %s, cannot send quota alert email to account %s(%s)", emailType, account.getAccountName(), account.getUuid()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2179,8 +2179,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("User " + username + " in domain " + domainName + " is disabled/locked (or account is disabled/locked)");
|
||||
}
|
||||
throw new CloudAuthenticationException("User " + username + " in domain " + domainName + " is disabled/locked (or account is disabled/locked)");
|
||||
// return null;
|
||||
throw new CloudAuthenticationException("User " + username + " (or their account) in domain " + domainName + " is disabled/locked. Please contact the administrator.");
|
||||
}
|
||||
// Whenever the user is able to log in successfully, reset the login attempts to zero
|
||||
if (!isInternalAccount(userAccount.getId()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue