Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public class ApiConstants {
public static final String VIRTUAL_MACHINE_ID_IP = "vmidipmap";
public static final String VIRTUAL_MACHINE_COUNT = "virtualmachinecount";
public static final String USAGE_ID = "usageid";
public static final String USAGE_TYPE = "usagetype";

public static final String VLAN = "vlan";
public static final String VLAN_RANGE = "vlanrange";
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/apache/cloudstack/api/BaseCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static enum HTTPMethod {
GET, POST, PUT, DELETE
}
public static enum CommandType {
BOOLEAN, DATE, FLOAT, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID
BOOLEAN, DATE, FLOAT, DOUBLE, INTEGER, SHORT, LIST, LONG, OBJECT, MAP, STRING, TZDATE, UUID
}

private Object _responseObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ public Long getProjectId() {
public String getUsageId() {
return usageId;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}

public void setDomainId(Long domainId) {
this.domainId = domainId;
}

public void setEndDate(Date endDate) {
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

public void setStartDate(Date startDate) {
this.startDate = startDate == null ? null : new Date(startDate.getTime());
}

public void setAccountId(Long accountId) {
this.accountId = accountId;
}

public void setUsageId(String usageId) {
this.usageId = usageId;
}


/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
Expand Down
1 change: 1 addition & 0 deletions api/src/org/apache/cloudstack/usage/UsageTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.cloudstack.api.response.UsageTypeResponse;

public class UsageTypes {
/* Any changes here should also reflect in cloud_usage.quota_mapping table */
public static final int RUNNING_VM = 1;
public static final int ALLOCATED_VM = 2; // used for tracking how long storage has been allocated for a VM
public static final int IP_ADDRESS = 3;
Expand Down
19 changes: 19 additions & 0 deletions api/test/org/apache/cloudstack/api/command/test/UsageCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.cloudstack.api.command.test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import junit.framework.TestCase;
Expand Down Expand Up @@ -70,4 +71,22 @@ public void testExecuteEmptyResult() {

}

@Test
public void testCrud() {
getUsageRecordsCmd.setDomainId(1L);
assertTrue(getUsageRecordsCmd.getDomainId().equals(1L));

getUsageRecordsCmd.setAccountName("someAccount");
assertTrue(getUsageRecordsCmd.getAccountName().equals("someAccount"));

Date d = new Date();
getUsageRecordsCmd.setStartDate(d);
getUsageRecordsCmd.setEndDate(d);
assertTrue(getUsageRecordsCmd.getStartDate().equals(d));
assertTrue(getUsageRecordsCmd.getEndDate().equals(d));

getUsageRecordsCmd.setUsageId("someId");
assertTrue(getUsageRecordsCmd.getUsageId().equals("someId"));
}

}
41 changes: 41 additions & 0 deletions client/WEB-INF/classes/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,47 @@ label.show.advanced.settings=Show advanced settings
label.delete.OpenDaylight.device=Delete OpenDaylight Controller
label.polling.interval.sec=Polling Interval (in sec)
label.quiet.time.sec=Quiet Time (in sec)
label.usage.type=Usage Type
label.usage.unit=Unit
label.quota.value=Quota Value
label.quota.description=Quota Description
label.quota.configuration=Quota Configuration
label.quota.configure=Configure Quota
label.quota.remove=Remove Quota
label.quota.totalusage=Total Usage
label.quota.balance=Balance
label.quota.minbalance=Min Balance
label.quota.enforcequota=Enforce Quota
label.quota.summary=Summary
label.quota.fullsummary=All Accounts
label.quota.tariff=Tariff
label.quota.state=State
label.quota.startdate=Start Date
label.quota.enddate=End Date
label.quota.total=Total
label.quota.startquota=Start Quota
label.quota.endquota=End Quota
label.quota.type.name=Usage Type
label.quota.type.unit=Usage Unit
label.quota.usage=Quota Consumption
label.quota.add.credits=Add Credits
label.quota.email.template=Email Template
label.quota.statement=Statement
label.quota.statement.balance=Quota Balance
label.quota.statement.quota=Quota Usage
label.quota.statement.tariff=Quota Tariff
label.quota.tariff.value=Tariff Value
label.quota.tariff.edit=Edit Tariff
label.quota.tariff.effectivedate=Effective Date
label.quota.date=Date
label.quota.dates=Update Dates
label.quota.credit=Credit
label.quota.credits=Credits
label.quota.value=Quota Value
label.quota.statement.bydates=Statement
label.quota.email.subject=Subject
label.quota.email.body=Body
label.quota.email.lastupdated=Last Update
label.destroy.vm.graceperiod=Destroy VM Grace Period
label.SNMP.community=SNMP Community
label.SNMP.port=SNMP Port
Expand Down
10 changes: 10 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@
<artifactId>cloud-framework-ipc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-quota</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-rest</artifactId>
Expand Down Expand Up @@ -366,6 +371,11 @@
<artifactId>cloud-plugin-network-globodns</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-database-quota</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
11 changes: 11 additions & 0 deletions client/tomcatconf/commands.properties.in
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,14 @@ addGloboDnsHost=1
### volume/template post upload
getUploadParamsForVolume=15
getUploadParamsForTemplate=15

### Quota Service
quotaStatement=15
quotaBalance=15
quotaSummary=15
quotaUpdate=1
quotaTariffList=15
quotaTariffUpdate=1
quotaCredits=1
quotaEmailTemplateList=1
quotaEmailTemplateUpdate=1
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,4 @@ private void updateSystemVmTemplates(final Connection conn) {
}
s_logger.debug("Updating System Vm Template IDs Complete");
}
}
}
17 changes: 17 additions & 0 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade461to470.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Upgrade461to470 implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade461to470.class);
Expand Down Expand Up @@ -51,8 +53,23 @@ public File[] getPrepareScripts() {
return new File[] {new File(script)};
}

public void alterAddColumnToCloudUsage(final Connection conn) {
final String alterTableSql = "ALTER TABLE `cloud_usage`.`cloud_usage` ADD COLUMN `quota_calculated` tinyint(1) DEFAULT 0 NOT NULL COMMENT 'quota calculation status'";
try (PreparedStatement pstmt = conn.prepareStatement(alterTableSql)) {
pstmt.executeUpdate();
s_logger.info("Altered cloud_usage.cloud_usage table and added column quota_calculated");
} catch (SQLException e) {
if (e.getMessage().contains("quota_calculated")) {
s_logger.warn("cloud_usage.cloud_usage table already has a column called quota_calculated");
} else {
throw new CloudRuntimeException("Unable to create column quota_calculated in table cloud_usage.cloud_usage", e);
}
}
}

@Override
public void performDataMigration(Connection conn) {
alterAddColumnToCloudUsage(conn);
}

@Override
Expand Down
83 changes: 69 additions & 14 deletions engine/schema/src/com/cloud/usage/UsageVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ public class UsageVO implements Usage, InternalIdentity {
@Temporal(value = TemporalType.TIMESTAMP)
private Date endDate = null;

@Column(name = "quota_calculated")
private Integer quotaCalculated = 0;

public Integer getQuotaCalculated() {
return quotaCalculated;
}

public void setQuotaCalculated(Integer quotaCalculated) {
this.quotaCalculated = quotaCalculated;
}

public UsageVO() {
}

Expand All @@ -121,8 +132,8 @@ public UsageVO(Long zoneId, Long accountId, Long domainId, String description, S
this.templateId = templateId;
this.usageId = usageId;
this.size = size;
this.startDate = startDate;
this.endDate = endDate;
this.startDate = startDate == null ? null : new Date(startDate.getTime());
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, int usageType, Double rawUsage, Long vmId, String vmName,
Expand All @@ -141,8 +152,8 @@ public UsageVO(Long zoneId, Long accountId, Long domainId, String description, S
this.usageId = usageId;
this.size = size;
this.virtualSize = virtualSize;
this.startDate = startDate;
this.endDate = endDate;
this.startDate = startDate == null ? null : new Date(startDate.getTime());
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, int usageType, Double rawUsage, Long usageId, String type,
Expand All @@ -157,8 +168,8 @@ public UsageVO(Long zoneId, Long accountId, Long domainId, String description, S
this.usageId = usageId;
this.type = type;
this.networkId = networkId;
this.startDate = startDate;
this.endDate = endDate;
this.startDate = startDate == null ? null : new Date(startDate.getTime());
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, int usageType, Double rawUsage, Long vmId, String vmName,
Expand All @@ -176,8 +187,8 @@ public UsageVO(Long zoneId, Long accountId, Long domainId, String description, S
this.templateId = templateId;
this.usageId = usageId;
this.type = type;
this.startDate = startDate;
this.endDate = endDate;
this.startDate = startDate == null ? null : new Date(startDate.getTime());
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, int usageType, Double rawUsage, Long vmId, String vmName,
Expand All @@ -198,8 +209,8 @@ public UsageVO(Long zoneId, Long accountId, Long domainId, String description, S
this.templateId = templateId;
this.usageId = usageId;
this.type = type;
this.startDate = startDate;
this.endDate = endDate;
this.startDate = startDate == null ? null : new Date(startDate.getTime());
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

//IPAddress Usage
Expand All @@ -215,8 +226,8 @@ public UsageVO(Long zoneId, Long accountId, Long domainId, String description, S
this.usageId = usageId;
this.size = size;
this.type = type;
this.startDate = startDate;
this.endDate = endDate;
this.startDate = startDate == null ? null : new Date(startDate.getTime());
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

@Override
Expand Down Expand Up @@ -321,11 +332,55 @@ public Long getVirtualSize() {

@Override
public Date getStartDate() {
return startDate;
return startDate == null ? null : new Date(startDate.getTime());
}

@Override
public Date getEndDate() {
return endDate;
return endDate == null ? null : new Date(endDate.getTime());
}

public void setId(Long id) {
this.id = id;
}

public void setType(String type) {
this.type = type;
}

public void setStartDate(Date startDate) {
this.startDate = startDate == null ? null : new Date(startDate.getTime());
}

public void setEndDate(Date endDate) {
this.endDate = endDate == null ? null : new Date(endDate.getTime());
}

public void setDomainId(Long domainId) {
this.domainId = domainId;
}

public void setAccountId(Long accountId) {
this.accountId = accountId;
}

public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}

public void setUsageType(int usageType) {
this.usageType = usageType;
}

public void setRawUsage(Double rawUsage) {
this.rawUsage = rawUsage;
}

public void setSize(Long size) {
this.size = size;
}

public void setVirtualSize(Long virtualSize) {
this.virtualSize = virtualSize;
}
}
4 changes: 4 additions & 0 deletions engine/schema/src/com/cloud/usage/dao/UsageDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public interface UsageDao extends GenericDao<UsageVO, Long> {
void saveUsageRecords(List<UsageVO> usageRecords);

void removeOldUsageRecords(int days);

UsageVO persistUsage(final UsageVO usage);

Pair<List<? extends UsageVO>, Integer> getUsageRecordsPendingQuotaAggregation(long accountId, long domainId);
}
Loading