You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2015/12/07 19:25:34 UTC
[4/8] git commit: updated refs/heads/master to 24d0609
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/framework/quota/test/org/apache/cloudstack/quota/QuotaStatementTest.java
----------------------------------------------------------------------
diff --git a/framework/quota/test/org/apache/cloudstack/quota/QuotaStatementTest.java b/framework/quota/test/org/apache/cloudstack/quota/QuotaStatementTest.java
new file mode 100644
index 0000000..f2a0ded
--- /dev/null
+++ b/framework/quota/test/org/apache/cloudstack/quota/QuotaStatementTest.java
@@ -0,0 +1,255 @@
+// 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.quota;
+
+import com.cloud.user.AccountVO;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.db.TransactionLegacy;
+import junit.framework.TestCase;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.quota.QuotaStatementImpl.STATEMENT_PERIODS;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.dao.QuotaAccountDao;
+import org.apache.cloudstack.quota.dao.QuotaUsageDao;
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import javax.mail.MessagingException;
+import javax.naming.ConfigurationException;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QuotaStatementTest extends TestCase {
+
+ @Mock
+ AccountDao accountDao;
+ @Mock
+ QuotaAccountDao quotaAcc;
+ @Mock
+ ConfigurationDao configDao;
+ @Mock
+ QuotaUsageDao quotaUsage;
+ @Mock
+ QuotaAlertManager alertManager;
+
+ @Spy
+ QuotaStatementImpl quotaStatement = new QuotaStatementImpl();
+
+ private void injectMockToField(Object mock, String fieldName) throws NoSuchFieldException, IllegalAccessException {
+ Field f = QuotaStatementImpl.class.getDeclaredField(fieldName);
+ f.setAccessible(true);
+ f.set(quotaStatement, mock);
+ }
+
+ @Before
+ public void setup() throws IllegalAccessException, NoSuchFieldException, ConfigurationException {
+ // Dummy transaction stack setup
+ TransactionLegacy.open("QuotaStatementImplTest");
+
+ injectMockToField(accountDao, "_accountDao");
+ injectMockToField(quotaAcc, "_quotaAcc");
+ injectMockToField(configDao, "_configDao");
+ injectMockToField(quotaUsage, "_quotaUsage");
+ injectMockToField(alertManager, "_quotaAlert");
+ }
+
+ @Test
+ public void testStatementPeriodBIMONTHLY() {
+ Calendar date = Calendar.getInstance();
+
+ //BIMONTHLY - first statement of month
+ date.set(Calendar.DATE, QuotaStatementImpl.s_LAST_STATEMENT_SENT_DAYS + 1);
+ Calendar period[] = quotaStatement.statementTime(date, STATEMENT_PERIODS.BIMONTHLY);
+ assertTrue(period == null);
+
+ //1 of this month
+ date.set(Calendar.DATE, 1);
+ period = quotaStatement.statementTime(date, STATEMENT_PERIODS.BIMONTHLY);
+ assertTrue(period != null);
+ assertTrue(period.length == 2);
+ assertTrue(period[0].toString(), period[0].before(period[1]));
+ assertTrue(period[0].toString(), period[0].get(Calendar.DATE) == 1);
+ assertTrue(period[1].toString(), period[1].get(Calendar.DATE) == 15);
+
+ //BIMONTHLY - second statement of month
+ date = Calendar.getInstance();
+ date.set(Calendar.DATE, QuotaStatementImpl.s_LAST_STATEMENT_SENT_DAYS + 16);
+ period = quotaStatement.statementTime(date, STATEMENT_PERIODS.BIMONTHLY);
+ assertTrue(period == null);
+
+ //17 of this month
+ date.set(Calendar.DATE, 17);
+ period = quotaStatement.statementTime(date, STATEMENT_PERIODS.BIMONTHLY);
+ assertTrue(period != null);
+ assertTrue(period.length == 2);
+ assertTrue(period[0].toString(), period[0].before(period[1]));
+ assertTrue(period[0].toString(), period[0].get(Calendar.DATE) == 16);
+
+ //get last day of the previous month
+ Calendar aCalendar = Calendar.getInstance();
+ aCalendar.add(Calendar.MONTH, -1);
+ aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH) + 1);
+
+ assertTrue(period[1].toString(), period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE));
+
+ }
+
+ @Test
+ public void testStatementPeriodMONTHLY() {
+ Calendar date = Calendar.getInstance();
+ Calendar aCalendar = Calendar.getInstance();
+
+ //MONTHLY
+ date = Calendar.getInstance();
+ date.set(Calendar.DATE, QuotaStatementImpl.s_LAST_STATEMENT_SENT_DAYS + 1);
+ Calendar period[] = quotaStatement.statementTime(date, STATEMENT_PERIODS.MONTHLY);
+ assertTrue(period == null);
+
+ //1 of this month
+ date.set(Calendar.DATE, QuotaStatementImpl.s_LAST_STATEMENT_SENT_DAYS - 1);
+ period = quotaStatement.statementTime(date, STATEMENT_PERIODS.MONTHLY);
+ assertTrue(period != null);
+ assertTrue(period.length == 2);
+ assertTrue(period[0].toString(), period[0].before(period[1]));
+ assertTrue(period[0].toString(), period[0].get(Calendar.DATE) == 1);
+
+ //get last day of the previous month
+ aCalendar = Calendar.getInstance();
+ aCalendar.add(Calendar.MONTH, -1);
+ aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH) + 1);
+
+ assertTrue(period[1].toString(), period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE));
+
+ }
+
+ @Test
+ public void testStatementPeriodQUATERLY() {
+ Calendar date = Calendar.getInstance();
+ Calendar aCalendar = Calendar.getInstance();
+
+ //QUATERLY
+ date = Calendar.getInstance();
+ date.set(Calendar.MONTH, Calendar.JANUARY); // 1 Jan
+ date.set(Calendar.DATE, 1);
+ Calendar period[] = quotaStatement.statementTime(date, STATEMENT_PERIODS.QUATERLY);
+ assertTrue(period != null);
+ assertTrue(period.length == 2);
+ assertTrue("period[0].before(period[1])" + period[0].toString(), period[0].before(period[1]));
+ assertTrue("period[0].get(Calendar.DATE) == 1" + period[0].toString(), period[0].get(Calendar.DATE) == 1);
+ assertTrue("period[0].get(Calendar.MONTH) == Calendar.OCTOBER" + period[0].toString(), period[0].get(Calendar.MONTH) == Calendar.OCTOBER); //october
+
+ //get last day of the previous month
+ aCalendar = Calendar.getInstance();
+ aCalendar.set(Calendar.MONTH, Calendar.DECEMBER);
+ aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH) + 1);
+ assertTrue(" period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE)" + period[1].toString(), period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE));
+ assertTrue("period[1].get(Calendar.MONTH) == aCalendar.get(Calendar.MONTH)" + period[1].toString(), period[1].get(Calendar.MONTH) == aCalendar.get(Calendar.MONTH));
+
+ }
+
+ @Test
+ public void testStatementPeriodHALFYEARLY() {
+ Calendar date = Calendar.getInstance();
+ Calendar aCalendar = Calendar.getInstance();
+
+ //QUATERLY
+ date = Calendar.getInstance();
+ date.set(Calendar.MONTH, Calendar.JANUARY); // 1 Jan
+ date.set(Calendar.DATE, 1);
+ Calendar period[] = quotaStatement.statementTime(date, STATEMENT_PERIODS.HALFYEARLY);
+ assertTrue(period != null);
+ assertTrue(period.length == 2);
+ assertTrue("period[0].before(period[1])" + period[0].toString(), period[0].before(period[1]));
+ assertTrue("period[0].get(Calendar.DATE) == 1" + period[0].toString(), period[0].get(Calendar.DATE) == 1);
+ assertTrue("period[0].get(Calendar.MONTH) == Calendar.JULY" + period[0].toString(), period[0].get(Calendar.MONTH) == Calendar.JULY); //july
+
+ //get last day of the previous month
+ aCalendar = Calendar.getInstance();
+ aCalendar.set(Calendar.MONTH, Calendar.DECEMBER);
+ aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH) + 1);
+ assertTrue(" period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE)" + period[1].toString(), period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE));
+ assertTrue("period[1].get(Calendar.MONTH) == aCalendar.get(Calendar.MONTH)" + period[1].toString(), period[1].get(Calendar.MONTH) == aCalendar.get(Calendar.MONTH));
+
+ }
+
+ @Test
+ public void testStatementPeriodYEARLY() {
+ Calendar date = Calendar.getInstance();
+ Calendar aCalendar = Calendar.getInstance();
+
+ //QUATERLY
+ date = Calendar.getInstance();
+ date.set(Calendar.MONTH, Calendar.JANUARY); // 1 Jan
+ date.set(Calendar.DATE, 1);
+ Calendar period[] = quotaStatement.statementTime(date, STATEMENT_PERIODS.YEARLY);
+ assertTrue("period != null", period != null);
+ assertTrue(period.length == 2);
+ assertTrue("period[0].before(period[1])" + period[0].toString(), period[0].before(period[1]));
+ assertTrue("period[0].get(Calendar.DATE) == 1" + period[0].toString(), period[0].get(Calendar.DATE) == 1);
+ assertTrue("period[0].get(Calendar.MONTH) == Calendar.JANUARY" + period[0].toString(), period[0].get(Calendar.MONTH) == Calendar.JANUARY); //january
+
+ //get last day of the previous month
+ aCalendar = Calendar.getInstance();
+ aCalendar.set(Calendar.MONTH, Calendar.DECEMBER);
+ aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH) + 1);
+ assertTrue(" period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE)" + period[1].toString(), period[1].get(Calendar.DATE) == aCalendar.get(Calendar.DATE));
+ assertTrue("period[1].get(Calendar.MONTH) == aCalendar.get(Calendar.MONTH)" + period[1].toString(), period[1].get(Calendar.MONTH) == aCalendar.get(Calendar.MONTH));
+
+ }
+
+ @Test
+ public void testSendStatement() throws UnsupportedEncodingException, MessagingException {
+ Calendar date = Calendar.getInstance();
+ AccountVO accountVO = new AccountVO();
+ accountVO.setId(2L);
+ accountVO.setDomainId(1L);
+ Mockito.when(accountDao.findById(Mockito.anyLong())).thenReturn(accountVO);
+
+ QuotaAccountVO acc = new QuotaAccountVO(2L);
+ acc.setQuotaBalance(new BigDecimal(404));
+ acc.setLastStatementDate(null);
+ List<QuotaAccountVO> accounts = new ArrayList<>();
+ accounts.add(acc);
+ Mockito.when(quotaAcc.listAllQuotaAccount()).thenReturn(accounts);
+
+ Mockito.when(quotaUsage.findTotalQuotaUsage(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.any(Date.class), Mockito.any(Date.class)))
+ .thenReturn(new BigDecimal(100));
+
+ QuotaAlertManagerImpl.DeferredQuotaEmail email = new QuotaAlertManagerImpl.DeferredQuotaEmail(accountVO, acc, new BigDecimal(100),
+ QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW);
+ // call real method on send monthly statement
+ Mockito.doCallRealMethod().when(quotaStatement).sendStatement();
+ Calendar period[] = quotaStatement.statementTime(date, STATEMENT_PERIODS.MONTHLY);
+ if (period != null){
+ Mockito.verify(alertManager, Mockito.times(1)).sendQuotaAlert(email);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/framework/quota/test/org/apache/cloudstack/quota/constant/QuotaTypesTest.java
----------------------------------------------------------------------
diff --git a/framework/quota/test/org/apache/cloudstack/quota/constant/QuotaTypesTest.java b/framework/quota/test/org/apache/cloudstack/quota/constant/QuotaTypesTest.java
new file mode 100644
index 0000000..4270439
--- /dev/null
+++ b/framework/quota/test/org/apache/cloudstack/quota/constant/QuotaTypesTest.java
@@ -0,0 +1,48 @@
+// 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.quota.constant;
+
+import junit.framework.TestCase;
+
+import org.apache.cloudstack.api.response.UsageTypeResponse;
+import org.apache.cloudstack.usage.UsageTypes;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.List;
+import java.util.Map;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QuotaTypesTest extends TestCase {
+
+ @Test
+ public void testQuotaTypesList() {
+ Map<Integer, QuotaTypes> quotaTypes = QuotaTypes.listQuotaTypes();
+ List<UsageTypeResponse> usageTypesResponseList = UsageTypes.listUsageTypes();
+ for (UsageTypeResponse usageTypeResponse : usageTypesResponseList) {
+ final Integer usageTypeInt = usageTypeResponse.getUsageType();
+ assertTrue(quotaTypes.containsKey(usageTypeInt));
+ }
+ }
+
+ @Test
+ public void testQuotaTypeDescription() {
+ assertNull(QuotaTypes.getDescription(-1));
+ assertNotNull(QuotaTypes.getDescription(QuotaTypes.MEMORY));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/database/quota/pom.xml b/plugins/database/quota/pom.xml
new file mode 100644
index 0000000..ee0a04b
--- /dev/null
+++ b/plugins/database/quota/pom.xml
@@ -0,0 +1,99 @@
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>cloud-plugin-database-quota</artifactId>
+ <name>Apache CloudStack Plugin - Quota Service</name>
+ <parent>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloudstack-plugins</artifactId>
+ <version>4.7.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-engine-schema</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-framework-quota</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${cs.commons-lang3.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>${cs.joda-time.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${cs.junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>${cs.hamcrest.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>${cs.mockito.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${cs.powermock.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>${cs.powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${org.springframework.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/resources/META-INF/cloudstack/quota/module.properties
----------------------------------------------------------------------
diff --git a/plugins/database/quota/resources/META-INF/cloudstack/quota/module.properties b/plugins/database/quota/resources/META-INF/cloudstack/quota/module.properties
new file mode 100644
index 0000000..7332f15
--- /dev/null
+++ b/plugins/database/quota/resources/META-INF/cloudstack/quota/module.properties
@@ -0,0 +1,18 @@
+# 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.
+name=quota
+parent=api
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/resources/META-INF/cloudstack/quota/spring-quota-context.xml
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..15bc144
--- /dev/null
+++ b/plugins/database/quota/resources/META-INF/cloudstack/quota/spring-quota-context.xml
@@ -0,0 +1,31 @@
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <bean id="QuotaService" class="org.apache.cloudstack.quota.QuotaServiceImpl" />
+ <bean id="QuotaResponseBuilder" class="org.apache.cloudstack.api.response.QuotaResponseBuilderImpl"/>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaBalanceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaBalanceCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaBalanceCmd.java
new file mode 100644
index 0000000..ef9d49a
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaBalanceCmd.java
@@ -0,0 +1,125 @@
+//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 java.util.Date;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.QuotaBalanceResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.api.response.QuotaStatementItemResponse;
+
+@APICommand(name = "quotaBalance", responseObject = QuotaStatementItemResponse.class, description = "Create a quota balance statement", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaBalanceCmd extends BaseCmd {
+
+ public static final Logger s_logger = Logger.getLogger(QuotaBalanceCmd.class);
+
+ private static final String s_name = "quotabalanceresponse";
+
+ @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which statement needs to be generated")
+ private String accountName;
+
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "If domain Id is given and the caller is domain admin then the statement is generated for domain.")
+ private Long domainId;
+
+ @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "End date range for quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.")
+ private Date endDate;
+
+ @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "Start date range quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.")
+ private Date startDate;
+
+ @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account")
+ private Long accountId;
+
+ @Inject
+ QuotaResponseBuilder _responseBuilder;
+
+ public Long getAccountId() {
+ return accountId;
+ }
+
+ public void setAccountId(Long accountId) {
+ this.accountId = accountId;
+ }
+
+ 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 Date getEndDate() {
+ return endDate == null ? null : _responseBuilder.startOfNextDay(endDate == null ? null : new Date(endDate.getTime()));
+ }
+
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate == null ? null : new Date(endDate.getTime());
+ }
+
+ public Date getStartDate() {
+ return startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return _accountService.getActiveAccountByName(accountName, domainId).getAccountId();
+ }
+
+ @Override
+ public void execute() {
+ List<QuotaBalanceVO> quotaUsage = _responseBuilder.getQuotaBalance(this);
+
+ QuotaBalanceResponse response;
+ if (getEndDate() == null) {
+ response = _responseBuilder.createQuotaLastBalanceResponse(quotaUsage, getStartDate());
+ } else {
+ response = _responseBuilder.createQuotaBalanceResponse(quotaUsage, getStartDate(), endDate == null ? null : new Date(endDate.getTime()));
+ }
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..ce00e23
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java
@@ -0,0 +1,147 @@
+//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.ApiConstants;
+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.DomainResponse;
+import org.apache.cloudstack.api.response.QuotaCreditsResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+@APICommand(name = "quotaCredits", responseObject = QuotaCreditsResponse.class, description = "Add +-credits to an account", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaCreditsCmd extends BaseCmd {
+
+ @Inject
+ QuotaResponseBuilder _responseBuilder;
+
+ @Inject
+ QuotaService _quotaService;
+
+ public static final Logger s_logger = Logger.getLogger(QuotaStatementCmd.class);
+
+ private static final String s_name = "quotacreditsresponse";
+
+ @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which quota credits need to be added")
+ private String accountName;
+
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added")
+ private Long domainId;
+
+ @Parameter(name = ApiConstants.VALUE, type = CommandType.DOUBLE, required = true, description = "Value of the credits to be added+, subtracted-")
+ private Double value;
+
+ @Parameter(name = "min_balance", type = CommandType.DOUBLE, required = false, description = "Minimum balance threshold of the account")
+ private Double minBalance;
+
+ @Parameter(name = "quota_enforce", type = CommandType.BOOLEAN, required = false, description = "Account for which quota enforce is set to false will not be locked when there is no credit balance")
+ private Boolean quotaEnforce;
+
+ public Double getMinBalance() {
+ return minBalance;
+ }
+
+ public void setMinBalance(Double minBalance) {
+ this.minBalance = minBalance;
+ }
+
+ public Boolean getQuotaEnforce() {
+ return quotaEnforce;
+ }
+
+ public void setQuotaEnforce(Boolean quotaEnforce) {
+ this.quotaEnforce = quotaEnforce;
+ }
+
+ 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 Double getValue() {
+ return value;
+ }
+
+ public void setValue(Double value) {
+ this.value = value;
+ }
+
+ public QuotaCreditsCmd() {
+ super();
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() {
+ Long accountId = null;
+ Account account = _accountService.getActiveAccountByName(accountName, domainId);
+ if (account != null) {
+ accountId = account.getAccountId();
+ }
+ if (accountId == null) {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "The account does not exists or has been removed/disabled");
+ }
+ if (getValue() == null) {
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please send a valid non-empty quota value");
+ }
+ if (getQuotaEnforce() != null && getQuotaEnforce()) {
+ _quotaService.setLockAccount(accountId, getQuotaEnforce());
+ }
+ if (getMinBalance() != null) {
+ _quotaService.setMinBalance(accountId, getMinBalance());
+ }
+ else {
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please set a value for min balance");
+ }
+
+ final QuotaCreditsResponse response = _responseBuilder.addQuotaCredits(accountId, getDomainId(), getValue(), CallContext.current().getCallingUserId());
+ response.setResponseName(getCommandName());
+ response.setObjectName("quotacredits");
+ setResponseObject(response);
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java
new file mode 100644
index 0000000..8b717eb
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java
@@ -0,0 +1,60 @@
+//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);
+ 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;
+ }
+
+ public void setTemplateName(String templateName) {
+ this.templateName = 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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java
new file mode 100644
index 0000000..469fd4d
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java
@@ -0,0 +1,122 @@
+//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.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaEmailTemplateUpdateCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateUpdateCmd.class);
+ 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, max: 77 characters", length = 77)
+ private String templateSubject;
+
+ @Parameter(name = "templatebody", type = CommandType.STRING, required=true, description = "The quota email template body, max: 500k characters", length = 512000)
+ 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;
+ }
+
+ public 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;
+ }
+
+ public void setTemplateSubject(String templateSubject) {
+ this.templateSubject = templateSubject;
+ }
+
+ public void setTemplateBody(String templateBody) {
+ this.templateBody = templateBody;
+ }
+
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaStatementCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaStatementCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaStatementCmd.java
new file mode 100644
index 0000000..fa97960
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaStatementCmd.java
@@ -0,0 +1,141 @@
+//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 java.util.Date;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.api.response.QuotaStatementResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.quota.vo.QuotaUsageVO;
+import org.apache.cloudstack.api.response.QuotaStatementItemResponse;
+
+import com.cloud.user.Account;
+
+@APICommand(name = "quotaStatement", responseObject = QuotaStatementItemResponse.class, description = "Create a quota statement", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaStatementCmd extends BaseCmd {
+
+ public static final Logger s_logger = Logger.getLogger(QuotaStatementCmd.class);
+
+ private static final String s_name = "quotastatementresponse";
+
+ @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Optional, Account Id for which statement needs to be generated")
+ private String accountName;
+
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "Optional, If domain Id is given and the caller is domain admin then the statement is generated for domain.")
+ private Long domainId;
+
+ @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = true, description = "End date range for quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.")
+ private Date endDate;
+
+ @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "Start date range quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.")
+ private Date startDate;
+
+ @Parameter(name = ApiConstants.TYPE, type = CommandType.INTEGER, description = "List quota usage records for the specified usage type")
+ private Integer usageType;
+
+ @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account")
+ private Long accountId;
+
+ @Inject
+ QuotaResponseBuilder _responseBuilder;
+
+ public Long getAccountId() {
+ return accountId;
+ }
+
+ public void setAccountId(Long accountId) {
+ this.accountId = accountId;
+ }
+
+ public Integer getUsageType() {
+ return usageType;
+ }
+
+ public void setUsageType(Integer usageType) {
+ this.usageType = usageType;
+ }
+
+ 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 Date getEndDate() {
+ return _responseBuilder.startOfNextDay(endDate == null ? new Date() : new Date(endDate.getTime()));
+ }
+
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate == null ? null : new Date(endDate.getTime());
+ }
+
+ public Date getStartDate() {
+ return startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = _accountService.getActiveAccountByName(accountName, domainId).getAccountId();
+ if (accountId == null) {
+ return CallContext.current().getCallingAccount().getId();
+ }
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute() {
+ List<QuotaUsageVO> quotaUsage = _responseBuilder.getQuotaUsage(this);
+
+ QuotaStatementResponse response = _responseBuilder.createQuotaStatementResponse(quotaUsage);
+ response.setStartDate(startDate == null ? null : new Date(startDate.getTime()));
+ response.setEndDate(endDate == null ? null : new Date(endDate.getTime()));
+
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaSummaryCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaSummaryCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaSummaryCmd.java
new file mode 100644
index 0000000..773bac6
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaSummaryCmd.java
@@ -0,0 +1,110 @@
+//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.ApiConstants;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.BaseCmd.CommandType;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.api.response.QuotaSummaryResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+@APICommand(name = "quotaSummary", responseObject = QuotaSummaryResponse.class, description = "Lists balance and quota usage for all accounts", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaSummaryCmd extends BaseListCmd {
+ public static final Logger s_logger = Logger.getLogger(QuotaSummaryCmd.class);
+ private static final String s_name = "quotasummaryresponse";
+
+ @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = false, description = "Optional, Account Id for which statement needs to be generated")
+ private String accountName;
+
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = false, entityType = DomainResponse.class, description = "Optional, If domain Id is given and the caller is domain admin then the statement is generated for domain.")
+ private Long domainId;
+
+ @Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, required = false, description = "Optional, to list all accounts irrespective of the quota activity")
+ private Boolean listAll;
+
+ @Inject
+ QuotaResponseBuilder _responseBuilder;
+
+ public QuotaSummaryCmd() {
+ super();
+ }
+
+ @Override
+ public void execute() {
+ Account caller = CallContext.current().getCallingAccount();
+ List<QuotaSummaryResponse> responses;
+ if (caller.getAccountId() <= 2) { //non root admin or system
+ if (getAccountName() != null && getDomainId() != null)
+ responses = _responseBuilder.createQuotaSummaryResponse(caller.getAccountName(), caller.getDomainId());
+ else
+ responses = _responseBuilder.createQuotaSummaryResponse(getListAll());
+ } else {
+ responses = _responseBuilder.createQuotaSummaryResponse(caller.getAccountName(), caller.getDomainId());
+ }
+ final ListResponse<QuotaSummaryResponse> response = new ListResponse<QuotaSummaryResponse>();
+ response.setResponses(responses);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+ 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;
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public Boolean getListAll() {
+ return listAll == null ? false: listAll;
+ }
+
+ public void setListAll(Boolean listAll) {
+ this.listAll = listAll;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java
new file mode 100644
index 0000000..c190594
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java
@@ -0,0 +1,95 @@
+//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.ApiConstants;
+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.QuotaResponseBuilder;
+import org.apache.cloudstack.api.response.QuotaTariffResponse;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@APICommand(name = "quotaTariffList", responseObject = QuotaTariffResponse.class, description = "Lists all quota tariff plans", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaTariffListCmd extends BaseListCmd {
+ public static final Logger s_logger = Logger.getLogger(QuotaTariffListCmd.class);
+ private static final String s_name = "quotatarifflistresponse";
+
+ @Inject
+ QuotaResponseBuilder _responseBuilder;
+
+ @Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, required = false, description = "Usage type of the resource")
+ private Integer usageType;
+
+ @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = false, description = "The effective start date on/after which the quota tariff is effective and older tariffs are no longer used for the usage type. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.")
+ private Date effectiveDate;
+
+ public QuotaTariffListCmd() {
+ super();
+ }
+
+ @Override
+ public void execute() {
+ final List<QuotaTariffVO> result = _responseBuilder.listQuotaTariffPlans(this);
+
+ final List<QuotaTariffResponse> responses = new ArrayList<QuotaTariffResponse>();
+ for (final QuotaTariffVO resource : result) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Result desc=" + resource.getDescription() + " date=" + resource.getEffectiveOn() + " val=" + resource.getCurrencyValue());
+ }
+ responses.add(_responseBuilder.createQuotaTariffResponse(resource));
+ }
+
+ final ListResponse<QuotaTariffResponse> response = new ListResponse<QuotaTariffResponse>();
+ response.setResponses(responses);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ public Date getEffectiveDate() {
+ return effectiveDate ==null ? null : new Date(effectiveDate.getTime());
+ }
+
+ public Integer getUsageType() {
+ return usageType;
+ }
+
+ public void setUsageType(Integer usageType) {
+ this.usageType = usageType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java
new file mode 100644
index 0000000..04af3ec
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java
@@ -0,0 +1,102 @@
+//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.ApiConstants;
+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.QuotaTariffResponse;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+import java.util.Date;
+
+@APICommand(name = "quotaTariffUpdate", responseObject = QuotaTariffResponse.class, description = "Update the tariff plan for a resource", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaTariffUpdateCmd extends BaseCmd {
+ public static final Logger s_logger = Logger.getLogger(QuotaTariffUpdateCmd.class);
+ private static final String s_name = "quotatariffupdateresponse";
+
+ @Inject
+ QuotaResponseBuilder _responseBuilder;
+
+ @Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, required = true, description = "Integer value for the usage type of the resource")
+ private Integer usageType;
+
+ @Parameter(name = "value", type = CommandType.DOUBLE, required = true, description = "The quota tariff value of the resource as per the default unit")
+ private Double value;
+
+ @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "The effective start date on/after which the quota tariff is effective and older tariffs are no longer used for the usage type. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.")
+ private Date startDate;
+
+ public int getUsageType() {
+ return usageType;
+ }
+
+ public void setUsageType(int usageType) {
+ this.usageType = usageType;
+ }
+
+ public Double getValue() {
+ return value;
+ }
+
+ public void setValue(Double value) {
+ this.value = value;
+ }
+
+ public Date getStartDate() {
+ return startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ public QuotaTariffUpdateCmd() {
+ super();
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() {
+ final QuotaTariffVO result = _responseBuilder.updateQuotaTariffPlan(this);
+ if (result == null) {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update quota tariff plan");
+ }
+ final QuotaTariffResponse response = _responseBuilder.createQuotaTariffResponse(result);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaUpdateCmd.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaUpdateCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaUpdateCmd.java
new file mode 100644
index 0000000..e3c0fd2
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaUpdateCmd.java
@@ -0,0 +1,72 @@
+//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.BaseCmd;
+import org.apache.cloudstack.api.response.QuotaUpdateResponse;
+import org.apache.cloudstack.quota.QuotaAlertManager;
+import org.apache.cloudstack.quota.QuotaManager;
+import org.apache.cloudstack.quota.QuotaStatement;
+import org.apache.log4j.Logger;
+
+import java.util.Calendar;
+
+import javax.inject.Inject;
+
+@APICommand(name = "quotaUpdate", responseObject = QuotaUpdateResponse.class, description = "Update quota calculations, alerts and statements", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaUpdateCmd extends BaseCmd {
+
+ public static final Logger s_logger = Logger.getLogger(QuotaUpdateCmd.class);
+
+ private static final String s_name = "quotaupdateresponse";
+
+ @Inject
+ QuotaManager _manager;
+ @Inject
+ QuotaStatement _statement;
+ @Inject
+ QuotaAlertManager _alert;
+
+ public QuotaUpdateCmd() {
+ super();
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() {
+ _manager.calculateQuotaUsage();
+ _statement.sendStatement();
+ _alert.checkAndSendQuotaAlertEmails();
+ QuotaUpdateResponse response = new QuotaUpdateResponse(Calendar.getInstance());
+ response.setResponseName(getCommandName());
+ response.setObjectName("quotacredits");
+ setResponseObject(response);
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaBalanceResponse.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaBalanceResponse.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaBalanceResponse.java
new file mode 100644
index 0000000..fca6b6c
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaBalanceResponse.java
@@ -0,0 +1,153 @@
+//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 java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import com.google.gson.annotations.SerializedName;
+
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+
+import com.cloud.serializer.Param;
+
+public class QuotaBalanceResponse extends BaseResponse {
+
+ @SerializedName("accountid")
+ @Param(description = "account id")
+ private Long accountId;
+
+ @SerializedName("account")
+ @Param(description = "account name")
+ private String accountName;
+
+ @SerializedName("domain")
+ @Param(description = "domain id")
+ private Long domainId;
+
+ @SerializedName("startquota")
+ @Param(description = "quota started with")
+ private BigDecimal startQuota;
+
+ @SerializedName("endquota")
+ @Param(description = "quota by end of this period")
+ private BigDecimal endQuota;
+
+ @SerializedName("credits")
+ @Param(description = "list of credits made during this period")
+ private List<QuotaCreditsResponse> credits = null;
+
+ @SerializedName("startdate")
+ @Param(description = "start date")
+ private Date startDate = null;
+
+ @SerializedName("enddate")
+ @Param(description = "end date")
+ private Date endDate = null;
+
+ @SerializedName("currency")
+ @Param(description = "currency")
+ private String currency;
+
+ public QuotaBalanceResponse() {
+ super();
+ credits = new ArrayList<QuotaCreditsResponse>();
+ }
+
+ public Long getAccountId() {
+ return accountId;
+ }
+
+ public void setAccountId(Long accountId) {
+ this.accountId = accountId;
+ }
+
+ 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 BigDecimal getStartQuota() {
+ return startQuota;
+ }
+
+ public void setStartQuota(BigDecimal startQuota) {
+ this.startQuota = startQuota.setScale(2, RoundingMode.HALF_EVEN);
+ }
+
+ public BigDecimal getEndQuota() {
+ return endQuota;
+ }
+
+ public void setEndQuota(BigDecimal endQuota) {
+ this.endQuota = endQuota.setScale(2, RoundingMode.HALF_EVEN);
+ }
+
+ public List<QuotaCreditsResponse> getCredits() {
+ return credits;
+ }
+
+ public void setCredits(List<QuotaCreditsResponse> credits) {
+ this.credits = credits;
+ }
+
+ public void addCredits(QuotaBalanceVO credit) {
+ QuotaCreditsResponse cr = new QuotaCreditsResponse();
+ cr.setCredits(credit.getCreditBalance());
+ cr.setUpdatedOn(credit.getUpdatedOn() == null ? null : new Date(credit.getUpdatedOn().getTime()));
+ credits.add(0, cr);
+ }
+
+ public Date getStartDate() {
+ return startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate == null ? null : new Date(startDate.getTime());
+ }
+
+ public Date getEndDate() {
+ return endDate == null ? null : new Date(endDate.getTime());
+ }
+
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate == null ? null : new Date(endDate.getTime());
+ }
+
+ public String getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(String currency) {
+ this.currency = currency;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaCreditsResponse.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..2c16cf4
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaCreditsResponse.java
@@ -0,0 +1,91 @@
+//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 com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Date;
+
+public class QuotaCreditsResponse extends BaseResponse {
+
+ @SerializedName("credits")
+ @Param(description = "the credit deposited")
+ private BigDecimal credits;
+
+ @SerializedName("updated_by")
+ @Param(description = "the user 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 Date updatedOn;
+
+ @SerializedName("currency")
+ @Param(description = "currency")
+ private String currency;
+
+ public QuotaCreditsResponse() {
+ super();
+ }
+
+ public QuotaCreditsResponse(QuotaCreditsVO result, String updatedBy) {
+ super();
+ if (result != null) {
+ setCredits(result.getCredit());
+ setUpdatedBy(updatedBy);
+ setUpdatedOn(new Date());
+ }
+ }
+
+ public BigDecimal getCredits() {
+ return credits;
+ }
+
+ public void setCredits(BigDecimal credits) {
+ this.credits = credits.setScale(2, RoundingMode.HALF_EVEN);
+ }
+
+ public String getUpdatedBy() {
+ return updatedBy;
+ }
+
+ public void setUpdatedBy(String updatedBy) {
+ this.updatedBy = updatedBy;
+ }
+
+ public Date getUpdatedOn() {
+ return updatedOn;
+ }
+
+ public void setUpdatedOn(Date updatedOn) {
+ this.updatedOn = updatedOn;
+ }
+
+ public String getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(String currency) {
+ this.currency = currency;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaEmailTemplateResponse.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaEmailTemplateResponse.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaEmailTemplateResponse.java
new file mode 100644
index 0000000..c4a2b7c
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaEmailTemplateResponse.java
@@ -0,0 +1,90 @@
+//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 com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+import org.apache.cloudstack.api.BaseResponse;
+
+import java.util.Date;
+
+public class QuotaEmailTemplateResponse extends BaseResponse {
+ @SerializedName("templatetype")
+ @Param(description = "Template type")
+ private String templateType;
+
+ @SerializedName("templatesubject")
+ @Param(description = "The quota email template subject")
+ private String templateSubject;
+
+ @SerializedName("templatebody")
+ @Param(description = "The quota email template content")
+ private String templateText;
+
+ @SerializedName("locale")
+ @Param(description = "The quota email template locale")
+ private String locale;
+
+ @SerializedName("last_updated")
+ @Param(description = "Last date/time when template was updated")
+ private Date lastUpdatedOn;
+
+ public QuotaEmailTemplateResponse() {
+ super();
+ this.setObjectName("quotaemailtemplate");
+ }
+
+ public String getTemplateType() {
+ return templateType;
+ }
+
+ public void setTemplateType(String templateType) {
+ this.templateType = templateType;
+ }
+
+ public String getTemplateSubject() {
+ return templateSubject;
+ }
+
+ public void setTemplateSubject(String templateSubject) {
+ this.templateSubject = templateSubject;
+ }
+
+ public String getTemplateText() {
+ return templateText;
+ }
+
+ public void setTemplateText(String templateText) {
+ this.templateText = templateText;
+ }
+
+ public String getLocale() {
+ return locale;
+ }
+
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+
+ public Date getLastUpdatedOn() {
+ return lastUpdatedOn;
+ }
+
+ public void setLastUpdatedOn(Date lastUpdatedOn) {
+ this.lastUpdatedOn = lastUpdatedOn;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/987fcbd4/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilder.java
----------------------------------------------------------------------
diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilder.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilder.java
new file mode 100644
index 0000000..a4260cb
--- /dev/null
+++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilder.java
@@ -0,0 +1,65 @@
+//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.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;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.cloudstack.quota.vo.QuotaUsageVO;
+
+import java.util.Date;
+import java.util.List;
+
+public interface QuotaResponseBuilder {
+
+ QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd);
+
+ List<QuotaTariffVO> listQuotaTariffPlans(QuotaTariffListCmd cmd);
+
+ QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO configuration);
+
+ QuotaStatementResponse createQuotaStatementResponse(List<QuotaUsageVO> quotaUsage);
+
+ QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaUsage, Date startDate, Date endDate);
+
+ List<QuotaSummaryResponse> createQuotaSummaryResponse(Boolean listAll);
+
+ List<QuotaSummaryResponse> createQuotaSummaryResponse(String accountName, Long domainId);
+
+ QuotaBalanceResponse createQuotaLastBalanceResponse(List<QuotaBalanceVO> quotaBalance, Date startDate);
+
+ QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Double amount, Long updatedBy, Date despositedOn);
+
+ List<QuotaUsageVO> getQuotaUsage(QuotaStatementCmd cmd);
+
+ List<QuotaBalanceVO> getQuotaBalance(QuotaBalanceCmd cmd);
+
+ QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Double amount, Long updatedBy);
+
+ List<QuotaEmailTemplateResponse> listQuotaEmailTemplates(QuotaEmailTemplateListCmd cmd);
+
+ boolean updateQuotaEmailTemplate(QuotaEmailTemplateUpdateCmd cmd);
+
+ Date startOfNextDay(Date dt);
+
+ Date startOfNextDay();
+}