CLOUDSTACK-4369 [UPGRADE]Upgrade failed from 307 to 4.2

Changes:
- Do not consider removed zones
- Create affinity group per domain
This commit is contained in:
Prachi Damle 2013-08-16 13:30:49 -07:00
parent a0b48a45c0
commit 0115db0819

View File

@ -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) {
}
}
}
}