cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [18/18] git commit: upgrade external devices support from 2.2.14 to network offering framework
Date Tue, 18 Sep 2012 22:49:59 GMT
upgrade external devices support from 2.2.14 to network offering framework


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/87850b79
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/87850b79
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/87850b79

Branch: refs/heads/4.0
Commit: 87850b794c7371a325fef4495ccd01f2ba72c49a
Parents: 54f9af1
Author: Murali Reddy <Murali.Reddy@citrix.com>
Authored: Mon Sep 17 11:39:41 2012 +0530
Committer: Edison Su <sudison@gmail.com>
Committed: Tue Sep 18 15:32:50 2012 -0700

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade302to40.java  |  348 +++++++++++++++
 1 files changed, 348 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/87850b79/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade302to40.java b/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
index 0a836e9..00e1a3c 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
@@ -68,6 +68,8 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade
{
         addVpcProvider(conn);
         updateRouterNetworkRef(conn);
         fixForeignKeys(conn);
+        setupExternalNetworkDevices(conn);
+        fixZoneUsingExternalDevices(conn);
     }
 
     @Override
@@ -681,4 +683,350 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade
{
             throw new CloudRuntimeException("Unable to execute ssh_keypairs table update
for adding domain_id foreign key", e);
         }
     }
+
+    // upgrades deployment with F5 and SRX devices, to 3.0's Network offerings & service
providers paradigm
+    private void setupExternalNetworkDevices(Connection conn) {
+        PreparedStatement zoneSearchStmt = null, pNetworkStmt = null, f5DevicesStmt = null,
srxDevicesStmt = null;
+        ResultSet zoneResults = null, pNetworksResults = null, f5DevicesResult = null, srxDevicesResult
= null;
+
+        try {
+            zoneSearchStmt = conn.prepareStatement("SELECT id, networktype FROM `cloud`.`data_center`");
+            zoneResults = zoneSearchStmt.executeQuery();
+            while (zoneResults.next()) {
+                long zoneId = zoneResults.getLong(1);
+                String networkType = zoneResults.getString(2);
+
+                if (!NetworkType.Advanced.toString().equalsIgnoreCase(networkType)) {
+                    continue;
+                }
+
+                pNetworkStmt = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network`
where data_center_id=?");
+                pNetworkStmt.setLong(1, zoneId);
+                pNetworksResults = pNetworkStmt.executeQuery();
+                while (pNetworksResults.next()) {
+                    long physicalNetworkId = pNetworksResults.getLong(1);
+                    PreparedStatement fetchF5NspStmt = conn.prepareStatement("SELECT id from
`cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId
+                            + " and provider_name = 'F5BigIp'");
+                    ResultSet rsF5NSP = fetchF5NspStmt.executeQuery();
+                    boolean hasF5Nsp = rsF5NSP.next();
+                    fetchF5NspStmt.close();
+
+                    if (!hasF5Nsp) {
+                        f5DevicesStmt = conn.prepareStatement("SELECT id FROM host WHERE
data_center_id=? AND type = 'ExternalLoadBalancer' AND removed IS NULL");
+                        f5DevicesStmt.setLong(1, zoneId);
+                        f5DevicesResult = f5DevicesStmt.executeQuery();
+
+                        while (f5DevicesResult.next()) {
+                            long f5HostId = f5DevicesResult.getLong(1);;
+                            // add F5BigIP provider and provider instance to physical network
+                            addF5ServiceProvider(conn, physicalNetworkId, zoneId);
+                            addF5LoadBalancer(conn, f5HostId, physicalNetworkId);
+                        }
+                    }
+
+                    PreparedStatement fetchSRXNspStmt = conn.prepareStatement("SELECT id
from `cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId
+                            + " and provider_name = 'JuniperSRX'");
+                    ResultSet rsSRXNSP = fetchSRXNspStmt.executeQuery();
+                    boolean hasSrxNsp = rsSRXNSP.next();
+                    fetchSRXNspStmt.close();
+
+                    if (!hasSrxNsp) {
+                        srxDevicesStmt = conn.prepareStatement("SELECT id FROM host WHERE
data_center_id=? AND type = 'ExternalFirewall' AND removed IS NULL");
+                        srxDevicesStmt.setLong(1, zoneId);
+                        srxDevicesResult = srxDevicesStmt.executeQuery();
+
+                        while (srxDevicesResult.next()) {
+                            long srxHostId = srxDevicesResult.getLong(1);
+                            // add SRX provider and provider instance to physical network
+                            addSrxServiceProvider(conn, physicalNetworkId, zoneId);
+                            addSrxFirewall(conn, srxHostId, physicalNetworkId);
+                        }
+                    }
+                }
+            }
+
+            if (zoneResults != null) {
+                try {
+                    zoneResults.close();
+                } catch (SQLException e) {
+                }
+            }
+            if (zoneSearchStmt != null) {
+                try {
+                    zoneSearchStmt.close();
+                } catch (SQLException e) {
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
+        } finally {
+
+        }
+    }
+
+    private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetworkId){
+        PreparedStatement pstmtUpdate = null;
+        try{
+            s_logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in
to physical network" + physicalNetworkId);
+            String insertF5 = "INSERT INTO `cloud`.`external_load_balancer_devices` (physical_network_id,
host_id, provider_name, " +
+                    "device_name, capacity, is_dedicated, device_state, allocation_state,
is_inline, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+            pstmtUpdate = conn.prepareStatement(insertF5);
+            pstmtUpdate.setLong(1, physicalNetworkId);
+            pstmtUpdate.setLong(2, hostId);
+            pstmtUpdate.setString(3, "F5BigIp");
+            pstmtUpdate.setString(4, "F5BigIpLoadBalancer");
+            pstmtUpdate.setLong(5, 0);
+            pstmtUpdate.setBoolean(6, false);
+            pstmtUpdate.setString(7, "Enabled");
+            pstmtUpdate.setString(8, "Shared");
+            pstmtUpdate.setBoolean(9, false);
+            pstmtUpdate.setBoolean(10, false);
+            pstmtUpdate.setString(11, UUID.randomUUID().toString());
+            pstmtUpdate.executeUpdate();
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding F5 load balancer device"
,  e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
+
+    private void addSrxFirewall(Connection conn, long hostId, long physicalNetworkId){
+        PreparedStatement pstmtUpdate = null;
+        try{
+            s_logger.debug("Adding SRX firewall device with host id " + hostId + " in to
physical network" + physicalNetworkId);
+            String insertSrx = "INSERT INTO `cloud`.`external_firewall_devices` (physical_network_id,
host_id, provider_name, " +
+                    "device_name, capacity, is_dedicated, device_state, allocation_state,
uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+            pstmtUpdate = conn.prepareStatement(insertSrx);
+            pstmtUpdate.setLong(1, physicalNetworkId);
+            pstmtUpdate.setLong(2, hostId);
+            pstmtUpdate.setString(3, "JuniperSRX");
+            pstmtUpdate.setString(4, "JuniperSRXFirewall");
+            pstmtUpdate.setLong(5, 0);
+            pstmtUpdate.setBoolean(6, false);
+            pstmtUpdate.setString(7, "Enabled");
+            pstmtUpdate.setString(8, "Shared");
+            pstmtUpdate.setString(9, UUID.randomUUID().toString());
+            pstmtUpdate.executeUpdate();
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding SRX firewall device ",
 e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
+
+    private void addF5ServiceProvider(Connection conn, long physicalNetworkId, long zoneId){
+        PreparedStatement pstmtUpdate = null;
+        try{
+            // add physical network service provider - F5BigIp
+            s_logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical
network" + physicalNetworkId);
+            String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers`
(`uuid`, `physical_network_id` , `provider_name`, `state` ," +
+                    "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`,
`dns_service_provided`, `gateway_service_provided`," +
+                    "`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,0,0,0,0,0,0,1,0,0,0,0)";
+
+            pstmtUpdate = conn.prepareStatement(insertPNSP);
+            pstmtUpdate.setString(1, UUID.randomUUID().toString());
+            pstmtUpdate.setLong(2, physicalNetworkId);
+            pstmtUpdate.setString(3, "F5BigIp");
+            pstmtUpdate.setString(4, "Enabled");
+            pstmtUpdate.executeUpdate();
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding PhysicalNetworkServiceProvider
F5BigIp", e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
+
+    private void addSrxServiceProvider(Connection conn, long physicalNetworkId, long zoneId){
+        PreparedStatement pstmtUpdate = null;
+        try{
+            // add physical network service provider - JuniperSRX
+            s_logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX");
+            String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers`
(`uuid`, `physical_network_id` , `provider_name`, `state` ," +
+                    "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`,
`dns_service_provided`, `gateway_service_provided`," +
+                    "`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,0,0,0,1,1,1,0,1,1,0,0)";
+
+            pstmtUpdate = conn.prepareStatement(insertPNSP);
+            pstmtUpdate.setString(1, UUID.randomUUID().toString());
+            pstmtUpdate.setLong(2, physicalNetworkId);
+            pstmtUpdate.setString(3, "JuniperSRX");
+            pstmtUpdate.setString(4, "Enabled");
+            pstmtUpdate.executeUpdate();
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding PhysicalNetworkServiceProvider
JuniperSRX" ,  e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
+
+    // 1) ensure that networks using external load balancer/firewall in 2.2.14 or prior releases
deployments
+    //    has entry in network_external_lb_device_map and network_external_firewall_device_map
+    //
+    // 2) Some keys of host details for F5 and SRX devices were stored in Camel Case in 2.x
releases. From 3.0
+    //    they are made in lowercase. On upgrade change the host details name to lower case
+    private void fixZoneUsingExternalDevices(Connection conn) {
+        //Get zones to upgrade
+        List<Long> zoneIds = new ArrayList<Long>();
+        PreparedStatement pstmt = null;
+        PreparedStatement pstmtUpdate = null;
+        ResultSet rs = null;
+        long networkOfferingId, networkId;
+        long f5DeviceId, f5HostId;
+        long srxDevivceId,  srxHostId;
+
+        try {
+            pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where lb_provider='F5BigIp'
or firewall_provider='JuniperSRX' or gateway_provider='JuniperSRX'");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                zoneIds.add(rs.getLong(1));
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to create network to LB & firewalla
device mapping for networks  that use them", e);
+        }
+
+        if (zoneIds.size() == 0) {
+                return; // no zones using F5 and SRX devices so return
+        }
+
+        // find the default network offering created for external devices during upgrade
from 2.2.14
+        try {
+            pstmt = conn.prepareStatement("select id from `cloud`.`network_offerings` where
unique_name='Isolated with external providers' ");
+            rs = pstmt.executeQuery();
+            if (rs.first()) {
+                    networkOfferingId = rs.getLong(1);
+            } else {
+                    throw new CloudRuntimeException("Cannot upgrade as there is no 'Isolated
with external providers' network offering crearted .");
+            }
+        } catch  (SQLException e) {
+                throw new CloudRuntimeException("Unable to create network to LB & firewalla
device mapping for networks  that use them", e);
+        }
+
+        for (Long zoneId : zoneIds) {
+            try {
+        // find the F5 device id  in the zone
+                pstmt = conn.prepareStatement("SELECT id FROM host WHERE data_center_id=?
AND type = 'ExternalLoadBalancer' AND removed IS NULL");
+                pstmt.setLong(1, zoneId);
+                rs = pstmt.executeQuery();
+                if (rs.first()) {
+                   f5HostId  = rs.getLong(1);
+                } else {
+                    throw new CloudRuntimeException("Cannot upgrade as there is no F5 load
balancer device found in data center " + zoneId);
+                }
+                pstmt = conn.prepareStatement("SELECT id FROM external_load_balancer_devices
WHERE  host_id=?");
+                pstmt.setLong(1, f5HostId);
+                rs = pstmt.executeQuery();
+                if (rs.first()) {
+                        f5DeviceId = rs.getLong(1);
+                } else {
+                    throw new CloudRuntimeException("Cannot upgrade as there is no F5 load
balancer device with host ID " + f5HostId + " found in external_load_balancer_device");
+                }
+
+            // find the SRX device id  in the zone
+                pstmt = conn.prepareStatement("SELECT id FROM host WHERE data_center_id=?
AND type = 'ExternalFirewall' AND removed IS NULL");
+                pstmt.setLong(1, zoneId);
+                rs = pstmt.executeQuery();
+                if (rs.first()) {
+                        srxHostId = rs.getLong(1);
+                } else {
+                    throw new CloudRuntimeException("Cannot upgrade as there is no SRX firewall
device found in data center " + zoneId);
+                }
+                pstmt = conn.prepareStatement("SELECT id FROM external_firewall_devices WHERE
 host_id=?");
+                pstmt.setLong(1, srxHostId);
+                rs = pstmt.executeQuery();
+                if (rs.first()) {
+                        srxDevivceId = rs.getLong(1);
+                } else {
+                    throw new CloudRuntimeException("Cannot upgrade as there is no SRX firewall
device found with host ID " + srxHostId + " found in external_firewall_devices");
+                }
+
+            // check if network any uses F5 or SRX devices  in the zone
+                pstmt = conn.prepareStatement("select id from `cloud`.`networks` where guest_type='Virtual'
and data_center_id=? and network_offering_id=? and removed IS NULL");
+                pstmt.setLong(1, zoneId);
+                pstmt.setLong(2, networkOfferingId);
+                rs = pstmt.executeQuery();
+                while (rs.next()) {
+            // get the network Id
+                      networkId = rs.getLong(1);
+
+                     // add mapping for the network in network_external_lb_device_map
+                    String insertLbMapping = "INSERT INTO `cloud`.`network_external_lb_device_map`
(uuid, network_id, external_load_balancer_device_id, created) VALUES ( ?, ?, ?, now())";
+                    pstmtUpdate = conn.prepareStatement(insertLbMapping);
+                    pstmtUpdate.setString(1, UUID.randomUUID().toString());
+                    pstmtUpdate.setLong(2, networkId);
+                    pstmtUpdate.setLong(3, f5DeviceId);
+                    pstmtUpdate.executeUpdate();
+                    s_logger.debug("Successfully added entry in network_external_lb_device_map
for network " +  networkId + " and F5 device ID " +  f5DeviceId);
+
+                     // add mapping for the network in network_external_firewall_device_map
+                    String insertFwMapping = "INSERT INTO `cloud`.`network_external_firewall_device_map`
(uuid, network_id, external_firewall_device_id, created) VALUES ( ?, ?, ?, now())";
+                    pstmtUpdate = conn.prepareStatement(insertFwMapping);
+                    pstmtUpdate.setString(1, UUID.randomUUID().toString());
+                    pstmtUpdate.setLong(2, networkId);
+                    pstmtUpdate.setLong(3, srxDevivceId);
+                    pstmtUpdate.executeUpdate();
+                    s_logger.debug("Successfully added entry in network_external_firewall_device_map
for network " +  networkId + " and SRX device ID " +  srxDevivceId);
+                }
+
+                // update host details for F5 and SRX devices
+                s_logger.debug("Updating the host details for F5 and SRX devices");
+                pstmt = conn.prepareStatement("SELECT host_id, name FROM `cloud`.`host_details`
WHERE  host_id=? OR host_id=?");
+                pstmt.setLong(1, f5HostId);
+                pstmt.setLong(2, srxHostId);
+                rs = pstmt.executeQuery();
+                while (rs.next()) {
+                    long hostId = rs.getLong(1);
+                    String camlCaseName = rs.getString(2);
+                    if (!(camlCaseName.equalsIgnoreCase("numRetries") ||
+                            camlCaseName.equalsIgnoreCase("publicZone") ||
+                            camlCaseName.equalsIgnoreCase("privateZone") ||
+                            camlCaseName.equalsIgnoreCase("publicInterface") ||
+                            camlCaseName.equalsIgnoreCase("privateInterface") ||
+                            camlCaseName.equalsIgnoreCase("usageInterface") )) {
+                        continue;
+                    }
+                    String lowerCaseName = camlCaseName.toLowerCase();
+                    pstmt = conn.prepareStatement("update `cloud`.`host_details` set name=?
where host_id=? AND name=?");
+                    pstmt.setString(1, lowerCaseName);
+                    pstmt.setLong(2, hostId);
+                    pstmt.setString(3, camlCaseName);
+                    pstmt.executeUpdate();
+                }
+                s_logger.debug("Successfully updated host details for F5 and SRX devices");
+            } catch (SQLException e) {
+                throw new CloudRuntimeException("Unable create a mapping for the networks
in network_external_lb_device_map and network_external_firewall_device_map", e);
+            }  finally {
+                try {
+                    if (rs != null) {
+                        rs.close();
+                    }
+                    if (pstmt != null) {
+                        pstmt.close();
+                    }
+                } catch (SQLException e) {
+                }
+            }
+            s_logger.info("Successfully upgraded networks using F5 and SRX devices to have
a entry in the network_external_lb_device_map and network_external_firewall_device_map");
+        }
+    }
 }


Mime
View raw message