use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class CapacityDaoImpl method orderHostsByFreeCapacity.
@Override
public List<Long> orderHostsByFreeCapacity(final Long clusterId, final short capacityTypeForOrdering) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
final List<Long> result = new ArrayList<>();
final StringBuilder sql = new StringBuilder(ORDER_HOSTS_BY_FREE_CAPACITY_PART1);
if (clusterId != null) {
sql.append("AND cluster_id = ?");
}
sql.append(ORDER_HOSTS_BY_FREE_CAPACITY_PART2);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setShort(1, capacityTypeForOrdering);
if (clusterId != null) {
pstmt.setLong(2, clusterId);
}
final ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
}
return result;
} catch (final SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class DataCenterIpAddressDaoImpl method addIpRange.
@Override
@DB
public void addIpRange(final long dcId, final long podId, final String start, final String end) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
final String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id, mac_address) " + "VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?))";
final String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
long startIP = NetUtils.ip2Long(start);
final long endIP = NetUtils.ip2Long(end);
try {
txn.start();
while (startIP <= endIP) {
try (PreparedStatement insertPstmt = txn.prepareStatement(insertSql)) {
insertPstmt.setString(1, NetUtils.long2Ip(startIP++));
insertPstmt.setLong(2, dcId);
insertPstmt.setLong(3, podId);
insertPstmt.setLong(4, dcId);
insertPstmt.executeUpdate();
}
try (PreparedStatement updatePstmt = txn.prepareStatement(updateSql)) {
updatePstmt.setLong(1, dcId);
updatePstmt.executeUpdate();
}
}
txn.commit();
} catch (final SQLException ex) {
throw new CloudRuntimeException("Unable to persist ip address range ", ex);
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class DataCenterLinkLocalIpAddressDaoImpl method addIpRange.
@Override
@DB
public void addIpRange(final long dcId, final long podId, final String start, final String end) {
final String insertSql = "INSERT INTO `cloud`.`op_dc_link_local_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
PreparedStatement stmt = null;
long startIP = NetUtils.ip2Long(start);
final long endIP = NetUtils.ip2Long(end);
final TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
txn.start();
stmt = txn.prepareAutoCloseStatement(insertSql);
while (startIP <= endIP) {
stmt.setString(1, NetUtils.long2Ip(startIP++));
stmt.setLong(2, dcId);
stmt.setLong(3, podId);
stmt.addBatch();
}
stmt.executeBatch();
txn.commit();
} catch (final SQLException e) {
throw new CloudRuntimeException("Unable to insert", e);
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class ClusterDaoImpl method getPodClusterIdMap.
@Override
public Map<Long, List<Long>> getPodClusterIdMap(final List<Long> clusterIds) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
final Map<Long, List<Long>> result = new HashMap<>();
try {
final StringBuilder sql = new StringBuilder(GET_POD_CLUSTER_MAP_PREFIX);
if (clusterIds.size() > 0) {
for (final Long clusterId : clusterIds) {
sql.append(clusterId).append(",");
}
sql.delete(sql.length() - 1, sql.length());
sql.append(GET_POD_CLUSTER_MAP_SUFFIX);
}
pstmt = txn.prepareAutoCloseStatement(sql.toString());
final ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
final Long podId = rs.getLong(1);
final Long clusterIdInPod = rs.getLong(2);
if (result.containsKey(podId)) {
final List<Long> clusterList = result.get(podId);
clusterList.add(clusterIdInPod);
result.put(podId, clusterList);
} else {
final List<Long> clusterList = new ArrayList<>();
clusterList.add(clusterIdInPod);
result.put(podId, clusterList);
}
}
return result;
} catch (final SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + GET_POD_CLUSTER_MAP_PREFIX, e);
}
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class HostDetailsDaoImpl method persist.
@Override
public void persist(final long hostId, final Map<String, String> details) {
final String InsertOrUpdateSql = "INSERT INTO `cloud`.`host_details` (host_id, name, value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE value=?";
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
for (final Map.Entry<String, String> detail : details.entrySet()) {
String value = detail.getValue();
if ("password".equals(detail.getKey())) {
value = DBEncryptionUtil.encrypt(value);
}
try {
final PreparedStatement pstmt = txn.prepareAutoCloseStatement(InsertOrUpdateSql);
pstmt.setLong(1, hostId);
pstmt.setString(2, detail.getKey());
pstmt.setString(3, value);
pstmt.setString(4, value);
pstmt.executeUpdate();
} catch (final SQLException e) {
throw new CloudRuntimeException("Unable to persist the host_details key: " + detail.getKey() + " for host id: " + hostId, e);
}
}
txn.commit();
}
Aggregations