From 294e30d7c23ca9ddf536d129f89c7f18cfddccac Mon Sep 17 00:00:00 2001 From: alena Date: Thu, 4 Aug 2011 10:14:40 -0700 Subject: [PATCH] Merged 228-229 db upgrade from 228 branch --- .../cloud/upgrade/DatabaseUpgradeChecker.java | 2 +- .../cloud/upgrade/dao/Upgrade228to229.java | 54 +++++++++++++++++-- setup/db/db/schema-228to229.sql | 46 +++++++++++++--- 3 files changed, 90 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java b/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java index f082c745d49..117a8fcca3a 100755 --- a/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java +++ b/server/src/com/cloud/upgrade/DatabaseUpgradeChecker.java @@ -77,7 +77,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { _upgradeMap.put("2.2.2", new DbUpgrade[] { new Upgrade222to224(), new UpgradeSnapshot223to224(), new Upgrade224to225(), new Upgrade225to226(), new Upgrade227to228(), new Upgrade228to229()}); _upgradeMap.put("2.2.3", new DbUpgrade[] { new Upgrade222to224(), new UpgradeSnapshot223to224(), new Upgrade224to225(), new Upgrade225to226(), new Upgrade227to228(), new Upgrade228to229()}); _upgradeMap.put("2.2.4", new DbUpgrade[] { new Upgrade224to225(), new Upgrade225to226(), new Upgrade227to228(), new Upgrade228to229()}); - _upgradeMap.put("2.2.5", new DbUpgrade[] { new Upgrade225to226(), new Upgrade227to228() }); + _upgradeMap.put("2.2.5", new DbUpgrade[] { new Upgrade225to226(), new Upgrade227to228(), new Upgrade228to229() }); _upgradeMap.put("2.2.6", new DbUpgrade[] { new Upgrade227to228(), new Upgrade228to229()}); _upgradeMap.put("2.2.7", new DbUpgrade[] { new Upgrade227to228(), new Upgrade228to229()}); _upgradeMap.put("2.2.8", new DbUpgrade[] { new Upgrade228to229()}); diff --git a/server/src/com/cloud/upgrade/dao/Upgrade228to229.java b/server/src/com/cloud/upgrade/dao/Upgrade228to229.java index df97b079b5e..15503811e93 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade228to229.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade228to229.java @@ -19,6 +19,8 @@ package com.cloud.upgrade.dao; import java.io.File; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -52,35 +54,81 @@ public class Upgrade228to229 implements DbUpgrade { if (script == null) { throw new CloudRuntimeException("Unable to find db/schema-228to229.sql"); } - + return new File[] { new File(script) }; } @Override public void performDataMigration(Connection conn) { dropKeysIfExist(conn); + PreparedStatement pstmt; + try { + /*fk_cluster__data_center_id has been wrongly added in previous upgrade(not sure which one), 228to229 upgrade drops it and re-add again*/ + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`cluster` ADD CONSTRAINT `fk_cluster__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `cloud`.`data_center`(`id`) ON DELETE CASCADE"); + pstmt.executeUpdate(); + + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`snapshots` ADD INDEX `i_snapshots__removed`(`removed`)"); + pstmt.executeUpdate(); + + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`network_tags` ADD CONSTRAINT `fk_network_tags__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE"); + pstmt.executeUpdate(); + + pstmt.close(); + + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to execute cluster update", e); + } } @Override public File[] getCleanupScripts() { return null; } - + + private void dropKeysIfExist(Connection conn) { HashMap> indexes = new HashMap>(); HashMap> foreignKeys = new HashMap>(); //indexes to drop + + //for network_offering List keys = new ArrayList(); keys.add("name"); indexes.put("network_offerings", keys); + + //for snapshot + keys = new ArrayList(); + keys.add("i_snapshots__removed"); + indexes.put("snapshots", keys); + + + //for domain router + keys = new ArrayList(); + keys.add("i_domain_router__public_ip_address"); + indexes.put("domain_router", keys); + + //for user_ip_address + keys = new ArrayList(); + keys.add("i_user_ip_address__public_ip_address"); + indexes.put("user_ip_address", keys); + //foreign keys to drop - this key would be re-added later keys = new ArrayList(); keys.add("fk_cluster__data_center_id"); foreignKeys.put("cluster", keys); + + keys = new ArrayList(); + keys.add("fk_domain_router__public_ip_address"); + foreignKeys.put("domain_router", keys); + //drop foreign key from network tags table - it would be re-added later + keys = new ArrayList(); + keys.add("fk_network_tags__network_id"); + foreignKeys.put("network_tags", keys); + // drop all foreign keys first s_logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); for (String tableName : foreignKeys.keySet()) { @@ -92,5 +140,5 @@ public class Upgrade228to229 implements DbUpgrade { DbUpgradeUtils.dropKeysIfExist(conn, tableName, indexes.get(tableName), false); } } - + } diff --git a/setup/db/db/schema-228to229.sql b/setup/db/db/schema-228to229.sql index a772f1013b8..92226ad7028 100644 --- a/setup/db/db/schema-228to229.sql +++ b/setup/db/db/schema-228to229.sql @@ -2,11 +2,6 @@ -- Schema upgrade from 2.2.8 to 2.2.9; --; -ALTER TABLE `cloud`.`account` ADD COLUMN `network_domain` varchar(255); -ALTER TABLE `cloud`.`domain` ADD COLUMN `network_domain` varchar(255); - -ALTER TABLE `cloud`.`cluster` ADD CONSTRAINT `fk_cluster__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `cloud`.`data_center`(`id`) ON DELETE CASCADE; - INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'network.dns.basiczone.updates', 'all', 'This parameter can take 2 values: all (default) and pod. It defines if DHCP/DNS requests have to be send to all dhcp servers in cloudstack, or only to the one in the same pod'); ALTER TABLE `cloud`.`op_host_capacity` DROP FOREIGN KEY `fk_op_host_capacity__pod_id`; @@ -14,6 +9,44 @@ ALTER TABLE `cloud`.`op_host_capacity` DROP FOREIGN KEY `fk_op_host_capacity__da ALTER TABLE `cloud`.`op_host_capacity` DROP FOREIGN KEY `fk_op_host_capacity__cluster_id`; ALTER TABLE `cloud`.`firewall_rules_cidrs` ADD UNIQUE INDEX `unique_rule_cidrs` (`firewall_rule_id`, `source_cidr`); +ALTER TABLE `cloud`.`firewall_rules` ADD INDEX `i_firewall_rules__purpose` (`purpose`); + +ALTER TABLE `cloud`.`cluster` ADD INDEX `i_cluster__removed`(`removed`); +ALTER TABLE `cloud`.`data_center` ADD INDEX `i_data_center__removed`(`removed`); +ALTER TABLE `cloud`.`host_pod_ref` ADD INDEX `i_host_pod_ref__removed`(`removed`); + +ALTER TABLE `cloud`.`mshost` ADD INDEX `i_mshost__removed`(`removed`); +ALTER TABLE `cloud`.`mshost` ADD INDEX `i_mshost__last_update` (`last_update`); + +ALTER TABLE `cloud`.`template_zone_ref` ADD INDEX `i_template_zone_ref__removed`(`removed`); +ALTER TABLE `cloud`.`domain` ADD INDEX `i_domain__removed`(`removed`); +ALTER TABLE `cloud`.`disk_offering` ADD INDEX `i_disk_offering__removed`(`removed`); +ALTER TABLE `cloud`.`storage_pool` ADD INDEX `i_storage_pool__removed`(`removed`); +ALTER TABLE `cloud`.`instance_group` ADD INDEX `i_instance_group__removed`(`removed`); + +ALTER TABLE `cloud`.`sync_queue_item` ADD INDEX `i_sync_queue_item__queue_proc_number`(`queue_proc_number`); +ALTER TABLE `cloud`.`sync_queue_item` ADD INDEX `i_sync_queue_item__queue_proc_msid`(`queue_proc_msid`); +ALTER TABLE `cloud`.`op_nwgrp_work` ADD INDEX `i_op_nwgrp_work__taken`(`taken`); +ALTER TABLE `cloud`.`op_nwgrp_work` ADD INDEX `i_op_nwgrp_work__step`(`step`); +ALTER TABLE `cloud`.`op_nwgrp_work` ADD INDEX `i_op_nwgrp_work__seq_no`(`seq_no`); +ALTER TABLE `cloud`.`volumes` ADD INDEX `i_volumes__state`(`state`); + +ALTER TABLE `cloud`.`op_vm_ruleset_log` ADD INDEX `i_op_vm_ruleset_log__instance_id` (`instance_id`); + +ALTER TABLE `cloud`.`storage_pool_host_ref` ADD CONSTRAINT `fk_storage_pool_host_ref__host_id` FOREIGN KEY `fk_storage_pool_host_ref__host_id`(`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`storage_pool_host_ref` ADD CONSTRAINT `fk_storage_pool_host_ref__pool_id` FOREIGN KEY `fk_storage_pool_host_ref__pool_id`(`pool_id`) REFERENCES `storage_pool`(`id`) ON DELETE CASCADE; + +ALTER TABLE `cloud`.`network_offerings` ADD INDEX `i_network_offerings__system_only` (`system_only`); +ALTER TABLE `cloud`.`resource_count` ADD CONSTRAINT `fk_resource_count__account_id` FOREIGN KEY `fk_resource_count__account_id`(`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`resource_count` ADD CONSTRAINT `fk_resource_count__domain_id` FOREIGN KEY `fk_resource_count__domain_id`(`domain_id`) REFERENCES `domain` (`id`) ON DELETE CASCADE; +ALTER TABLE `cloud`.`resource_count` ADD INDEX `i_resource_count__type` (`type`); + +ALTER TABLE `cloud`.`configuration` ADD INDEX `i_configuration__instance`(`instance`); +ALTER TABLE `cloud`.`configuration` ADD INDEX `i_configuration__name` (`name`); +ALTER TABLE `cloud`.`configuration` ADD INDEX `i_configuration__category` (`category`); +ALTER TABLE `cloud`.`configuration` ADD INDEX `i_configuration__component` (`component`); + +ALTER TABLE `cloud`.`port_forwarding_rules` ADD CONSTRAINT `fk_port_forwarding_rules__instance_id` FOREIGN KEY `fk_port_forwarding_rules__instance_id` (`instance_id`) REFERENCES `vm_instance` (`id`) ON DELETE CASCADE; INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-server', 'agent.load.threshold', '0.70', 'Percentage (as a value between 0 and 1) of connected agents after which agent load balancing will start happening'); INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.loadbalancer.haproxy.stats.visibility', 'global', 'Load Balancer(haproxy) stats visibilty, it can be global,guest-network,disabled'); @@ -21,7 +54,4 @@ INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-serve INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.loadbalancer.haproxy.stats.auth','admin1:AdMiN123','Load Balancer(haproxy) authetication string in the format username:password'); INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.loadbalancer.haproxy.stats.port','8081','Load Balancer(haproxy) stats port number.'); - -INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'use.external.dns', 'false', 'Bypass internal dns, use exetrnal dns1 and dns2'); UPDATE `cloud`.`nics` SET strategy='Start' where reserver_name='DirectPodBasedNetworkGuru'; -