Search in sources :

Example 51 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class Upgrade410to420 method upgradeResourceCountforAccount.

private static void upgradeResourceCountforAccount(Connection conn, Long accountId, Long domainId, String type, Long resourceCount) throws SQLException {
    //update or insert into resource_count table.
    try (PreparedStatement pstmt = 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);
        pstmt.setLong(4, resourceCount);
        pstmt.executeUpdate();
    } catch (SQLException e) {
        throw new CloudRuntimeException("upgradeResourceCountforAccount:Exception:" + e.getMessage(), e);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement)

Example 52 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class Upgrade410to420 method addHostDetailsIndex.

private void addHostDetailsIndex(Connection conn) {
    s_logger.debug("Checking if host_details index exists, if not we will add it");
    try (PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` where KEY_NAME = 'fk_host_details__host_id'")) {
        try (ResultSet rs = pstmt.executeQuery()) {
            if (rs.next()) {
                s_logger.debug("Index already exists on host_details - not adding new one");
            } else {
                // add the index
                try (PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id` (`host_id`)")) {
                    pstmtUpdate.executeUpdate();
                    s_logger.debug("Index did not exist on host_details -  added new one");
                } catch (SQLException e) {
                    throw new CloudRuntimeException("Failed to check/update the host_details index ", e);
                }
            }
        } catch (SQLException e) {
            throw new CloudRuntimeException("Failed to check/update the host_details index ", e);
        }
    } catch (SQLException e) {
        throw new CloudRuntimeException("Failed to check/update the host_details index ", e);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 53 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class Upgrade410to420 method migrateS3ToImageStore.

// migrate secondary storages S3 from s3 tables to image_store table
private void migrateS3ToImageStore(Connection conn) {
    Long storeId = null;
    Map<Long, Long> s3_store_id_map = new HashMap<Long, Long>();
    s_logger.debug("Migrating S3 to image store");
    try (PreparedStatement storeQuery = conn.prepareStatement("select id from `cloud`.`image_store` where uuid = ?");
        PreparedStatement storeDetailInsert = conn.prepareStatement("INSERT INTO `cloud`.`image_store_details` (store_id, name, value) values(?, ?, ?)");
        // migrate S3 to image_store
        PreparedStatement storeInsert = conn.prepareStatement("INSERT INTO `cloud`.`image_store` (uuid, name, image_provider_name, protocol, scope, role, created) " + "values(?, ?, 'S3', ?, 'REGION', 'Image', ?)");
        PreparedStatement 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`");
        ResultSet rs = s3Query.executeQuery()) {
        while (rs.next()) {
            Long s3_id = rs.getLong("id");
            String s3_uuid = rs.getString("uuid");
            String s3_accesskey = rs.getString("access_key");
            String s3_secretkey = rs.getString("secret_key");
            String s3_endpoint = rs.getString("end_point");
            String s3_bucket = rs.getString("bucket");
            boolean s3_https = rs.getObject("https") != null ? (rs.getInt("https") == 0 ? false : true) : false;
            Integer s3_connectiontimeout = rs.getObject("connection_timeout") != null ? rs.getInt("connection_timeout") : null;
            Integer s3_retry = rs.getObject("max_error_retry") != null ? rs.getInt("max_error_retry") : null;
            Integer s3_sockettimeout = rs.getObject("socket_timeout") != null ? rs.getInt("socket_timeout") : null;
            Date s3_created = rs.getDate("created");
            // insert entry in image_store table and image_store_details
            // table and store s3_id and store_id mapping
            storeInsert.setString(1, s3_uuid);
            storeInsert.setString(2, s3_uuid);
            storeInsert.setString(3, s3_https ? "https" : "http");
            storeInsert.setDate(4, s3_created);
            storeInsert.executeUpdate();
            storeQuery.setString(1, s3_uuid);
            try (ResultSet storeInfo = storeQuery.executeQuery()) {
                if (storeInfo.next()) {
                    storeId = storeInfo.getLong("id");
                }
            }
            Map<String, String> detailMap = new HashMap<String, String>();
            detailMap.put(ApiConstants.S3_ACCESS_KEY, s3_accesskey);
            detailMap.put(ApiConstants.S3_SECRET_KEY, s3_secretkey);
            detailMap.put(ApiConstants.S3_BUCKET_NAME, s3_bucket);
            detailMap.put(ApiConstants.S3_END_POINT, s3_endpoint);
            detailMap.put(ApiConstants.S3_HTTPS_FLAG, String.valueOf(s3_https));
            if (s3_connectiontimeout != null) {
                detailMap.put(ApiConstants.S3_CONNECTION_TIMEOUT, String.valueOf(s3_connectiontimeout));
            }
            if (s3_retry != null) {
                detailMap.put(ApiConstants.S3_MAX_ERROR_RETRY, String.valueOf(s3_retry));
            }
            if (s3_sockettimeout != null) {
                detailMap.put(ApiConstants.S3_SOCKET_TIMEOUT, String.valueOf(s3_sockettimeout));
            }
            Iterator<String> keyIt = detailMap.keySet().iterator();
            while (keyIt.hasNext()) {
                String key = keyIt.next();
                String val = detailMap.get(key);
                storeDetailInsert.setLong(1, storeId);
                storeDetailInsert.setString(2, key);
                storeDetailInsert.setString(3, val);
                storeDetailInsert.executeUpdate();
            }
            s3_store_id_map.put(s3_id, storeId);
        }
    } catch (SQLException e) {
        String msg = "Unable to migrate S3 secondary storages." + e.getMessage();
        s_logger.error(msg);
        throw new CloudRuntimeException(msg, e);
    }
    s_logger.debug("Migrating template_s3_ref to template_store_ref");
    migrateTemplateS3Ref(conn, s3_store_id_map);
    s_logger.debug("Migrating s3 backedup snapshots to snapshot_store_ref");
    migrateSnapshotS3Ref(conn, s3_store_id_map);
    s_logger.debug("Completed migrating S3 secondary storage to image store");
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Date(java.sql.Date) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet)

Example 54 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class Upgrade410to420 method upgradeDefaultVpcOffering.

private void upgradeDefaultVpcOffering(Connection conn) {
    try (PreparedStatement 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'")) {
        try (ResultSet rs = pstmt.executeQuery()) {
            while (rs.next()) {
                long id = rs.getLong(1);
                //Add internal LB vm as a supported provider for the load balancer service
                try (PreparedStatement insert_pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vpc_offering_service_map` (vpc_offering_id, service, provider) VALUES (?,?,?)")) {
                    insert_pstmt.setLong(1, id);
                    insert_pstmt.setString(2, "Lb");
                    insert_pstmt.setString(3, "InternalLbVm");
                    insert_pstmt.executeUpdate();
                } catch (SQLException e) {
                    throw new CloudRuntimeException("Unable update the default VPC offering with the internal lb service", e);
                }
            }
        } catch (SQLException e) {
            throw new CloudRuntimeException("Unable update the default VPC offering with the internal lb service", e);
        }
    } catch (SQLException e) {
        throw new CloudRuntimeException("Unable update the default VPC offering with the internal lb service", e);
    }
}
Also used : SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 55 with CloudRuntimeException

use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.

the class Upgrade410to420 method updateConcurrentConnectionsInNetworkOfferings.

protected void updateConcurrentConnectionsInNetworkOfferings(Connection conn) {
    try {
        try (PreparedStatement sel_pstmt = conn.prepareStatement("SELECT *  FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'network_offerings' AND COLUMN_NAME = 'concurrent_connections'")) {
            try (ResultSet rs = sel_pstmt.executeQuery()) {
                if (!rs.next()) {
                    try (PreparedStatement alter_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)'")) {
                        alter_pstmt.executeUpdate();
                    } catch (SQLException e) {
                        throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
                    }
                }
            } catch (SQLException e) {
                throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
            }
        } catch (SQLException e) {
            throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
        }
        try (PreparedStatement sel_net_pstmt = conn.prepareStatement("select network_id, value from `cloud`.`network_details` where name='maxconnections'")) {
            try (ResultSet rs = sel_net_pstmt.executeQuery()) {
                while (rs.next()) {
                    long networkId = rs.getLong(1);
                    int maxconnections = Integer.parseInt(rs.getString(2));
                    try (PreparedStatement sel_net_off_pstmt = conn.prepareStatement("select network_offering_id from `cloud`.`networks` where id= ?")) {
                        sel_net_off_pstmt.setLong(1, networkId);
                        try (ResultSet rs1 = sel_net_off_pstmt.executeQuery()) {
                            if (rs1.next()) {
                                long network_offering_id = rs1.getLong(1);
                                try (PreparedStatement pstmt = conn.prepareStatement("select concurrent_connections from `cloud`.`network_offerings` where id= ?")) {
                                    pstmt.setLong(1, network_offering_id);
                                    try (ResultSet rs2 = pstmt.executeQuery()) {
                                        if ((!rs2.next()) || (rs2.getInt(1) < maxconnections)) {
                                            try (PreparedStatement update_net_pstmt = conn.prepareStatement("update network_offerings set concurrent_connections=? where id=?")) {
                                                update_net_pstmt.setInt(1, maxconnections);
                                                update_net_pstmt.setLong(2, network_offering_id);
                                                update_net_pstmt.executeUpdate();
                                            } catch (SQLException e) {
                                                throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
                                            }
                                        }
                                    } catch (SQLException e) {
                                        throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
                                    }
                                } catch (SQLException e) {
                                    throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
                                }
                            }
                        } catch (SQLException e) {
                            throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
                        }
                    } catch (SQLException e) {
                        throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
                    }
                }
            } catch (SQLException e) {
                throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
            }
        } catch (SQLException e) {
            throw new CloudRuntimeException("migration of concurrent connections from network_details failed");
        }
    } catch (RuntimeException e) {
        throw new CloudRuntimeException("migration of concurrent connections from network_details failed", e);
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) 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