From 7d02ed344e1079a2ccb6367413bbce6b923b7e7a Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 1 Aug 2011 16:59:54 -0700 Subject: [PATCH] Bug 10197: do not check timeout against cluster which is not managed --- .../cloud/agent/manager/AgentManagerImpl.java | 2 +- .../com/cloud/agent/manager/AgentMonitor.java | 15 ++--- server/src/com/cloud/host/dao/HostDao.java | 8 --- .../src/com/cloud/host/dao/HostDaoImpl.java | 57 ++++++++++--------- 4 files changed, 38 insertions(+), 44 deletions(-) diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 77b2e504377..a9ba5e2528a 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -1085,7 +1085,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager { _hostDao.disconnect(host, event, _nodeId); host = _hostDao.findById(host.getId()); - if (event.equals(Event.PrepareUnmanaged) && (host.getStatus() == Status.Alert || host.getStatus() == Status.Down)) { + if (!event.equals(Event.PrepareUnmanaged) && (host.getStatus() == Status.Alert || host.getStatus() == Status.Down)) { _haMgr.scheduleRestartForVmsOnHost(host, investigate); } diff --git a/server/src/com/cloud/agent/manager/AgentMonitor.java b/server/src/com/cloud/agent/manager/AgentMonitor.java index 8b7f455dc07..2cac83bf698 100755 --- a/server/src/com/cloud/agent/manager/AgentMonitor.java +++ b/server/src/com/cloud/agent/manager/AgentMonitor.java @@ -33,6 +33,7 @@ import com.cloud.agent.api.StartupCommand; import com.cloud.alert.AlertManager; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; +import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.host.Host; @@ -40,6 +41,7 @@ import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.Status.Event; import com.cloud.host.dao.HostDao; +import com.cloud.utils.component.Inject; import com.cloud.utils.db.ConnectionConcierge; import com.cloud.utils.db.DB; import com.cloud.utils.db.GlobalLock; @@ -60,6 +62,8 @@ public class AgentMonitor extends Thread implements Listener { private AlertManager _alertMgr; private long _msId; private ConnectionConcierge _concierge; + @Inject + ClusterDao _clusterDao; protected AgentMonitor() { } @@ -117,13 +121,6 @@ public class AgentMonitor extends Thread implements Listener { } for (HostVO host : hosts) { - if (host.getType().equals(Host.Type.ExternalFirewall) || - host.getType().equals(Host.Type.ExternalLoadBalancer) || - host.getType().equals(Host.Type.TrafficMonitor) || - host.getType().equals(Host.Type.SecondaryStorage)) { - continue; - } - if (host.getManagementServerId() == null || host.getManagementServerId() == _msId) { if (s_logger.isInfoEnabled()) { s_logger.info("Asking agent mgr to investgate why host " + host.getId() + " is behind on ping. last ping time: " + host.getLastPinged()); @@ -137,10 +134,10 @@ public class AgentMonitor extends Thread implements Listener { long hostId = host.getId(); DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId()); HostPodVO podVO = _podDao.findById(host.getPodId()); - String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName(); + String hostDesc = "name: " + host.getName() + " (id:" + hostId + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName(); if (host.getType() != Host.Type.Storage) { - List vos = _vmDao.listByHostId(host.getId()); + List vos = _vmDao.listByHostId(hostId); if (vos.size() == 0) { _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc, "Host [" + hostDesc + "] is ready for maintenance"); _hostDao.updateStatus(host, Event.PreparationComplete, _msId); diff --git a/server/src/com/cloud/host/dao/HostDao.java b/server/src/com/cloud/host/dao/HostDao.java index 882b035cbdc..ecfe2135c19 100755 --- a/server/src/com/cloud/host/dao/HostDao.java +++ b/server/src/com/cloud/host/dao/HostDao.java @@ -109,14 +109,6 @@ public interface HostDao extends GenericDao { */ List listByType(Type type); - /** - * Find hosts that have not responded to a ping regardless of state - * @param timeout - * @param type - * @return - */ - List findLostHosts2(long timeout, Type type); - /** * update the host and changes the status depending on the Event and * the current status. If the status changed between diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index 0afc4df832e..b61d6181352 100755 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -73,8 +73,6 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao protected final SearchBuilder IdStatusSearch; protected final SearchBuilder TypeDcSearch; protected final SearchBuilder TypeDcStatusSearch; - protected final SearchBuilder LastPingedSearch; - protected final SearchBuilder LastPingedSearch2; protected final SearchBuilder MsStatusSearch; protected final SearchBuilder DcPrivateIpAddressSearch; protected final SearchBuilder DcStorageIpAddressSearch; @@ -104,7 +102,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao protected final GenericSearchBuilder HostsInStatusSearch; protected final GenericSearchBuilder CountRoutingByDc; protected final SearchBuilder HostTransferSearch; - protected final SearchBuilder ClusterManagedSearch; + protected SearchBuilder ClusterManagedSearch; protected final SearchBuilder RoutingSearch; protected final Attribute _statusAttr; @@ -133,16 +131,6 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao TypePodDcStatusSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ); TypePodDcStatusSearch.done(); - LastPingedSearch = createSearchBuilder(); - LastPingedSearch.and("ping", LastPingedSearch.entity().getLastPinged(), SearchCriteria.Op.LT); - LastPingedSearch.and("state", LastPingedSearch.entity().getStatus(), SearchCriteria.Op.IN); - LastPingedSearch.done(); - - LastPingedSearch2 = createSearchBuilder(); - LastPingedSearch2.and("ping", LastPingedSearch2.entity().getLastPinged(), SearchCriteria.Op.LT); - LastPingedSearch2.and("type", LastPingedSearch2.entity().getType(), SearchCriteria.Op.EQ); - LastPingedSearch2.done(); - MsStatusSearch = createSearchBuilder(); MsStatusSearch.and("ms", MsStatusSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ); MsStatusSearch.and("statuses", MsStatusSearch.entity().getStatus(), SearchCriteria.Op.NIN); @@ -382,8 +370,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao @Override @DB public List findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) { Transaction txn = Transaction.currentTxn(); - txn.start(); - + txn.start(); SearchCriteria sc = UnmanagedDirectConnectSearch.create(); sc.setParameters("lastPinged", lastPingSecondsAfter); sc.setParameters("statuses", Status.ErrorInMaintenance, Status.Maintenance, Status.PrepareForMaintenance); @@ -682,12 +669,36 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao return findOneBy(sc); } + @DB @Override public List findLostHosts(long timeout) { - SearchCriteria sc = LastPingedSearch.create(); - sc.setParameters("ping", timeout); - sc.setParameters("state", Status.Up, Status.Updating, Status.Disconnected, Status.Connecting); - return listBy(sc); + Transaction txn = Transaction.currentTxn(); + PreparedStatement pstmt = null; + List result = new ArrayList(); + ResultSet rs = null; + try { + String sql = "select h.id from host h left join cluster c on h.cluster_id=c.id where h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage') and (h.cluster_id is null or c.managed_state = 'Managed') ;" ; + pstmt = txn.prepareStatement(sql); + pstmt.setLong(1, timeout); + rs = pstmt.executeQuery(); + while (rs.next()) { + long id = rs.getLong(1); //ID column + result.add(findById(id)); + } + } catch (Exception e) { + s_logger.warn("Exception: ", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + return result; } @Override @@ -697,13 +708,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao return listBy(sc); } - @Override - public List findLostHosts2(long timeout, Type type) { - SearchCriteria sc = LastPingedSearch2.create(); - sc.setParameters("ping", timeout); - sc.setParameters("type", type.toString()); - return listBy(sc); - } + @Override public List listByDataCenter(long dcId) {