mirror of https://github.com/apache/cloudstack.git
quota: email template backend and apis
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
15b9a894eb
commit
f5be8aaf8f
|
|
@ -783,13 +783,12 @@ listOpenDaylightControllers=1
|
|||
addGloboDnsHost=1
|
||||
|
||||
### Quota Service
|
||||
quotaTariffList=15
|
||||
quotaTariffUpdate=7
|
||||
quotaRefresh=1
|
||||
quotaStatement=15
|
||||
quotaCredits=1
|
||||
quotaBalance=15
|
||||
quotaRefresh=7
|
||||
quotaEmailTemplateUpdate=15
|
||||
quotaEmailTemplateDelete=15
|
||||
quotaEmailTemplateAdd=15
|
||||
quotaCredits=1
|
||||
quotaTariffList=15
|
||||
quotaTariffUpdate=1
|
||||
quotaEmailTemplateList=1
|
||||
quotaEmailTemplateUpdate=1
|
||||
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
//Licensed to the Apache Software Foundation (ASF) under one
|
||||
//or more contributor license agreements. See the NOTICE file
|
||||
//distributed with this work for additional information
|
||||
//regarding copyright ownership. The ASF licenses this file
|
||||
//to you under the Apache License, Version 2.0 (the
|
||||
//"License"); you may not use this file except in compliance
|
||||
//with the License. You may obtain a copy of the License at
|
||||
//
|
||||
//http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//Unless required by applicable law or agreed to in writing,
|
||||
//software distributed under the License is distributed on an
|
||||
//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
//KIND, either express or implied. See the License for the
|
||||
//specific language governing permissions and limitations
|
||||
//under the License.
|
||||
package org.apache.cloudstack.api.command;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.QuotaEmailTemplateResponse;
|
||||
|
||||
@APICommand(name = "quotaEmailTemplateAdd", responseObject = QuotaEmailTemplateResponse.class, description = "Add a new email template", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class QuotaEmailTemplateAddCmd extends BaseListCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateAddCmd.class.getName());
|
||||
|
||||
private static final String s_name = "quotaemailtemplateresponse";
|
||||
|
||||
@Parameter(name = "templatename", type = CommandType.STRING, required=true, description = "The name of email template")
|
||||
private String templateName;
|
||||
|
||||
@Parameter(name = "templatetext", type = CommandType.STRING, required=true, description = "The text of the email")
|
||||
private Long templateText;
|
||||
|
||||
@Parameter(name = "locale", type = CommandType.STRING, description = "The locale of the email text")
|
||||
private Integer locale;
|
||||
|
||||
public QuotaEmailTemplateAddCmd() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
final QuotaEmailTemplateResponse templResponse = null;
|
||||
|
||||
setResponseObject(templResponse);
|
||||
}
|
||||
|
||||
public String getTemplateName() {
|
||||
return templateName;
|
||||
}
|
||||
|
||||
public void setTemplateName(String templateName) {
|
||||
this.templateName = templateName;
|
||||
}
|
||||
|
||||
public Long getTemplateText() {
|
||||
return templateText;
|
||||
}
|
||||
|
||||
public void setTemplateText(Long templateText) {
|
||||
this.templateText = templateText;
|
||||
}
|
||||
|
||||
public Integer getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(Integer locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
//Licensed to the Apache Software Foundation (ASF) under one
|
||||
//or more contributor license agreements. See the NOTICE file
|
||||
//distributed with this work for additional information
|
||||
//regarding copyright ownership. The ASF licenses this file
|
||||
//to you under the Apache License, Version 2.0 (the
|
||||
//"License"); you may not use this file except in compliance
|
||||
//with the License. You may obtain a copy of the License at
|
||||
//
|
||||
//http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//Unless required by applicable law or agreed to in writing,
|
||||
//software distributed under the License is distributed on an
|
||||
//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
//KIND, either express or implied. See the License for the
|
||||
//specific language governing permissions and limitations
|
||||
//under the License.
|
||||
package org.apache.cloudstack.api.command;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.QuotaEmailTemplateResponse;
|
||||
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@APICommand(name = "quotaEmailTemplateList", responseObject = QuotaEmailTemplateResponse.class, description = "Lists all quota email templates", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class QuotaEmailTemplateListCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateListCmd.class.getName());
|
||||
private static final String s_name = "quotaemailtemplatelistresponse";
|
||||
|
||||
@Inject
|
||||
QuotaResponseBuilder _quotaResponseBuilder;
|
||||
|
||||
@Parameter(name = "templatetype", type = CommandType.STRING, description = "List by type of the quota email template, allowed types: QUOTA_LOW, QUOTA_EMPTY")
|
||||
private String templateName;
|
||||
|
||||
public String getTemplateName() {
|
||||
return templateName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
final ListResponse<QuotaEmailTemplateResponse> response = new ListResponse<QuotaEmailTemplateResponse>();
|
||||
response.setResponses(_quotaResponseBuilder.listQuotaEmailTemplates(this));
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
//Licensed to the Apache Software Foundation (ASF) under one
|
||||
//or more contributor license agreements. See the NOTICE file
|
||||
//distributed with this work for additional information
|
||||
//regarding copyright ownership. The ASF licenses this file
|
||||
//to you under the Apache License, Version 2.0 (the
|
||||
//"License"); you may not use this file except in compliance
|
||||
//with the License. You may obtain a copy of the License at
|
||||
//
|
||||
//http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//Unless required by applicable law or agreed to in writing,
|
||||
//software distributed under the License is distributed on an
|
||||
//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
//KIND, either express or implied. See the License for the
|
||||
//specific language governing permissions and limitations
|
||||
//under the License.
|
||||
package org.apache.cloudstack.api.command;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.quota.constant.QuotaConfig;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
|
||||
@APICommand(name = "quotaEmailTemplateUpdate", responseObject = SuccessResponse.class, description = "Updates existing email templates for quota alerts", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class QuotaEmailTemplateUpdateCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateUpdateCmd.class.getName());
|
||||
private static final String s_name = "quotaemailtemplateupdateresponse";
|
||||
|
||||
@Inject
|
||||
QuotaResponseBuilder _quotaResponseBuilder;
|
||||
|
||||
@Parameter(name = "templatetype", type = CommandType.STRING, required=true, description = "Type of the quota email template, allowed types: QUOTA_LOW, QUOTA_EMPTY")
|
||||
private String templateName;
|
||||
|
||||
@Parameter(name = "templatesubject", type = CommandType.STRING, required=true, description = "The quota email template subject")
|
||||
private String templateSubject;
|
||||
|
||||
@Parameter(name = "templatebody", type = CommandType.STRING, required=true, description = "The quota email template body")
|
||||
private String templateBody;
|
||||
|
||||
@Parameter(name = "locale", type = CommandType.STRING, description = "The locale of the email text")
|
||||
private String locale;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
final String templateName = getTemplateName();
|
||||
if (templateName == null || getTemplateSubject() == null || getTemplateBody() == null) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to update quota email template due to empty or invalid template name or text");
|
||||
}
|
||||
|
||||
boolean isValidTemplateName = false;
|
||||
for (QuotaConfig.QuotaEmailTemplateTypes e: QuotaConfig.QuotaEmailTemplateTypes.values()) {
|
||||
if (e.toString().equalsIgnoreCase(templateName)) {
|
||||
isValidTemplateName = true;
|
||||
setTemplateName(e.toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isValidTemplateName) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid quota email template type, allowed values are: " + Arrays.toString(QuotaConfig.QuotaEmailTemplateTypes.values()));
|
||||
}
|
||||
|
||||
if (!_quotaResponseBuilder.updateQuotaEmailTemplate(this)) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to update quota email template due to an internal error");
|
||||
}
|
||||
final SuccessResponse response = new SuccessResponse();
|
||||
response.setResponseName(getCommandName());
|
||||
response.setSuccess(true);
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
private void setTemplateName(String templateName) {
|
||||
this.templateName = templateName;
|
||||
}
|
||||
|
||||
public String getTemplateName() {
|
||||
return templateName;
|
||||
}
|
||||
|
||||
public String getTemplateSubject() {
|
||||
return templateSubject;
|
||||
}
|
||||
|
||||
public String getTemplateBody() {
|
||||
return templateBody;
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,67 +16,75 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import java.util.Date;
|
||||
|
||||
public class QuotaEmailTemplateResponse extends BaseResponse {
|
||||
@SerializedName("templatetype")
|
||||
@Param(description = "Template type")
|
||||
private String templateType;
|
||||
|
||||
@SerializedName(ApiConstants.ID)
|
||||
@Param(description = "the ID of the credit")
|
||||
private String id;
|
||||
@SerializedName("templatesubject")
|
||||
@Param(description = "The quota email template subject")
|
||||
private String templateSubject;
|
||||
|
||||
@SerializedName(ApiConstants.ACCOUNT)
|
||||
@Param(description = "the account name of the api remaining count")
|
||||
private String accountName;
|
||||
@SerializedName("templatebody")
|
||||
@Param(description = "The quota email template content")
|
||||
private String templateText;
|
||||
|
||||
@SerializedName(ApiConstants.DOMAIN_ID)
|
||||
@Param(description = "the domain ID of the iam policy")
|
||||
private String domainId;
|
||||
@SerializedName("locale")
|
||||
@Param(description = "The quota email template locale")
|
||||
private String locale;
|
||||
|
||||
@SerializedName("sent_on")
|
||||
@Param(description = "the account name of the admin who updated the credits")
|
||||
private Timestamp SentOn;
|
||||
@SerializedName("last_updated")
|
||||
@Param(description = "Last date/time when template was updated")
|
||||
private Date lastUpdatedOn;
|
||||
|
||||
public QuotaEmailTemplateResponse() {
|
||||
super();
|
||||
this.setObjectName("quotaemailtemplate");
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
public String getTemplateType() {
|
||||
return templateType;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
public void setTemplateType(String templateType) {
|
||||
this.templateType = templateType;
|
||||
}
|
||||
|
||||
public String getAccountName() {
|
||||
return accountName;
|
||||
public String getTemplateSubject() {
|
||||
return templateSubject;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
public void setTemplateSubject(String templateSubject) {
|
||||
this.templateSubject = templateSubject;
|
||||
}
|
||||
|
||||
public String getDomainId() {
|
||||
return domainId;
|
||||
public String getTemplateText() {
|
||||
return templateText;
|
||||
}
|
||||
|
||||
public void setDomainId(String domainId) {
|
||||
this.domainId = domainId;
|
||||
public void setTemplateText(String templateText) {
|
||||
this.templateText = templateText;
|
||||
}
|
||||
|
||||
public Timestamp getSentOn() {
|
||||
return SentOn;
|
||||
public String getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setSentOn(Timestamp sentOn) {
|
||||
SentOn = sentOn;
|
||||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public Date getLastUpdatedOn() {
|
||||
return lastUpdatedOn;
|
||||
}
|
||||
|
||||
public void setLastUpdatedOn(Date lastUpdatedOn) {
|
||||
this.lastUpdatedOn = lastUpdatedOn;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ package org.apache.cloudstack.api.response;
|
|||
|
||||
|
||||
import org.apache.cloudstack.api.command.QuotaBalanceCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaStatementCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaTariffListCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
|
||||
|
|
@ -50,4 +52,7 @@ public interface QuotaResponseBuilder {
|
|||
|
||||
QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Double amount, Long updatedBy);
|
||||
|
||||
List<QuotaEmailTemplateResponse> listQuotaEmailTemplates(QuotaEmailTemplateListCmd cmd);
|
||||
|
||||
boolean updateQuotaEmailTemplate(QuotaEmailTemplateUpdateCmd cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ import com.cloud.exception.InvalidParameterValueException;
|
|||
import com.cloud.user.User;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
|
||||
import org.apache.cloudstack.api.command.QuotaBalanceCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaStatementCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaTariffListCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
|
||||
|
|
@ -29,17 +30,19 @@ import org.apache.cloudstack.quota.QuotaService;
|
|||
import org.apache.cloudstack.quota.constant.QuotaTypes;
|
||||
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.vo.QuotaBalanceVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaUsageVO;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -60,6 +63,9 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
|
|||
private QuotaBalanceDao _quotaBalanceDao;
|
||||
@Inject
|
||||
private QuotaCreditsDao _quotaCreditsDao;
|
||||
@Inject
|
||||
private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
|
||||
|
||||
@Inject
|
||||
private UserDao _userDao;
|
||||
@Inject
|
||||
|
|
@ -295,6 +301,47 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
|
|||
return new QuotaCreditsResponse(result, creditor);
|
||||
}
|
||||
|
||||
private QuotaEmailTemplateResponse createQuotaEmailResponse(QuotaEmailTemplatesVO template) {
|
||||
QuotaEmailTemplateResponse response = new QuotaEmailTemplateResponse();
|
||||
response.setTemplateType(template.getTemplateName());
|
||||
response.setTemplateSubject(template.getTemplateSubject());
|
||||
response.setTemplateText(template.getTemplateBody());
|
||||
response.setLocale(template.getLocale());
|
||||
response.setLastUpdatedOn(template.getLastUpdated());
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuotaEmailTemplateResponse> listQuotaEmailTemplates(QuotaEmailTemplateListCmd cmd) {
|
||||
final String templateName = cmd.getTemplateName();
|
||||
List<QuotaEmailTemplatesVO> templates = _quotaEmailTemplateDao.listAllQuotaEmailTemplates(templateName);
|
||||
final List<QuotaEmailTemplateResponse> responses = new ArrayList<QuotaEmailTemplateResponse>();
|
||||
for (final QuotaEmailTemplatesVO template : templates) {
|
||||
responses.add(createQuotaEmailResponse(template));
|
||||
}
|
||||
return responses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateQuotaEmailTemplate(QuotaEmailTemplateUpdateCmd cmd) {
|
||||
final String templateName = cmd.getTemplateName();
|
||||
final String templateSubject = StringEscapeUtils.escapeHtml(cmd.getTemplateSubject());
|
||||
final String templateBody = StringEscapeUtils.escapeHtml(cmd.getTemplateBody());
|
||||
final String locale = cmd.getLocale();
|
||||
|
||||
final List<QuotaEmailTemplatesVO> templates = _quotaEmailTemplateDao.listAllQuotaEmailTemplates(templateName);
|
||||
if (templates.size() == 1) {
|
||||
final QuotaEmailTemplatesVO template = templates.get(0);
|
||||
template.setTemplateSubject(templateSubject);
|
||||
template.setTemplateBody(templateBody);
|
||||
if (locale != null) {
|
||||
template.setLocale(locale);
|
||||
}
|
||||
return _quotaEmailTemplateDao.updateQuotaEmailTemplate(template);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuotaUsageVO> getQuotaUsage(QuotaStatementCmd cmd) {
|
||||
return _quotaService.getQuotaUsage(cmd.getAccountId(), cmd.getAccountName(), cmd.getDomainId(), cmd.getUsageType(), cmd.getStartDate(), cmd.getEndDate());
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ import com.cloud.utils.db.TransactionLegacy;
|
|||
|
||||
import org.apache.cloudstack.api.command.QuotaBalanceCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaCreditsCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaEmailTemplateAddCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaRefreshCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaStatementCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaTariffListCmd;
|
||||
|
|
@ -108,13 +109,14 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi
|
|||
@Override
|
||||
public List<Class<?>> getCommands() {
|
||||
final List<Class<?>> cmdList = new ArrayList<Class<?>>();
|
||||
cmdList.add(QuotaTariffListCmd.class);
|
||||
cmdList.add(QuotaTariffUpdateCmd.class);
|
||||
cmdList.add(QuotaCreditsCmd.class);
|
||||
cmdList.add(QuotaEmailTemplateAddCmd.class);
|
||||
cmdList.add(QuotaRefreshCmd.class);
|
||||
cmdList.add(QuotaStatementCmd.class);
|
||||
cmdList.add(QuotaBalanceCmd.class);
|
||||
cmdList.add(QuotaTariffListCmd.class);
|
||||
cmdList.add(QuotaTariffUpdateCmd.class);
|
||||
cmdList.add(QuotaCreditsCmd.class);
|
||||
cmdList.add(QuotaEmailTemplateListCmd.class);
|
||||
cmdList.add(QuotaEmailTemplateUpdateCmd.class);
|
||||
return cmdList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,51 +20,52 @@ import org.apache.cloudstack.framework.config.ConfigKey;
|
|||
|
||||
public interface QuotaConfig {
|
||||
|
||||
public static final ConfigKey<Boolean> QuotaPluginEnabled = new ConfigKey<Boolean>("Advanced", Boolean.class, "quota.enable.service", "false",
|
||||
"Indicates whether Quota plugin is enabled or not", true);
|
||||
public static final ConfigKey<Boolean> QuotaPluginEnabled = new ConfigKey<Boolean>("Advanced", Boolean.class, "quota.enable.service", "false",
|
||||
"Indicates whether Quota plugin is enabled or not", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaPeriodType = new ConfigKey<String>("Advanced", String.class, "quota.period.type", "2",
|
||||
"Quota period type: 1 for every x days, 2 for certain day of the month, 3 for yearly on activation day - default quota usage reporting cycl", true);
|
||||
public static final ConfigKey<String> QuotaPeriodType = new ConfigKey<String>("Advanced", String.class, "quota.period.type", "2",
|
||||
"Quota period type: 1 for every x days, 2 for certain day of the month, 3 for yearly on activation day - default quota usage reporting cycl", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaPeriod = new ConfigKey<String>("Advanced", String.class, "quota.period.config", "15",
|
||||
"The period config in number of days for the quota period type", true);
|
||||
public static final ConfigKey<String> QuotaPeriod = new ConfigKey<String>("Advanced", String.class, "quota.period.config", "15",
|
||||
"The period config in number of days for the quota period type", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaGenerateActivity = new ConfigKey<String>("Advanced", String.class, "quota.activity.generate", "true",
|
||||
"Set true to enable a detailed log of the quota usage, rating and billing activity, on daily basis. Valid values (true, false)", true);
|
||||
public static final ConfigKey<String> QuotaGenerateActivity = new ConfigKey<String>("Advanced", String.class, "quota.activity.generate", "true",
|
||||
"Set true to enable a detailed log of the quota usage, rating and billing activity, on daily basis. Valid values (true, false)", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaEmailRecordOutgoing = new ConfigKey<String>("Advanced", String.class, "quota.email.outgoing.record", "false",
|
||||
"true means all the emails sent out will be stored in local DB, by default it is false", true);
|
||||
public static final ConfigKey<String> QuotaEmailRecordOutgoing = new ConfigKey<String>("Advanced", String.class, "quota.email.outgoing.record", "false",
|
||||
"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);
|
||||
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);
|
||||
|
||||
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> 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);
|
||||
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);
|
||||
|
||||
public static final ConfigKey<String> QuotaLimitIncremental = new ConfigKey<String>("Advanced", String.class, "quota.limit.increment", "5",
|
||||
"Quota limit incremental", true);
|
||||
public static final ConfigKey<String> QuotaLimitIncremental = new ConfigKey<String>("Advanced", String.class, "quota.limit.increment", "5",
|
||||
"Quota limit incremental", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpHost = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.host", "",
|
||||
"Quota SMTP host for quota related emails", true);
|
||||
public static final ConfigKey<String> QuotaSmtpHost = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.host", "",
|
||||
"Quota SMTP host for quota related emails", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpTimeout = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.connection.timeout", "60",
|
||||
"Quota SMTP server connection timeout duration", true);
|
||||
public static final ConfigKey<String> QuotaSmtpTimeout = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.connection.timeout", "60",
|
||||
"Quota SMTP server connection timeout duration", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpUser = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.user", "",
|
||||
"Quota SMTP server username", true);
|
||||
public static final ConfigKey<String> QuotaSmtpUser = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.user", "",
|
||||
"Quota SMTP server username", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpPassword = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.password", "",
|
||||
"Quota SMTP server password", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpPort = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.port", "",
|
||||
"Quota SMTP port", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpAuthType = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.useAuth", "",
|
||||
"Quota SMTP authorization type", true);
|
||||
public static final ConfigKey<String> QuotaSmtpPassword = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.password", "",
|
||||
"Quota SMTP server password", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpPort = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.port", "",
|
||||
"Quota SMTP port", true);
|
||||
|
||||
public static final ConfigKey<String> QuotaSmtpAuthType = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.useAuth", "",
|
||||
"Quota SMTP authorization type", true);
|
||||
|
||||
enum QuotaEmailTemplateTypes {
|
||||
QUOTA_LOW, QUOTA_EMPTY
|
||||
}
|
||||
}
|
||||
|
|
@ -16,20 +16,12 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.quota.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import java.util.List;
|
||||
|
||||
public interface QuotaEmailTemplatesDao extends GenericDao<QuotaEmailTemplatesVO, Long> {
|
||||
|
||||
QuotaEmailTemplatesVO fetchTemplate(String templateName);
|
||||
|
||||
Pair<List<QuotaBalanceVO>, Integer> searchBalance(SearchCriteria<QuotaBalanceVO> sc, Filter filter);
|
||||
|
||||
List<QuotaEmailTemplatesVO> listAllQuotaEmailTemplates(String templateName);
|
||||
boolean updateQuotaEmailTemplate(QuotaEmailTemplatesVO template);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,33 +16,49 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.quota.dao;
|
||||
|
||||
import java.util.List;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Local(value = { QuotaEmailTemplatesDao.class })
|
||||
public class QuotaEmailTemplatesDaoImpl extends GenericDaoBase<QuotaEmailTemplatesVO, Long> implements QuotaEmailTemplatesDao {
|
||||
|
||||
@Override
|
||||
public QuotaEmailTemplatesVO fetchTemplate(String templateName) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
protected SearchBuilder<QuotaEmailTemplatesVO> QuotaEmailTemplateSearch;
|
||||
|
||||
public QuotaEmailTemplatesDaoImpl() {
|
||||
super();
|
||||
|
||||
QuotaEmailTemplateSearch = createSearchBuilder();
|
||||
QuotaEmailTemplateSearch.and("template_name", QuotaEmailTemplateSearch.entity().getTemplateName(), SearchCriteria.Op.EQ);
|
||||
QuotaEmailTemplateSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<QuotaBalanceVO>, Integer> searchBalance(SearchCriteria<QuotaBalanceVO> sc, Filter filter) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public List<QuotaEmailTemplatesVO> listAllQuotaEmailTemplates(String templateName) {
|
||||
final short opendb = TransactionLegacy.currentTxn().getDatabaseId();
|
||||
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
|
||||
SearchCriteria<QuotaEmailTemplatesVO> sc = QuotaEmailTemplateSearch.create();
|
||||
if (templateName != null) {
|
||||
sc.setParameters("template_name", templateName);
|
||||
}
|
||||
List<QuotaEmailTemplatesVO> result = this.listBy(sc);
|
||||
TransactionLegacy.open(opendb).close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateQuotaEmailTemplate(QuotaEmailTemplatesVO template) {
|
||||
final short opendb = TransactionLegacy.currentTxn().getDatabaseId();
|
||||
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
|
||||
final boolean result = this.update(template.getId(), template);
|
||||
TransactionLegacy.open(opendb).close();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class QuotaTariffDaoImpl extends GenericDaoBase<QuotaTariffVO, Long> impl
|
|||
final short opendb = TransactionLegacy.currentTxn().getDatabaseId();
|
||||
TransactionLegacy.open(TransactionLegacy.USAGE_DB).close(); // Switch to
|
||||
// Usage DB
|
||||
boolean result = this.update(plan.getId(), plan);
|
||||
final boolean result = this.update(plan.getId(), plan);
|
||||
TransactionLegacy.open(opendb).close(); // Switch back
|
||||
return result;
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ public class QuotaTariffDaoImpl extends GenericDaoBase<QuotaTariffVO, Long> impl
|
|||
TransactionLegacy.open(TransactionLegacy.USAGE_DB).close(); // Switch to
|
||||
// Usage DB
|
||||
plan.setId(null);
|
||||
QuotaTariffVO result = this.persist(plan);
|
||||
final QuotaTariffVO result = this.persist(plan);
|
||||
TransactionLegacy.open(opendb).close(); // Switch back
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,6 @@ import com.cloud.utils.component.Manager;
|
|||
|
||||
public interface QuotaManager extends Manager {
|
||||
|
||||
public boolean calculateQuotaUsage();
|
||||
boolean calculateQuotaUsage();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,11 +27,10 @@ import com.cloud.utils.Pair;
|
|||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.quota.constant.QuotaTypes;
|
||||
import org.apache.cloudstack.quota.dao.QuotaTariffDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaTariffDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaUsageDao;
|
||||
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
|
||||
|
|
@ -43,7 +42,6 @@ import org.springframework.stereotype.Component;
|
|||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
|
|
|
|||
|
|
@ -16,60 +16,54 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.quota.vo;
|
||||
|
||||
import java.util.Date;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "quota_email_templates")
|
||||
public class QuotaEmailTemplatesVO implements InternalIdentity {
|
||||
|
||||
private static final long serialVersionUID = -7117933842834553210L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "template_name")
|
||||
private String templateName;
|
||||
|
||||
@Column(name = "template_text")
|
||||
private String templateText;
|
||||
@Column(name = "template_subject")
|
||||
private String templateSubject;
|
||||
|
||||
@Column(name = "category")
|
||||
private Integer category;
|
||||
|
||||
@Column(name = "last_updated")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
private Date lastUpdated = null;
|
||||
@Column(name = "template_body")
|
||||
private String templateBody;
|
||||
|
||||
@Column(name = "locale")
|
||||
private String locale;
|
||||
|
||||
@Column(name = "version")
|
||||
private Integer version;
|
||||
@Column(name = "updated")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
private Date lastUpdated = null;
|
||||
|
||||
public QuotaEmailTemplatesVO() {
|
||||
}
|
||||
|
||||
public QuotaEmailTemplatesVO(String templateName, String templateText, String locale, Integer version) {
|
||||
public QuotaEmailTemplatesVO(String templateName, String templateSubject, String templateBody) {
|
||||
super();
|
||||
this.templateName = templateName;
|
||||
this.templateText = templateText;
|
||||
this.locale = locale;
|
||||
this.version = version;
|
||||
this.templateSubject = templateSubject;
|
||||
this.templateBody = templateBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
@ -81,20 +75,20 @@ public class QuotaEmailTemplatesVO implements InternalIdentity {
|
|||
this.templateName = templateName;
|
||||
}
|
||||
|
||||
public String getTemplateText() {
|
||||
return templateText;
|
||||
public String getTemplateSubject() {
|
||||
return templateSubject;
|
||||
}
|
||||
|
||||
public void setTemplateText(String templateText) {
|
||||
this.templateText = templateText;
|
||||
public void setTemplateSubject(String templateSubject) {
|
||||
this.templateSubject = templateSubject;
|
||||
}
|
||||
|
||||
public Integer getCategory() {
|
||||
return category;
|
||||
public String getTemplateBody() {
|
||||
return templateBody;
|
||||
}
|
||||
|
||||
public void setCategory(Integer version) {
|
||||
this.category = category;
|
||||
public void setTemplateBody(String templateBody) {
|
||||
this.templateBody = templateBody;
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
|
|
@ -112,13 +106,4 @@ public class QuotaEmailTemplatesVO implements InternalIdentity {
|
|||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public Integer getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Integer version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,15 +119,19 @@ CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_balance` (
|
|||
|
||||
CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_email_templates` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`template_name` varchar(64) DEFAULT NULL,
|
||||
`template_text` longtext,
|
||||
`category` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
`last_updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`template_name` varchar(64) NOT NULL UNIQUE,
|
||||
`template_subject` longtext,
|
||||
`template_body` longtext,
|
||||
`locale` varchar(25) DEFAULT 'en_US',
|
||||
`version` int(11) DEFAULT '0',
|
||||
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
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');
|
||||
UNLOCK TABLES;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_sent_emails` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
|||
Loading…
Reference in New Issue