|
27 | 27 | import java.sql.Types; |
28 | 28 | import java.util.ArrayList; |
29 | 29 | import java.util.HashMap; |
30 | | -import java.util.HashSet; |
31 | 30 | import java.util.Iterator; |
32 | 31 | import java.util.List; |
33 | 32 | import java.util.Map; |
34 | | -import java.util.Set; |
35 | 33 | import java.util.UUID; |
36 | 34 |
|
37 | 35 | import org.apache.log4j.Logger; |
@@ -83,7 +81,6 @@ public void performDataMigration(Connection conn) { |
83 | 81 | persistVswitchConfiguration(conn); |
84 | 82 | createPlaceHolderNics(conn); |
85 | 83 | updateRemoteAccessVpn(conn); |
86 | | - updateSystemVmTemplates(conn); |
87 | 84 | updateOverCommitRatioClusterDetails(conn); |
88 | 85 | updatePrimaryStore(conn); |
89 | 86 | addEgressFwRulesForSRXGuestNw(conn); |
@@ -629,162 +626,6 @@ private void dropUploadTable(Connection conn) { |
629 | 626 |
|
630 | 627 | } |
631 | 628 |
|
632 | | - private void updateSystemVmTemplates(Connection conn) { |
633 | | - // TODO: system vm template migration after storage refactoring |
634 | | - PreparedStatement pstmt = null; |
635 | | - ResultSet rs = null; |
636 | | - s_logger.debug("Updating System Vm template IDs"); |
637 | | - try{ |
638 | | - //Get all hypervisors in use |
639 | | - Set<HypervisorType> hypervisorsListInUse = new HashSet<HypervisorType>(); |
640 | | - try { |
641 | | - pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); |
642 | | - rs = pstmt.executeQuery(); |
643 | | - while(rs.next()){ |
644 | | - switch (HypervisorType.getType(rs.getString(1))) { |
645 | | - case XenServer: hypervisorsListInUse.add(HypervisorType.XenServer); |
646 | | - break; |
647 | | - case KVM: hypervisorsListInUse.add(HypervisorType.KVM); |
648 | | - break; |
649 | | - case VMware: hypervisorsListInUse.add(HypervisorType.VMware); |
650 | | - break; |
651 | | - case Hyperv: hypervisorsListInUse.add(HypervisorType.Hyperv); |
652 | | - break; |
653 | | - case LXC: hypervisorsListInUse.add(HypervisorType.LXC); |
654 | | - break; |
655 | | - } |
656 | | - } |
657 | | - } catch (SQLException e) { |
658 | | - throw new CloudRuntimeException("Error while listing hypervisors in use", e); |
659 | | - } |
660 | | - |
661 | | - Map<HypervisorType, String> NewTemplateNameList = new HashMap<HypervisorType, String>(){ |
662 | | - { put(HypervisorType.XenServer, "systemvm-xenserver-4.2"); |
663 | | - put(HypervisorType.VMware, "systemvm-vmware-4.2"); |
664 | | - put(HypervisorType.KVM, "systemvm-kvm-4.2"); |
665 | | - put(HypervisorType.LXC, "systemvm-lxc-4.2"); |
666 | | - put(HypervisorType.Hyperv, "systemvm-hyperv-4.2"); |
667 | | - } |
668 | | - }; |
669 | | - |
670 | | - Map<HypervisorType, String> routerTemplateConfigurationNames = new HashMap<HypervisorType, String>(){ |
671 | | - { put(HypervisorType.XenServer, "router.template.xen"); |
672 | | - put(HypervisorType.VMware, "router.template.vmware"); |
673 | | - put(HypervisorType.KVM, "router.template.kvm"); |
674 | | - put(HypervisorType.LXC, "router.template.lxc"); |
675 | | - put(HypervisorType.Hyperv, "router.template.hyperv"); |
676 | | - } |
677 | | - }; |
678 | | - |
679 | | - Map<HypervisorType, String> newTemplateUrl = new HashMap<HypervisorType, String>(){ |
680 | | - { put(HypervisorType.XenServer, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-07-12-master-xen.vhd.bz2"); |
681 | | - put(HypervisorType.VMware, "http://download.cloud.com/templates/4.2/systemvmtemplate-4.2-vh7.ova"); |
682 | | - put(HypervisorType.KVM, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2"); |
683 | | - put(HypervisorType.LXC, "http://download.cloud.com/templates/acton/acton-systemvm-02062012.qcow2.bz2"); |
684 | | - put(HypervisorType.Hyperv, "http://download.cloud.com/templates/4.2/systemvmtemplate-2013-06-12-master-xen.vhd.bz2"); |
685 | | - } |
686 | | - }; |
687 | | - |
688 | | - Map<HypervisorType, String> newTemplateChecksum = new HashMap<HypervisorType, String>(){ |
689 | | - { put(HypervisorType.XenServer, "fb1b6e032a160d86f2c28feb5add6d83"); |
690 | | - put(HypervisorType.VMware, "8fde62b1089e5844a9cd3b9b953f9596"); |
691 | | - put(HypervisorType.KVM, "6cea42b2633841648040becb588bd8f0"); |
692 | | - put(HypervisorType.LXC, "2755de1f9ef2ce4d6f2bee2efbb4da92"); |
693 | | - put(HypervisorType.Hyperv, "fb1b6e032a160d86f2c28feb5add6d83"); |
694 | | - } |
695 | | - }; |
696 | | - |
697 | | - for (Map.Entry<HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){ |
698 | | - s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); |
699 | | - try { |
700 | | - //Get 4.2.0 system Vm template Id for corresponding hypervisor |
701 | | - pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1"); |
702 | | - pstmt.setString(1, hypervisorAndTemplateName.getValue()); |
703 | | - rs = pstmt.executeQuery(); |
704 | | - if(rs.next()){ |
705 | | - long templateId = rs.getLong(1); |
706 | | - rs.close(); |
707 | | - pstmt.close(); |
708 | | - // Mark the old system templates as removed |
709 | | - pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET removed = now() WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null"); |
710 | | - pstmt.setString(1, hypervisorAndTemplateName.getKey().toString()); |
711 | | - pstmt.executeUpdate(); |
712 | | - pstmt.close(); |
713 | | - // change template type to SYSTEM |
714 | | - pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?"); |
715 | | - pstmt.setLong(1, templateId); |
716 | | - pstmt.executeUpdate(); |
717 | | - pstmt.close(); |
718 | | - // update templete ID of system Vms |
719 | | - pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?"); |
720 | | - pstmt.setLong(1, templateId); |
721 | | - pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); |
722 | | - pstmt.executeUpdate(); |
723 | | - pstmt.close(); |
724 | | - // Change value of global configuration parameter router.template.* for the corresponding hypervisor |
725 | | - pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?"); |
726 | | - pstmt.setString(1, hypervisorAndTemplateName.getValue()); |
727 | | - pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); |
728 | | - pstmt.executeUpdate(); |
729 | | - pstmt.close(); |
730 | | - } else { |
731 | | - if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){ |
732 | | - throw new CloudRuntimeException("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); |
733 | | - } else { |
734 | | - s_logger.warn("4.2.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade"); |
735 | | - // Update the latest template URLs for corresponding hypervisor |
736 | | - 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"); |
737 | | - pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); |
738 | | - pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); |
739 | | - pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); |
740 | | - pstmt.executeUpdate(); |
741 | | - pstmt.close(); |
742 | | - } |
743 | | - } |
744 | | - } catch (SQLException e) { |
745 | | - throw new CloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey() +" systemVm template", e); |
746 | | - } |
747 | | - } |
748 | | - try { |
749 | | - pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` set dynamically_scalable = 1 where name = ? and type = 'SYSTEM'"); |
750 | | - pstmt.setString(1, NewTemplateNameList.get(HypervisorType.VMware)); |
751 | | - pstmt.executeUpdate(); |
752 | | - pstmt.close(); |
753 | | - } catch (SQLException e) { |
754 | | - throw new CloudRuntimeException("Error while updating dynamically_scalable flag to 1 for SYSTEM template systemvm-vmware-4.2"); |
755 | | - } |
756 | | - s_logger.debug("Updating System Vm Template IDs Complete"); |
757 | | - } |
758 | | - finally { |
759 | | - try { |
760 | | - if (rs != null) { |
761 | | - rs.close(); |
762 | | - } |
763 | | - |
764 | | - if (pstmt != null) { |
765 | | - pstmt.close(); |
766 | | - } |
767 | | - } catch (SQLException e) { |
768 | | - } |
769 | | - } |
770 | | - /* |
771 | | - pstmt = null; |
772 | | - try { |
773 | | - pstmt = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'"); |
774 | | - pstmt.executeUpdate(); |
775 | | - } catch (SQLException e) { |
776 | | - throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString()); |
777 | | - } finally { |
778 | | - if (pstmt != null) { |
779 | | - try { |
780 | | - pstmt.close(); |
781 | | - } catch (SQLException e) { |
782 | | - } |
783 | | - } |
784 | | - } |
785 | | - */ |
786 | | - } |
787 | | - |
788 | 629 | //KVM snapshot flag: only turn on if Customers is using snapshot; |
789 | 630 | private void setKVMSnapshotFlag(Connection conn) { |
790 | 631 | s_logger.debug("Verify and set the KVM snapshot flag if snapshot was used. "); |
|
0 commit comments