use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade305to306 method removeFirewallServiceFromSharedNetworkOfferingWithSGService.
private void removeFirewallServiceFromSharedNetworkOfferingWithSGService(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement("select id from `cloud`.`network_offerings` where unique_name='DefaultSharedNetworkOfferingWithSGService'");
rs = pstmt.executeQuery();
while (rs.next()) {
long id = rs.getLong(1);
// remove Firewall service for SG shared network offering
pstmt = conn.prepareStatement("DELETE FROM `cloud`.`ntwk_offering_service_map` where network_offering_id=? and service='Firewall'");
pstmt.setLong(1, id);
pstmt.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to remove Firewall service for SG shared network offering.", e);
} finally {
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade305to306 method addIndexForAlert.
private void addIndexForAlert(Connection conn) {
//First drop if it exists. (Due to patches shipped to customers some will have the index and some wont.)
List<String> indexList = new ArrayList<String>();
s_logger.debug("Dropping index i_alert__last_sent if it exists");
indexList.add("i_alert__last_sent");
DbUpgradeUtils.dropKeysIfExist(conn, "alert", indexList, false);
//Now add index.
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);
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade307to410 method updateRegionEntries.
private void updateRegionEntries(Connection conn) {
final Properties dbProps = DbProperties.getDbProperties();
int region_id = 1;
String regionId = dbProps.getProperty("region.id");
if (regionId != null) {
region_id = Integer.parseInt(regionId);
}
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.setInt(1, region_id);
pstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Error while updating region entries", e);
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade30xBase method addDefaultSGProvider.
protected void addDefaultSGProvider(Connection conn, long physicalNetworkId, long zoneId, String networkType, boolean is304) {
PreparedStatement pstmtUpdate = null, pstmt2 = null;
try {
//add security group service provider (if security group service is enabled for at least one guest network)
boolean isSGServiceEnabled = false;
String selectSG = "";
if (is304) {
selectSG = "SELECT nm.* FROM `cloud`.`ntwk_service_map` nm JOIN `cloud`.`networks` n ON nm.network_id = n.id where n.data_center_id = ? and nm.service='SecurityGroup'";
} else {
selectSG = "SELECT * from `cloud`.`networks` where is_security_group_enabled=1 and data_center_id=?";
}
pstmt2 = conn.prepareStatement(selectSG);
pstmt2.setLong(1, zoneId);
ResultSet sgDcSet = pstmt2.executeQuery();
if (sgDcSet.next()) {
isSGServiceEnabled = true;
}
sgDcSet.close();
pstmt2.close();
if (isSGServiceEnabled) {
s_logger.debug("Adding PhysicalNetworkServiceProvider SecurityGroupProvider to the physical network id=" + 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,0,0,0,0,1)";
pstmtUpdate = conn.prepareStatement(insertPNSP);
pstmtUpdate.setString(1, UUID.randomUUID().toString());
pstmtUpdate.setLong(2, physicalNetworkId);
pstmtUpdate.setString(3, "SecurityGroupProvider");
pstmtUpdate.setString(4, "Enabled");
pstmtUpdate.executeUpdate();
pstmtUpdate.close();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding default Security Group Provider", e);
} finally {
closeAutoCloseable(pstmt2);
closeAutoCloseable(pstmtUpdate);
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade30xBase method addTrafficType.
protected void addTrafficType(Connection conn, long physicalNetworkId, String trafficType, String xenPublicLabel, String kvmPublicLabel, String vmwarePublicLabel) {
// add traffic types
PreparedStatement pstmtUpdate = null;
try {
s_logger.debug("Adding PhysicalNetwork traffic types");
String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` (physical_network_id, traffic_type, xen_network_label, kvm_network_label, vmware_network_label, uuid) VALUES ( ?, ?, ?, ?, ?, ?)";
pstmtUpdate = conn.prepareStatement(insertTraficType);
pstmtUpdate.setLong(1, physicalNetworkId);
pstmtUpdate.setString(2, trafficType);
pstmtUpdate.setString(3, xenPublicLabel);
pstmtUpdate.setString(4, kvmPublicLabel);
pstmtUpdate.setString(5, vmwarePublicLabel);
pstmtUpdate.setString(6, UUID.randomUUID().toString());
pstmtUpdate.executeUpdate();
pstmtUpdate.close();
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
} finally {
closeAutoCloseable(pstmtUpdate);
}
}
Aggregations