Skip to content

Commit c0d2e32

Browse files
author
Prachi Damle
committed
CLOUDSTACK-4369 [UPGRADE]Upgrade failed from 307 to 4.2
Changes: - Do not consider removed zones - Create affinity group per domain
1 parent 016faea commit c0d2e32

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

‎engine/schema/src/com/cloud/upgrade/dao/Upgrade412to420.java‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,21 @@ private void movePrivateZoneToDedicatedResource(Connection conn) {
116116
PreparedStatement pstmt = null;
117117
ResultSet rs = null;
118118
PreparedStatement pstmtUpdate = null;
119+
PreparedStatement pstmt3 = null;
120+
ResultSet rs3 = null;
121+
119122

120123
try {
121-
pstmt = conn.prepareStatement("SELECT `id`, `domain_id` FROM `cloud`.`data_center` WHERE `domain_id` IS NOT NULL");
122-
rs = pstmt.executeQuery();
123124

124-
while (rs.next()) {
125-
long zoneId = rs.getLong(1);
126-
long domainId = rs.getLong(2);
127-
long affinityGroupId;
125+
pstmt3 = conn.prepareStatement("SELECT distinct(`domain_id`) FROM `cloud`.`data_center` WHERE `domain_id` IS NOT NULL AND removed IS NULL");
126+
rs3 = pstmt3.executeQuery();
127+
128+
while (rs3.next()) {
129+
long domainId = rs3.getLong(1);
130+
long affinityGroupId = 0;
128131

129132
// create or find an affinity group for this domain of type
130133
// 'ExplicitDedication'
131-
132134
PreparedStatement pstmt2 = null;
133135
ResultSet rs2 = null;
134136
pstmt2 = conn
@@ -138,7 +140,6 @@ private void movePrivateZoneToDedicatedResource(Connection conn) {
138140
if (rs2.next()) {
139141
// group exists, use it
140142
affinityGroupId = rs2.getLong(1);
141-
dedicateZone(conn, zoneId, domainId, affinityGroupId);
142143
} else {
143144
// create new group
144145
rs2.close();
@@ -149,7 +150,6 @@ private void movePrivateZoneToDedicatedResource(Connection conn) {
149150
rs2 = pstmt2.executeQuery();
150151
String domainName = "";
151152
if (rs2.next()) {
152-
// group exists, use it
153153
domainName = rs2.getString(1);
154154
}
155155
rs2.close();
@@ -175,11 +175,20 @@ private void movePrivateZoneToDedicatedResource(Connection conn) {
175175
rs2 = pstmt2.executeQuery();
176176
if (rs2.next()) {
177177
affinityGroupId = rs2.getLong(1);
178-
dedicateZone(conn, zoneId, domainId, affinityGroupId);
179178
}
180179
}
180+
181181
rs2.close();
182182
pstmt2.close();
183+
184+
pstmt = conn.prepareStatement("SELECT `id` FROM `cloud`.`data_center` WHERE `domain_id` = ? AND removed IS NULL");
185+
pstmt.setLong(1, domainId);
186+
rs = pstmt.executeQuery();
187+
188+
while (rs.next()) {
189+
long zoneId = rs.getLong(1);
190+
dedicateZone(conn, zoneId, domainId, affinityGroupId);
191+
}
183192
}
184193

185194
} catch (SQLException e) {
@@ -203,6 +212,18 @@ private void movePrivateZoneToDedicatedResource(Connection conn) {
203212
} catch (SQLException e) {
204213
}
205214
}
215+
if (rs3 != null) {
216+
try {
217+
rs3.close();
218+
} catch (SQLException e) {
219+
}
220+
}
221+
if (pstmt3 != null) {
222+
try {
223+
pstmt3.close();
224+
} catch (SQLException e) {
225+
}
226+
}
206227

207228
}
208229
}

0 commit comments

Comments
 (0)