mirror of https://github.com/apache/cloudstack.git
CS-14553: db upgrade - for default network offerings:
1) Change display text to match fresh 3.0.2 2) Delete lb service for the offerings using VR as a provider and not having source nat service
This commit is contained in:
parent
b142911515
commit
d51d018a1b
|
|
@ -17,6 +17,9 @@ package com.cloud.upgrade.dao;
|
|||
*/
|
||||
import java.io.File;
|
||||
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 java.util.List;
|
||||
|
|
@ -70,6 +73,7 @@ public class Upgrade301to302 implements DbUpgrade {
|
|||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
dropKeysIfExists(conn);
|
||||
updateSharedNetworks(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -81,4 +85,76 @@ public class Upgrade301to302 implements DbUpgrade {
|
|||
|
||||
return new File[] { new File(script) };
|
||||
}
|
||||
|
||||
|
||||
protected void updateSharedNetworks(Connection conn) {
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs1 = null;
|
||||
|
||||
try {
|
||||
pstmt = conn.prepareStatement("select n.id, map.id from `cloud`.`network_offerings` n, `cloud`.`ntwk_offering_service_map` map " +
|
||||
"where n.id=map.network_offering_id and map.service='Lb' and map.provider='VirtualRouter';");
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
long ntwkOffId = rs.getLong(1);
|
||||
long mapId = rs.getLong(2);
|
||||
|
||||
//check if the network offering has source nat service enabled
|
||||
pstmt = conn.prepareStatement("select n.id from `cloud`.`network_offerings` n, `cloud`.`ntwk_offering_service_map`" +
|
||||
" map where n.id=map.network_offering_id and map.service='SourceNat' AND n.id=?");
|
||||
pstmt.setLong(1, ntwkOffId);
|
||||
rs1 = pstmt.executeQuery();
|
||||
if (rs1.next()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//delete the service only when there are no lb rules for the network(s) using this network offering
|
||||
pstmt = conn.prepareStatement("select * from `cloud`.`firewall_rules` f, `cloud`.`networks` n, `cloud`.`network_offerings`" +
|
||||
" off where f.purpose='LB' and f.network_id=n.id and n.network_offering_id=off.id and off.id=?");
|
||||
pstmt.setLong(1, ntwkOffId);
|
||||
rs1 = pstmt.executeQuery();
|
||||
if (rs1.next()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//delete lb service for the network offering
|
||||
pstmt = conn.prepareStatement("DELETE FROM `cloud`.`ntwk_offering_service_map` WHERE id=?");
|
||||
pstmt.setLong(1, mapId);
|
||||
pstmt.executeUpdate();
|
||||
s_logger.debug("Deleted lb service for network offering id=" + ntwkOffId + " as it doesn't have source nat service enabled");
|
||||
|
||||
//delete lb service for the network
|
||||
pstmt = conn.prepareStatement("SELECT map.id, n.id FROM `cloud`.`ntwk_service_map` map, networks n WHERE n.network_offering_id=? " +
|
||||
"AND map.network_id=n.id AND map.service='Lb'");
|
||||
pstmt.setLong(1, ntwkOffId);
|
||||
rs1 = pstmt.executeQuery();
|
||||
while (rs1.next()) {
|
||||
mapId = rs1.getLong(1);
|
||||
long ntwkId=rs1.getLong(2);
|
||||
|
||||
pstmt = conn.prepareStatement("DELETE FROM `cloud`.`ntwk_service_map` WHERE id=?");
|
||||
pstmt.setLong(1, mapId);
|
||||
pstmt.executeUpdate();
|
||||
s_logger.debug("Deleted lb service for network id=" + ntwkId + " as it doesn't have source nat service enabled");
|
||||
}
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to update shared networks due to exception while executing query " + pstmt, e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (rs1 != null) {
|
||||
rs1.close();
|
||||
}
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,5 +27,4 @@ ALTER TABLE `cloud_usage`.`usage_ip_address` MODIFY `id` bigint(20) UNSIGNED NOT
|
|||
ALTER TABLE `cloud_usage`.`usage_ip_address` MODIFY `is_source_nat` smallint(1) NOT NULL;
|
||||
ALTER TABLE `cloud_usage`.`usage_network` MODIFY `host_id` bigint(20) UNSIGNED NOT NULL;
|
||||
ALTER TABLE `cloud_usage`.`usage_network` MODIFY `host_type` varchar(32) DEFAULT NULL;
|
||||
ALTER TABLE `cloud_usage`.`user_statistics` MODIFY `device_id` bigint(20) UNSIGNED NOT NULL;
|
||||
|
||||
ALTER TABLE `cloud_usage`.`user_statistics` MODIFY `device_id` bigint(20) UNSIGNED NOT NULL;
|
||||
|
|
@ -22,3 +22,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag
|
|||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'secstorage.service.offering', NULL, 'Service offering used by secondary storage; if NULL - system offering will be used');
|
||||
|
||||
DROP INDEX `i_host__allocation_state` ON `cloud`.`host`;
|
||||
|
||||
UPDATE `cloud`.`network_offerings` SET display_text='Offering for Isolated networks with Source Nat service enabled' WHERE name='DefaultIsolatedNetworkOfferingWithSourceNatService' and `cloud`.`network_offerings`.default=1;
|
||||
UPDATE `cloud`.`network_offerings` SET display_text='Offering for Isolated networks with no Source Nat service' WHERE name='DefaultIsolatedNetworkOffering' and `cloud`.`network_offerings`.default=1;
|
||||
UPDATE `cloud`.`network_offerings` SET display_text='Offering for Shared networks' WHERE name='DefaultSharedNetworkOffering' and `cloud`.`network_offerings`.default=1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue