CS-15606 Dogfood Setup: Virtual Router (DHCP Server) fails to create in Pods

Reviewed-By: Alena

Changes:
- Correct the virtual router entries from table' virtual_router_providers' that wrongly refer to SecurityGroupProvider instead of VirtualRouter provider in physical_network_service_providers table
- For such entries, we update them to point to the VirtualRouter provider in physical_network_service_providers table
This commit is contained in:
prachi 2012-07-17 16:16:21 -07:00
parent 302485e8ef
commit 317e0df566
2 changed files with 86 additions and 2 deletions

View File

@ -49,9 +49,91 @@ public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade {
@Override
public void performDataMigration(Connection conn) {
correctVRProviders(conn);
correctMultiplePhysicaNetworkSetups(conn);
}
private void correctVRProviders(Connection conn) {
PreparedStatement pstmtVR = null;
ResultSet rsVR = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
pstmtVR = conn.prepareStatement("SELECT id, nsp_id FROM `cloud`.`virtual_router_providers` where type = 'VirtualRouter' AND removed IS NULL");
rsVR = pstmtVR.executeQuery();
while (rsVR.next()) {
long vrId = rsVR.getLong(1);
long nspId = rsVR.getLong(2);
//check that this nspId points to a VR provider.
pstmt = conn.prepareStatement("SELECT physical_network_id, provider_name FROM `cloud`.`physical_network_service_providers` where id = ?");
pstmt.setLong(1, nspId);
rs = pstmt.executeQuery();
if(rs.next()){
long physicalNetworkId = rs.getLong(1);
String providerName = rs.getString(2);
if(!providerName.equalsIgnoreCase("VirtualRouter")){
//mismatch, correct the nsp_id in VR
PreparedStatement pstmt1 = null;
ResultSet rs1 = null;
pstmt1 = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network_service_providers` where physical_network_id = ? AND provider_name = ? AND removed IS NULL");
pstmt1.setLong(1, physicalNetworkId);
pstmt1.setString(2, "VirtualRouter");
rs1 = pstmt1.executeQuery();
if(rs1.next()){
long correctNSPId = rs1.getLong(1);
//update VR entry
PreparedStatement pstmtUpdate = null;
String updateNSPId = "UPDATE `cloud`.`virtual_router_providers` SET nsp_id = ? WHERE id = ?";
pstmtUpdate = conn.prepareStatement(updateNSPId);
pstmtUpdate.setLong(1, correctNSPId);
pstmtUpdate.setLong(2, vrId);
pstmtUpdate.executeUpdate();
pstmtUpdate.close();
}
rs1.close();
pstmt1.close();
}
}
rs.close();
pstmt.close();
}
}catch (SQLException e) {
throw new CloudRuntimeException("Exception while correcting Virtual Router Entries", e);
} finally {
if (rsVR != null) {
try {
rsVR.close();
}catch (SQLException e) {
}
}
if (pstmtVR != null) {
try {
pstmtVR.close();
} catch (SQLException e) {
}
}
if (rs != null) {
try {
rs.close();
}catch (SQLException e) {
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
}
}
}
}
private void correctMultiplePhysicaNetworkSetups(Connection conn) {
PreparedStatement pstmtZone = null;
ResultSet rsZone = null;

View File

@ -224,8 +224,9 @@ public abstract class Upgrade30xBase implements DbUpgrade{
"`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," +
"`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,1,1,1,1,1,1,1,1,1,1,0)";
String routerUUID = UUID.randomUUID().toString();
pstmtUpdate = conn.prepareStatement(insertPNSP);
pstmtUpdate.setString(1, UUID.randomUUID().toString());
pstmtUpdate.setString(1, routerUUID );
pstmtUpdate.setLong(2, physicalNetworkId);
pstmtUpdate.setString(3, "VirtualRouter");
pstmtUpdate.setString(4, "Enabled");
@ -233,8 +234,9 @@ public abstract class Upgrade30xBase implements DbUpgrade{
pstmtUpdate.close();
// add virtual_router_element
String fetchNSPid = "SELECT id from `cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId;
String fetchNSPid = "SELECT id from `cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId + " AND provider_name = 'VirtualRouter' AND uuid = ?";
pstmt2 = conn.prepareStatement(fetchNSPid);
pstmt2.setString(1, routerUUID);
ResultSet rsNSPid = pstmt2.executeQuery();
rsNSPid.next();
long nspId = rsNSPid.getLong(1);