mirror of https://github.com/apache/cloudstack.git
quota: added quota_account
This commit is contained in:
parent
e123f2aa79
commit
9deed58fad
|
|
@ -0,0 +1,25 @@
|
|||
//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.dao;
|
||||
|
||||
import org.apache.cloudstack.quota.vo.QuotaAccountVO;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface QuotaAccountDao extends GenericDao<QuotaAccountVO, Long> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
//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.dao;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.quota.vo.QuotaAccountVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
@Component
|
||||
@Local(value = { QuotaAccountDao.class })
|
||||
public class QuotaAccountDaoImpl extends GenericDaoBase<QuotaAccountVO, Long> implements QuotaAccountDao {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
//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.vo;
|
||||
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "quota_balance")
|
||||
public class QuotaAccountVO implements InternalIdentity {
|
||||
|
||||
private static final long serialVersionUID = -7112846845287653210L;
|
||||
|
||||
@Id
|
||||
@Column(name = "account_id")
|
||||
private Long accountId = null;
|
||||
|
||||
@Column(name = "quota_enforce")
|
||||
private Integer quotaEnforce = null;
|
||||
|
||||
@Column(name = "quota_balance")
|
||||
private BigDecimal quotaBalance;
|
||||
|
||||
@Column(name = "quota_balance_date")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
private Date quotaBalanceDate = null;
|
||||
|
||||
@Column(name = "quota_min_balance")
|
||||
private BigDecimal quotaMinBalance;
|
||||
|
||||
@Column(name = "quota_alert_type")
|
||||
private Integer quotaAlertType = null;
|
||||
|
||||
@Column(name = "quota_alert_date")
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
private Date quotaAlertDate = null;
|
||||
|
||||
public QuotaAccountVO(Long accountId) {
|
||||
super();
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public Long getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(Long accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
public Integer getQuotaEnforce() {
|
||||
return quotaEnforce;
|
||||
}
|
||||
|
||||
public void setQuotaEnforce(Integer quotaEnforce) {
|
||||
this.quotaEnforce = quotaEnforce;
|
||||
}
|
||||
|
||||
public BigDecimal getQuotaBalance() {
|
||||
return quotaBalance;
|
||||
}
|
||||
|
||||
public void setQuotaBalance(BigDecimal quotaBalance) {
|
||||
this.quotaBalance = quotaBalance;
|
||||
}
|
||||
|
||||
public BigDecimal getQuotaMinBalance() {
|
||||
return quotaMinBalance;
|
||||
}
|
||||
|
||||
public void setQuotaMinBalance(BigDecimal quotaMinBalance) {
|
||||
this.quotaMinBalance = quotaMinBalance;
|
||||
}
|
||||
|
||||
public Integer getQuotaAlertType() {
|
||||
return quotaAlertType;
|
||||
}
|
||||
|
||||
public void setQuotaAlertType(Integer quotaAlertType) {
|
||||
this.quotaAlertType = quotaAlertType;
|
||||
}
|
||||
|
||||
public Date getQuotaAlertDate() {
|
||||
return quotaAlertDate;
|
||||
}
|
||||
|
||||
public void setQuotaAlertDate(Date quotaAlertDate) {
|
||||
this.quotaAlertDate = quotaAlertDate;
|
||||
}
|
||||
|
||||
public Date getQuotaBalanceDate() {
|
||||
return quotaBalanceDate;
|
||||
}
|
||||
|
||||
public void setQuotaBalanceDate(Date quotaBalanceDate) {
|
||||
this.quotaBalanceDate = quotaBalanceDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -40,12 +40,21 @@ CREATE TABLE `cloud`.`saml_token` (
|
|||
|
||||
ALTER TABLE `cloud_usage`.`cloud_usage` ADD COLUMN `quota_calculated` tinyint(1) DEFAULT 0 COMMENT "quota calculation status";
|
||||
|
||||
ALTER TABLE `cloud_usage`.`account`
|
||||
ADD COLUMN `quota_enforce` INT(1) NULL AFTER `default`,
|
||||
ADD COLUMN `quota_balance` DECIMAL(15,2) NULL AFTER `quota_enforce`,
|
||||
ADD COLUMN `quota_min_balance` DECIMAL(15,2) NULL AFTER `quota_balance`,
|
||||
ADD COLUMN `quota_balance_date` DATETIME NULL AFTER `quota_min_balance`,
|
||||
ADD COLUMN `quota_alert_date` DATETIME NULL AFTER `quota_balance_date`;
|
||||
DROP TABLE IF EXISTS `cloud_usage`.`quota_account`;
|
||||
CREATE TABLE `quota_account` (
|
||||
`account_id` int(11) NOT NULL,
|
||||
`quota_balance` decimal(15,2) NOT NULL,
|
||||
`quota_balance_date` datetime NOT NULL,
|
||||
`quota_enforce` int(1) DEFAULT NULL,
|
||||
`quota_min_balance` decimal(15,2) DEFAULT NULL,
|
||||
`quota_alert_date` datetime DEFAULT NULL,
|
||||
`quota_alert_type` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`account_id`),
|
||||
CONSTRAINT `account_id` FOREIGN KEY (`account_id`) REFERENCES `cloud_usage`.`account` (`quota_enforce`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_tariff` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
|||
|
|
@ -43,10 +43,12 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
|||
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||
import org.apache.cloudstack.quota.constant.QuotaConfig;
|
||||
import org.apache.cloudstack.quota.constant.QuotaTypes;
|
||||
import org.apache.cloudstack.quota.dao.QuotaAccountDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaTariffDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaUsageDao;
|
||||
import org.apache.cloudstack.quota.vo.QuotaAccountVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
|
||||
|
|
@ -89,6 +91,8 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager, Runna
|
|||
@Inject
|
||||
private AccountDao _accountDao;
|
||||
@Inject
|
||||
private QuotaAccountDao _quotaAcc;
|
||||
@Inject
|
||||
private UserDao _userDao;
|
||||
@Inject
|
||||
private DomainDao _domainDao;
|
||||
|
|
@ -292,8 +296,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager, Runna
|
|||
}
|
||||
|
||||
QuotaBalanceVO newbalance = new QuotaBalanceVO(account.getAccountId(), account.getDomainId(), aggrUsage, endDate);
|
||||
// s_logger.info("Balance entry=" + aggrUsage +
|
||||
// " on Date=" + endDate);
|
||||
// s_logger.info("Balance entry=" + aggrUsage + " on Date=" + endDate);
|
||||
_quotaBalanceDao.persist(newbalance);
|
||||
aggrUsage = new BigDecimal(0);
|
||||
}
|
||||
|
|
@ -301,6 +304,19 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager, Runna
|
|||
endDate = entry.getEndDate();
|
||||
aggrUsage = aggrUsage.subtract(entry.getQuotaUsed());
|
||||
}
|
||||
// update is quota_accounts
|
||||
QuotaAccountVO quota_account = _quotaAcc.findById(account.getAccountId());
|
||||
if (quota_account == null) {
|
||||
quota_account = new QuotaAccountVO(account.getAccountId());
|
||||
quota_account.setQuotaBalance(aggrUsage);
|
||||
quota_account.setQuotaBalanceDate(endDate);
|
||||
_quotaAcc.persist(quota_account);
|
||||
}
|
||||
else {
|
||||
quota_account.setQuotaBalance(aggrUsage);
|
||||
quota_account.setQuotaBalanceDate(endDate);
|
||||
_quotaAcc.update(account.getAccountId(), quota_account);
|
||||
}
|
||||
}// balance processed
|
||||
} // END ACCOUNT
|
||||
jobResult = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue