|
23 | 23 | import java.sql.ResultSet; |
24 | 24 | import java.sql.SQLException; |
25 | 25 | import java.util.ArrayList; |
26 | | -import java.util.HashMap; |
27 | | -import java.util.HashSet; |
28 | 26 | import java.util.List; |
29 | | -import java.util.Map; |
30 | | -import java.util.Set; |
31 | 27 |
|
32 | 28 | import org.apache.log4j.Logger; |
33 | 29 |
|
34 | | -import com.cloud.hypervisor.Hypervisor; |
35 | 30 | import com.cloud.utils.exception.CloudRuntimeException; |
36 | 31 | import com.cloud.utils.script.Script; |
37 | 32 |
|
@@ -65,7 +60,6 @@ public File[] getPrepareScripts() { |
65 | 60 |
|
66 | 61 | @Override |
67 | 62 | public void performDataMigration(final Connection conn) { |
68 | | - updateSystemVmTemplates(conn); |
69 | 63 | updateVMInstanceUserId(conn); |
70 | 64 | addIndexForVMInstance(conn); |
71 | 65 | } |
@@ -170,174 +164,4 @@ public File[] getCleanupScripts() { |
170 | 164 |
|
171 | 165 | return new File[] { new File(script) }; |
172 | 166 | } |
173 | | - |
174 | | - @SuppressWarnings("serial") |
175 | | - private void updateSystemVmTemplates(final Connection conn) { |
176 | | - s_logger.debug("Updating System Vm template IDs"); |
177 | | - // Get all hypervisors in use |
178 | | - final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>(); |
179 | | - try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) { |
180 | | - while (rs.next()) { |
181 | | - switch (Hypervisor.HypervisorType.getType(rs.getString(1))) { |
182 | | - case XenServer: |
183 | | - hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); |
184 | | - break; |
185 | | - case KVM: |
186 | | - hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); |
187 | | - break; |
188 | | - case VMware: |
189 | | - hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); |
190 | | - break; |
191 | | - case Hyperv: |
192 | | - hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); |
193 | | - break; |
194 | | - case LXC: |
195 | | - hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); |
196 | | - break; |
197 | | - case Ovm3: |
198 | | - hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3); |
199 | | - break; |
200 | | - default: // no action on cases Any, BareMetal, None, Ovm, |
201 | | - // Parralels, Simulator and VirtualBox: |
202 | | - break; |
203 | | - } |
204 | | - } |
205 | | - } catch (final SQLException e) { |
206 | | - s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: " + e.getMessage()); |
207 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e); |
208 | | - } |
209 | | - |
210 | | - final Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() { |
211 | | - { |
212 | | - put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.6"); |
213 | | - put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.6"); |
214 | | - put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.6"); |
215 | | - put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.6"); |
216 | | - put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.6"); |
217 | | - put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.6"); |
218 | | - } |
219 | | - }; |
220 | | - |
221 | | - final Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() { |
222 | | - { |
223 | | - put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver"); |
224 | | - put(Hypervisor.HypervisorType.VMware, "router.template.vmware"); |
225 | | - put(Hypervisor.HypervisorType.KVM, "router.template.kvm"); |
226 | | - put(Hypervisor.HypervisorType.LXC, "router.template.lxc"); |
227 | | - put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv"); |
228 | | - put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3"); |
229 | | - } |
230 | | - }; |
231 | | - |
232 | | - final Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() { |
233 | | - { |
234 | | - put(Hypervisor.HypervisorType.XenServer, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-xen.vhd.bz2"); |
235 | | - put(Hypervisor.HypervisorType.VMware, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-vmware.ova"); |
236 | | - put(Hypervisor.HypervisorType.KVM, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2"); |
237 | | - put(Hypervisor.HypervisorType.LXC, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2"); |
238 | | - put(Hypervisor.HypervisorType.Hyperv, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-hyperv.vhd.zip"); |
239 | | - put(Hypervisor.HypervisorType.Ovm3, "http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-ovm.raw.bz2"); |
240 | | - } |
241 | | - }; |
242 | | - |
243 | | - final Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() { |
244 | | - { |
245 | | - put(Hypervisor.HypervisorType.XenServer, "8886f554a499ec5405b6f203d9d36460"); |
246 | | - put(Hypervisor.HypervisorType.VMware, "4b415224fe00b258f66cad9fce9f73fc"); |
247 | | - put(Hypervisor.HypervisorType.KVM, "c059b0d051e0cd6fbe9d5d4fc40c7e5d"); |
248 | | - put(Hypervisor.HypervisorType.LXC, "c059b0d051e0cd6fbe9d5d4fc40c7e5d"); |
249 | | - put(Hypervisor.HypervisorType.Hyperv, "53e24bddfa56ea3139ed37af4b519013"); |
250 | | - put(Hypervisor.HypervisorType.Ovm3, "c8577d27b2daafb2d9a4ed307ce2f00f"); |
251 | | - } |
252 | | - }; |
253 | | - |
254 | | - for (final Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) { |
255 | | - s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); |
256 | | - try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) { |
257 | | - // Get 4.6.0 system Vm template Id for corresponding hypervisor |
258 | | - long templateId = -1; |
259 | | - pstmt.setString(1, hypervisorAndTemplateName.getValue()); |
260 | | - try (ResultSet rs = pstmt.executeQuery()) { |
261 | | - if (rs.next()) { |
262 | | - templateId = rs.getLong(1); |
263 | | - } |
264 | | - } catch (final SQLException e) { |
265 | | - s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); |
266 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); |
267 | | - } |
268 | | - |
269 | | - // change template type to SYSTEM |
270 | | - if (templateId != -1) { |
271 | | - try (PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) { |
272 | | - templ_type_pstmt.setLong(1, templateId); |
273 | | - templ_type_pstmt.executeUpdate(); |
274 | | - } catch (final SQLException e) { |
275 | | - s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage()); |
276 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e); |
277 | | - } |
278 | | - // update template ID of system Vms |
279 | | - try (PreparedStatement update_templ_id_pstmt = conn |
280 | | - .prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) { |
281 | | - update_templ_id_pstmt.setLong(1, templateId); |
282 | | - update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); |
283 | | - update_templ_id_pstmt.executeUpdate(); |
284 | | - } catch (final Exception e) { |
285 | | - s_logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId |
286 | | - + ": " + e.getMessage()); |
287 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " |
288 | | - + templateId, e); |
289 | | - } |
290 | | - |
291 | | - // Change value of global configuration parameter |
292 | | - // router.template.* for the corresponding hypervisor |
293 | | - try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) { |
294 | | - update_pstmt.setString(1, hypervisorAndTemplateName.getValue()); |
295 | | - update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); |
296 | | - update_pstmt.executeUpdate(); |
297 | | - } catch (final SQLException e) { |
298 | | - s_logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " |
299 | | - + hypervisorAndTemplateName.getValue() + ": " + e.getMessage()); |
300 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting " |
301 | | - + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e); |
302 | | - } |
303 | | - |
304 | | - // Change value of global configuration parameter |
305 | | - // minreq.sysvmtemplate.version for the ACS version |
306 | | - try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) { |
307 | | - update_pstmt.setString(1, getUpgradedVersion()); |
308 | | - update_pstmt.setString(2, "minreq.sysvmtemplate.version"); |
309 | | - update_pstmt.executeUpdate(); |
310 | | - } catch (final SQLException e) { |
311 | | - s_logger.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.6.0: " + e.getMessage()); |
312 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.6.0", e); |
313 | | - } |
314 | | - } else { |
315 | | - if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) { |
316 | | - throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); |
317 | | - } else { |
318 | | - s_logger.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() |
319 | | - + " hypervisor is not used, so not failing upgrade"); |
320 | | - // Update the latest template URLs for corresponding |
321 | | - // hypervisor |
322 | | - try (PreparedStatement update_templ_url_pstmt = conn |
323 | | - .prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) { |
324 | | - update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); |
325 | | - update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); |
326 | | - update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); |
327 | | - update_templ_url_pstmt.executeUpdate(); |
328 | | - } catch (final SQLException e) { |
329 | | - s_logger.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " |
330 | | - + hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage()); |
331 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " |
332 | | - + hypervisorAndTemplateName.getKey().toString(), e); |
333 | | - } |
334 | | - } |
335 | | - } |
336 | | - } catch (final SQLException e) { |
337 | | - s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); |
338 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); |
339 | | - } |
340 | | - } |
341 | | - s_logger.debug("Updating System Vm Template IDs Complete"); |
342 | | - } |
343 | 167 | } |
0 commit comments