Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
605239d
quota: initial commit
abhinandanprateek Jun 26, 2015
aee0492
adding quota API to commands.properties
abhinandanprateek Jul 1, 2015
38f26e9
updating sql scripts
abhinandanprateek Jul 1, 2015
1da4271
adding quota credit api
abhinandanprateek Jul 1, 2015
c9770e7
merging fixes
abhinandanprateek Jul 1, 2015
46be58d
raised the version to 4.5.2 in pom
agneya2001 Jul 2, 2015
56707ad
CLOUDSTACK-8592: add quota email template management commands
abhinandanprateek Jul 6, 2015
389b041
schema-451to452: Re-add SAML SQL changes reverted in 5ea1a89
rohityadavcloud Jul 6, 2015
bf57cb6
apidoc: add section for quota APIs
rohityadavcloud Jul 6, 2015
1f75299
quota: fix db bean issue
rohityadavcloud Jul 6, 2015
1345b9f
CLOUDSTACK-8592: Adding email management APIs
agneya2001 Jul 6, 2015
3103dcf
CLOUDSTACK-8592: updated quota email templates
agneya2001 Jul 6, 2015
dbee0a9
adding pom dependencies for usage
abhinandanprateek Jul 6, 2015
2c37ddb
CLOUDSTACK-8592: adding quota usaage and balance tables
abhinandanprateek Jul 7, 2015
6c4dea7
CLOUDSTACK-8592: creating respective VO objects
abhinandanprateek Jul 7, 2015
d160da0
CLOUDSTACK-8592: adding corresponding DAOs with stubs
abhinandanprateek Jul 7, 2015
65618bb
CLOUDSTACK-8592: adding corresponding DAOs with stubs
abhinandanprateek Jul 7, 2015
dec8928
ui: Allow plugins to be shown on navigation bar, if they want to
rohityadavcloud Jul 7, 2015
0b64910
ui/plugins: Add initial Quota plugin
rohityadavcloud Jul 7, 2015
f6e7c52
ui/scripts/cloudStack: simplify plugin loop and display check
rohityadavcloud Jul 7, 2015
a558afa
CLOUDSTACK-8592: Adding new APIs and implementing the API stubs
abhinandanprateek Jul 8, 2015
b5e0162
CLOUDSTACK-8592: keep track of quota job runs - adding schema and daos
abhinandanprateek Jul 8, 2015
53c22f6
CLOUDSTACK-8592: adding QuotaEditResourceMappingCmd
abhinandanprateek Jul 8, 2015
1b579af
CLOUDSTACK-8592: refactoring, cleanup
abhinandanprateek Jul 9, 2015
135af2c
CLOUDSTACK-8592: calculation of quota
abhinandanprateek Jul 13, 2015
df79834
CLOUDSTACK-8592: reverting debug statement
abhinandanprateek Jul 13, 2015
b08f228
setup/db: fix saml sql files, and create quota tables only if that do…
rohityadavcloud Jul 14, 2015
7dd68a1
CLOUDSTACK-8592: Schema updates
abhinandanprateek Jul 13, 2015
ae0eb6e
CLOUDSTACK-8592: first cut implementation of quota statement
abhinandanprateek Jul 14, 2015
46931f9
setup/db: fix schema issues, put quota stuff in cloud_usage db
rohityadavcloud Jul 14, 2015
25cbdcc
setup/db: fix schema issues, put quota stuff in cloud_usage db
rohityadavcloud Jul 14, 2015
9dc60bb
quota: fix quotaRefresh API response keys
rohityadavcloud Jul 14, 2015
ccbe8de
quota: fix quota refresh API, reuse success response
rohityadavcloud Jul 14, 2015
829bb17
quota: rename quotamapping to quotamappingcmd
rohityadavcloud Jul 14, 2015
fe422de
client: fix label and usage
rohityadavcloud Jul 14, 2015
473496b
quota: use uniform response names
rohityadavcloud Jul 14, 2015
c4d82f0
quota: take value as string in add credit cmd
rohityadavcloud Jul 14, 2015
c8cfb38
quota: for BigDecimal use String in API cmd and responses
rohityadavcloud Jul 14, 2015
82d9a6a
quota: inject quota balance dao to quota db utils to be used later
rohityadavcloud Jul 14, 2015
47ffa60
iCLOUDSTACK-8592: adding accountid and domainid to quota statement
abhinandanprateek Jul 14, 2015
26c3628
CLOUDSTACK-8592: added quota balance command that aggregates quota li…
abhinandanprateek Jul 14, 2015
82b176b
quota-ui: fix settings view
rohityadavcloud Jul 14, 2015
2a8bb5f
CLOUDSTACK-8592: close transactions used for swicthing DBs
abhinandanprateek Jul 14, 2015
af2cccf
CLOUDSTACK-8592: formatting
abhinandanprateek Jul 14, 2015
c8473d2
quota: remove unwanted changes
rohityadavcloud Jul 14, 2015
13b0455
CLOUDSTACK-8592: put a limit on number of usage records read for proc…
abhinandanprateek Jul 15, 2015
f4226a7
iCLOUDSTACK-8592: Incremental update for credits and balance
abhinandanprateek Jul 15, 2015
d28365b
quota: refactor and fix code around quota tariff
rohityadavcloud Jul 15, 2015
7c10013
quota: rename/refactor quota mapping usage to quotaTariff
rohityadavcloud Jul 15, 2015
a2143e3
CLOUDSTACK-8592: calculating balance, adjusting credits and API comma…
abhinandanprateek Jul 16, 2015
b13d2b9
quota: UI view for quota tariff
rohityadavcloud Jul 16, 2015
9955171
CLOUDSTACK-8592: increase precision
abhinandanprateek Jul 17, 2015
a9e71c7
CLOUDSTACK-8592: in responses print values rounded to two decimal places
abhinandanprateek Jul 17, 2015
a4dac9a
CLOUDSTACK-8592: added current balance and balance on a date
abhinandanprateek Jul 20, 2015
6f17364
quota: fix quota statement api, db schema and implement UI tab for st…
rohityadavcloud Jul 20, 2015
5397fc2
quota: add credit management in the ui
rohityadavcloud Jul 21, 2015
a9e8cec
quota: add quota currency on tarriff table
rohityadavcloud Jul 21, 2015
b3eeb6c
quota: remove console.log statement
rohityadavcloud Jul 21, 2015
0223477
quota: add quota balance/credit statement in the statement tab
rohityadavcloud Jul 21, 2015
ccde3cf
CLOUDSTACK-8592: splitting out quotamanager into quotamanager and quo…
abhinandanprateek Jul 20, 2015
c99346c
quota: added checks for boundary cases
abhinandanprateek Jul 21, 2015
c13b329
quota: fix quota credits api, NPE
rohityadavcloud Jul 21, 2015
6688220
quota: fixed transaction, boundary conditions
abhinandanprateek Jul 21, 2015
ab68f38
quota: remove invalid ui code, add additional checks
rohityadavcloud Jul 21, 2015
945103b
quota: for quota calc from start date to end date, adjust the credits…
abhinandanprateek Jul 21, 2015
e38cd45
quota: re-order date vs domain/account checking
rohityadavcloud Jul 21, 2015
3008502
quota: add apache commons 3.4 lang3 library for using StrSubstitutor …
rohityadavcloud Jul 21, 2015
5c7befb
quota: assume start/end date in the balance API will be returned
rohityadavcloud Jul 21, 2015
f51eb1b
quota: adding config initialization to quota manager and taking care …
abhinandanprateek Jul 21, 2015
22dccd1
quota: make tariff plans updatable and schedulable
abhinandanprateek Jul 22, 2015
cf003cb
quotq: optimizing tariff retrival while calculating quota usage.
abhinandanprateek Jul 22, 2015
6c944dc
quota: fix tariff type
abhinandanprateek Jul 22, 2015
e2ab24a
ui: add effective from date in tariff list/table, add error handling …
rohityadavcloud Jul 22, 2015
ae26d67
quota: fix schema, set all quota tariff values to 0; effective date a…
rohityadavcloud Jul 22, 2015
c991b08
quota: fix tariff update cmd to accept start date, update effective/s…
rohityadavcloud Jul 22, 2015
df2687a
quota: fix db quota usage
rohityadavcloud Jul 22, 2015
a539574
quota: fix stuff
rohityadavcloud Jul 22, 2015
e14fbc5
quota: adding final where ever required
abhinandanprateek Jul 22, 2015
72e16be
quota: transaction commit when a account is processed
abhinandanprateek Jul 23, 2015
e5ce5e9
quota: renaming DBUtils to ResponseBuilder as that is what it is
abhinandanprateek Jul 23, 2015
15b9a89
quota: restructuring
abhinandanprateek Jul 23, 2015
f5be8aa
quota: email template backend and apis
rohityadavcloud Jul 23, 2015
1725266
quota: escape javascript, but not html
rohityadavcloud Jul 23, 2015
6b11c83
quota: add email template UI
rohityadavcloud Jul 23, 2015
6fedff6
quota: fix UI's escaping quotes
rohityadavcloud Jul 23, 2015
9afd579
quota: fix getusagerecords name to reflect its for getting unprocesse…
rohityadavcloud Jul 24, 2015
355b2e6
quota: implement quota email alert methods/classes and template engin…
rohityadavcloud Jul 24, 2015
0e0df49
quota: remove include column from tariff, fix list tariff api to acce…
rohityadavcloud Jul 24, 2015
7617182
quota: fix ui - statement, tariff and templates
rohityadavcloud Jul 24, 2015
247e539
ui: fix UI, API usage and display rendering; fix template saving to u…
rohityadavcloud Jul 27, 2015
38146d8
quota: fix template update API to increase body/subject size/length
rohityadavcloud Jul 27, 2015
d9c3824
quota: fix balance api to send result when no debits have been made
rohityadavcloud Jul 27, 2015
b08736a
quota: add logic to send email using a deferred approach
rohityadavcloud Jul 27, 2015
8df0a53
quota: statement genertaion date should not be in future
abhinandanprateek Jul 28, 2015
fdfcd95
quota: fix stuff
rohityadavcloud Jul 28, 2015
c11f84d
ui: show actual backend error, if it's not auth failure
rohityadavcloud Jul 28, 2015
6d92dad
quota: remove unused import
rohityadavcloud Jul 28, 2015
2a64e94
quota: account for 0 tariff
abhinandanprateek Jul 28, 2015
b64aee0
Merge branch 'quota' of https://github.com/shapeblue/cloudstack into …
abhinandanprateek Jul 28, 2015
ca6dfc9
quota: added a method to get the last balance in balancedao
abhinandanprateek Jul 28, 2015
b388512
quota: rename method to lastQuotaBalance
abhinandanprateek Jul 28, 2015
d29a4e9
quota: only lock normal accounts
rohityadavcloud Jul 28, 2015
19fefbc
quota: on getting enough credits, unlock the account which got new cr…
rohityadavcloud Jul 28, 2015
b001bf6
quota: for checking/sending email use the new lastQuotaBalance method…
rohityadavcloud Jul 28, 2015
7a55e82
quota: get last balance api
abhinandanprateek Jul 28, 2015
a4e8301
quota ui: grab current date in the browser's tariff
rohityadavcloud Jul 28, 2015
9e3dadc
quota: unlock/lock logic with addCredits api
rohityadavcloud Jul 28, 2015
7a6b536
quota: only add the initial credit entries to the balance as they have
abhinandanprateek Jul 29, 2015
e4125a2
quota: allow locked accounts to be credited
abhinandanprateek Jul 29, 2015
70aada6
quota: don't lock account, only unlock with adding credits
rohityadavcloud Jul 29, 2015
7b562b0
quota: add new template for sending unlocked email account
rohityadavcloud Jul 29, 2015
def9e90
quota: add currency to list/readonly apis
rohityadavcloud Jul 29, 2015
b2dd5e1
quota: fix ui to grab currency from the response
rohityadavcloud Jul 29, 2015
60125d3
quota: add quota monthly statement email template
rohityadavcloud Jul 29, 2015
7c4c67b
quota fixed misc boundary conditions
abhinandanprateek Jul 29, 2015
2f7ebc7
quota: fixed permisison and date flip
abhinandanprateek Jul 29, 2015
8483c4a
quota: add currency in case of users too
rohityadavcloud Jul 30, 2015
50c579d
quota: restructured/refactored to make quota run inside the usage server
abhinandanprateek Jul 30, 2015
ddba6d5
quota: run the calculations after the usage server is done collecting
abhinandanprateek Jul 30, 2015
9d82488
quota: send currency with add credits response
rohityadavcloud Jul 30, 2015
53f3b3c
quota: fix css of the ui, make element similar to other cloudstack UI…
rohityadavcloud Jul 30, 2015
40914ed
quota: improve css and element usage; align inputs below labels
rohityadavcloud Jul 30, 2015
1590b66
quota: adding book keeping columns in accounts table
abhinandanprateek Jul 31, 2015
8c81b02
quota: fine tuning dates
abhinandanprateek Jul 31, 2015
124d1da
quota: fix stuff
rohityadavcloud Jul 31, 2015
e123f2a
quota/usage: fix license
rohityadavcloud Jul 31, 2015
9deed58
quota: added quota_account
abhinandanprateek Jul 31, 2015
5535e81
quota: fixing account bean
abhinandanprateek Aug 1, 2015
eaf3d21
quota: tariff fix
abhinandanprateek Aug 1, 2015
92269d2
quota: fixing warped up db
abhinandanprateek Aug 1, 2015
bd1d12d
quota: added min_balance and quota enforce for each account
abhinandanprateek Aug 3, 2015
a39b6cd
quota ui: add min threshold and checkbox to enforce locking
rohityadavcloud Aug 3, 2015
8943839
quota: due to interpackage dependency the account lock functionality …
abhinandanprateek Aug 3, 2015
b0a8598
quota: even if there is no usage for some resources show them in the
abhinandanprateek Aug 3, 2015
fc95ece
quota: fixes
abhinandanprateek Aug 3, 2015
57bc5cb
quota: minor credits ui fixes
rohityadavcloud Aug 3, 2015
eafefb0
quota: fix database
rohityadavcloud Aug 3, 2015
d5eabfb
quota: refactored email code and pulled it into ALertManager that will
abhinandanprateek Aug 3, 2015
b38f738
quota: added checks for quota enforce and threshold per account
abhinandanprateek Aug 4, 2015
e2c2e06
quota: show ui balance if start/end balance are defined (any values)
rohityadavcloud Aug 4, 2015
173f6ba
quota:fixes
abhinandanprateek Aug 4, 2015
ed28e4f
Revert "quota: fixes"
abhinandanprateek Aug 4, 2015
f0467c8
quota: streamlined emailing
abhinandanprateek Aug 4, 2015
731d9b8
quota: +send last month statement at the start of the month
abhinandanprateek Aug 5, 2015
d3f65ae
quota: code cleanup
abhinandanprateek Aug 6, 2015
32c5004
quota: though default value for quota_calculated is 0, the usage server
abhinandanprateek Aug 7, 2015
bf5d388
quota: check if quota is enabled, only then expose APIs
rohityadavcloud Aug 6, 2015
74c34d7
quota;e2etesting
rohityadavcloud Aug 6, 2015
73cedf1
quota: remove quotaRefresh
rohityadavcloud Aug 7, 2015
43c893c
quota: by default make the global quota enforement flag as false. fix
abhinandanprateek Aug 7, 2015
fb94a67
quota: to maintain idempotency the alter table statement is moved to
abhinandanprateek Aug 12, 2015
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 @@ -269,6 +269,7 @@ public class ApiConstants {
public static final String VIRTUAL_MACHINE_IDS = "virtualmachineids";
public static final String VIRTUAL_MACHINE_ID_IP = "vmidipmap";
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 @@ -97,7 +97,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 @@ -38,6 +38,7 @@
@APICommand(name = "listUsageRecords", description = "Lists usage records for accounts", responseObject = UsageRecordResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class GetUsageRecordsCmd extends BaseListCmd {

public static final Logger s_logger = Logger.getLogger(GetUsageRecordsCmd.class.getName());

private static final String s_name = "listusagerecordsresponse";
Expand Down Expand Up @@ -111,6 +112,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;
}

public void setStartDate(Date startDate) {
this.startDate = startDate;
}

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

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


/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
Expand Down
2 changes: 2 additions & 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,8 @@
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
7 changes: 7 additions & 0 deletions client/WEB-INF/classes/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,13 @@ 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.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 @@ -246,6 +246,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 @@ -356,6 +361,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
10 changes: 10 additions & 0 deletions client/tomcatconf/commands.properties.in
Original file line number Diff line number Diff line change
Expand Up @@ -781,3 +781,13 @@ listOpenDaylightControllers=1

### GloboDNS commands
addGloboDnsHost=1

### Quota Service
quotaStatement=15
quotaBalance=15
quotaTariffList=15
quotaTariffUpdate=1
quotaCredits=1
quotaEmailTemplateList=1
quotaEmailTemplateUpdate=1

Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,5 @@ public ServiceOfferingVO getcomputeOffering(ServiceOfferingVO serviceOffering, M

return dummyoffering;
}

}
23 changes: 20 additions & 3 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade451to452.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@

import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;

import org.apache.log4j.Logger;

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

public class Upgrade451to452 implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade451to452.class);

@Override
public String[] getUpgradableVersionRange() {
return new String[] {"4.5.1", "4.5.2"};
return new String[] { "4.5.1", "4.5.2" };
}

@Override
Expand All @@ -48,11 +51,24 @@ public File[] getPrepareScripts() {
if (script == null) {
throw new CloudRuntimeException("Unable to find db/schema-451to452.sql");
}
return new File[] {new File(script)};
return new File[] { new File(script) };
}

@Override
public void performDataMigration(Connection conn) {
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement("ALTER TABLE `cloud_usage`.`cloud_usage` ADD COLUMN `quota_calculated` tinyint(1) DEFAULT 0 NOT NULL COMMENT 'quota calculation status'");
pstmt.executeUpdate();
pstmt.close();
s_logger.debug("Altered usage table and added column quota_calculated");
} catch (SQLException e) {
if (e.getMessage().contains("quota_calculated")) {
s_logger.debug("Usage table already has a column called quota_calculated");
} else {
throw new CloudRuntimeException("Unable to create column quota_calculated", e);
}
}
}

@Override
Expand All @@ -62,6 +78,7 @@ public File[] getCleanupScripts() {
throw new CloudRuntimeException("Unable to find db/schema-451to452-cleanup.sql");
}

return new File[] {new File(script)};
return new File[] { new File(script) };
}

}
11 changes: 11 additions & 0 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 = null;

public Integer getQuotaCalculated() {
return quotaCalculated;
}

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

public UsageVO() {
}

Expand Down
2 changes: 2 additions & 0 deletions engine/schema/src/com/cloud/usage/dao/UsageDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public interface UsageDao extends GenericDao<UsageVO, Long> {
void saveVmDiskStats(List<VmDiskStatisticsVO> vmDiskStats);

void saveUsageRecords(List<UsageVO> usageRecords);

Pair<List<? extends UsageVO>, Integer> getUsageRecordsPendingQuotaAggregation(long accountId, long domainId);
}
75 changes: 53 additions & 22 deletions engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,30 @@
import com.cloud.utils.exception.CloudRuntimeException;

@Component
@Local(value = {UsageDao.class})
@Local(value = { UsageDao.class })
public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements UsageDao {
public static final Logger s_logger = Logger.getLogger(UsageDaoImpl.class.getName());
private static final String DELETE_ALL = "DELETE FROM cloud_usage";
private static final String DELETE_ALL_BY_ACCOUNTID = "DELETE FROM cloud_usage WHERE account_id = ?";
private static final String INSERT_ACCOUNT = "INSERT INTO cloud_usage.account (id, account_name, type, domain_id, removed, cleanup_needed) VALUES (?,?,?,?,?,?)";
private static final String INSERT_USER_STATS =
"INSERT INTO cloud_usage.user_statistics (id, data_center_id, account_id, public_ip_address, device_id, device_type, network_id, net_bytes_received,"
+ " net_bytes_sent, current_bytes_received, current_bytes_sent, agg_bytes_received, agg_bytes_sent) VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?)";
private static final String INSERT_USER_STATS = "INSERT INTO cloud_usage.user_statistics (id, data_center_id, account_id, public_ip_address, device_id, device_type, network_id, net_bytes_received,"
+ " net_bytes_sent, current_bytes_received, current_bytes_sent, agg_bytes_received, agg_bytes_sent) VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?)";

private static final String UPDATE_ACCOUNT = "UPDATE cloud_usage.account SET account_name=?, removed=? WHERE id=?";
private static final String UPDATE_USER_STATS =
"UPDATE cloud_usage.user_statistics SET net_bytes_received=?, net_bytes_sent=?, current_bytes_received=?, current_bytes_sent=?, agg_bytes_received=?, agg_bytes_sent=? WHERE id=?";
private static final String UPDATE_USER_STATS = "UPDATE cloud_usage.user_statistics SET net_bytes_received=?, net_bytes_sent=?, current_bytes_received=?, current_bytes_sent=?, agg_bytes_received=?, agg_bytes_sent=? WHERE id=?";

private static final String GET_LAST_ACCOUNT = "SELECT id FROM cloud_usage.account ORDER BY id DESC LIMIT 1";
private static final String GET_LAST_USER_STATS = "SELECT id FROM cloud_usage.user_statistics ORDER BY id DESC LIMIT 1";
private static final String GET_PUBLIC_TEMPLATES_BY_ACCOUNTID = "SELECT id FROM cloud.vm_template WHERE account_id = ? AND public = '1' AND removed IS NULL";

private static final String GET_LAST_VM_DISK_STATS = "SELECT id FROM cloud_usage.vm_disk_statistics ORDER BY id DESC LIMIT 1";
private static final String INSERT_VM_DISK_STATS =
"INSERT INTO cloud_usage.vm_disk_statistics (id, data_center_id, account_id, vm_id, volume_id, net_io_read, net_io_write, current_io_read, "
+ "current_io_write, agg_io_read, agg_io_write, net_bytes_read, net_bytes_write, current_bytes_read, current_bytes_write, agg_bytes_read, agg_bytes_write) "
+ " VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?, ?,?, ?, ?)";
private static final String UPDATE_VM_DISK_STATS =
"UPDATE cloud_usage.vm_disk_statistics SET net_io_read=?, net_io_write=?, current_io_read=?, current_io_write=?, agg_io_read=?, agg_io_write=?, "
+ "net_bytes_read=?, net_bytes_write=?, current_bytes_read=?, current_bytes_write=?, agg_bytes_read=?, agg_bytes_write=? WHERE id=?";
private static final String INSERT_VM_DISK_STATS = "INSERT INTO cloud_usage.vm_disk_statistics (id, data_center_id, account_id, vm_id, volume_id, net_io_read, net_io_write, current_io_read, "
+ "current_io_write, agg_io_read, agg_io_write, net_bytes_read, net_bytes_write, current_bytes_read, current_bytes_write, agg_bytes_read, agg_bytes_write) "
+ " VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?, ?,?, ?, ?)";
private static final String UPDATE_VM_DISK_STATS = "UPDATE cloud_usage.vm_disk_statistics SET net_io_read=?, net_io_write=?, current_io_read=?, current_io_write=?, agg_io_read=?, agg_io_write=?, "
+ "net_bytes_read=?, net_bytes_write=?, current_bytes_read=?, current_bytes_write=?, agg_bytes_read=?, agg_bytes_write=? WHERE id=?";
private static final String INSERT_USAGE_RECORDS = "INSERT INTO cloud_usage.cloud_usage (zone_id, account_id, domain_id, description, usage_display, "
+
"usage_type, raw_usage, vm_instance_id, vm_name, offering_id, template_id, "
+ "usage_type, raw_usage, vm_instance_id, vm_name, offering_id, template_id, "
+ "usage_id, type, size, network_id, start_date, end_date, virtual_size) VALUES (?,?,?,?,?,?,?,?,?, ?, ?, ?,?,?,?,?,?,?)";

protected final static TimeZone s_gmtTimeZone = TimeZone.getTimeZone("GMT");
Expand Down Expand Up @@ -111,7 +106,9 @@ public void saveAccounts(List<AccountVO> accounts) {
txn.start();
String sql = INSERT_ACCOUNT;
PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just
// want CLOUD_USAGE
// dataSource connection
for (AccountVO acct : accounts) {
pstmt.setLong(1, acct.getId());
pstmt.setString(2, acct.getAccountName());
Expand Down Expand Up @@ -145,7 +142,9 @@ public void updateAccounts(List<AccountVO> accounts) {
txn.start();
String sql = UPDATE_ACCOUNT;
PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just
// want CLOUD_USAGE
// dataSource connection
for (AccountVO acct : accounts) {
pstmt.setString(1, acct.getAccountName());

Expand Down Expand Up @@ -175,7 +174,9 @@ public void saveUserStats(List<UserStatisticsVO> userStats) {
txn.start();
String sql = INSERT_USER_STATS;
PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just
// want CLOUD_USAGE
// dataSource connection
for (UserStatisticsVO userStat : userStats) {
pstmt.setLong(1, userStat.getId());
pstmt.setLong(2, userStat.getDataCenterId());
Expand Down Expand Up @@ -216,7 +217,9 @@ public void updateUserStats(List<UserStatisticsVO> userStats) {
txn.start();
String sql = UPDATE_USER_STATS;
PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just
// want CLOUD_USAGE
// dataSource connection
for (UserStatisticsVO userStat : userStats) {
pstmt.setLong(1, userStat.getNetBytesReceived());
pstmt.setLong(2, userStat.getNetBytesSent());
Expand Down Expand Up @@ -313,7 +316,9 @@ public void updateVmDiskStats(List<VmDiskStatisticsVO> vmDiskStats) {
txn.start();
String sql = UPDATE_VM_DISK_STATS;
PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just
// want CLOUD_USAGE
// dataSource connection
for (VmDiskStatisticsVO vmDiskStat : vmDiskStats) {
pstmt.setLong(1, vmDiskStat.getNetIORead());
pstmt.setLong(2, vmDiskStat.getNetIOWrite());
Expand Down Expand Up @@ -347,7 +352,9 @@ public void saveVmDiskStats(List<VmDiskStatisticsVO> vmDiskStats) {
txn.start();
String sql = INSERT_VM_DISK_STATS;
PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just
// want CLOUD_USAGE
// dataSource connection
for (VmDiskStatisticsVO vmDiskStat : vmDiskStats) {
pstmt.setLong(1, vmDiskStat.getId());
pstmt.setLong(2, vmDiskStat.getDataCenterId());
Expand Down Expand Up @@ -393,7 +400,9 @@ public void saveUsageRecords(List<UsageVO> usageRecords) {
txn.start();
String sql = INSERT_USAGE_RECORDS;
PreparedStatement pstmt = null;
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just
// want CLOUD_USAGE
// dataSource connection
for (UsageVO usageRecord : usageRecords) {
pstmt.setLong(1, usageRecord.getZoneId());
pstmt.setLong(2, usageRecord.getAccountId());
Expand Down Expand Up @@ -451,4 +460,26 @@ public void saveUsageRecords(List<UsageVO> usageRecords) {
throw new CloudRuntimeException(ex.getMessage());
}
}

@Override
@SuppressWarnings("deprecation")
public Pair<List<? extends UsageVO>, Integer> getUsageRecordsPendingQuotaAggregation(final long accountId, final long domainId) {
final short opendb = TransactionLegacy.currentTxn().getDatabaseId();
TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
s_logger.debug("getting usage records for account: " + accountId + ", domainId: " + domainId);
Filter usageFilter = new Filter(UsageVO.class, "startDate", true, 0L, 10000L);
SearchCriteria<UsageVO> sc = createSearchCriteria();
if (accountId != -1) {
sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
}
if (domainId != -1) {
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
}
sc.addAnd("quotaCalculated", SearchCriteria.Op.NULL);
sc.addOr("quotaCalculated", SearchCriteria.Op.EQ, 0);
s_logger.debug("Getting usage records" + usageFilter.getOrderBy());
Pair<List<UsageVO>, Integer> usageRecords = searchAndCountAllRecords(sc, usageFilter);
TransactionLegacy.open(opendb).close();
return new Pair<List<? extends UsageVO>, Integer>(usageRecords.first(), usageRecords.second());
}
}
1 change: 1 addition & 0 deletions framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<module>rest</module>
<module>events</module>
<module>jobs</module>
<module>quota</module>
<module>cluster</module>
<module>db</module>
<module>config</module>
Expand Down
Loading