@@ -51,11 +51,12 @@ public InputStream[] getPrepareScripts() {
5151
5252 @ Override
5353 public void performDataMigration (Connection conn ) {
54- updateVpcDefaultOfferingsWithFirewallService (conn );
54+ updateNetworkDefaultOfferingsForVPCWithFirewallService (conn );
55+ updateVpcOfferingsWithFirewallService (conn );
5556 }
5657
57- private void updateVpcDefaultOfferingsWithFirewallService (Connection conn ) {
58- logger .debug ("Updating default VPC offerings to add Firewall service with VpcVirtualRouter provider" );
58+ private void updateNetworkDefaultOfferingsForVPCWithFirewallService (Connection conn ) {
59+ logger .debug ("Updating default Network offerings for VPC to add Firewall service with VpcVirtualRouter provider" );
5960
6061 final List <String > defaultVpcOfferingUniqueNames = Arrays .asList (
6162 "DefaultIsolatedNetworkOfferingForVpcNetworks" ,
@@ -114,4 +115,63 @@ private void updateVpcDefaultOfferingsWithFirewallService(Connection conn) {
114115 logger .warn ("Exception while updating VPC default offerings with Firewall service: " + e .getMessage (), e );
115116 }
116117 }
118+
119+ private void updateVpcOfferingsWithFirewallService (Connection conn ) {
120+ logger .debug ("Updating default VPC offerings to add Firewall service with VpcVirtualRouter provider" );
121+
122+ final List <String > vpcOfferingUniqueNames = Arrays .asList (
123+ "Default VPC offering" ,
124+ "Default VPC offering with Netscaler" ,
125+ "Redundant VPC offering" ,
126+ "VPC offering with NSX - NAT Mode" ,
127+ "VPC offering with NSX - Route Mode" ,
128+ "VPC offering with Netris - Route Mode" ,
129+ "VPC offering with Netris - NAT Mode"
130+ );
131+
132+ try {
133+ for (String uniqueName : vpcOfferingUniqueNames ) {
134+ PreparedStatement pstmt = conn .prepareStatement ("SELECT id FROM `cloud`.`vpc_offerings` WHERE unique_name = ?" );
135+ pstmt .setString (1 , uniqueName );
136+
137+ ResultSet rs = pstmt .executeQuery ();
138+ if (!rs .next ()) {
139+ continue ;
140+ }
141+
142+ long vpcOfferingId = rs .getLong (1 );
143+ rs .close ();
144+ pstmt .close ();
145+
146+ // Insert into vpc_offering_service_map (if not exists)
147+ pstmt = conn .prepareStatement ("INSERT INTO `cloud`.`vpc_offering_service_map` " +
148+ "(vpc_offering_id, service, provider, created) " +
149+ "VALUES (?, 'Firewall', 'VpcVirtualRouter', now())" );
150+ pstmt .setLong (1 , vpcOfferingId );
151+ pstmt .executeUpdate ();
152+ pstmt .close ();
153+
154+ // Update existing VPCs
155+ pstmt = conn .prepareStatement ("SELECT id FROM `cloud`.`vpcs` WHERE vpc_offering_id = ?" );
156+ pstmt .setLong (1 , vpcOfferingId );
157+
158+ rs = pstmt .executeQuery ();
159+ while (rs .next ()) {
160+ long vpcId = rs .getLong (1 );
161+ PreparedStatement insertService = conn .prepareStatement ("INSERT INTO `cloud`.`vpc_service_map` " +
162+ "(vpc_id, service, provider, created) " +
163+ "VALUES (?, 'Firewall', 'VpcVirtualRouter', now())" );
164+ insertService .setLong (1 , vpcId );
165+ insertService .executeUpdate ();
166+ insertService .close ();
167+ }
168+
169+ rs .close ();
170+ pstmt .close ();
171+ }
172+
173+ } catch (SQLException e ) {
174+ logger .warn ("Exception while updating VPC offerings with Firewall service: " + e .getMessage (), e );
175+ }
176+ }
117177}
0 commit comments