bug 12361: db upgrade for network offering22s

This commit is contained in:
Alena Prokharchyk 2011-12-28 14:28:51 -08:00
parent 873bef6970
commit 1d0429233d
3 changed files with 134 additions and 16 deletions

View File

@ -31,6 +31,7 @@ import java.util.UUID;
import org.apache.log4j.Logger;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
@ -318,6 +319,7 @@ public class Upgrade2214to30 implements DbUpgrade {
encryptHostDetails(conn);
encryptVNCPassword(conn);
encryptUserCredentials(conn);
createNetworkOfferingServices(conn);
}
private void encryptConfigValues(Connection conn) {
@ -479,4 +481,83 @@ public class Upgrade2214to30 implements DbUpgrade {
DbUpgradeUtils.dropKeysIfExist(conn, tableName, uniqueKeys.get(tableName), true);
}
}
private void createNetworkOfferingServices(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("select id, dns_service, gateway_service, firewall_service, lb_service, userdata_service, vpn_service, dhcp_service, unique_name from network_offerings where traffic_type='Guest'");
rs = pstmt.executeQuery();
while (rs.next()) {
long id = rs.getLong(1);
String uniqueName = rs.getString(9);
ArrayList<String> services = new ArrayList<String>();
if (rs.getLong(2) != 0) {
services.add("Dns");
}
if (rs.getLong(3) != 0) {
services.add("Gateway");
}
if (rs.getLong(4) != 0) {
services.add("Firewall");
}
if (rs.getLong(5) != 0) {
services.add("Lb");
}
if (rs.getLong(6) != 0) {
services.add("UserData");
}
if (rs.getLong(7) != 0) {
services.add("Vpn");
}
if (rs.getLong(8) != 0) {
services.add("Dhcp");
}
if (uniqueName.equalsIgnoreCase(NetworkOffering.DefaultSharedNetworkOfferingWithSGService.toString())) {
services.add("SecurityGroup");
}
if (uniqueName.equals(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService.toString())) {
services.add("SourceNat");
services.add("PortForwarding");
services.add("StaticNat");
}
for (String service : services) {
pstmt = conn.prepareStatement("INSERT INTO ntwk_offering_service_map (`network_offering_id`, `service`, `provider`, `created`) values (?,?,?, now())");
pstmt.setLong(1, id);
pstmt.setString(2, service);
if (service.equalsIgnoreCase("SecurityGroup")) {
pstmt.setString(3, "SecurityGroupProvider");
} else {
pstmt.setString(3, "VirtualRouter");
}
pstmt.executeUpdate();
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to upgrade network offering", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
}

View File

@ -14,4 +14,10 @@ ALTER TABLE `cloud`.`host` DROP COLUMN `allocation_state`;
ALTER TABLE `cloud`.`data_center` DROP COLUMN `vnet`;
ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `dns_service`;
ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `gateway_service`;
ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `firewall_service`;
ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `lb_service`;
ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `userdata_service`;
ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `vpn_service`;
ALTER TABLE `cloud`.`network_offerings` DROP COLUMN `dhcp_service`;

View File

@ -291,27 +291,12 @@ ALTER TABLE `cloud`.`host` ADD COLUMN `resource_state` varchar(32) NOT NULL DEFA
ALTER TABLE `cloud`.`vm_template` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
ALTER TABLE `cloud`.`service_offering` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
ALTER TABLE `cloud`.`network_offerings` MODIFY `name` varchar(64) COMMENT 'name of the network offering';
ALTER TABLE `cloud`.`network_offerings` MODIFY `unique_name` varchar(64) COMMENT 'unique name of the network offering';
ALTER TABLE `cloud`.`network_offerings` DROP `concurrent_connections`;
--;
--NAAS;
--;
CREATE TABLE `ntwk_offering_service_map` (
`id` bigint unsigned NOT NULL auto_increment,
`network_offering_id` bigint unsigned NOT NULL COMMENT 'network_offering_id',
`service` varchar(255) NOT NULL COMMENT 'service',
`provider` varchar(255) COMMENT 'service provider',
`created` datetime COMMENT 'date created',
PRIMARY KEY (`id`),
CONSTRAINT `fk_ntwk_offering_service_map__network_offering_id` FOREIGN KEY(`network_offering_id`) REFERENCES `network_offerings`(`id`) ON DELETE CASCADE,
UNIQUE (`network_offering_id`, `service`, `provider`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `ntwk_service_map` (
`id` bigint unsigned NOT NULL auto_increment,
@ -499,3 +484,49 @@ CREATE TABLE `cloud`.`op_user_stats_log` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `cloud`.`physical_network_traffic_types` ADD COLUMN `simulator_network_label` varchar(255) COMMENT 'The name labels needed for identifying the simulator';
--;
-- Network offerings
--;
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `dedicated_lb_service` int(1) unsigned NOT NULL DEFAULT 1 COMMENT 'true if the network offering provides a dedicated load balancer for each network';
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `redundant_router_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network offering provides the redundant router service';
ALTER TABLE `cloud`.`network_offerings` MODIFY `name` varchar(64) COMMENT 'name of the network offering';
ALTER TABLE `cloud`.`network_offerings` MODIFY `unique_name` varchar(64) COMMENT 'unique name of the network offering';
ALTER TABLE `cloud`.`network_offerings` DROP `concurrent_connections`;
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `state` char(32) COMMENT 'state of the network offering that has Disabled value by default';
UPDATE `cloud`.`network_offerings` SET `state`='Enabled';
UPDATE `cloud`.`network_offerings` SET `state`='Disabled' where `availability`='Unavailable';
UPDATE `cloud`.`network_offerings` SET `availability`='Optional' where `availability`='Unavailable';
UPDATE `cloud`.`network_offerings` SET `system_only`=0 where `traffic_type`='Guest';
UPDATE `cloud`.`network_offerings` SET `specify_vlan`=1 where `unique_name`='System-Guest-Network';
UPDATE `cloud`.`network_offerings` SET `unique_name`='DefaultSharedNetworkOfferingWithSGService' where `unique_name`='System-Guest-Network';
UPDATE `cloud`.`network_offerings` SET `unique_name`='DefaultIsolatedNetworkOfferingWithSourceNatService' where `unique_name`='DefaultVirtualizedNetworkOffering';
UPDATE `cloud`.`network_offerings` SET `unique_name`='DefaultSharedNetworkOffering' where `unique_name`='DefaultDirectNetworkOffering';
UPDATE `cloud`.`network_offerings` SET `name`='DefaultSharedNetworkOfferingWithSGService' where `name`='System-Guest-Network';
UPDATE `cloud`.`network_offerings` SET `name`='DefaultIsolatedNetworkOfferingWithSourceNatService' where `name`='DefaultVirtualizedNetworkOffering';
UPDATE `cloud`.`network_offerings` SET `name`='DefaultSharedNetworkOffering' where `name`='DefaultDirectNetworkOffering';
UPDATE `cloud`.`network_offerings` SET `guest_type`='Shared' where `guest_type`='Direct';
UPDATE `cloud`.`network_offerings` SET `guest_type`='Isolated' where `guest_type`='Virtual';
UPDATE `cloud`.`network_offerings` SET `availability`='Optional' where `availability`='Required' and `guest_type`='Shared';
insert into network_offerings (`name`, `unique_name`, `display_text`, `traffic_type`, `system_only`, `specify_vlan`, `default`, `availability`, `state`, `guest_type`, `created`, `userdata_service`, `dns_service`, `dhcp_service`) values ('DefaultIsolatedNetworkOffering', 'DefaultIsolatedNetworkOffering', 'Offering for Isolated networks with no Source Nat service', 'Guest', 0, 1, 1, 'Optional', 'Enabled', 'Isolated', now(), 1, 1, 1);
CREATE TABLE `ntwk_offering_service_map` (
`id` bigint unsigned NOT NULL auto_increment,
`network_offering_id` bigint unsigned NOT NULL COMMENT 'network_offering_id',
`service` varchar(255) NOT NULL COMMENT 'service',
`provider` varchar(255) COMMENT 'service provider',
`created` datetime COMMENT 'date created',
PRIMARY KEY (`id`),
CONSTRAINT `fk_ntwk_offering_service_map__network_offering_id` FOREIGN KEY(`network_offering_id`) REFERENCES `network_offerings`(`id`) ON DELETE CASCADE,
UNIQUE (`network_offering_id`, `service`, `provider`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;