diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index e55a2eaaf9e..b9a216442df 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -786,6 +786,7 @@ addGloboDnsHost=1 ### Quota Service quotaStatement=15 quotaBalance=15 +quotaSummary=1 quotaTariffList=15 quotaTariffUpdate=1 quotaCredits=1 diff --git a/framework/quota/src/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java b/framework/quota/src/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java index afa7cfe3198..b1a1f1635ec 100644 --- a/framework/quota/src/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java +++ b/framework/quota/src/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java @@ -165,7 +165,7 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana s_logger.info("Sending alert " + account.getAccountName() + " due to quota < 0."); deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY)); } - } else if (accountBalance.compareTo(thresholdBalance) <= 0) { + } else if (accountBalance.compareTo(thresholdBalance) < 0) { if (alertDate == null || (balanceDate.after(alertDate) && getDifferenceDays(alertDate, new Date()) > 1)) { s_logger.info("Sending alert " + account.getAccountName() + " due to quota below threshold."); deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW)); 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 00000000000..aaf35e7f81d --- /dev/null +++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaSummaryCmd.java @@ -0,0 +1,64 @@ +//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.BaseListCmd; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.QuotaResponseBuilder; +import org.apache.cloudstack.api.response.QuotaSummaryResponse; +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"; + + @Inject + QuotaResponseBuilder _responseBuilder; + + public QuotaSummaryCmd() { + super(); + } + + @Override + public void execute() { + + List responses = _responseBuilder.createQuotaSummaryResponse(); + final ListResponse response = new ListResponse(); + response.setResponses(responses); + response.setResponseName(getCommandName()); + setResponseObject(response); + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + +} 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 index eb971989436..576ab2b45b2 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilder.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilder.java @@ -16,7 +16,6 @@ //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; @@ -42,6 +41,8 @@ public interface QuotaResponseBuilder { QuotaBalanceResponse createQuotaBalanceResponse(List quotaUsage, Date startDate, Date endDate); + List createQuotaSummaryResponse(); + QuotaBalanceResponse createQuotaLastBalanceResponse(List quotaBalance, Date startDate); QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Double amount, Long updatedBy, Date despositedOn); diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java index 29efd5d8119..d415f79c087 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java @@ -97,6 +97,12 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { return response; } + @Override + public List createQuotaSummaryResponse() { + List result = new ArrayList(); + return result; + } + @Override public QuotaBalanceResponse createQuotaBalanceResponse(List quotaBalance, Date startDate, Date endDate) { if (quotaBalance == null || quotaBalance.isEmpty()) { @@ -115,7 +121,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { for (Iterator it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaBalanceResponse: Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId()); + s_logger.debug( + "createQuotaBalanceResponse: Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId()); } if (entry.getCreditsId() > 0) { if (consecutive) { diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaServiceImpl.java b/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaServiceImpl.java index 7ed1bebedca..5cae59abc49 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaServiceImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaServiceImpl.java @@ -31,6 +31,7 @@ import org.apache.cloudstack.api.command.QuotaCreditsCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaStatementCmd; +import org.apache.cloudstack.api.command.QuotaSummaryCmd; import org.apache.cloudstack.api.command.QuotaTariffListCmd; import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd; import org.apache.cloudstack.api.response.QuotaResponseBuilder; @@ -117,6 +118,7 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi } cmdList.add(QuotaStatementCmd.class); cmdList.add(QuotaBalanceCmd.class); + cmdList.add(QuotaSummaryCmd.class); cmdList.add(QuotaTariffListCmd.class); cmdList.add(QuotaTariffUpdateCmd.class); cmdList.add(QuotaCreditsCmd.class);