mirror of https://github.com/apache/cloudstack.git
quota: add new template for sending unlocked email account
This commit is contained in:
parent
70aada690b
commit
7b562b0696
|
|
@ -36,6 +36,7 @@ import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
|
|||
import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaTariffDao;
|
||||
import org.apache.cloudstack.quota.job.QuotaManager;
|
||||
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
|
|
@ -76,6 +77,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
|
|||
@Inject
|
||||
private QuotaService _quotaService;
|
||||
@Inject
|
||||
private QuotaManager _quotaMgr;
|
||||
@Inject
|
||||
AccountDao _accountDao;
|
||||
@Inject
|
||||
private RegionManager _regionMgr;
|
||||
|
|
@ -282,10 +285,12 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
|
|||
TransactionLegacy.open(TransactionLegacy.CLOUD_DB).close();
|
||||
final AccountVO account = _accountDao.findById(accountId);
|
||||
final boolean lockAccountEnforcement = QuotaConfig.QuotaEnableEnforcement.value().equalsIgnoreCase("true");
|
||||
if (lockAccountEnforcement && (_quotaBalanceDao.lastQuotaBalance(accountId, domainId, new Date()).compareTo(new BigDecimal(0)) >= 0)) {
|
||||
final BigDecimal currentAccountBalance = _quotaBalanceDao.lastQuotaBalance(accountId, domainId, new Date());
|
||||
if (lockAccountEnforcement && (currentAccountBalance.compareTo(new BigDecimal(0)) >= 0)) {
|
||||
if (account.getState() == Account.State.locked) {
|
||||
try {
|
||||
_regionMgr.enableAccount(account.getAccountName(), domainId, accountId);
|
||||
_quotaMgr.sendQuotaAlert(account, currentAccountBalance, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_UNLOCK_ACCOUNT);
|
||||
} catch (Exception e) {
|
||||
s_logger.error(String.format("Unable to unlock account %s after getting enough quota credits", account.getAccountName()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,6 @@ public interface QuotaConfig {
|
|||
"Sender of quota alert email (will be in the From header of the email)", true);
|
||||
|
||||
enum QuotaEmailTemplateTypes {
|
||||
QUOTA_LOW, QUOTA_EMPTY
|
||||
QUOTA_LOW, QUOTA_EMPTY, QUOTA_UNLOCK_ACCOUNT
|
||||
}
|
||||
}
|
||||
|
|
@ -16,10 +16,15 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.quota.job;
|
||||
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import org.apache.cloudstack.quota.constant.QuotaConfig;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public interface QuotaManager extends Manager {
|
||||
|
||||
boolean calculateQuotaUsage();
|
||||
void sendQuotaAlert(AccountVO account, BigDecimal balance, QuotaConfig.QuotaEmailTemplateTypes emailType);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
|||
return quota_usage;
|
||||
}
|
||||
|
||||
private void sendQuotaAlert(AccountVO account, BigDecimal balance, QuotaConfig.QuotaEmailTemplateTypes emailType) {
|
||||
public void sendQuotaAlert(AccountVO account, BigDecimal balance, QuotaConfig.QuotaEmailTemplateTypes emailType) {
|
||||
sendQuotaAlert(new DeferredQuotaEmail(account, balance, emailType));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,8 +128,9 @@ CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_email_templates` (
|
|||
|
||||
LOCK TABLES `cloud_usage`.`quota_email_templates` WRITE;
|
||||
INSERT INTO `cloud_usage`.`quota_email_templates` (`template_name`, `template_subject`, `template_body`) VALUES
|
||||
('QUOTA_LOW', 'Quota Usage Threshold crossed ${accountName}', 'Your account "${accountName}" in the domain "${domainName}" has reached usage threshold, the current balance is ${quotaCurrency} ${quotaValue}'),
|
||||
('QUOTA_EMPTY', 'Quota Exhausted, account ${accountName} is locked now', 'Your account "${accountName}" in the domain "${domainName}" has exhausted allocated quota due to which your account has locked now, please contact the administrator');
|
||||
('QUOTA_LOW', 'Quota Usage Threshold crossed by your account ${accountName}', 'Your account ${accountName} in the domain ${domainName} has reached quota usage threshold, your current quota balance is ${quotaBalance}.'),
|
||||
('QUOTA_EMPTY', 'Quota Exhausted, account ${accountName} is locked now', 'Your account ${accountName} in the domain ${domainName} has exhausted allocated quota and has been locked now, please contact the administrator.'),
|
||||
('QUOTA_UNLOCK_ACCOUNT', 'Quota credits added, account ${accountName} is unlocked now', 'Your account ${accountName} in the domain ${domainName} has enough quota credits now with the current balance of ${quotaBalance}. Your account has been unlocked now.');
|
||||
UNLOCK TABLES;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_sent_emails` (
|
||||
|
|
|
|||
|
|
@ -587,7 +587,7 @@ var g_quotaCurrency = '';
|
|||
|
||||
var emailTemplateForm = $('<div class="quota-email-form">');
|
||||
var templateDropdown = $('<div class="quota-template-dropdown">');
|
||||
var templateOptions = $('<select><option value="QUOTA_LOW">Template for accounts with low quota balance</option><option value="QUOTA_EMPTY">Template for accounts with no quota balance</option></select>');
|
||||
var templateOptions = $('<select><option value="QUOTA_LOW">Template for accounts with low quota balance</option><option value="QUOTA_EMPTY">Template for accounts with no quota balance that will be locked</option><option value="QUOTA_UNLOCK_ACCOUNT">Template for accounts with enough credits getting unlocked</option></select>');
|
||||
templateOptions.appendTo($('<p>Select Template: </p>').appendTo(templateDropdown));
|
||||
$('<br>').appendTo(templateDropdown);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue