|
25 | 25 | import java.sql.SQLException; |
26 | 26 | import java.util.ArrayList; |
27 | 27 | import java.util.HashMap; |
28 | | -import java.util.HashSet; |
29 | 28 | import java.util.List; |
30 | 29 | import java.util.Map; |
31 | | -import java.util.Set; |
32 | | - |
33 | | -import com.cloud.hypervisor.Hypervisor; |
34 | | -import com.cloud.utils.crypt.DBEncryptionUtil; |
35 | 30 |
|
36 | 31 | import org.apache.log4j.Logger; |
37 | 32 |
|
| 33 | +import com.cloud.utils.crypt.DBEncryptionUtil; |
38 | 34 | import com.cloud.utils.exception.CloudRuntimeException; |
39 | 35 | import com.cloud.utils.script.Script; |
40 | 36 |
|
@@ -68,7 +64,6 @@ public File[] getPrepareScripts() { |
68 | 64 |
|
69 | 65 | @Override |
70 | 66 | public void performDataMigration(Connection conn) { |
71 | | - updateSystemVmTemplates(conn); |
72 | 67 | dropInvalidKeyFromStoragePoolTable(conn); |
73 | 68 | dropDuplicatedForeignKeyFromAsyncJobTable(conn); |
74 | 69 | updateMaxRouterSizeConfig(conn); |
@@ -152,150 +147,6 @@ public File[] getCleanupScripts() { |
152 | 147 | return new File[] {new File(script)}; |
153 | 148 | } |
154 | 149 |
|
155 | | - private void updateSystemVmTemplates(Connection conn) { |
156 | | - s_logger.debug("Updating System Vm template IDs"); |
157 | | - //Get all hypervisors in use |
158 | | - Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>(); |
159 | | - try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); |
160 | | - ResultSet rs = pstmt.executeQuery() |
161 | | - ) { |
162 | | - while(rs.next()){ |
163 | | - switch (Hypervisor.HypervisorType.getType(rs.getString(1))) { |
164 | | - case XenServer: hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); |
165 | | - break; |
166 | | - case KVM: hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); |
167 | | - break; |
168 | | - case VMware: hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); |
169 | | - break; |
170 | | - case Hyperv: hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); |
171 | | - break; |
172 | | - case LXC: hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); |
173 | | - break; |
174 | | - default: // no action on cases Any, BareMetal, None, Ovm, Parralels, Simulator and VirtualBox: |
175 | | - break; |
176 | | - } |
177 | | - } |
178 | | - } catch (SQLException e) { |
179 | | - s_logger.error("updateSystemVmTemplates:Exception while getting hypervisor types from clusters: "+e.getMessage()); |
180 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e); |
181 | | - } |
182 | | - |
183 | | - Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() { |
184 | | - { |
185 | | - put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.5"); |
186 | | - put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.5"); |
187 | | - put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.5"); |
188 | | - put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.5"); |
189 | | - put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.5"); |
190 | | - } |
191 | | - }; |
192 | | - |
193 | | - Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() { |
194 | | - { |
195 | | - put(Hypervisor.HypervisorType.XenServer, "router.template.xen"); |
196 | | - put(Hypervisor.HypervisorType.VMware, "router.template.vmware"); |
197 | | - put(Hypervisor.HypervisorType.KVM, "router.template.kvm"); |
198 | | - put(Hypervisor.HypervisorType.LXC, "router.template.lxc"); |
199 | | - put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv"); |
200 | | - } |
201 | | - }; |
202 | | - |
203 | | - Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() { |
204 | | - { |
205 | | - put(Hypervisor.HypervisorType.XenServer, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-xen.vhd.bz2"); |
206 | | - put(Hypervisor.HypervisorType.VMware, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-vmware.ova"); |
207 | | - put(Hypervisor.HypervisorType.KVM, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-kvm.qcow2.bz2"); |
208 | | - put(Hypervisor.HypervisorType.LXC, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-kvm.qcow2.bz2"); |
209 | | - put(Hypervisor.HypervisorType.Hyperv, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-hyperv.vhd.zip"); |
210 | | - } |
211 | | - }; |
212 | | - |
213 | | - Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() { |
214 | | - { |
215 | | - put(Hypervisor.HypervisorType.XenServer, "2b15ab4401c2d655264732d3fc600241"); |
216 | | - put(Hypervisor.HypervisorType.VMware, "3106a79a4ce66cd7f6a7c50e93f2db57"); |
217 | | - put(Hypervisor.HypervisorType.KVM, "aa9f501fecd3de1daeb9e2f357f6f002"); |
218 | | - put(Hypervisor.HypervisorType.LXC, "aa9f501fecd3de1daeb9e2f357f6f002"); |
219 | | - put(Hypervisor.HypervisorType.Hyperv, "70bd30ea02ee9ed67d2c6b85c179cee9"); |
220 | | - } |
221 | | - }; |
222 | | - |
223 | | - for (Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) { |
224 | | - s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); |
225 | | - try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1")) { |
226 | | - //Get 4.5.0 system Vm template Id for corresponding hypervisor |
227 | | - long templateId = -1; |
228 | | - pstmt.setString(1, hypervisorAndTemplateName.getValue()); |
229 | | - try (ResultSet rs = pstmt.executeQuery()) { |
230 | | - if(rs.next()){ |
231 | | - templateId = rs.getLong(1); |
232 | | - } |
233 | | - } catch (SQLException e) |
234 | | - { |
235 | | - s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: "+e.getMessage()); |
236 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); |
237 | | - } |
238 | | - |
239 | | - // change template type to SYSTEM |
240 | | - if (templateId != -1) { |
241 | | - try(PreparedStatement templ_type_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) |
242 | | - { |
243 | | - templ_type_pstmt.setLong(1, templateId); |
244 | | - templ_type_pstmt.executeUpdate(); |
245 | | - } |
246 | | - catch (SQLException e) |
247 | | - { |
248 | | - s_logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': "+e.getMessage()); |
249 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e); |
250 | | - } |
251 | | - // update template ID of system Vms |
252 | | - try(PreparedStatement update_templ_id_pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) |
253 | | - { |
254 | | - update_templ_id_pstmt.setLong(1, templateId); |
255 | | - update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); |
256 | | - update_templ_id_pstmt.executeUpdate(); |
257 | | - }catch (Exception e) |
258 | | - { |
259 | | - s_logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId + ": "+e.getMessage()); |
260 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId, e); |
261 | | - } |
262 | | - // Change value of global configuration parameter router.template.* for the corresponding hypervisor |
263 | | - try(PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) { |
264 | | - update_pstmt.setString(1, hypervisorAndTemplateName.getValue()); |
265 | | - update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); |
266 | | - update_pstmt.executeUpdate(); |
267 | | - }catch (SQLException e) |
268 | | - { |
269 | | - s_logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue() + ": "+e.getMessage()); |
270 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e); |
271 | | - } |
272 | | - } else { |
273 | | - if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){ |
274 | | - throw new CloudRuntimeException("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); |
275 | | - } else { |
276 | | - s_logger.warn("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade"); |
277 | | - // Update the latest template URLs for corresponding hypervisor |
278 | | - try(PreparedStatement update_templ_url_pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) { |
279 | | - update_templ_url_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); |
280 | | - update_templ_url_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); |
281 | | - update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); |
282 | | - update_templ_url_pstmt.executeUpdate(); |
283 | | - }catch (SQLException e) |
284 | | - { |
285 | | - s_logger.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString() + ": "+e.getMessage()); |
286 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString(), e); |
287 | | - } |
288 | | - } |
289 | | - } |
290 | | - } catch (SQLException e) { |
291 | | - s_logger.error("updateSystemVmTemplates:Exception while getting ids of templates: "+e.getMessage()); |
292 | | - throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); |
293 | | - } |
294 | | - } |
295 | | - s_logger.debug("Updating System Vm Template IDs Complete"); |
296 | | - } |
297 | | - |
298 | | - |
299 | 150 | private void dropInvalidKeyFromStoragePoolTable(Connection conn) { |
300 | 151 | HashMap<String, List<String>> uniqueKeys = new HashMap<String, List<String>>(); |
301 | 152 | List<String> keys = new ArrayList<String>(); |
|
0 commit comments