CLOUDSTACK-4369 [UPGRADE]Upgrade failed from 307 to 4.2 Changes: - Do not consider removed zones - Create affinity group per domain
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0115db08 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0115db08 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0115db08 Branch: refs/heads/master Commit: 0115db08196e373bab6d2742a26a1699747a47b7 Parents: a0b48a4 Author: Prachi Damle <[email protected]> Authored: Fri Aug 16 13:30:49 2013 -0700 Committer: Prachi Damle <[email protected]> Committed: Tue Sep 3 20:03:08 2013 -0700 ---------------------------------------------------------------------- .../com/cloud/upgrade/dao/Upgrade410to420.java | 41 +++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0115db08/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index c1db30e..c24ac11 100755 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -268,19 +268,21 @@ public class Upgrade410to420 implements DbUpgrade { PreparedStatement pstmt = null; ResultSet rs = null; PreparedStatement pstmtUpdate = null; + PreparedStatement pstmt3 = null; + ResultSet rs3 = null; + try { - pstmt = conn.prepareStatement("SELECT `id`, `domain_id` FROM `cloud`.`data_center` WHERE `domain_id` IS NOT NULL"); - rs = pstmt.executeQuery(); - while (rs.next()) { - long zoneId = rs.getLong(1); - long domainId = rs.getLong(2); - long affinityGroupId; + pstmt3 = conn.prepareStatement("SELECT distinct(`domain_id`) FROM `cloud`.`data_center` WHERE `domain_id` IS NOT NULL AND removed IS NULL"); + rs3 = pstmt3.executeQuery(); + + while (rs3.next()) { + long domainId = rs3.getLong(1); + long affinityGroupId = 0; // create or find an affinity group for this domain of type // 'ExplicitDedication' - PreparedStatement pstmt2 = null; ResultSet rs2 = null; pstmt2 = conn @@ -290,7 +292,6 @@ public class Upgrade410to420 implements DbUpgrade { if (rs2.next()) { // group exists, use it affinityGroupId = rs2.getLong(1); - dedicateZone(conn, zoneId, domainId, affinityGroupId); } else { // create new group rs2.close(); @@ -301,7 +302,6 @@ public class Upgrade410to420 implements DbUpgrade { rs2 = pstmt2.executeQuery(); String domainName = ""; if (rs2.next()) { - // group exists, use it domainName = rs2.getString(1); } rs2.close(); @@ -327,7 +327,6 @@ public class Upgrade410to420 implements DbUpgrade { rs2 = pstmt2.executeQuery(); if (rs2.next()) { affinityGroupId = rs2.getLong(1); - dedicateZone(conn, zoneId, domainId, affinityGroupId); } // add the domain map @@ -339,8 +338,18 @@ public class Upgrade410to420 implements DbUpgrade { pstmtUpdate.close(); } + rs2.close(); pstmt2.close(); + + pstmt = conn.prepareStatement("SELECT `id` FROM `cloud`.`data_center` WHERE `domain_id` = ? AND removed IS NULL"); + pstmt.setLong(1, domainId); + rs = pstmt.executeQuery(); + + while (rs.next()) { + long zoneId = rs.getLong(1); + dedicateZone(conn, zoneId, domainId, affinityGroupId); + } } } catch (SQLException e) { @@ -364,6 +373,18 @@ public class Upgrade410to420 implements DbUpgrade { } catch (SQLException e) { } } + if (rs3 != null) { + try { + rs3.close(); + } catch (SQLException e) { + } + } + if (pstmt3 != null) { + try { + pstmt3.close(); + } catch (SQLException e) { + } + } } }
