mirror of https://github.com/apache/cloudstack.git
Added a check for duplicate public networks.
This commit is contained in:
parent
4b803d1676
commit
828b68186c
|
|
@ -22,6 +22,7 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -75,6 +76,7 @@ public class Upgrade222to224 implements DbUpgrade {
|
|||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
try {
|
||||
checkForDuplicatePublicNetworks(conn);
|
||||
fixRelatedFkeyOnNetworksTable(conn);
|
||||
updateClusterIdInOpHostCapacity(conn);
|
||||
updateGuestOsType(conn);
|
||||
|
|
@ -88,7 +90,7 @@ public class Upgrade222to224 implements DbUpgrade {
|
|||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to perform data migration", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getCleanupScripts() {
|
||||
|
|
@ -99,6 +101,39 @@ public class Upgrade222to224 implements DbUpgrade {
|
|||
|
||||
return new File[] { new File(file) };
|
||||
}
|
||||
|
||||
private void checkForDuplicatePublicNetworks(Connection conn) {
|
||||
try {
|
||||
// There should be one public network per zone
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`data_center`");
|
||||
ResultSet zones = pstmt.executeQuery();
|
||||
ArrayList<Long> zonesWithDuplicateNetworks = new ArrayList<Long>();
|
||||
String errorMsg = "Found zones with duplicate public networks during 222 to 224 upgrade. Zone IDs: ";
|
||||
long zoneId;
|
||||
|
||||
while (zones.next()) {
|
||||
zoneId = zones.getLong(1);
|
||||
pstmt = conn.prepareStatement("SELECT count(*) FROM `cloud`.`networks` WHERE `networks`.`traffic_type`='Public' AND `data_center_id`=?");
|
||||
pstmt.setLong(1, zoneId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
long numNetworks = rs.getLong(1);
|
||||
if (numNetworks > 1) {
|
||||
zonesWithDuplicateNetworks.add(zoneId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zonesWithDuplicateNetworks.size() > 0) {
|
||||
s_logger.warn(errorMsg + zonesWithDuplicateNetworks);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn(e);
|
||||
throw new CloudRuntimeException("Unable to check for duplicate public networks as part of 222 to 224 upgrade.");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateGuestOsType(Connection conn) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue