1717
1818package com .cloud .upgrade .dao ;
1919
20- import com .cloud .deploy .DeploymentPlanner ;
21- import com .cloud .utils .exception .CloudRuntimeException ;
22- import com .cloud .utils .script .Script ;
23- import com .cloud .hypervisor .Hypervisor .HypervisorType ;
24-
25- import org .apache .cloudstack .api .ApiConstants ;
26- import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreProvider ;
27- import org .apache .log4j .Logger ;
2820import java .io .File ;
2921import java .sql .Connection ;
3022import java .sql .Date ;
3426import java .sql .Types ;
3527import java .util .ArrayList ;
3628import java .util .HashMap ;
37- import java .util .Iterator ;
29+ import java .util .HashSet ;
3830import java .util .List ;
3931import java .util .Map ;
40- import java .util .UUID ;
4132import java .util .Set ;
42- import java .util .HashSet ;
33+ import java .util .UUID ;
34+
35+ import org .apache .log4j .Logger ;
36+
37+ import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreProvider ;
38+
39+ import com .cloud .deploy .DeploymentPlanner ;
40+ import com .cloud .hypervisor .Hypervisor .HypervisorType ;
4341import com .cloud .network .vpc .NetworkACL ;
42+ import com .cloud .utils .exception .CloudRuntimeException ;
43+ import com .cloud .utils .script .Script ;
4444
4545public class Upgrade410to420 implements DbUpgrade {
46- final static Logger s_logger = Logger .getLogger (Upgrade410to420 .class );
47-
48- // private Map<Long, Long> host_store_id_map = new HashMap<Long, Long>();
49- // private Map<Long, Long> s3_store_id_map = new HashMap<Long, Long>();
50- // private Map<Long, Long> swift_store_id_map = new HashMap<Long, Long>();
51-
52- @ Override
53- public String [] getUpgradableVersionRange () {
54- return new String [] { "4.1.0" , "4.2.0" };
55- }
56-
57- @ Override
58- public String getUpgradedVersion () {
59- return "4.2.0" ;
60- }
61-
62- @ Override
63- public boolean supportsRollingUpgrade () {
64- return false ;
65- }
66-
67- @ Override
68- public File [] getPrepareScripts () {
69- String script = Script .findScript ("" , "db/schema-410to420.sql" );
46+ final static Logger s_logger = Logger .getLogger (Upgrade410to420 .class );
47+
48+ @ Override
49+ public String [] getUpgradableVersionRange () {
50+ return new String [] { "4.1.0" , "4.2.0" };
51+ }
52+
53+ @ Override
54+ public String getUpgradedVersion () {
55+ return "4.2.0" ;
56+ }
57+
58+ @ Override
59+ public boolean supportsRollingUpgrade () {
60+ return false ;
61+ }
62+
63+ @ Override
64+ public File [] getPrepareScripts () {
65+ String script = Script .findScript ("" , "db/schema-410to420.sql" );
7066 if (script == null ) {
7167 throw new CloudRuntimeException ("Unable to find db/schema-410to420.sql" );
7268 }
7369
7470 return new File [] { new File (script ) };
75- }
71+ }
7672
77- @ Override
78- public void performDataMigration (Connection conn ) {
73+ @ Override
74+ public void performDataMigration (Connection conn ) {
7975 upgradeVmwareLabels (conn );
8076 persistLegacyZones (conn );
8177 createPlaceHolderNics (conn );
@@ -111,12 +107,12 @@ private void fixBaremetalForeignKeys(Connection conn) {
111107 keys .add ("fk_external_dhcp_devices_pod_id" );
112108 keys .add ("fk_external_dhcp_devices_physical_network_id" );
113109 DbUpgradeUtils .dropKeysIfExist (conn , "baremetal_dhcp_devices" , keys , true );
114-
110+
115111 keys .add ("fk_external_pxe_devices_nsp_id" );
116112 keys .add ("fk_external_pxe_devices_host_id" );
117113 keys .add ("fk_external_pxe_devices_physical_network_id" );
118114 DbUpgradeUtils .dropKeysIfExist (conn , "baremetal_pxe_devices" , keys , true );
119-
115+
120116 PreparedStatement pstmt = null ;
121117 try {
122118 pstmt = conn .prepareStatement ("ALTER TABLE `cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT `fk_external_dhcp_devices_nsp_id` FOREIGN KEY (`nsp_id`) REFERENCES `physical_network_service_providers` (`id`) ON DELETE CASCADE" );
@@ -180,8 +176,8 @@ private void addIndexForAlert(Connection conn) {
180176
181177 }
182178
183- private void updateSystemVmTemplates (Connection conn ) {
184- // TODO: system vm template migration after storage refactoring
179+ private void updateSystemVmTemplates (Connection conn ) {
180+ // TODO: system vm template migration after storage refactoring
185181 PreparedStatement pstmt = null ;
186182 ResultSet rs = null ;
187183 s_logger .debug ("Updating System Vm template IDs" );
@@ -193,16 +189,16 @@ private void updateSystemVmTemplates(Connection conn) {
193189 rs = pstmt .executeQuery ();
194190 while (rs .next ()){
195191 switch (HypervisorType .getType (rs .getString (1 ))) {
196- case XenServer : hypervisorsListInUse .add (HypervisorType .XenServer );
197- break ;
198- case KVM : hypervisorsListInUse .add (HypervisorType .KVM );
199- break ;
200- case VMware : hypervisorsListInUse .add (HypervisorType .VMware );
201- break ;
202- case Hyperv : hypervisorsListInUse .add (HypervisorType .Hyperv );
203- break ;
204- case LXC : hypervisorsListInUse .add (HypervisorType .LXC );
205- break ;
192+ case XenServer : hypervisorsListInUse .add (HypervisorType .XenServer );
193+ break ;
194+ case KVM : hypervisorsListInUse .add (HypervisorType .KVM );
195+ break ;
196+ case VMware : hypervisorsListInUse .add (HypervisorType .VMware );
197+ break ;
198+ case Hyperv : hypervisorsListInUse .add (HypervisorType .Hyperv );
199+ break ;
200+ case LXC : hypervisorsListInUse .add (HypervisorType .LXC );
201+ break ;
206202 }
207203 }
208204 } catch (SQLException e ) {
@@ -211,19 +207,19 @@ private void updateSystemVmTemplates(Connection conn) {
211207
212208 Map <HypervisorType , String > NewTemplateNameList = new HashMap <HypervisorType , String >(){
213209 { put (HypervisorType .XenServer , "systemvm-xenserver-4.2" );
214- put (HypervisorType .VMware , "systemvm-vmware-4.2" );
215- put (HypervisorType .KVM , "systemvm-kvm-4.2" );
216- put (HypervisorType .LXC , "systemvm-lxc-4.2" );
217- put (HypervisorType .Hyperv , "systemvm-hyperv-4.2" );
210+ put (HypervisorType .VMware , "systemvm-vmware-4.2" );
211+ put (HypervisorType .KVM , "systemvm-kvm-4.2" );
212+ put (HypervisorType .LXC , "systemvm-lxc-4.2" );
213+ put (HypervisorType .Hyperv , "systemvm-hyperv-4.2" );
218214 }
219215 };
220216
221217 Map <HypervisorType , String > routerTemplateConfigurationNames = new HashMap <HypervisorType , String >(){
222218 { put (HypervisorType .XenServer , "router.template.xen" );
223- put (HypervisorType .VMware , "router.template.vmware" );
224- put (HypervisorType .KVM , "router.template.kvm" );
225- put (HypervisorType .LXC , "router.template.lxc" );
226- put (HypervisorType .Hyperv , "router.template.hyperv" );
219+ put (HypervisorType .VMware , "router.template.vmware" );
220+ put (HypervisorType .KVM , "router.template.kvm" );
221+ put (HypervisorType .LXC , "router.template.lxc" );
222+ put (HypervisorType .Hyperv , "router.template.hyperv" );
227223 }
228224 };
229225
@@ -296,20 +292,20 @@ private void updateSystemVmTemplates(Connection conn) {
296292 }
297293 }
298294 }
299- */
300- }
295+ */
296+ }
301297
302- private void updatePrimaryStore (Connection conn ) {
303- PreparedStatement sql = null ;
304- PreparedStatement sql2 = null ;
298+ private void updatePrimaryStore (Connection conn ) {
299+ PreparedStatement sql = null ;
300+ PreparedStatement sql2 = null ;
305301 try {
306302 sql = conn .prepareStatement ("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'" );
307- sql .setString (1 , "ancient primary data store provider" );
303+ sql .setString (1 , DataStoreProvider . DEFAULT_PRIMARY );
308304 sql .setString (2 , "HOST" );
309305 sql .executeUpdate ();
310306
311307 sql2 = conn .prepareStatement ("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'" );
312- sql2 .setString (1 , "ancient primary data store provider" );
308+ sql2 .setString (1 , DataStoreProvider . DEFAULT_PRIMARY );
313309 sql2 .setString (2 , "CLUSTER" );
314310 sql2 .executeUpdate ();
315311 } catch (SQLException e ) {
@@ -329,7 +325,7 @@ private void updatePrimaryStore(Connection conn) {
329325 }
330326 }
331327 }
332- }
328+ }
333329
334330 //update the cluster_details table with default overcommit ratios.
335331 private void updateCluster_details (Connection conn ) {
@@ -367,8 +363,8 @@ private void updateCluster_details(Connection conn) {
367363 }
368364
369365
370- @ Override
371- public File [] getCleanupScripts () {
366+ @ Override
367+ public File [] getCleanupScripts () {
372368 String script = Script .findScript ("" , "db/schema-410to420-cleanup.sql" );
373369 if (script == null ) {
374370 throw new CloudRuntimeException ("Unable to find db/schema-410to420-cleanup.sql" );
@@ -632,18 +628,18 @@ private void createPlaceHolderNics(Connection conn) {
632628 pstmt = conn .prepareStatement ("SELECT network_id, gateway, ip4_address FROM `cloud`.`nics` WHERE reserver_name IN ('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' AND removed IS null" );
633629 rs = pstmt .executeQuery ();
634630 while (rs .next ()) {
635- Long networkId = rs .getLong (1 );
636- String gateway = rs .getString (2 );
637- String ip = rs .getString (3 );
638- String uuid = UUID .randomUUID ().toString ();
639- //Insert placeholder nic for each Domain router nic in Shared network
640- pstmt = conn .prepareStatement ("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')" );
641- pstmt .setString (1 , uuid );
642- pstmt .setString (2 , ip );
643- pstmt .setString (3 , gateway );
644- pstmt .setLong (4 , networkId );
645- pstmt .executeUpdate ();
646- s_logger .debug ("Created placeholder nic for the ipAddress " + ip );
631+ Long networkId = rs .getLong (1 );
632+ String gateway = rs .getString (2 );
633+ String ip = rs .getString (3 );
634+ String uuid = UUID .randomUUID ().toString ();
635+ //Insert placeholder nic for each Domain router nic in Shared network
636+ pstmt = conn .prepareStatement ("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')" );
637+ pstmt .setString (1 , uuid );
638+ pstmt .setString (2 , ip );
639+ pstmt .setString (3 , gateway );
640+ pstmt .setLong (4 , networkId );
641+ pstmt .executeUpdate ();
642+ s_logger .debug ("Created placeholder nic for the ipAddress " + ip );
647643
648644 }
649645 } catch (SQLException e ) {
@@ -671,14 +667,14 @@ private void updateRemoteAccessVpn(Connection conn) {
671667 rs = pstmt .executeQuery ();
672668 long id =1 ;
673669 while (rs .next ()) {
674- String uuid = UUID .randomUUID ().toString ();
675- Long ipId = rs .getLong (1 );
676- pstmt = conn .prepareStatement ("UPDATE `cloud`.`remote_access_vpn` set uuid=?, id=? where vpn_server_addr_id=?" );
677- pstmt .setString (1 , uuid );
678- pstmt .setLong (2 , id );
679- pstmt .setLong (3 , ipId );
680- pstmt .executeUpdate ();
681- id ++;
670+ String uuid = UUID .randomUUID ().toString ();
671+ Long ipId = rs .getLong (1 );
672+ pstmt = conn .prepareStatement ("UPDATE `cloud`.`remote_access_vpn` set uuid=?, id=? where vpn_server_addr_id=?" );
673+ pstmt .setString (1 , uuid );
674+ pstmt .setLong (2 , id );
675+ pstmt .setLong (3 , ipId );
676+ pstmt .executeUpdate ();
677+ id ++;
682678 }
683679 } catch (SQLException e ) {
684680 throw new CloudRuntimeException ("Unable to update id/uuid of remote_access_vpn table" , e );
@@ -1035,15 +1031,15 @@ private void upgradePhysicalNtwksWithInternalLbProvider(Connection conn) {
10351031 String uuid = UUID .randomUUID ().toString ();
10361032 //Add internal LB VM to the list of physical network service providers
10371033 pstmt = conn .prepareStatement ("INSERT INTO `cloud`.`physical_network_service_providers` " +
1038- "(uuid, physical_network_id, provider_name, state, load_balance_service_provided, destination_physical_network_id)" +
1039- " VALUES (?, ?, 'InternalLbVm', 'Enabled', 1, 0)" );
1034+ "(uuid, physical_network_id, provider_name, state, load_balance_service_provided, destination_physical_network_id)" +
1035+ " VALUES (?, ?, 'InternalLbVm', 'Enabled', 1, 0)" );
10401036 pstmt .setString (1 , uuid );
10411037 pstmt .setLong (2 , pNtwkId );
10421038 pstmt .executeUpdate ();
10431039
10441040 //Add internal lb vm to the list of physical network elements
10451041 PreparedStatement pstmt1 = conn .prepareStatement ("SELECT id FROM `cloud`.`physical_network_service_providers`" +
1046- " WHERE physical_network_id=? AND provider_name='InternalLbVm'" );
1042+ " WHERE physical_network_id=? AND provider_name='InternalLbVm'" );
10471043 pstmt1 .setLong (1 , pNtwkId );
10481044 ResultSet rs1 = pstmt1 .executeQuery ();
10491045 while (rs1 .next ()) {
0 commit comments