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