Fix resource leak CID-1116654

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

Branch: refs/heads/master
Commit: 086b8c0c4a61e3930c0440bda9116f23cbfd6a9f
Parents: 71611da
Author: Hugo Trippaers <htrippa...@schubergphilis.com>
Authored: Tue Sep 16 09:45:43 2014 +0200
Committer: Hugo Trippaers <htrippa...@schubergphilis.com>
Committed: Wed Sep 17 11:40:40 2014 +0200

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 178 ++++++++++---------
 1 file changed, 90 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/086b8c0c/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java 
b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 097f6c5..18303b0 100755
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -132,10 +132,10 @@ public class Upgrade410to420 implements DbUpgrade {
             }
             if (numRows > 0) {
                 update =
-                    conn.prepareStatement("insert into `cloud`.`configuration` 
(`category`, `instance`, `component`, `name`, `value`, `description`) VALUES 
('Advanced', 'DEFAULT', 'UserVmManager', 'vmware.create.full.clone' , 'false', 
'If set to true, creates VMs as full clones on ESX hypervisor');");
+                        conn.prepareStatement("insert into 
`cloud`.`configuration` (`category`, `instance`, `component`, `name`, `value`, 
`description`) VALUES ('Advanced', 'DEFAULT', 'UserVmManager', 
'vmware.create.full.clone' , 'false', 'If set to true, creates VMs as full 
clones on ESX hypervisor');");
             } else {
                 update =
-                    conn.prepareStatement("insert into `cloud`.`configuration` 
(`category`, `instance`, `component`, `name`, `value`, `description`) VALUES 
('Advanced', 'DEFAULT', 'UserVmManager', 'vmware.create.full.clone' , 'true', 
'If set to true, creates VMs as full clones on ESX hypervisor');");
+                        conn.prepareStatement("insert into 
`cloud`.`configuration` (`category`, `instance`, `component`, `name`, `value`, 
`description`) VALUES ('Advanced', 'DEFAULT', 'UserVmManager', 
'vmware.create.full.clone' , 'true', 'If set to true, creates VMs as full 
clones on ESX hypervisor');");
             }
             update.executeUpdate();
         } catch (SQLException e) {
@@ -293,7 +293,7 @@ public class Upgrade410to420 implements DbUpgrade {
         PreparedStatement pstmt = null;
         try {
             pstmt =
-                conn.prepareStatement("select value from 
`cloud`.`configuration` where category='" + category + "' and value is not NULL 
and name = '" + paramName + "';");
+                    conn.prepareStatement("select value from 
`cloud`.`configuration` where category='" + category + "' and value is not NULL 
and name = '" + paramName + "';");
             rs = pstmt.executeQuery();
             while (rs.next()) {
                 return rs.getString("value");
@@ -354,7 +354,7 @@ public class Upgrade410to420 implements DbUpgrade {
                 PreparedStatement pstmt2 = null;
                 ResultSet rs2 = null;
                 pstmt2 =
-                    conn.prepareStatement("SELECT affinity_group.id FROM 
`cloud`.`affinity_group` INNER JOIN `cloud`.`affinity_group_domain_map` ON 
affinity_group.id=affinity_group_domain_map.affinity_group_id WHERE 
affinity_group.type = 'ExplicitDedication' AND affinity_group.acl_type = 
'Domain'  AND  (affinity_group_domain_map.domain_id = ?)");
+                        conn.prepareStatement("SELECT affinity_group.id FROM 
`cloud`.`affinity_group` INNER JOIN `cloud`.`affinity_group_domain_map` ON 
affinity_group.id=affinity_group_domain_map.affinity_group_id WHERE 
affinity_group.type = 'ExplicitDedication' AND affinity_group.acl_type = 
'Domain'  AND  (affinity_group_domain_map.domain_id = ?)");
                 pstmt2.setLong(1, domainId);
                 rs2 = pstmt2.executeQuery();
                 if (rs2.next()) {
@@ -381,7 +381,7 @@ public class Upgrade410to420 implements DbUpgrade {
                     s_logger.debug("Adding AffinityGroup of type " + type + " 
for domain id " + domainId);
 
                     String sql =
-                        "INSERT INTO `cloud`.`affinity_group` (`name`, `type`, 
`uuid`, `description`, `domain_id`, `account_id`, `acl_type`) VALUES (?, ?, ?, 
?, 1, 1, 'Domain')";
+                            "INSERT INTO `cloud`.`affinity_group` (`name`, 
`type`, `uuid`, `description`, `domain_id`, `account_id`, `acl_type`) VALUES 
(?, ?, ?, ?, 1, 1, 'Domain')";
                     pstmtUpdate = conn.prepareStatement(sql);
                     pstmtUpdate.setString(1, groupName);
                     pstmtUpdate.setString(2, type);
@@ -497,16 +497,16 @@ public class Upgrade410to420 implements DbUpgrade {
         PreparedStatement pstmt = null;
         try {
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT 
`fk_external_dhcp_devices_nsp_id` FOREIGN KEY (`nsp_id`) REFERENCES 
`physical_network_service_providers` (`id`) ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT 
`fk_external_dhcp_devices_nsp_id` FOREIGN KEY (`nsp_id`) REFERENCES 
`physical_network_service_providers` (`id`) ON DELETE CASCADE");
             pstmt.executeUpdate();
             pstmt.close();
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT 
`fk_external_dhcp_devices_host_id` FOREIGN KEY (`host_id`) REFERENCES 
`host`(`id`) ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT 
`fk_external_dhcp_devices_host_id` FOREIGN KEY (`host_id`) REFERENCES 
`host`(`id`) ON DELETE CASCADE");
             pstmt.executeUpdate();
             pstmt.close();
             pstmt.close();
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT 
`fk_external_dhcp_devices_physical_network_id` FOREIGN KEY 
(`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT 
`fk_external_dhcp_devices_physical_network_id` FOREIGN KEY 
(`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE");
             pstmt.executeUpdate();
             pstmt.close();
             s_logger.debug("Added foreign keys for table 
baremetal_dhcp_devices");
@@ -516,15 +516,15 @@ public class Upgrade410to420 implements DbUpgrade {
 
         try {
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_pxe_devices` ADD CONSTRAINT `fk_external_pxe_devices_nsp_id` 
FOREIGN KEY (`nsp_id`) REFERENCES `physical_network_service_providers` (`id`) 
ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_pxe_devices` ADD CONSTRAINT `fk_external_pxe_devices_nsp_id` 
FOREIGN KEY (`nsp_id`) REFERENCES `physical_network_service_providers` (`id`) 
ON DELETE CASCADE");
             pstmt.executeUpdate();
             pstmt.close();
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_pxe_devices` ADD CONSTRAINT 
`fk_external_pxe_devices_host_id` FOREIGN KEY (`host_id`) REFERENCES 
`host`(`id`) ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_pxe_devices` ADD CONSTRAINT 
`fk_external_pxe_devices_host_id` FOREIGN KEY (`host_id`) REFERENCES 
`host`(`id`) ON DELETE CASCADE");
             pstmt.executeUpdate();
             pstmt.close();
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_pxe_devices` ADD CONSTRAINT 
`fk_external_pxe_devices_physical_network_id` FOREIGN KEY 
(`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`baremetal_pxe_devices` ADD CONSTRAINT 
`fk_external_pxe_devices_physical_network_id` FOREIGN KEY 
(`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE");
             pstmt.executeUpdate();
             pstmt.close();
             s_logger.debug("Added foreign keys for table 
baremetal_pxe_devices");
@@ -595,7 +595,7 @@ public class Upgrade410to420 implements DbUpgrade {
             rs2 = pstmt2.executeQuery();
 
             pstmt3 =
-                conn.prepareStatement("INSERT IGNORE INTO volume_store_ref 
(volume_id, store_id, zone_id, created, state, download_url, 
download_url_created, install_path) VALUES (?,?,?,?,?,?,?,?)");
+                    conn.prepareStatement("INSERT IGNORE INTO volume_store_ref 
(volume_id, store_id, zone_id, created, state, download_url, 
download_url_created, install_path) VALUES (?,?,?,?,?,?,?,?)");
             //insert into template_store_ref
             while (rs2.next()) {
                 pstmt3.setLong(1, rs2.getLong("type_id"));
@@ -822,7 +822,7 @@ public class Upgrade410to420 implements DbUpgrade {
         try {
             // update the existing vmware traffic labels
             pstmt =
-                conn.prepareStatement("select name,value from 
`cloud`.`configuration` where category='Hidden' and value is not NULL and name 
REGEXP 'vmware*.vswitch';");
+                    conn.prepareStatement("select name,value from 
`cloud`.`configuration` where category='Hidden' and value is not NULL and name 
REGEXP 'vmware*.vswitch';");
             rsParams = pstmt.executeQuery();
             while (rsParams.next()) {
                 trafficTypeVswitchParam = rsParams.getString("name");
@@ -836,13 +836,13 @@ public class Upgrade410to420 implements DbUpgrade {
                     trafficType = "Guest";
                 }
                 pstmt =
-                    conn.prepareStatement("select physical_network_id, 
traffic_type, vmware_network_label from physical_network_traffic_types where 
vmware_network_label is not NULL and traffic_type='" +
-                        trafficType + "';");
+                        conn.prepareStatement("select physical_network_id, 
traffic_type, vmware_network_label from physical_network_traffic_types where 
vmware_network_label is not NULL and traffic_type='" +
+                                trafficType + "';");
                 rsLabel = pstmt.executeQuery();
                 newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue);
                 pstmt =
-                    conn.prepareStatement("update 
physical_network_traffic_types set vmware_network_label = " + newLabel + " 
where traffic_type = '" + trafficType +
-                        "' and vmware_network_label is not NULL;");
+                        conn.prepareStatement("update 
physical_network_traffic_types set vmware_network_label = " + newLabel + " 
where traffic_type = '" + trafficType +
+                                "' and vmware_network_label is not NULL;");
                 s_logger.debug("Updating vmware label for " + trafficType + " 
traffic. Update SQL statement is " + pstmt);
                 pstmt.executeUpdate();
             }
@@ -1114,7 +1114,7 @@ public class Upgrade410to420 implements DbUpgrade {
 
         try {
             pstmt =
-                conn.prepareStatement("SELECT network_id, gateway, ip4_address 
FROM `cloud`.`nics` WHERE reserver_name IN 
('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' 
AND removed IS null");
+                    conn.prepareStatement("SELECT network_id, gateway, 
ip4_address FROM `cloud`.`nics` WHERE reserver_name IN 
('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' 
AND removed IS null");
             rs = pstmt.executeQuery();
             while (rs.next()) {
                 Long networkId = rs.getLong(1);
@@ -1123,7 +1123,7 @@ public class Upgrade410to420 implements DbUpgrade {
                 String uuid = UUID.randomUUID().toString();
                 //Insert placeholder nic for each Domain router nic in Shared 
network
                 pstmt =
-                    conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, 
ip4_address, gateway, network_id, state, strategy, vm_type, default_nic, 
created) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter', 0, 
now())");
+                        conn.prepareStatement("INSERT INTO `cloud`.`nics` 
(uuid, ip4_address, gateway, network_id, state, strategy, vm_type, default_nic, 
created) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter', 0, 
now())");
                 pstmt.setString(1, uuid);
                 pstmt.setString(2, ip);
                 pstmt.setString(3, gateway);
@@ -1192,7 +1192,7 @@ public class Upgrade410to420 implements DbUpgrade {
                 long netId = rs.getLong(1);
                 //checking for Isolated OR Virtual
                 pstmt =
-                    conn.prepareStatement("select account_id, domain_id FROM 
`cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and 
traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR 
state='Shutdown') and id=? ");
+                        conn.prepareStatement("select account_id, domain_id 
FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') 
and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR 
state='Shutdown') and id=? ");
                 pstmt.setLong(1, netId);
                 s_logger.debug("Getting account_id, domain_id from networks 
table: " + pstmt);
                 rsNw = pstmt.executeQuery();
@@ -1204,7 +1204,7 @@ public class Upgrade410to420 implements DbUpgrade {
                     //Add new rule for the existing networks
                     s_logger.debug("Adding default egress firewall rule for 
network " + netId);
                     pstmt =
-                        conn.prepareStatement("INSERT INTO firewall_rules 
(uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, 
created,  traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, 
now(), 'Egress')");
+                            conn.prepareStatement("INSERT INTO firewall_rules 
(uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, 
created,  traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, 
now(), 'Egress')");
                     pstmt.setString(1, UUID.randomUUID().toString());
                     pstmt.setLong(2, accountId);
                     pstmt.setLong(3, domainId);
@@ -1292,7 +1292,7 @@ public class Upgrade410to420 implements DbUpgrade {
                 Long vpcId = rs.getLong(2);
                 String tierUuid = rs.getString(3);
                 pstmt =
-                    conn.prepareStatement("SELECT id, uuid, start_port, 
end_port, state, protocol, icmp_code, icmp_type, created, traffic_type FROM 
`cloud`.`firewall_rules` where network_id = ? and purpose = 'NetworkACL'");
+                        conn.prepareStatement("SELECT id, uuid, start_port, 
end_port, state, protocol, icmp_code, icmp_type, created, traffic_type FROM 
`cloud`.`firewall_rules` where network_id = ? and purpose = 'NetworkACL'");
                 pstmt.setLong(1, networkId);
                 rsAcls = pstmt.executeQuery();
                 boolean hasAcls = false;
@@ -1336,7 +1336,7 @@ public class Upgrade410to420 implements DbUpgrade {
                     //Move acl to network_acl_item table
                     s_logger.debug("Moving firewall rule: " + aclItemUuid);
                     pstmt =
-                        conn.prepareStatement("INSERT INTO 
`cloud`.`network_acl_item` (uuid, acl_id, start_port, end_port, state, 
protocol, icmp_code, icmp_type, created, traffic_type, cidr, number, action) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
+                            conn.prepareStatement("INSERT INTO 
`cloud`.`network_acl_item` (uuid, acl_id, start_port, end_port, state, 
protocol, icmp_code, icmp_type, created, traffic_type, cidr, number, action) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
                     //uuid
                     pstmt.setString(1, aclItemUuid);
                     //aclId
@@ -1480,7 +1480,7 @@ public class Upgrade410to420 implements DbUpgrade {
 
         try {
             pstmt =
-                conn.prepareStatement("select distinct map.vpc_offering_id 
from `cloud`.`vpc_offering_service_map` map, `cloud`.`vpc_offerings` off where 
off.id=map.vpc_offering_id AND service='Lb'");
+                    conn.prepareStatement("select distinct map.vpc_offering_id 
from `cloud`.`vpc_offering_service_map` map, `cloud`.`vpc_offerings` off where 
off.id=map.vpc_offering_id AND service='Lb'");
             rs = pstmt.executeQuery();
             while (rs.next()) {
                 long id = rs.getLong(1);
@@ -1520,16 +1520,16 @@ public class Upgrade410to420 implements DbUpgrade {
                 String uuid = UUID.randomUUID().toString();
                 //Add internal LB VM to the list of physical network service 
providers
                 pstmt =
-                    conn.prepareStatement("INSERT INTO 
`cloud`.`physical_network_service_providers` "
-                        + "(uuid, physical_network_id, provider_name, state, 
load_balance_service_provided, destination_physical_network_id)"
-                        + " VALUES (?, ?, 'InternalLbVm', 'Enabled', 1, 0)");
+                        conn.prepareStatement("INSERT INTO 
`cloud`.`physical_network_service_providers` "
+                                + "(uuid, physical_network_id, provider_name, 
state, load_balance_service_provided, destination_physical_network_id)"
+                                + " VALUES (?, ?, 'InternalLbVm', 'Enabled', 
1, 0)");
                 pstmt.setString(1, uuid);
                 pstmt.setLong(2, pNtwkId);
                 pstmt.executeUpdate();
 
                 //Add internal lb vm to the list of physical network elements
                 PreparedStatement pstmt1 =
-                    conn.prepareStatement("SELECT id FROM 
`cloud`.`physical_network_service_providers`" + " WHERE physical_network_id=? 
AND provider_name='InternalLbVm'");
+                        conn.prepareStatement("SELECT id FROM 
`cloud`.`physical_network_service_providers`" + " WHERE physical_network_id=? 
AND provider_name='InternalLbVm'");
                 pstmt1.setLong(1, pNtwkId);
                 ResultSet rs1 = pstmt1.executeQuery();
                 while (rs1.next()) {
@@ -1649,7 +1649,7 @@ public class Upgrade410to420 implements DbUpgrade {
         s_logger.debug("Updating KVM snapshots");
         try {
             pstmt =
-                conn.prepareStatement("select id, backup_snap_id from 
`cloud`.`snapshots` where hypervisor_type='KVM' and removed is null and 
backup_snap_id is not null");
+                    conn.prepareStatement("select id, backup_snap_id from 
`cloud`.`snapshots` where hypervisor_type='KVM' and removed is null and 
backup_snap_id is not null");
             rs = pstmt.executeQuery();
             while (rs.next()) {
                 long id = rs.getLong(1);
@@ -1707,8 +1707,8 @@ public class Upgrade410to420 implements DbUpgrade {
                 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'");
+                            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();
@@ -1730,8 +1730,8 @@ public class Upgrade410to420 implements DbUpgrade {
                     }
 
                     PreparedStatement fetchSRXNspStmt =
-                        conn.prepareStatement("SELECT id from 
`cloud`.`physical_network_service_providers` where physical_network_id=" + 
physicalNetworkId +
-                            " and provider_name = 'JuniperSRX'");
+                            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();
@@ -1783,8 +1783,8 @@ public class Upgrade410to420 implements DbUpgrade {
         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_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                    "INSERT INTO `cloud`.`external_load_balancer_devices` 
(physical_network_id, host_id, provider_name, "
+                            + "device_name, capacity, is_dedicated, 
device_state, allocation_state, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, 
?, ?, ?)";
             pstmtUpdate = conn.prepareStatement(insertF5);
             pstmtUpdate.setLong(1, physicalNetworkId);
             pstmtUpdate.setLong(2, hostId);
@@ -1814,8 +1814,8 @@ public class Upgrade410to420 implements DbUpgrade {
         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 ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                    "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);
@@ -1845,10 +1845,10 @@ public class Upgrade410to420 implements DbUpgrade {
             // 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)";
+                    "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());
@@ -1874,10 +1874,10 @@ public class Upgrade410to420 implements DbUpgrade {
             // 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)";
+                    "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());
@@ -1916,7 +1916,7 @@ public class Upgrade410to420 implements DbUpgrade {
 
         try {
             pstmt =
-                conn.prepareStatement("select id from `cloud`.`data_center` 
where lb_provider='F5BigIp' or firewall_provider='JuniperSRX' or 
gateway_provider='JuniperSRX'");
+                    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));
@@ -1960,7 +1960,7 @@ public class Upgrade410to420 implements DbUpgrade {
                     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");
+                            " found in external_load_balancer_device");
                 }
 
                 // find the SRX device id  in the zone
@@ -1979,12 +1979,12 @@ public class Upgrade410to420 implements DbUpgrade {
                     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");
+                            " 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");
+                        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();
@@ -1994,7 +1994,7 @@ public class Upgrade410to420 implements DbUpgrade {
 
                     // 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())";
+                            "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);
@@ -2004,7 +2004,7 @@ public class Upgrade410to420 implements DbUpgrade {
 
                     // 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())";
+                            "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);
@@ -2023,7 +2023,7 @@ public class Upgrade410to420 implements DbUpgrade {
                     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"))) {
+                            camlCaseName.equalsIgnoreCase("publicInterface") 
|| camlCaseName.equalsIgnoreCase("privateInterface") || 
camlCaseName.equalsIgnoreCase("usageInterface"))) {
                         continue;
                     }
                     String lowerCaseName = camlCaseName.toLowerCase();
@@ -2099,9 +2099,9 @@ public class Upgrade410to420 implements DbUpgrade {
 
             // migrate NFS secondary storage, for nfs, keep previous host_id 
as the store_id
             storeInsert =
-                conn.prepareStatement("INSERT INTO `cloud`.`image_store` (id, 
uuid, name, image_provider_name, protocol, url, data_center_id, scope, role, 
parent, total_size, created) values(?, ?, ?, 'NFS', 'nfs', ?, ?, 'ZONE', ?, ?, 
?, ?)");
+                    conn.prepareStatement("INSERT INTO `cloud`.`image_store` 
(id, uuid, name, image_provider_name, protocol, url, data_center_id, scope, 
role, parent, total_size, created) values(?, ?, ?, 'NFS', 'nfs', ?, ?, 'ZONE', 
?, ?, ?, ?)");
             nfsQuery =
-                conn.prepareStatement("select id, uuid, url, data_center_id, 
parent, total_size, created from `cloud`.`host` where type = 'SecondaryStorage' 
and removed is null");
+                    conn.prepareStatement("select id, uuid, url, 
data_center_id, parent, total_size, created from `cloud`.`host` where type = 
'SecondaryStorage' and removed is null");
             rs = nfsQuery.executeQuery();
 
             while (rs.next()) {
@@ -2174,7 +2174,7 @@ public class Upgrade410to420 implements DbUpgrade {
         s_logger.debug("Updating volume_store_ref table from volume_host_ref 
table");
         try {
             volStoreInsert =
-                conn.prepareStatement("INSERT INTO `cloud`.`volume_store_ref` 
(store_id,  volume_id, zone_id, created, last_updated, job_id, download_pct, 
size, physical_size, download_state, checksum, error_str, local_path, 
install_path, url, destroyed, update_count, ref_cnt, state) select host_id, 
volume_id, zone_id, created, last_updated, job_id, download_pct, size, 
physical_size, download_state, checksum, error_str, local_path, install_path, 
url, destroyed, 0, 0, 'Allocated' from `cloud`.`volume_host_ref`");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`volume_store_ref` (store_id,  volume_id, zone_id, created, 
last_updated, job_id, download_pct, size, physical_size, download_state, 
checksum, error_str, local_path, install_path, url, destroyed, update_count, 
ref_cnt, state) select host_id, volume_id, zone_id, created, last_updated, 
job_id, download_pct, size, physical_size, download_state, checksum, error_str, 
local_path, install_path, url, destroyed, 0, 0, 'Allocated' from 
`cloud`.`volume_host_ref`");
             int rowCount = volStoreInsert.executeUpdate();
             s_logger.debug("Insert modified " + rowCount + " rows");
 
@@ -2207,7 +2207,7 @@ public class Upgrade410to420 implements DbUpgrade {
         s_logger.debug("Updating template_store_ref table from 
template_host_ref table");
         try {
             tmplStoreInsert =
-                conn.prepareStatement("INSERT INTO 
`cloud`.`template_store_ref` (store_id,  template_id, created, last_updated, 
job_id, download_pct, size, physical_size, download_state, error_str, 
local_path, install_path, url, destroyed, is_copy, update_count, ref_cnt, 
store_role, state) select host_id, template_id, created, last_updated, job_id, 
download_pct, size, physical_size, download_state, error_str, local_path, 
install_path, url, destroyed, is_copy, 0, 0, 'Image', 'Allocated' from 
`cloud`.`template_host_ref`");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`template_store_ref` (store_id,  template_id, created, last_updated, 
job_id, download_pct, size, physical_size, download_state, error_str, 
local_path, install_path, url, destroyed, is_copy, update_count, ref_cnt, 
store_role, state) select host_id, template_id, created, last_updated, job_id, 
download_pct, size, physical_size, download_state, error_str, local_path, 
install_path, url, destroyed, is_copy, 0, 0, 'Image', 'Allocated' from 
`cloud`.`template_host_ref`");
             int rowCount = tmplStoreInsert.executeUpdate();
             s_logger.debug("Insert modified " + rowCount + " rows");
 
@@ -2240,14 +2240,16 @@ public class Upgrade410to420 implements DbUpgrade {
         try {
             //Update all snapshots except KVM snapshots
             snapshotStoreInsert =
-                conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) select sechost_id, id, created, size, prev_snap_id, CONCAT('snapshots', 
'/', account_id, '/', volume_id, '/', backup_snap_id), volume_id, 0, 0, 
'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and 
hypervisor_type <> 'KVM' and sechost_id is not null and removed is null");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) select sechost_id, id, created, size, prev_snap_id, CONCAT('snapshots', 
'/', account_id, '/', volume_id, '/', backup_snap_id), volume_id, 0, 0, 
'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and 
hypervisor_type <> 'KVM' and sechost_id is not null and removed is null");
             int rowCount = snapshotStoreInsert.executeUpdate();
+            snapshotStoreInsert.close();
             s_logger.debug("Inserted " + rowCount + " snapshots into 
snapshot_store_ref");
 
             //backsnap_id for KVM snapshots is complate path. CONCAT is not 
required
             snapshotStoreInsert =
-                conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) select sechost_id, id, created, size, prev_snap_id, backup_snap_id, 
volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 
'BackedUp' and hypervisor_type = 'KVM' and sechost_id is not null and removed 
is null");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) select sechost_id, id, created, size, prev_snap_id, backup_snap_id, 
volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 
'BackedUp' and hypervisor_type = 'KVM' and sechost_id is not null and removed 
is null");
             rowCount = snapshotStoreInsert.executeUpdate();
+            snapshotStoreInsert.close();
             s_logger.debug("Inserted " + rowCount + " KVM snapshots into 
snapshot_store_ref");
         } catch (SQLException e) {
             String msg = "Unable to migrate snapshot_store_ref." + 
e.getMessage();
@@ -2282,9 +2284,9 @@ public class Upgrade410to420 implements DbUpgrade {
 
             // migrate S3 to image_store
             storeInsert = conn.prepareStatement("INSERT INTO 
`cloud`.`image_store` (uuid, name, image_provider_name, protocol, scope, role, 
created) " +
-                "values(?, ?, 'S3', ?, 'REGION', 'Image', ?)");
+                    "values(?, ?, 'S3', ?, 'REGION', 'Image', ?)");
             s3Query = conn.prepareStatement("select id, uuid, access_key, 
secret_key, end_point, bucket, https, connection_timeout, " +
-                "max_error_retry, socket_timeout, created from `cloud`.`s3`");
+                    "max_error_retry, socket_timeout, created from 
`cloud`.`s3`");
             rs = s3Query.executeQuery();
 
             while (rs.next()) {
@@ -2389,9 +2391,9 @@ public class Upgrade410to420 implements DbUpgrade {
         s_logger.debug("Updating template_store_ref table from template_s3_ref 
table");
         try {
             tmplStoreInsert =
-                conn.prepareStatement("INSERT INTO 
`cloud`.`template_store_ref` (store_id,  template_id, created, download_pct, 
size, physical_size, download_state, local_path, install_path, update_count, 
ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 
0, 0, 'Image', 'Ready')");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`template_store_ref` (store_id,  template_id, created, download_pct, 
size, physical_size, download_state, local_path, install_path, update_count, 
ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 
0, 0, 'Image', 'Ready')");
             s3Query =
-                conn.prepareStatement("select template_s3_ref.s3_id, 
template_s3_ref.template_id, template_s3_ref.created, template_s3_ref.size, 
template_s3_ref.physical_size, vm_template.account_id from 
`cloud`.`template_s3_ref`, `cloud`.`vm_template` where vm_template.id = 
template_s3_ref.template_id");
+                    conn.prepareStatement("select template_s3_ref.s3_id, 
template_s3_ref.template_id, template_s3_ref.created, template_s3_ref.size, 
template_s3_ref.physical_size, vm_template.account_id from 
`cloud`.`template_s3_ref`, `cloud`.`vm_template` where vm_template.id = 
template_s3_ref.template_id");
             rs = s3Query.executeQuery();
 
             while (rs.next()) {
@@ -2450,9 +2452,9 @@ public class Upgrade410to420 implements DbUpgrade {
         s_logger.debug("Updating snapshot_store_ref table from snapshots table 
for s3");
         try {
             snapshotStoreInsert =
-                conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')");
             s3Query =
-                conn.prepareStatement("select s3_id, id, created, size, 
prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', 
backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` 
where status = 'BackedUp' and hypervisor_type <> 'KVM' and s3_id is not null 
and removed is null");
+                    conn.prepareStatement("select s3_id, id, created, size, 
prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', 
backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` 
where status = 'BackedUp' and hypervisor_type <> 'KVM' and s3_id is not null 
and removed is null");
             rs = s3Query.executeQuery();
 
             while (rs.next()) {
@@ -2514,7 +2516,7 @@ public class Upgrade410to420 implements DbUpgrade {
 
             // migrate SWIFT secondary storage
             storeInsert =
-                conn.prepareStatement("INSERT INTO `cloud`.`image_store` 
(uuid, name, image_provider_name, protocol, url, scope, role, created) 
values(?, ?, 'Swift', 'http', ?, 'REGION', 'Image', ?)");
+                    conn.prepareStatement("INSERT INTO `cloud`.`image_store` 
(uuid, name, image_provider_name, protocol, url, scope, role, created) 
values(?, ?, 'Swift', 'http', ?, 'REGION', 'Image', ?)");
             swiftQuery = conn.prepareStatement("select id, uuid, url, account, 
username, swift.key, created from `cloud`.`swift`");
             rs = swiftQuery.executeQuery();
 
@@ -2604,7 +2606,7 @@ public class Upgrade410to420 implements DbUpgrade {
         s_logger.debug("Updating template_store_ref table from 
template_swift_ref table");
         try {
             tmplStoreInsert =
-                conn.prepareStatement("INSERT INTO 
`cloud`.`template_store_ref` (store_id,  template_id, created, download_pct, 
size, physical_size, download_state, local_path, install_path, update_count, 
ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 
0, 0, 'Image', 'Ready')");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`template_store_ref` (store_id,  template_id, created, download_pct, 
size, physical_size, download_state, local_path, install_path, update_count, 
ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 
0, 0, 'Image', 'Ready')");
             s3Query = conn.prepareStatement("select swift_id, template_id, 
created, path, size, physical_size from `cloud`.`template_swift_ref`");
             rs = s3Query.executeQuery();
 
@@ -2663,9 +2665,9 @@ public class Upgrade410to420 implements DbUpgrade {
         s_logger.debug("Updating snapshot_store_ref table from snapshots table 
for swift");
         try {
             snapshotStoreInsert =
-                conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')");
+                    conn.prepareStatement("INSERT INTO 
`cloud`.`snapshot_store_ref` (store_id,  snapshot_id, created, size, 
parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, 
state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')");
             s3Query =
-                conn.prepareStatement("select swift_id, id, created, size, 
prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', 
backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` 
where status = 'BackedUp' and hypervisor_type <> 'KVM' and swift_id is not null 
and removed is null");
+                    conn.prepareStatement("select swift_id, id, created, size, 
prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', 
backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` 
where status = 'BackedUp' and hypervisor_type <> 'KVM' and swift_id is not null 
and removed is null");
             rs = s3Query.executeQuery();
 
             while (rs.next()) {
@@ -2712,7 +2714,7 @@ public class Upgrade410to420 implements DbUpgrade {
         PreparedStatement pstmt = null;
         try {
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`nicira_nvp_nic_map` ADD CONSTRAINT `fk_nicira_nvp_nic_map__nic` 
FOREIGN KEY (`nic`) REFERENCES `nics` (`uuid`) ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`nicira_nvp_nic_map` ADD CONSTRAINT `fk_nicira_nvp_nic_map__nic` 
FOREIGN KEY (`nic`) REFERENCES `nics` (`uuid`) ON DELETE CASCADE");
             pstmt.executeUpdate();
             s_logger.debug("Added foreign key fk_nicira_nvp_nic_map__nic to 
the table nicira_nvp_nic_map");
         } catch (SQLException e) {
@@ -2738,7 +2740,7 @@ public class Upgrade410to420 implements DbUpgrade {
         PreparedStatement pstmt = null;
         try {
             pstmt =
-                conn.prepareStatement("ALTER TABLE 
`cloud`.`router_network_ref` ADD CONSTRAINT `fk_router_network_ref__router_id` 
FOREIGN KEY (`router_id`) REFERENCES `domain_router` (`id`) ON DELETE CASCADE");
+                    conn.prepareStatement("ALTER TABLE 
`cloud`.`router_network_ref` ADD CONSTRAINT `fk_router_network_ref__router_id` 
FOREIGN KEY (`router_id`) REFERENCES `domain_router` (`id`) ON DELETE CASCADE");
             pstmt.executeUpdate();
             s_logger.debug("Added foreign key fk_router_network_ref__router_id 
to the table router_network_ref");
         } catch (SQLException e) {
@@ -2799,11 +2801,11 @@ public class Upgrade410to420 implements DbUpgrade {
         try {
             try {
                 pstmt =
-                    conn.prepareStatement("SELECT *  FROM 
information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 
'network_offerings' AND COLUMN_NAME = 'concurrent_connections'");
+                        conn.prepareStatement("SELECT *  FROM 
information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 
'network_offerings' AND COLUMN_NAME = 'concurrent_connections'");
                 rs = pstmt.executeQuery();
                 if (!rs.next()) {
                     pstmt =
-                        conn.prepareStatement("ALTER TABLE 
`cloud`.`network_offerings` ADD COLUMN `concurrent_connections` int(10) 
unsigned COMMENT 'Load Balancer(haproxy) maximum number of concurrent 
connections(global max)'");
+                            conn.prepareStatement("ALTER TABLE 
`cloud`.`network_offerings` ADD COLUMN `concurrent_connections` int(10) 
unsigned COMMENT 'Load Balancer(haproxy) maximum number of concurrent 
connections(global max)'");
                     pstmt.executeUpdate();
                 }
             } catch (SQLException e) {
@@ -2860,7 +2862,7 @@ public class Upgrade410to420 implements DbUpgrade {
                 pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`volumes` 
DROP COLUMN `iso_id`");
                 pstmt.executeUpdate();
                 pstmt =
-                    conn.prepareStatement("ALTER TABLE `cloud`.`volumes` 
CHANGE COLUMN `iso_id1` `iso_id` bigint(20) unsigned COMMENT 'The id of the iso 
from which the volume was created'");
+                        conn.prepareStatement("ALTER TABLE `cloud`.`volumes` 
CHANGE COLUMN `iso_id1` `iso_id` bigint(20) unsigned COMMENT 'The id of the iso 
from which the volume was created'");
                 pstmt.executeUpdate();
             }
         } catch (SQLException e) {
@@ -2902,7 +2904,7 @@ public class Upgrade410to420 implements DbUpgrade {
                     String service = rs1.getString(1);
                     String provider = rs1.getString(2);
                     insertProviders =
-                        conn.prepareStatement("INSERT INTO 
`cloud`.`vpc_service_map` (`vpc_id`, `service`, `provider`, `created`) VALUES 
(?, ?, ?, now());");
+                            conn.prepareStatement("INSERT INTO 
`cloud`.`vpc_service_map` (`vpc_id`, `service`, `provider`, `created`) VALUES 
(?, ?, ?, now());");
                     insertProviders.setLong(1, vpc_id);
                     insertProviders.setString(2, service);
                     insertProviders.setString(3, provider);
@@ -2952,9 +2954,9 @@ public class Upgrade410to420 implements DbUpgrade {
                 long domain_id = rsAccount.getLong(2);
                 // 1. update cpu,memory for all accounts
                 pstmt2 =
-                    conn.prepareStatement("SELECT SUM(service_offering.cpu), 
SUM(service_offering.ram_size)" + " FROM `cloud`.`vm_instance`, 
`cloud`.`service_offering`"
-                        + " WHERE vm_instance.service_offering_id = 
service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed 
is NULL"
-                        + " AND vm_instance.vm_type='User' AND state not in 
('Destroyed', 'Error', 'Expunging')");
+                        conn.prepareStatement("SELECT 
SUM(service_offering.cpu), SUM(service_offering.ram_size)" + " FROM 
`cloud`.`vm_instance`, `cloud`.`service_offering`"
+                                + " WHERE vm_instance.service_offering_id = 
service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed 
is NULL"
+                                + " AND vm_instance.vm_type='User' AND state 
not in ('Destroyed', 'Error', 'Expunging')");
                 pstmt2.setLong(1, account_id);
                 rsCount = pstmt2.executeQuery();
                 if (rsCount.next()) {
@@ -2966,9 +2968,9 @@ public class Upgrade410to420 implements DbUpgrade {
                 }
                 // 2. update primary_storage for all accounts
                 pstmt3 =
-                    conn.prepareStatement("SELECT sum(size) FROM 
`cloud`.`volumes` WHERE account_id= ?"
-                        + " AND (path is not NULL OR state in ('Allocated')) 
AND removed is NULL"
-                        + " AND instance_id IN (SELECT id FROM 
`cloud`.`vm_instance` WHERE vm_type='User')");
+                        conn.prepareStatement("SELECT sum(size) FROM 
`cloud`.`volumes` WHERE account_id= ?"
+                                + " AND (path is not NULL OR state in 
('Allocated')) AND removed is NULL"
+                                + " AND instance_id IN (SELECT id FROM 
`cloud`.`vm_instance` WHERE vm_type='User')");
                 pstmt3.setLong(1, account_id);
                 rsCount = pstmt3.executeQuery();
                 if (rsCount.next()) {
@@ -2981,8 +2983,8 @@ public class Upgrade410to420 implements DbUpgrade {
                 long totalSnapshotsSize = 0;
                 long totalTemplatesSize = 0;
                 pstmt4 =
-                    conn.prepareStatement("SELECT sum(size) FROM 
`cloud`.`volumes` WHERE account_id= ?"
-                        + " AND path is NULL AND state not in ('Allocated') 
AND removed is NULL");
+                        conn.prepareStatement("SELECT sum(size) FROM 
`cloud`.`volumes` WHERE account_id= ?"
+                                + " AND path is NULL AND state not in 
('Allocated') AND removed is NULL");
                 pstmt4.setLong(1, account_id);
                 rsCount = pstmt4.executeQuery();
                 if (rsCount.next()) {
@@ -2995,8 +2997,8 @@ public class Upgrade410to420 implements DbUpgrade {
                     totalSnapshotsSize = rsCount.getLong(1);
                 }
                 pstmt4 =
-                    conn.prepareStatement("SELECT sum(template_store_ref.size) 
FROM `cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?"
-                        + " AND template_store_ref.template_id = 
vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND 
removed is NULL");
+                        conn.prepareStatement("SELECT 
sum(template_store_ref.size) FROM 
`cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?"
+                                + " AND template_store_ref.template_id = 
vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND 
removed is NULL");
                 pstmt4.setLong(1, account_id);
                 rsCount = pstmt4.executeQuery();
                 if (rsCount.next()) {
@@ -3018,8 +3020,8 @@ public class Upgrade410to420 implements DbUpgrade {
             for (int count = 0; count < resource_types.length; count++) {
                 String resource_type = resource_types[count];
                 pstmt5 =
-                    conn.prepareStatement("select 
account.domain_id,sum(resource_count.count) from `cloud`.`account` left join 
`cloud`.`resource_count` on account.id=resource_count.account_id "
-                        + "where resource_count.type=? group by 
account.domain_id;");
+                        conn.prepareStatement("select 
account.domain_id,sum(resource_count.count) from `cloud`.`account` left join 
`cloud`.`resource_count` on account.id=resource_count.account_id "
+                                + "where resource_count.type=? group by 
account.domain_id;");
                 pstmt5.setString(1, resource_type);
                 rsCount = pstmt5.executeQuery();
                 while (rsCount.next()) {
@@ -3066,7 +3068,7 @@ public class Upgrade410to420 implements DbUpgrade {
         //update or insert into resource_count table.
         PreparedStatement pstmt = null;
         pstmt =
-            conn.prepareStatement("INSERT INTO `cloud`.`resource_count` 
(account_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE 
id=LAST_INSERT_ID(id), count=?");
+                conn.prepareStatement("INSERT INTO `cloud`.`resource_count` 
(account_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE 
id=LAST_INSERT_ID(id), count=?");
         pstmt.setLong(1, accountId);
         pstmt.setString(2, type);
         pstmt.setLong(3, resourceCount);
@@ -3079,7 +3081,7 @@ public class Upgrade410to420 implements DbUpgrade {
         //update or insert into resource_count table.
         PreparedStatement pstmt = null;
         pstmt =
-            conn.prepareStatement("INSERT INTO `cloud`.`resource_count` 
(domain_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE 
id=LAST_INSERT_ID(id), count=?");
+                conn.prepareStatement("INSERT INTO `cloud`.`resource_count` 
(domain_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE 
id=LAST_INSERT_ID(id), count=?");
         pstmt.setLong(1, domainId);
         pstmt.setString(2, type);
         pstmt.setLong(3, resourceCount);

Reply via email to