diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 44575f514af..08b5862f216 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -354,7 +354,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS _nodeId = MacAddress.getMacAddress().toLong(); } - _hostDao.markHostsAsDisconnected(_nodeId, Status.Up, Status.Connecting, Status.Updating, Status.Disconnected, Status.Down); + _hostDao.markHostsAsDisconnected(_nodeId); _monitor = new AgentMonitor(_nodeId, _hostDao, _volDao, _vmDao, _dcDao, _podDao, this, _alertMgr, _pingTimeout); registerForHostEvents(_monitor, true, true, false); diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index 7b37dfa5d59..2582a00b603 100644 --- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -56,14 +56,14 @@ import com.cloud.utils.nio.Task; @Local(value={AgentManager.class, ResourceService.class}) public class ClusteredAgentManagerImpl extends AgentManagerImpl implements ClusterManagerListener { final static Logger s_logger = Logger.getLogger(ClusteredAgentManagerImpl.class); - + public final static long STARTUP_DELAY = 5000; public final static long SCAN_INTERVAL = 90000; // 90 seconds, it takes 60 sec for xenserver to fail login public final static int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds public long _loadSize = 100; - + @Inject protected ClusterManager _clusterMgr = null; - + protected HashMap _peers; private final Timer _timer = new Timer("ClusteredAgentManager Timer"); @@ -77,19 +77,19 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust public boolean configure(String name, Map xmlParams) throws ConfigurationException { _peers = new HashMap(7); _nodeId = _clusterMgr.getManagementNodeId(); - + ConfigurationDao configDao = ComponentLocator.getCurrentLocator().getDao(ConfigurationDao.class); Map params = configDao.getConfiguration(xmlParams); String value = params.get(Config.DirectAgentLoadSize.key()); _loadSize = NumbersUtil.parseInt(value, 16); - + ClusteredAgentAttache.initialize(this); _clusterMgr.registerListener(this); - + return super.configure(name, xmlParams); } - + @Override public boolean start() { if (!super.start()) { @@ -597,7 +597,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust public void onManagementNodeLeft(List nodeList, long selfNodeId) { for (ManagementServerHostVO vo : nodeList) { s_logger.info("Marking hosts as disconnected on Management server" + vo.getMsid()); - _hostDao.markHostsAsDisconnected(vo.getMsid(), Status.Up, Status.Connecting, Status.Updating, Status.Disconnected, Status.Down); + _hostDao.markHostsAsDisconnected(vo.getMsid()); } } } diff --git a/server/src/com/cloud/host/dao/HostDao.java b/server/src/com/cloud/host/dao/HostDao.java index 5f12bd2868b..ced955d4ed4 100644 --- a/server/src/com/cloud/host/dao/HostDao.java +++ b/server/src/com/cloud/host/dao/HostDao.java @@ -49,16 +49,15 @@ public interface HostDao extends GenericDao { * Lists all secondary storage hosts, across all zones * @return list of Hosts */ - List listSecondaryStorageHosts(); - - /** - * Mark all hosts in Up or Orphaned state as disconnected. This method - * is used at AgentManager startup to reset all of the connections. - * - * @param msId management server id. - * @param statuses states of the host. - */ - void markHostsAsDisconnected(long msId, Status... states); + List listSecondaryStorageHosts(); + + /** + * Mark all hosts associated with a certain management server + * as disconnected. + * + * @param msId management server id. + */ + void markHostsAsDisconnected(long msId); List findLostHosts(long timeout); diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index 2803f169ae6..9db14f5e92f 100644 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -188,7 +188,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao SequenceSearch = createSearchBuilder(); SequenceSearch.and("id", SequenceSearch.entity().getId(), SearchCriteria.Op.EQ); -// SequenceSearch.addRetrieve("sequence", SequenceSearch.entity().getSequence()); + // SequenceSearch.addRetrieve("sequence", SequenceSearch.entity().getSequence()); SequenceSearch.done(); DirectlyConnectedSearch = createSearchBuilder(); @@ -204,7 +204,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ); UnmanagedDirectConnectSearch.cp(); UnmanagedDirectConnectSearch.cp(); - */ + */ UnmanagedDirectConnectSearch.done(); DirectConnectSearch = createSearchBuilder(); @@ -258,25 +258,25 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao @Override public HostVO findSecondaryStorageHost(long dcId) { - SearchCriteria sc = TypeDcSearch.create(); - sc.setParameters("type", Host.Type.SecondaryStorage); - sc.setParameters("dc", dcId); - List storageHosts = listBy(sc); + SearchCriteria sc = TypeDcSearch.create(); + sc.setParameters("type", Host.Type.SecondaryStorage); + sc.setParameters("dc", dcId); + List storageHosts = listBy(sc); - if (storageHosts == null || storageHosts.size() != 1) { - return null; - } else { - return storageHosts.get(0); - } + if (storageHosts == null || storageHosts.size() != 1) { + return null; + } else { + return storageHosts.get(0); + } } @Override public List listSecondaryStorageHosts() { - SearchCriteria sc = TypeSearch.create(); - sc.setParameters("type", Host.Type.SecondaryStorage); - List secondaryStorageHosts = listIncludingRemovedBy(sc); + SearchCriteria sc = TypeSearch.create(); + sc.setParameters("type", Host.Type.SecondaryStorage); + List secondaryStorageHosts = listIncludingRemovedBy(sc); - return secondaryStorageHosts; + return secondaryStorageHosts; } @Override @@ -287,16 +287,15 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao @Override public List findDirectAgentToLoad(long msid, long lastPingSecondsAfter, Long limit) { - SearchCriteria sc = UnmanagedDirectConnectSearch.create(); - sc.setParameters("lastPinged", lastPingSecondsAfter); + SearchCriteria sc = UnmanagedDirectConnectSearch.create(); + sc.setParameters("lastPinged", lastPingSecondsAfter); return search(sc, new Filter(HostVO.class, "clusterId", true, 0L, limit)); } @Override - public void markHostsAsDisconnected(long msId, Status... states) { + public void markHostsAsDisconnected(long msId) { SearchCriteria sc = MsStatusSearch.create(); sc.setParameters("ms", msId); - sc.setParameters("statuses", (Object[])states); HostVO host = createForUpdate(); host.setManagementServerId(null); @@ -426,8 +425,8 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao @Override public void loadHostTags(HostVO host){ - List hostTags = _hostTagsDao.gethostTags(host.getId()); - host.setHostTags(hostTags); + List hostTags = _hostTagsDao.gethostTags(host.getId()); + host.setHostTags(hostTags); } @Override @@ -475,8 +474,8 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao sc.setParameters("status", oldStatus); sc.setParameters("id", host.getId()); if (newStatus.checkManagementServer()) { - sc.setParameters("ping", oldPingTime); - sc.setParameters("msid", msId); + sc.setParameters("ping", oldPingTime); + sc.setParameters("msid", msId); } UpdateBuilder ub = getUpdateBuilder(host); @@ -487,9 +486,9 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao } else { ub.set(host, _msIdAttr, msId); } - if( event.equals(Event.Ping) || event.equals(Event.AgentConnected)) { - ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10); - } + if( event.equals(Event.Ping) || event.equals(Event.AgentConnected)) { + ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10); + } } if ( event.equals(Event.ManagementServerDown)) { ub.set(host, _pingTimeAttr, (( System.currentTimeMillis() >> 10) - ( 10 * 60 ))); @@ -498,14 +497,14 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao assert result <= 1 : "How can this update " + result + " rows? "; if (s_logger.isDebugEnabled() && result == 0) { - HostVO vo = findById(host.getId()); - assert vo != null : "How how how? : " + host.getId(); + HostVO vo = findById(host.getId()); + assert vo != null : "How how how? : " + host.getId(); - StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); - str.append(". New=[status=").append(newStatus.toString()).append(":msid=").append(newStatus.lostConnection() ? "null" : msId).append(":lastpinged=").append(host.getLastPinged()).append("]"); - str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(msId).append(":lastpinged=").append(oldPingTime).append("]"); - str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()).append("]"); - s_logger.debug(str.toString()); + StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); + str.append(". New=[status=").append(newStatus.toString()).append(":msid=").append(newStatus.lostConnection() ? "null" : msId).append(":lastpinged=").append(host.getLastPinged()).append("]"); + str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(msId).append(":lastpinged=").append(oldPingTime).append("]"); + str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()).append("]"); + s_logger.debug(str.toString()); } return result > 0; } @@ -550,7 +549,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao @Override public List findHostsLike(String hostName) { - SearchCriteria sc = NameLikeSearch.create(); + SearchCriteria sc = NameLikeSearch.create(); sc.setParameters("name", "%" + hostName + "%"); return listBy(sc); } @@ -591,8 +590,8 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao @Override public List listByStatus(Status... status) { - SearchCriteria sc = StatusSearch.create(); - sc.setParameters("status", (Object[])status); + SearchCriteria sc = StatusSearch.create(); + sc.setParameters("status", (Object[])status); return listBy(sc); } @@ -675,17 +674,17 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao @Override @DB public List 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"; + 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 l = new ArrayList(); + ArrayList l = new ArrayList(); Transaction txn = Transaction.currentTxn();; PreparedStatement pstmt = null; @@ -697,12 +696,12 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao 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)); + RunningHostCountInfo info = new RunningHostCountInfo(); + info.setDcId(rs.getLong(1)); + info.setHostType(rs.getString(2)); + info.setCount(rs.getInt(3)); - l.add(info); + l.add(info); } } catch (SQLException e) { } catch (Throwable e) { @@ -758,8 +757,5 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao sc.setParameters("statuses", (Object[])statuses); return customSearch(sc, null); - } -} - - - + } +} \ No newline at end of file