diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 76818a768a7..911b2acbe7d 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -784,11 +784,13 @@ addGloboDnsHost=1
### Quota Service
listQuotaConfigurations=15
+quotaRefresh=15
quotaCredits=15
quotaStatement=15
-quotaEmailTemplateUpdate=3
-quotaEmailTemplateDelete=3
-quotaEmailTemplateAdd=3
-quotaReports=3
+quotaEmailTemplateUpdate=15
+quotaEmailTemplateDelete=15
+quotaEmailTemplateAdd=15
+quotaReports=15
+
diff --git a/plugins/database/quota/resources/META-INF/cloudstack/quota/spring-quota-context.xml b/plugins/database/quota/resources/META-INF/cloudstack/quota/spring-quota-context.xml
index b0cd3ca2ca3..331a10c8080 100644
--- a/plugins/database/quota/resources/META-INF/cloudstack/quota/spring-quota-context.xml
+++ b/plugins/database/quota/resources/META-INF/cloudstack/quota/spring-quota-context.xml
@@ -27,6 +27,10 @@
+
+
+
+
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java
index a14f5cf1693..6b408d3519a 100644
--- a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java
@@ -22,7 +22,7 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.DomainResponse;
@@ -30,87 +30,85 @@ import org.apache.cloudstack.api.response.QuotaCreditsResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.quota.QuotaManager;
+import com.cloud.user.Account;
@APICommand(name = "quotaCredits", responseObject = QuotaCreditsResponse.class, description = "Add +-credits to an account", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class QuotaCreditsCmd extends BaseListCmd {
+public class QuotaCreditsCmd extends BaseCmd {
-public static final Logger s_logger = Logger
- .getLogger(QuotaStatementCmd.class.getName());
+ public static final Logger s_logger = Logger
+ .getLogger(QuotaStatementCmd.class.getName());
-private static final String s_name = "quotacreditsresponse";
+ private static final String s_name = "quotacreditsresponse";
-@Inject
-private QuotaManager _quotaManager;
+ @Inject
+ private QuotaManager _quotaManager;
-@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Account Id for which quota credits need to be added")
-private String accountName;
+ @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Account Id for which quota credits need to be added")
+ private String accountName;
-@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added")
-private Long domainId;
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added")
+ private Long domainId;
+ @Parameter(name = ApiConstants.VALUE, type = CommandType.INTEGER, entityType = DomainResponse.class, description = "Value of the credits to be added+, subtracted-")
+ private Integer value;
-@Parameter(name = ApiConstants.VALUE, type = CommandType.INTEGER, entityType = DomainResponse.class, description = "Value of the credits to be added+, subtracted-")
-private Integer value;
-
-
-public String getAccountName() {
- return accountName;
-}
-
-
-public void setAccountName(String accountName) {
- this.accountName = accountName;
-}
-
-
-public Long getDomainId() {
- return domainId;
-}
-
-
-public void setDomainId(Long domainId) {
- this.domainId = domainId;
-}
-
-
-public Integer getValue() {
- return value;
-}
-
-
-public void setValue(Integer value) {
- this.value = value;
-}
-
-
-public QuotaCreditsCmd() {
- super();
-}
-
-
-public QuotaCreditsCmd(final QuotaManager quotaManager) {
- super();
- _quotaManager = quotaManager;
-}
-
-
-@Override
-public String getCommandName() {
- return s_name;
-}
-
-
-@Override
-public void execute() {
- Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
- if (accountId==null){
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "The account does not exists or has been removed/disabled");
+ public String getAccountName() {
+ return accountName;
}
- final QuotaCreditsResponse credit_response = _quotaManager.addQuotaCredits(accountId, domainId, value, CallContext.current().getCallingAccount().getId());
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
- setResponseObject(credit_response);
-}
+ public Long getDomainId() {
+ return domainId;
+ }
+ public void setDomainId(Long domainId) {
+ this.domainId = domainId;
+ }
+
+ public Integer getValue() {
+ return value;
+ }
+
+ public void setValue(Integer value) {
+ this.value = value;
+ }
+
+ public QuotaCreditsCmd() {
+ super();
+ }
+
+ public QuotaCreditsCmd(final QuotaManager quotaManager) {
+ super();
+ _quotaManager = quotaManager;
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() {
+ Long accountId = _accountService.finalyzeAccountId(accountName,
+ domainId, null, true);
+ if (accountId == null) {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
+ "The account does not exists or has been removed/disabled");
+ }
+
+ final QuotaCreditsResponse credit_response = _quotaManager
+ .addQuotaCredits(accountId, domainId, value, CallContext
+ .current().getCallingAccount().getId());
+
+ setResponseObject(credit_response);
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
}
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaRefreshCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaRefreshCmd.java
new file mode 100644
index 00000000000..9696aef773f
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaRefreshCmd.java
@@ -0,0 +1,67 @@
+//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 javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.QuotaRefreshResponse;
+import org.apache.cloudstack.quota.QuotaManager;
+
+import com.cloud.user.Account;
+
+@APICommand(name = "quotaRefresh", responseObject = QuotaRefreshResponse.class, description = "Refresh the quota for all accounts if enabled", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaRefreshCmd extends BaseCmd {
+
+ public static final Logger s_logger = Logger
+ .getLogger(QuotaStatementCmd.class.getName());
+
+ private static final String s_name = "quotarefreshresponse";
+
+ @Inject
+ private QuotaManager _quotaManager;
+
+ public QuotaRefreshCmd() {
+ super();
+ }
+
+ public QuotaRefreshCmd(final QuotaManager quotaManager) {
+ super();
+ _quotaManager = quotaManager;
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() throws ServerApiException {
+ final QuotaRefreshResponse response = new QuotaRefreshResponse(
+ "Success");
+ setResponseObject(response);
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+}
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaCreditsResponse.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaCreditsResponse.java
index 2eedb06ca02..0a24348bc36 100644
--- a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaCreditsResponse.java
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaCreditsResponse.java
@@ -20,38 +20,25 @@ import java.sql.Timestamp;
import com.google.gson.annotations.SerializedName;
-import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.quota.QuotaCreditsVO;
import com.cloud.serializer.Param;
public class QuotaCreditsResponse extends BaseResponse {
- @SerializedName(ApiConstants.ID)
- @Param(description = "the ID of the credit")
- private String id;
-
- @SerializedName(ApiConstants.ACCOUNT)
- @Param(description = "the account name of the api remaining count")
- private String accountName;
-
- @SerializedName(ApiConstants.DOMAIN_ID)
- @Param(description = "the domain ID of the iam policy")
- private String domainId;
-
@SerializedName("credits")
@Param(description = "the credit deposited")
- private String credits;
+ private Integer credits;
@SerializedName("balance")
@Param(description = "the balance credit in account")
- private String balance;
+ private Integer balance;
@SerializedName("updated_by")
@Param(description = "the account name of the admin who updated the credits")
private String updatedBy;
-
@SerializedName("updated_on")
@Param(description = "the account name of the admin who updated the credits")
private Timestamp updatedOn;
@@ -61,52 +48,34 @@ public class QuotaCreditsResponse extends BaseResponse {
super();
}
- public String getId() {
- return id;
- }
+
+ public QuotaCreditsResponse(QuotaCreditsVO result) {
+ super();
+ if (result != null){
+ this.credits = 100;
+ this.balance = 200;
+ this.updatedBy = "1";
+ this.updatedOn = new Timestamp(System.currentTimeMillis());
+ }
+ }
- public void setId(String id) {
- this.id = id;
- }
-
-
- public String getAccountName() {
- return accountName;
- }
-
-
- public void setAccountName(String accountName) {
- this.accountName = accountName;
- }
-
-
- public String getDomainId() {
- return domainId;
- }
-
-
- public void setDomainId(String domainId) {
- this.domainId = domainId;
- }
-
-
- public String getCredits() {
+ public Integer getCredits() {
return credits;
}
- public void setCredits(String credits) {
+ public void setCredits(Integer credits) {
this.credits = credits;
}
- public String getBalance() {
+ public Integer getBalance() {
return balance;
}
- public void setBalance(String balance) {
+ public void setBalance(Integer balance) {
this.balance = balance;
}
@@ -131,5 +100,4 @@ public class QuotaCreditsResponse extends BaseResponse {
}
-
}
\ No newline at end of file
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaRefreshResponse.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaRefreshResponse.java
new file mode 100644
index 00000000000..0e58ca4578d
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaRefreshResponse.java
@@ -0,0 +1,49 @@
+//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.response;
+
+import org.apache.cloudstack.api.BaseResponse;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class QuotaRefreshResponse extends BaseResponse {
+
+
+ @SerializedName("result")
+ @Param(description = "Execution result for the quota refresh command")
+ private String result;
+
+
+ public QuotaRefreshResponse() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public QuotaRefreshResponse(String result) {
+ super();
+ this.result = result;
+ }
+ public String getResult() {
+ return result;
+ }
+
+ public void setResult(String result) {
+ this.result = result;
+ }
+
+}
diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java b/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java
index 0a72c31ae30..3fb035991b8 100644
--- a/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java
+++ b/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java
@@ -24,6 +24,10 @@ import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.command.ListQuotaConfigurationsCmd;
+import org.apache.cloudstack.api.command.QuotaCreditsCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateAddCmd;
+import org.apache.cloudstack.api.command.QuotaRefreshCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
import org.apache.cloudstack.api.response.QuotaConfigurationResponse;
import org.apache.cloudstack.api.response.QuotaCreditsResponse;
import org.apache.cloudstack.quota.dao.QuotaConfigurationDao;
@@ -32,6 +36,7 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.utils.Pair;
+import com.cloud.utils.db.TransactionLegacy;
@Component
@Local(value = QuotaManager.class)
@@ -59,12 +64,17 @@ private QuotaCreditsDao _quotaCreditsDao;
public List> getCommands() {
final List> cmdList = new ArrayList>();
cmdList.add(ListQuotaConfigurationsCmd.class);
+ cmdList.add(QuotaCreditsCmd.class);
+ cmdList.add(QuotaEmailTemplateAddCmd.class);
+ cmdList.add(QuotaRefreshCmd.class);
+ cmdList.add(QuotaStatementCmd.class);
return cmdList;
}
@Override
public Pair, Integer> listConfigurations(final ListQuotaConfigurationsCmd cmd) {
final Pair, Integer> result = _quotaConfigurationDao.searchConfigurations();
+ TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
return result;
}
@@ -83,10 +93,17 @@ private QuotaCreditsDao _quotaCreditsDao;
@Override
public QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Integer amount, Long updatedBy) {
- QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, amount, updatedBy);
- credits.setUpdatedOn(new Date());
- _quotaCreditsDao.persist(credits);
- return null;
+ QuotaCreditsVO result=null;
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+ try {
+ QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, amount, updatedBy);
+ credits.setUpdatedOn(new Date());
+ result = _quotaCreditsDao.persist(credits);
+ } finally {
+ txn.close();
+ }
+ TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
+ return new QuotaCreditsResponse(result);
}
diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaConfigurationDaoImpl.java b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaConfigurationDaoImpl.java
index eafc9eace99..cd2e5358e16 100644
--- a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaConfigurationDaoImpl.java
+++ b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaConfigurationDaoImpl.java
@@ -27,6 +27,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
@Component
@Local(value = {QuotaConfigurationDao.class})
@@ -54,9 +55,14 @@ public class QuotaConfigurationDaoImpl extends GenericDaoBase, Integer> searchConfigurations() {
- final SearchCriteria sc = listAllIncludedUsageType.create();
- sc.setParameters("include", 1);
- return searchAndCount(sc, null);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+ try {
+ final SearchCriteria sc = listAllIncludedUsageType.create();
+ sc.setParameters("include", 1);
+ return searchAndCount(sc, null);
+ } finally {
+ txn.close();
+ }
}
diff --git a/setup/db/db/schema-451to452.sql b/setup/db/db/schema-451to452.sql
index 97c8934bbe1..6ce1e162f24 100644
--- a/setup/db/db/schema-451to452.sql
+++ b/setup/db/db/schema-451to452.sql
@@ -114,6 +114,7 @@ CREATE TABLE `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,
`locale` varchar(25) DEFAULT 'en_US',
`version` int(11) DEFAULT '0',