Search in sources :

Example 1 with RunningHostCountInfo

use of com.cloud.info.RunningHostCountInfo in project cosmic by MissionCriticalCloud.

the class HostDaoImpl method getRunningHostCounts.

@Override
@DB
public List<RunningHostCountInfo> getRunningHostCounts(final Date cutTime) {
    final String sql = "select * from (" + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid " + "where h.status='Up' and h.type='SecondaryStorage' and m.last_update > ? " + "group by h.data_center_id, h.type " + "UNION ALL " + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid " + "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type";
    final ArrayList<RunningHostCountInfo> l = new ArrayList<>();
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    try {
        pstmt = txn.prepareAutoCloseStatement(sql);
        final String gmtCutTime = DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime);
        pstmt.setString(1, gmtCutTime);
        pstmt.setString(2, gmtCutTime);
        final ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            final RunningHostCountInfo info = new RunningHostCountInfo();
            info.setDcId(rs.getLong(1));
            info.setHostType(rs.getString(2));
            info.setCount(rs.getInt(3));
            l.add(info);
        }
    } catch (final SQLException e) {
        s_logger.debug("SQLException caught", e);
    }
    return l;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) RunningHostCountInfo(com.cloud.info.RunningHostCountInfo) PreparedStatement(java.sql.PreparedStatement) DB(com.cloud.utils.db.DB)

Example 2 with RunningHostCountInfo

use of com.cloud.info.RunningHostCountInfo in project cloudstack by apache.

the class SecondaryStorageManagerImpl method getZoneHostInfo.

private synchronized Map<Long, ZoneHostInfo> getZoneHostInfo() {
    Date cutTime = DateUtil.currentGMTTime();
    List<RunningHostCountInfo> runningHostCountInfos = _hostDao.getRunningHostCounts(new Date(cutTime.getTime() - ClusterManager.HeartbeatThreshold.value()));
    RunningHostInfoAgregator aggregator = new RunningHostInfoAgregator();
    if (CollectionUtils.isNotEmpty(runningHostCountInfos)) {
        for (RunningHostCountInfo countInfo : runningHostCountInfos) {
            aggregator.aggregate(countInfo);
        }
    }
    return aggregator.getZoneHostInfoMap();
}
Also used : RunningHostCountInfo(com.cloud.info.RunningHostCountInfo) RunningHostInfoAgregator(com.cloud.info.RunningHostInfoAgregator) Date(java.util.Date)

Example 3 with RunningHostCountInfo

use of com.cloud.info.RunningHostCountInfo in project cloudstack by apache.

the class ConsoleProxyManagerImpl method getZoneHostInfo.

private synchronized Map<Long, ZoneHostInfo> getZoneHostInfo() {
    Date cutTime = DateUtil.currentGMTTime();
    List<RunningHostCountInfo> l = hostDao.getRunningHostCounts(new Date(cutTime.getTime() - ClusterManager.HeartbeatThreshold.value()));
    RunningHostInfoAgregator aggregator = new RunningHostInfoAgregator();
    if (l.size() > 0) {
        for (RunningHostCountInfo countInfo : l) {
            aggregator.aggregate(countInfo);
        }
    }
    return aggregator.getZoneHostInfoMap();
}
Also used : RunningHostCountInfo(com.cloud.info.RunningHostCountInfo) RunningHostInfoAgregator(com.cloud.info.RunningHostInfoAgregator) Date(java.util.Date)

Example 4 with RunningHostCountInfo

use of com.cloud.info.RunningHostCountInfo in project cloudstack by apache.

the class HostDaoImpl method getRunningHostCounts.

@Override
@DB
public List<RunningHostCountInfo> getRunningHostCounts(Date cutTime) {
    String sql = "select * from (" + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid " + "where h.status='Up' and h.type='SecondaryStorage' and m.last_update > ? " + "group by h.data_center_id, h.type " + "UNION ALL " + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid " + "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type";
    ArrayList<RunningHostCountInfo> l = new ArrayList<RunningHostCountInfo>();
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    ;
    PreparedStatement pstmt = null;
    try {
        pstmt = txn.prepareAutoCloseStatement(sql);
        String gmtCutTime = DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime);
        pstmt.setString(1, gmtCutTime);
        pstmt.setString(2, gmtCutTime);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            RunningHostCountInfo info = new RunningHostCountInfo();
            info.setDcId(rs.getLong(1));
            info.setHostType(rs.getString(2));
            info.setCount(rs.getInt(3));
            l.add(info);
        }
    } catch (SQLException e) {
        s_logger.debug("SQLException caught", e);
    }
    return l;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) RunningHostCountInfo(com.cloud.info.RunningHostCountInfo) PreparedStatement(java.sql.PreparedStatement) DB(com.cloud.utils.db.DB)

Example 5 with RunningHostCountInfo

use of com.cloud.info.RunningHostCountInfo in project cosmic by MissionCriticalCloud.

the class SystemVmManagerBase method getLongZoneHostInfoMap.

protected static Map<Long, ZoneHostInfo> getLongZoneHostInfoMap(final HostDao _hostDao) {
    final Date cutTime = DateUtil.currentGMTTime();
    final List<RunningHostCountInfo> l = _hostDao.getRunningHostCounts(new Date(cutTime.getTime() - ClusterManager.HeartbeatThreshold.value()));
    final RunningHostInfoAgregator aggregator = new RunningHostInfoAgregator();
    if (l.size() > 0) {
        for (final RunningHostCountInfo countInfo : l) {
            aggregator.aggregate(countInfo);
        }
    }
    return aggregator.getZoneHostInfoMap();
}
Also used : RunningHostCountInfo(com.cloud.info.RunningHostCountInfo) RunningHostInfoAgregator(com.cloud.info.RunningHostInfoAgregator) Date(java.util.Date)

Aggregations

RunningHostCountInfo (com.cloud.info.RunningHostCountInfo)5 RunningHostInfoAgregator (com.cloud.info.RunningHostInfoAgregator)3 Date (java.util.Date)3 DB (com.cloud.utils.db.DB)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2