use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class CapacityDaoImpl method listClustersInZoneOrPodByHostCapacities.
@Override
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
StringBuilder sql = new StringBuilder(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1);
if (isZone) {
sql.append("capacity.data_center_id = ?");
} else {
sql.append("capacity.pod_id = ?");
}
sql.append(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2);
if (isZone) {
sql.append("capacity.data_center_id = ?");
} else {
sql.append("capacity.pod_id = ?");
}
sql.append(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, id);
pstmt.setShort(2, Capacity.CAPACITY_TYPE_CPU);
pstmt.setString(3, "cpuOvercommitRatio");
pstmt.setLong(4, requiredCpu);
pstmt.setLong(5, id);
pstmt.setShort(6, Capacity.CAPACITY_TYPE_MEMORY);
pstmt.setString(7, "memoryOvercommitRatio");
pstmt.setLong(8, requiredRam);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
}
return result;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
} catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class CapacityDaoImpl method listPodsByHostCapacities.
@Override
public List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
StringBuilder sql = new StringBuilder(LIST_PODSINZONE_BY_HOST_CAPACITY_TYPE);
sql.append("AND capacity.pod_id IN (");
sql.append(LIST_PODSINZONE_BY_HOST_CAPACITY_TYPE);
sql.append(")");
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, zoneId);
pstmt.setShort(2, Capacity.CAPACITY_TYPE_CPU);
pstmt.setString(3, "cpuOvercommitRatio");
pstmt.setLong(4, requiredCpu);
pstmt.setLong(5, zoneId);
pstmt.setShort(6, Capacity.CAPACITY_TYPE_MEMORY);
pstmt.setString(7, "memoryOvercommitRatio");
pstmt.setLong(8, requiredRam);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
}
return result;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
} catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class EncryptionSecretKeyChanger method migrateData.
private boolean migrateData(String oldDBKey, String newDBKey) {
System.out.println("Begin Data migration");
initEncryptor(oldEncryptor, oldDBKey);
initEncryptor(newEncryptor, newDBKey);
System.out.println("Initialised Encryptors");
TransactionLegacy txn = TransactionLegacy.open("Migrate");
txn.start();
try {
Connection conn;
try {
conn = txn.getConnection();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to migrate encrypted data in the database", e);
}
migrateConfigValues(conn);
migrateHostDetails(conn);
migrateVNCPassword(conn);
migrateUserCredentials(conn);
txn.commit();
} finally {
txn.close();
}
System.out.println("End Data migration");
return true;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class ClusterManagerImpl method getHeartbeatTask.
private Runnable getHeartbeatTask() {
return new ManagedContextRunnable() {
@Override
protected void runInContext() {
final TransactionLegacy txn = TransactionLegacy.open("ClusterHeartbeat");
try {
final Profiler profiler = new Profiler();
final Profiler profilerHeartbeatUpdate = new Profiler();
final Profiler profilerPeerScan = new Profiler();
try {
profiler.start();
profilerHeartbeatUpdate.start();
txn.transitToUserManagedConnection(getHeartbeatConnection());
if (s_logger.isTraceEnabled()) {
s_logger.trace("Cluster manager heartbeat update, id:" + _mshostId);
}
_mshostDao.update(_mshostId, _runId, DateUtil.currentGMTTime());
profilerHeartbeatUpdate.stop();
profilerPeerScan.start();
if (s_logger.isTraceEnabled()) {
s_logger.trace("Cluster manager peer-scan, id:" + _mshostId);
}
if (!_peerScanInited) {
_peerScanInited = true;
initPeerScan();
}
peerScan();
profilerPeerScan.stop();
} finally {
profiler.stop();
if (profiler.getDurationInMillis() >= HeartbeatInterval.value()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Management server heartbeat takes too long to finish. profiler: " + profiler.toString() + ", profilerHeartbeatUpdate: " + profilerHeartbeatUpdate.toString() + ", profilerPeerScan: " + profilerPeerScan.toString());
}
}
}
} catch (final CloudRuntimeException e) {
s_logger.error("Runtime DB exception ", e.getCause());
if (e.getCause() instanceof ClusterInvalidSessionException) {
s_logger.error("Invalid cluster session found, fence it");
queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated));
}
if (isRootCauseConnectionRelated(e.getCause())) {
invalidHeartbeatConnection();
}
} catch (final ActiveFencingException e) {
queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated));
} catch (final Throwable e) {
s_logger.error("Unexpected exception in cluster heartbeat", e);
if (isRootCauseConnectionRelated(e.getCause())) {
invalidHeartbeatConnection();
}
} finally {
txn.transitToAutoManagedConnection(TransactionLegacy.CLOUD_DB);
txn.close("ClusterHeartbeat");
}
}
};
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class ManagementServerHostPeerDaoImpl method updatePeerInfo.
@Override
@DB
public void updatePeerInfo(long ownerMshost, long peerMshost, long peerRunid, ManagementServerHost.State peerState) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
txn.start();
SearchCriteria<ManagementServerHostPeerVO> sc = FindForUpdateSearch.create();
sc.setParameters("ownerMshost", ownerMshost);
sc.setParameters("peerMshost", peerMshost);
sc.setParameters("peerRunid", peerRunid);
List<ManagementServerHostPeerVO> l = listBy(sc);
if (l.size() == 1) {
ManagementServerHostPeerVO peer = l.get(0);
peer.setPeerState(peerState);
update(peer.getId(), peer);
} else {
ManagementServerHostPeerVO peer = new ManagementServerHostPeerVO(ownerMshost, peerMshost, peerRunid, peerState);
persist(peer);
}
txn.commit();
} catch (Exception e) {
s_logger.warn("Unexpected exception, ", e);
txn.rollback();
}
}
Aggregations