CLOUDSTACK-8656: log messages on exception in legacy sql upgrade code

This commit is contained in:
Daan Hoogland 2015-08-02 14:20:11 +02:00
parent 4e65845789
commit 04e9083c31
12 changed files with 219 additions and 579 deletions

View File

@ -0,0 +1,42 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.upgrade.dao;
import org.apache.log4j.Logger;
public abstract class LegacyDbUpgrade implements DbUpgrade{
final static Logger s_logger = Logger.getLogger(LegacyDbUpgrade.class);
public LegacyDbUpgrade() {
super();
}
/**
* @param closable
*/
protected void closeAutoCloseable(AutoCloseable closable) {
if (closable != null) {
try {
closable.close();
} catch (Exception e) {
s_logger.info("[ignored]",e);
}
}
}
}

View File

@ -411,6 +411,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade {
pstmt.close();
}
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
s_logger.debug("Done encrypting Config values");
@ -861,6 +862,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade {
pstmt.executeUpdate();
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
TransactionLegacy.closePstmts(pstmt2Close);
}
@ -1000,6 +1002,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade {
pstmt.executeUpdate();
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
TransactionLegacy.closePstmts(pstmt2Close);
}
@ -1053,6 +1056,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade {
pstmt.close();
}
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
}
@ -1151,11 +1155,10 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to switch networks to the new network offering", e);
} finally {
try {
pstmt = conn.prepareStatement("DROP TABLE `cloud`.`network_offerings2`");
pstmt.executeUpdate();
pstmt.close();
try (PreparedStatement dropStatement = conn.prepareStatement("DROP TABLE `cloud`.`network_offerings2`");){
dropStatement.executeUpdate();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
TransactionLegacy.closePstmts(pstmt2Close);
}

View File

@ -207,18 +207,21 @@ public class Upgrade222to224 implements DbUpgrade {
try {
pstmtUpdate.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
@ -406,18 +409,21 @@ public class Upgrade222to224 implements DbUpgrade {
try {
pstmtUpdate.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}

View File

@ -68,41 +68,29 @@ public class Upgrade229to2210 implements DbUpgrade {
}
private void updateSnapshots(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
long currentSnapshotId = 0;
try {
pstmt =
conn.prepareStatement("select id, prev_snap_id from snapshots where sechost_id is NULL and prev_snap_id is not NULL and status=\"BackedUp\" and removed is NULL order by id");
rs = pstmt.executeQuery();
try (
PreparedStatement pstmt = conn.prepareStatement("select id, prev_snap_id from snapshots where sechost_id is NULL and prev_snap_id is not NULL and status=\"BackedUp\" and removed is NULL order by id");
ResultSet rs = pstmt.executeQuery();
PreparedStatement pstmt2 = conn.prepareStatement("select sechost_id from snapshots where id=? and sechost_id is not NULL");
PreparedStatement updateSnapshotStatement = conn.prepareStatement("update snapshots set sechost_id=? where id=?");
){
while (rs.next()) {
long id = rs.getLong(1);
long preSnapId = rs.getLong(2);
currentSnapshotId = id;
pstmt = conn.prepareStatement("select sechost_id from snapshots where id=? and sechost_id is not NULL");
pstmt.setLong(1, preSnapId);
ResultSet sechost = pstmt.executeQuery();
if (sechost.next()) {
long secHostId = sechost.getLong(1);
pstmt = conn.prepareStatement("update snapshots set sechost_id=? where id=?");
pstmt.setLong(1, secHostId);
pstmt.setLong(2, id);
pstmt.executeUpdate();
pstmt2.setLong(1, preSnapId);
try (ResultSet sechost = pstmt2.executeQuery();) {
if (sechost.next()) {
long secHostId = sechost.getLong(1);
updateSnapshotStatement.setLong(1, secHostId);
updateSnapshotStatement.setLong(2, id);
updateSnapshotStatement.executeUpdate();
}
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to update snapshots id=" + currentSnapshotId, e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
@ -192,6 +180,7 @@ public class Upgrade229to2210 implements DbUpgrade {
pstmt.close();
}
} catch (SQLException e) {
s_logger.info("[ignored]",e);
}
}
}

View File

@ -31,7 +31,7 @@ import org.apache.log4j.Logger;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade301to302 implements DbUpgrade {
public class Upgrade301to302 extends LegacyDbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade301to302.class);
@Override
@ -150,18 +150,9 @@ public class Upgrade301to302 implements DbUpgrade {
} 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) {
}
closeAutoCloseable(rs);
closeAutoCloseable(rs1);
closeAutoCloseable(pstmt);
}
}
@ -177,55 +168,34 @@ public class Upgrade301to302 implements DbUpgrade {
DbUpgradeUtils.dropKeysIfExist(conn, "cloud.vm_instance", keys, true);
DbUpgradeUtils.dropKeysIfExist(conn, "cloud.vm_instance", keys, false);
PreparedStatement pstmt = null;
try {
pstmt =
try (
PreparedStatement pstmt =
conn.prepareStatement("ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__last_host_id` FOREIGN KEY (`last_host_id`) REFERENCES `host` (`id`)");
){
pstmt.executeUpdate();
pstmt.close();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to insert foreign key in vm_instance table ", e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
private void changeEngine(Connection conn) {
s_logger.debug("Fixing engine and row_format for op_lock and op_nwgrp_work tables");
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`op_lock` ENGINE=MEMORY, ROW_FORMAT = FIXED");
String sqlOpLock = "ALTER TABLE `cloud`.`op_lock` ENGINE=MEMORY, ROW_FORMAT = FIXED";
try (
PreparedStatement pstmt = conn.prepareStatement(sqlOpLock);
) {
pstmt.executeUpdate();
pstmt.close();
} catch (Exception e) {
s_logger.debug("Failed do execute the statement " + pstmt + ", moving on as it's not critical fix");
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
s_logger.debug("Failed do execute the statement " + sqlOpLock + ", moving on as it's not critical fix");
}
try {
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`op_nwgrp_work` ENGINE=MEMORY, ROW_FORMAT = FIXED");
String sqlOpNwgrpWork = "ALTER TABLE `cloud`.`op_nwgrp_work` ENGINE=MEMORY, ROW_FORMAT = FIXED";
try (
PreparedStatement pstmt = conn.prepareStatement(sqlOpNwgrpWork);
) {
pstmt.executeUpdate();
pstmt.close();
} catch (Exception e) {
s_logger.debug("Failed do execute the statement " + pstmt + ", moving on as it's not critical fix");
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
s_logger.debug("Failed do execute the statement " + sqlOpNwgrpWork + ", moving on as it's not critical fix");
}
}

View File

@ -36,7 +36,7 @@ import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade302to303 implements DbUpgrade {
public class Upgrade302to303 extends LegacyDbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade302to303.class);
@Override
@ -133,23 +133,10 @@ public class Upgrade302to303 implements DbUpgrade {
}
}
}
if (zoneResults != null) {
try {
zoneResults.close();
} catch (SQLException e) {
}
}
if (zoneSearchStmt != null) {
try {
zoneSearchStmt.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(zoneResults);
closeAutoCloseable(zoneSearchStmt);
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
} finally {
}
}
@ -176,12 +163,7 @@ public class Upgrade302to303 implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding F5 load balancer device", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmtUpdate);
}
}
@ -206,12 +188,7 @@ public class Upgrade302to303 implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding SRX firewall device ", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmtUpdate);
}
}
@ -235,12 +212,7 @@ public class Upgrade302to303 implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworkServiceProvider F5BigIp", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmtUpdate);
}
}
@ -264,12 +236,7 @@ public class Upgrade302to303 implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworkServiceProvider JuniperSRX", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmtUpdate);
}
}
@ -299,16 +266,8 @@ public class Upgrade302to303 implements DbUpgrade {
} catch (UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable encrypt configuration values ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
s_logger.debug("Done encrypting Config values");
}

View File

@ -34,7 +34,7 @@ import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
public class Upgrade302to40 extends Upgrade30xBase {
final static Logger s_logger = Logger.getLogger(Upgrade302to40.class);
@Override
@ -138,33 +138,10 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while correcting Virtual Router Entries", e);
} finally {
if (rsVR != null) {
try {
rsVR.close();
} catch (SQLException e) {
}
}
if (pstmtVR != null) {
try {
pstmtVR.close();
} catch (SQLException e) {
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(rsVR);
closeAutoCloseable(pstmtVR);
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}
@ -398,33 +375,10 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while correcting PhysicalNetwork setup", e);
} finally {
if (rsZone != null) {
try {
rsZone.close();
} catch (SQLException e) {
}
}
if (pstmtZone != null) {
try {
pstmtZone.close();
} catch (SQLException e) {
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(rsZone);
closeAutoCloseable(pstmtZone);
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}
@ -510,29 +464,23 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while cloning NetworkOffering", e);
} finally {
closeAutoCloseable(rs);
try {
pstmt = conn.prepareStatement("DROP TEMPORARY TABLE `cloud`.`network_offerings2`");
pstmt.executeUpdate();
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
s_logger.info("[ignored] ",e);
}
closeAutoCloseable(pstmt);
}
}
private void addHostDetailsUniqueKey(Connection conn) {
s_logger.debug("Checking if host_details unique key exists, if not we will add it");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'");
rs = pstmt.executeQuery();
try (
PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'");
ResultSet rs = pstmt.executeQuery();
) {
if (rs.next()) {
s_logger.debug("Unique key already exists on host_details - not adding new one");
} else {
@ -545,17 +493,6 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
}
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to check/update the host_details unique key ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
@ -602,16 +539,8 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable add VPC physical network service provider ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
s_logger.debug("Done adding VPC physical network service providers to all physical networks");
}
@ -619,46 +548,33 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
private void updateRouterNetworkRef(Connection conn) {
//Encrypt config params and change category to Hidden
s_logger.debug("Updating router network ref");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("SELECT d.id, d.network_id FROM `cloud`.`domain_router` d, `cloud`.`vm_instance` v " + "WHERE d.id=v.id AND v.removed is NULL");
rs = pstmt.executeQuery();
try (
PreparedStatement pstmt = conn.prepareStatement("SELECT d.id, d.network_id FROM `cloud`.`domain_router` d, `cloud`.`vm_instance` v " + "WHERE d.id=v.id AND v.removed is NULL");
PreparedStatement pstmt1 = conn.prepareStatement("SELECT guest_type from `cloud`.`networks` where id=?");
PreparedStatement pstmt2 = conn.prepareStatement("INSERT INTO `cloud`.`router_network_ref` (router_id, network_id, guest_type) " + "VALUES (?, ?, ?)");
ResultSet rs = pstmt.executeQuery();
){
while (rs.next()) {
Long routerId = rs.getLong(1);
Long networkId = rs.getLong(2);
//get the network type
pstmt = conn.prepareStatement("SELECT guest_type from `cloud`.`networks` where id=?");
pstmt.setLong(1, networkId);
ResultSet rs1 = pstmt.executeQuery();
rs1.next();
String networkType = rs1.getString(1);
//insert the reference
pstmt = conn.prepareStatement("INSERT INTO `cloud`.`router_network_ref` (router_id, network_id, guest_type) " + "VALUES (?, ?, ?)");
pstmt.setLong(1, routerId);
pstmt.setLong(2, networkId);
pstmt.setString(3, networkType);
pstmt.executeUpdate();
pstmt1.setLong(1, networkId);
try (ResultSet rs1 = pstmt1.executeQuery();) {
rs1.next();
String networkType = rs1.getString(1);
//insert the reference
pstmt2.setLong(1, routerId);
pstmt2.setLong(2, networkId);
pstmt2.setString(3, networkType);
pstmt2.executeUpdate();
}
s_logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId);
}
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to update the router/network reference ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
s_logger.debug("Done updating router/network references");
}
@ -768,33 +684,19 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
}
}
if (zoneResults != null) {
try {
zoneResults.close();
} catch (SQLException e) {
}
}
if (zoneSearchStmt != null) {
try {
zoneSearchStmt.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(zoneResults);
closeAutoCloseable(zoneSearchStmt);
} 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);
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 ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement pstmtUpdate = conn.prepareStatement(insertF5);) {
pstmtUpdate.setLong(1, physicalNetworkId);
pstmtUpdate.setLong(2, hostId);
pstmtUpdate.setString(3, "F5BigIp");
@ -809,24 +711,15 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
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);
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 ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement pstmtUpdate = conn.prepareStatement(insertSrx);) {
pstmtUpdate.setLong(1, physicalNetworkId);
pstmtUpdate.setLong(2, hostId);
pstmtUpdate.setString(3, "JuniperSRX");
@ -839,28 +732,18 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
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);
// 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)";
try (PreparedStatement pstmtUpdate = conn.prepareStatement(insertPNSP);) {
pstmtUpdate.setString(1, UUID.randomUUID().toString());
pstmtUpdate.setLong(2, physicalNetworkId);
pstmtUpdate.setString(3, "F5BigIp");
@ -868,28 +751,18 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
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);
// 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)";
try (PreparedStatement pstmtUpdate = conn.prepareStatement(insertPNSP);) {
pstmtUpdate.setString(1, UUID.randomUUID().toString());
pstmtUpdate.setLong(2, physicalNetworkId);
pstmtUpdate.setString(3, "JuniperSRX");
@ -897,13 +770,6 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
pstmtUpdate.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworkServiceProvider JuniperSRX", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
}
}
@ -1045,15 +911,8 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
} 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) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
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");
}
@ -1062,12 +921,11 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
private void encryptConfig(Connection conn) {
//Encrypt config params and change category to Hidden
s_logger.debug("Encrypting Config values");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt =
conn.prepareStatement("select name, value from `cloud`.`configuration` where name in ('router.ram.size', 'secondary.storage.vm', 'security.hash.key') and category <> 'Hidden'");
rs = pstmt.executeQuery();
try (
PreparedStatement pstmt = conn.prepareStatement("select name, value from `cloud`.`configuration` where name in ('router.ram.size', 'secondary.storage.vm', 'security.hash.key') and category <> 'Hidden'");
PreparedStatement pstmt1 = conn.prepareStatement("update `cloud`.`configuration` set value=?, category = 'Hidden' where name=?");
ResultSet rs = pstmt.executeQuery();
) {
while (rs.next()) {
String name = rs.getString(1);
String value = rs.getString(2);
@ -1075,37 +933,25 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
continue;
}
String encryptedValue = DBEncryptionUtil.encrypt(value);
pstmt = conn.prepareStatement("update `cloud`.`configuration` set value=?, category = 'Hidden' where name=?");
pstmt.setBytes(1, encryptedValue.getBytes("UTF-8"));
pstmt.setString(2, name);
pstmt.executeUpdate();
pstmt1.setBytes(1, encryptedValue.getBytes("UTF-8"));
pstmt1.setString(2, name);
pstmt1.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable encrypt configuration values ", e);
} catch (UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable encrypt configuration values ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
s_logger.debug("Done encrypting Config values");
}
private void encryptClusterDetails(Connection conn) {
s_logger.debug("Encrypting cluster details");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("select id, value from `cloud`.`cluster_details` where name = 'password'");
rs = pstmt.executeQuery();
try (
PreparedStatement pstmt = conn.prepareStatement("select id, value from `cloud`.`cluster_details` where name = 'password'");
PreparedStatement pstmt1 = conn.prepareStatement("update `cloud`.`cluster_details` set value=? where id=?");
ResultSet rs = pstmt.executeQuery();
) {
while (rs.next()) {
long id = rs.getLong(1);
String value = rs.getString(2);
@ -1113,26 +959,14 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
continue;
}
String encryptedValue = DBEncryptionUtil.encrypt(value);
pstmt = conn.prepareStatement("update `cloud`.`cluster_details` set value=? where id=?");
pstmt.setBytes(1, encryptedValue.getBytes("UTF-8"));
pstmt.setLong(2, id);
pstmt.executeUpdate();
pstmt1.setBytes(1, encryptedValue.getBytes("UTF-8"));
pstmt1.setLong(2, id);
pstmt1.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable encrypt cluster_details values ", e);
} catch (UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable encrypt cluster_details values ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
s_logger.debug("Done encrypting cluster_details");
}

View File

@ -33,7 +33,7 @@ import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
public class Upgrade304to305 extends Upgrade30xBase {
final static Logger s_logger = Logger.getLogger(Upgrade304to305.class);
@Override
@ -173,16 +173,8 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable add VPC physical network service provider ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
s_logger.debug("Done adding VPC physical network service providers to all physical networks");
}
@ -220,16 +212,8 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to update the router/network reference ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
s_logger.debug("Done updating router/network references");
}
@ -254,16 +238,8 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to check/update the host_details unique key ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}
@ -407,15 +383,8 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
} 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) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
s_logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map");
}
@ -487,16 +456,8 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
} catch (UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable encrypt cluster_details values ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
s_logger.debug("Done encrypting cluster_details");
}

View File

@ -31,7 +31,7 @@ import org.apache.log4j.Logger;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class Upgrade305to306 extends Upgrade30xBase implements DbUpgrade {
public class Upgrade305to306 extends Upgrade30xBase {
final static Logger s_logger = Logger.getLogger(Upgrade305to306.class);
@Override
@ -82,55 +82,33 @@ public class Upgrade305to306 extends Upgrade30xBase implements DbUpgrade {
DbUpgradeUtils.dropKeysIfExist(conn, "alert", indexList, false);
//Now add index.
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`alert` ADD INDEX `i_alert__last_sent`(`last_sent`)");
try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`alert` ADD INDEX `i_alert__last_sent`(`last_sent`)");) {
pstmt.executeUpdate();
s_logger.debug("Added index i_alert__last_sent for table alert");
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to add index i_alert__last_sent to alert table for the column last_sent", e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
private void upgradeEIPNetworkOfferings(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'");
rs = pstmt.executeQuery();
try (
PreparedStatement pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'");
PreparedStatement pstmt1 = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?");
ResultSet rs = pstmt.executeQuery();
){
while (rs.next()) {
long id = rs.getLong(1);
// check if elastic IP service is enabled for network offering
if (rs.getLong(2) != 0) {
//update network offering with eip_associate_public_ip set to true
pstmt = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?");
pstmt.setBoolean(1, true);
pstmt.setLong(2, id);
pstmt.executeUpdate();
pstmt1.setBoolean(1, true);
pstmt1.setLong(2, id);
pstmt1.executeUpdate();
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to set eip_associate_public_ip for network offerings with EIP service enabled.", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
@ -143,20 +121,11 @@ public class Upgrade305to306 extends Upgrade30xBase implements DbUpgrade {
DbUpgradeUtils.dropKeysIfExist(conn, "host_details", indexList, false);
//Now add index.
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id`(`host_id`)");
try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id`(`host_id`)");) {
pstmt.executeUpdate();
s_logger.debug("Added index fk_host_details__host_id for table host_details");
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to add index fk_host_details__host_id to host_details table for the column host_id", e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
@ -218,15 +187,8 @@ public class Upgrade305to306 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}
@ -247,16 +209,8 @@ public class Upgrade305to306 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to remove Firewall service for SG shared network offering.", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}
@ -288,16 +242,8 @@ public class Upgrade305to306 extends Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to update backup id for KVM snapshots", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}

View File

@ -98,19 +98,9 @@ public class Upgrade306to307 extends Upgrade30xBase implements DbUpgrade {
pstmt.executeUpdate();
} catch (SQLException e) {
} finally {
try {
if (rs != null) {
rs.close();
}
if (rs1 != null) {
rs1.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
closeAutoCloseable(rs);
closeAutoCloseable(rs1);
closeAutoCloseable(pstmt);
}
}

View File

@ -69,23 +69,14 @@ public class Upgrade307to410 implements DbUpgrade {
if (regionId != null) {
region_id = Integer.parseInt(regionId);
}
PreparedStatement pstmt = null;
try {
try (PreparedStatement pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");){
//Update regionId in region table
s_logger.debug("Updating region table with Id: " + region_id);
pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");
pstmt.setInt(1, region_id);
pstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Error while updating region entries", e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}

View File

@ -27,7 +27,7 @@ import org.apache.log4j.Logger;
import com.cloud.utils.exception.CloudRuntimeException;
public abstract class Upgrade30xBase implements DbUpgrade {
public abstract class Upgrade30xBase extends LegacyDbUpgrade implements DbUpgrade {
final static Logger s_logger = Logger.getLogger(Upgrade30xBase.class);
@ -46,18 +46,8 @@ public abstract class Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to fetch network label from configuration", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
return networkLabel;
}
@ -117,19 +107,8 @@ public abstract class Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
if (pstmt2 != null) {
try {
pstmt2.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmt2);
closeAutoCloseable(pstmtUpdate);
}
}
@ -152,12 +131,7 @@ public abstract class Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmtUpdate);
}
}
@ -204,18 +178,8 @@ public abstract class Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding default Security Group Provider", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
if (pstmt2 != null) {
try {
pstmt2.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmt2);
closeAutoCloseable(pstmtUpdate);
}
}
@ -261,18 +225,8 @@ public abstract class Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
if (pstmt2 != null) {
try {
pstmt2.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmt2);
closeAutoCloseable(pstmtUpdate);
}
}
@ -299,12 +253,7 @@ public abstract class Upgrade30xBase implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
} finally {
if (pstmtUpdate != null) {
try {
pstmtUpdate.close();
} catch (SQLException e) {
}
}
closeAutoCloseable(pstmtUpdate);
}
}