mirror of https://github.com/apache/cloudstack.git
bug 9420: update existing user_statistics records with device_id and device_type
status 9420: resolved fixed
This commit is contained in:
parent
1b9cbd9166
commit
c9989a7ddf
|
|
@ -1010,11 +1010,59 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
pstmt = conn.prepareStatement("UPDATE vm_instance SET account_id=1, domain_id=1 WHERE type='ConsoleProxy' or type='SecondaryStorageVm'");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
|
||||
// Update user statistics
|
||||
upadteUserStats(conn);
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Can't update data center ", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void upadteUserStats(Connection conn) {
|
||||
try {
|
||||
|
||||
// update device_type information
|
||||
PreparedStatement pstmt = conn.prepareStatement("UPDATE user_statistics SET device_type='DomainRouter'");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
s_logger.debug("Upgraded userStatistcis with device_type=DomainRouter");
|
||||
|
||||
// update device_id infrormation
|
||||
pstmt = conn.prepareStatement("SELECT id, account_id, data_center_id FROM user_statistics");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Long id = rs.getLong(1); // user stats id
|
||||
Long accountId = rs.getLong(2); // account id
|
||||
Long dataCenterId = rs.getLong(3); // zone id
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT id from vm_instance where account_id=? AND data_center_id=? AND type='DomainRouter'");
|
||||
pstmt.setLong(1, accountId);
|
||||
pstmt.setLong(2, dataCenterId);
|
||||
ResultSet rs1 = pstmt.executeQuery();
|
||||
|
||||
if (!rs1.next()) {
|
||||
throw new CloudRuntimeException("Unable to update user_statistics table with device id");
|
||||
}
|
||||
|
||||
Long deviceId = rs1.getLong(1);
|
||||
|
||||
pstmt = conn.prepareStatement("UPDATE user_statistics SET device_id=? where id=?");
|
||||
pstmt.setLong(1, deviceId);
|
||||
pstmt.setLong(2, id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
pstmt = conn.prepareStatement("");
|
||||
|
||||
}
|
||||
s_logger.debug("Upgraded userStatistcis with deviceId(s)");
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new CloudRuntimeException("Failed to migrate usage events: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradePortForwardingRules(Connection conn) {
|
||||
try {
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT id, public_ip_address, public_port, private_ip_address, private_port, protocol FROM ip_forwarding WHERE forwarding=1");
|
||||
|
|
|
|||
|
|
@ -379,8 +379,6 @@ ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `public_ip_address` varchar(15)
|
|||
ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `device_id` bigint unsigned NOT NULL default 0;
|
||||
ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `device_type` varchar(32) NOT NULL default 'DomainRouter';
|
||||
|
||||
INSERT INTO user_statistics ( account_id, data_center_id, device_id, device_type ) SELECT VM.account_id, VM.data_center_id, DR.id,'DomainRouter' FROM vm_instance VM, domain_router DR WHERE VM.id = DR.id;
|
||||
|
||||
CREATE TABLE `cloud`.`remote_access_vpn` (
|
||||
`vpn_server_addr_id` bigint unsigned UNIQUE NOT NULL,
|
||||
`account_id` bigint unsigned NOT NULL,
|
||||
|
|
|
|||
Loading…
Reference in New Issue