@@ -115,6 +115,7 @@ public void performDataMigration(Connection conn) {
115115 setRAWformatForRBDVolumes (conn );
116116 migrateVolumeOnSecondaryStorage (conn );
117117 createFullCloneFlag (conn );
118+ upgradeVpcServiceMap (conn );
118119 }
119120
120121 private void createFullCloneFlag (Connection conn ) {
@@ -2953,4 +2954,59 @@ protected void setRAWformatForRBDVolumes(Connection conn) {
29532954 throw new CloudRuntimeException ("Failed to update volume format to RAW for volumes on RBD pools due to exception " , e );
29542955 }
29552956 }
2957+
2958+
2959+ private void upgradeVpcServiceMap (Connection conn ){
2960+ s_logger .debug ("Upgrading VPC service Map" );
2961+ PreparedStatement listVpc = null ;
2962+ PreparedStatement listServiceProviders = null ;
2963+ PreparedStatement insertProviders = null ;
2964+ ResultSet rs = null ;
2965+ ResultSet rs1 = null ;
2966+ try {
2967+ //Get all vpc Ids along with vpc offering Id
2968+ listVpc = conn .prepareStatement ("SELECT id, vpc_offering_id FROM `cloud`.`vpc` where removed is NULL" );
2969+ rs = listVpc .executeQuery ();
2970+ while (rs .next ()) {
2971+ long vpc_id = rs .getLong (1 );
2972+ long offering_id = rs .getLong (2 );
2973+ //list all services and providers in offering
2974+ listServiceProviders = conn .prepareStatement ("SELECT service, provider FROM `cloud`.`vpc_offering_service_map` where vpc_offering_id = ?" );
2975+ listServiceProviders .setLong (1 , offering_id );
2976+ rs1 = listServiceProviders .executeQuery ();
2977+ //Insert entries in vpc_service_map
2978+ while (rs1 .next ()) {
2979+ String service = rs1 .getString (1 );
2980+ String provider = rs1 .getString (2 );
2981+ insertProviders = conn .prepareStatement ("INSERT INTO `cloud`.`vpc_service_map` (`vpc_id`, `service`, `provider`, `created`) VALUES (?, ?, ?, now());" );
2982+ insertProviders .setLong (1 , vpc_id );
2983+ insertProviders .setString (2 , service );
2984+ insertProviders .setString (3 , provider );
2985+ insertProviders .executeUpdate ();
2986+ }
2987+ s_logger .debug ("Upgraded service map for VPC: " +vpc_id );
2988+ }
2989+ }catch (SQLException e ) {
2990+ throw new CloudRuntimeException ("Error during VPC service map upgrade" , e );
2991+ } finally {
2992+ try {
2993+ if (rs != null ) {
2994+ rs .close ();
2995+ }
2996+ if (rs1 != null ) {
2997+ rs1 .close ();
2998+ }
2999+ if (listVpc != null ) {
3000+ listVpc .close ();
3001+ }
3002+ if (listServiceProviders != null ) {
3003+ listServiceProviders .close ();
3004+ }
3005+ if (insertProviders != null ) {
3006+ insertProviders .close ();
3007+ }
3008+ } catch (SQLException e ) {
3009+ }
3010+ }
3011+ }
29563012}
0 commit comments