Search in sources :

Example 71 with CloudRuntimeException

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);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 72 with CloudRuntimeException

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);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 73 with CloudRuntimeException

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);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) DbProperties(com.cloud.utils.db.DbProperties)

Example 74 with CloudRuntimeException

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);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 75 with CloudRuntimeException

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);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1279 PreparedStatement (java.sql.PreparedStatement)320 SQLException (java.sql.SQLException)320 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)236 ResultSet (java.sql.ResultSet)217 ArrayList (java.util.ArrayList)217 ConfigurationException (javax.naming.ConfigurationException)171 HashMap (java.util.HashMap)129 DB (com.cloud.utils.db.DB)118 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)115 IOException (java.io.IOException)95 HostVO (com.cloud.host.HostVO)94 Answer (com.cloud.agent.api.Answer)84 Account (com.cloud.user.Account)84 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)82 URISyntaxException (java.net.URISyntaxException)82 ActionEvent (com.cloud.event.ActionEvent)70 TransactionStatus (com.cloud.utils.db.TransactionStatus)65 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)63 InternalErrorException (com.cloud.exception.InternalErrorException)57