From da2be577a2406c5eb5c4dde0ff6f6403a530b621 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 20 Mar 2012 10:39:15 -0700 Subject: [PATCH] bug 14407: update network count for account/domain as a part of 3.0 to 3.0.1 upgrade status 14407: resolved fixed --- .../cloud/upgrade/dao/Upgrade2214to30.java | 58 +----------------- .../com/cloud/upgrade/dao/Upgrade30to301.java | 61 ++++++++++++++++++- setup/db/db/schema-2214to30.sql | 2 - setup/db/db/schema-30to301.sql | 3 + 4 files changed, 64 insertions(+), 60 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java b/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java index 1c198deda69..d41527ab5b2 100755 --- a/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade2214to30.java @@ -31,7 +31,6 @@ import java.util.UUID; import org.apache.log4j.Logger; -import com.cloud.configuration.Resource.ResourceType; import com.cloud.offering.NetworkOffering; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; @@ -89,10 +88,7 @@ public class Upgrade2214to30 implements DbUpgrade { migrateUserConcentratedPlannerChoice(conn); // update domain router table for element it; updateRouters(conn); - // update network account resource count - udpateAccountNetworkResourceCount(conn); - // update network domain resource count - udpateDomainNetworkResourceCount(conn); + } @Override @@ -1095,56 +1091,4 @@ public class Upgrade2214to30 implements DbUpgrade { } } } - - protected void udpateAccountNetworkResourceCount(Connection conn) { - PreparedStatement pstmt = null; - ResultSet rs = null; - ResultSet rs1 = null; - long accountId = 0; - try { - pstmt = conn.prepareStatement("select id from `cloud`.`account` where removed is null"); - rs = pstmt.executeQuery(); - while (rs.next()) { - accountId = rs.getLong(1); - - //get networks count for the account - pstmt = conn.prepareStatement("select count(*) from `cloud`.`networks` n, `cloud`.`account_network_ref` a, `cloud`.`network_offerings` no" + - " WHERE n.acl_type='Account' and n.id=a.network_id and a.account_id=? and a.is_owner=1 and no.specify_vlan=false and no.traffic_type='Guest'"); - pstmt.setLong(1, accountId); - rs1 = pstmt.executeQuery(); - long count = 0; - while (rs1.next()) { - count = rs1.getLong(1); - } - - pstmt = conn.prepareStatement("insert into `cloud`.`resource_count` (account_id, domain_id, type, count) VALUES (?, null, 'network', ?)"); - pstmt.setLong(1, accountId); - pstmt.setLong(2, count); - pstmt.executeUpdate(); - s_logger.debug("Updated network resource count for account id=" + accountId + " to be " + count); - } - } catch (SQLException e) { - throw new CloudRuntimeException("Unable to update network resource count for account id=" + accountId, e); - } finally { - try { - if (rs != null) { - rs.close(); - } - - if (rs1 != null) { - rs1.close(); - } - - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } - } - } - - protected void udpateDomainNetworkResourceCount(Connection conn) { - Upgrade218to22.upgradeDomainResourceCounts(conn, ResourceType.network); - } - } diff --git a/server/src/com/cloud/upgrade/dao/Upgrade30to301.java b/server/src/com/cloud/upgrade/dao/Upgrade30to301.java index 44e3ee1a46a..8eaf5706c2f 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade30to301.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade30to301.java @@ -19,9 +19,13 @@ package com.cloud.upgrade.dao; import java.io.File; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import org.apache.log4j.Logger; +import com.cloud.configuration.Resource.ResourceType; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; @@ -55,12 +59,67 @@ public class Upgrade30to301 implements DbUpgrade { @Override public void performDataMigration(Connection conn) { - + // update network account resource count + udpateAccountNetworkResourceCount(conn); + // update network domain resource count + udpateDomainNetworkResourceCount(conn); } @Override public File[] getCleanupScripts() { return null; } + + + protected void udpateAccountNetworkResourceCount(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rs = null; + ResultSet rs1 = null; + long accountId = 0; + try { + pstmt = conn.prepareStatement("select id from `cloud`.`account` where removed is null"); + rs = pstmt.executeQuery(); + while (rs.next()) { + accountId = rs.getLong(1); + + //get networks count for the account + pstmt = conn.prepareStatement("select count(*) from `cloud`.`networks` n, `cloud`.`account_network_ref` a, `cloud`.`network_offerings` no" + + " WHERE n.acl_type='Account' and n.id=a.network_id and a.account_id=? and a.is_owner=1 and no.specify_vlan=false and no.traffic_type='Guest'"); + pstmt.setLong(1, accountId); + rs1 = pstmt.executeQuery(); + long count = 0; + while (rs1.next()) { + count = rs1.getLong(1); + } + + pstmt = conn.prepareStatement("insert into `cloud`.`resource_count` (account_id, domain_id, type, count) VALUES (?, null, 'network', ?)"); + pstmt.setLong(1, accountId); + pstmt.setLong(2, count); + pstmt.executeUpdate(); + s_logger.debug("Updated network resource count for account id=" + accountId + " to be " + count); + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to update network resource count for account id=" + accountId, e); + } finally { + try { + if (rs != null) { + rs.close(); + } + + if (rs1 != null) { + rs1.close(); + } + + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } + + protected void udpateDomainNetworkResourceCount(Connection conn) { + Upgrade218to22.upgradeDomainResourceCounts(conn, ResourceType.network); + } } diff --git a/setup/db/db/schema-2214to30.sql b/setup/db/db/schema-2214to30.sql index 415d37d988a..c27d685b3f5 100755 --- a/setup/db/db/schema-2214to30.sql +++ b/setup/db/db/schema-2214to30.sql @@ -139,7 +139,6 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT' INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.templates', '20', 'The default maximum number of templates that can be deployed for a project'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.snapshots', '20', 'The default maximum number of snapshots that can be created for a project'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.volumes', '20', 'The default maximum number of volumes that can be created for a project'); -INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.networks', '20', 'The default maximum number of networks that can be created for a project'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'project.invite.required', 'false', 'If invitation confirmation is required when add account to project. Default value is false'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'project.invite.timeout', '86400', 'Invitation expiration time (in seconds). Default is 1 day - 86400 seconds'); @@ -720,7 +719,6 @@ UPDATE `cloud`.`network_offerings` SET display_text='Offering for Shared Securit UPDATE `cloud`.`configuration` SET category = 'Secure' where name in ('alert.smtp.password', 'network.loadbalancer.haproxy.stats.auth', 'security.singlesignon.key', 'project.smtp.password'); -INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Account Defaults', 'DEFAULT', 'management-server', 'max.account.networks', '20', 'The default maximum number of networks that can be created for an account'); INSERT IGNORE INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (143, 1, 'CentOS 6.0 (32-bit)'); INSERT IGNORE INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (144, 1, 'CentOS 6.0 (64-bit)'); diff --git a/setup/db/db/schema-30to301.sql b/setup/db/db/schema-30to301.sql index 9cef101fbe4..81de759a832 100755 --- a/setup/db/db/schema-30to301.sql +++ b/setup/db/db/schema-30to301.sql @@ -17,3 +17,6 @@ #Schema upgrade from 3.0 to 3.0.1; +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.networks', '20', 'The default maximum number of networks that can be created for a project'); + +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Account Defaults', 'DEFAULT', 'management-server', 'max.account.networks', '20', 'The default maximum number of networks that can be created for an account'); \ No newline at end of file