From 6e6b6ab2ab65172e36ef8a06a29f69db5629e0cc Mon Sep 17 00:00:00 2001 From: alena Date: Thu, 8 Sep 2011 14:33:28 -0700 Subject: [PATCH] Fixed the bug in AgentLB: consider only hosts of type=Routing when calculate average load --- .../agentlb/ClusterBasedAgentLoadBalancerPlanner.java | 5 ++++- server/src/com/cloud/host/dao/HostDao.java | 2 +- server/src/com/cloud/host/dao/HostDaoImpl.java | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java b/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java index a752601d871..d8075ece657 100644 --- a/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java +++ b/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java @@ -66,7 +66,7 @@ public class ClusterBasedAgentLoadBalancerPlanner implements AgentLoadBalancerPl @Override public List getHostsToRebalance(long msId, int avLoad) { - List allHosts = _hostDao.listByManagementServer(msId); + List allHosts = _hostDao.listRoutingHostsByManagementServer(msId); if (allHosts.size() <= avLoad) { s_logger.debug("Agent load = " + allHosts.size() + " for management server " + msId + " doesn't exceed average system agent load = " + avLoad + "; so it doesn't participate in agent rebalancing process"); @@ -101,6 +101,7 @@ public class ClusterBasedAgentLoadBalancerPlanner implements AgentLoadBalancerPl int hostsLeft = directHosts.size(); List hostsToReturn = new ArrayList(); + s_logger.debug("Management server " + msId + " can give away " + hostsToGive + " as it currently owns " + allHosts.size() + " and the average agent load in the system is " + avLoad + "; finalyzing list of hosts to give away..."); for (Long cluster : hostToClusterMap.keySet()) { List hostsInCluster = hostToClusterMap.get(cluster); hostsLeft = hostsLeft - hostsInCluster.size(); @@ -115,6 +116,7 @@ public class ClusterBasedAgentLoadBalancerPlanner implements AgentLoadBalancerPl //get all hosts that are needed from the cluster s_logger.debug("Taking " + hostsLeftToGive + " from cluster " + cluster); for (int i=0; i < hostsLeftToGive; i++) { + s_logger.trace("Taking host id=" + hostsInCluster.get(i) + " from cluster " + cluster); hostsToReturn.add(hostsInCluster.get(i)); } @@ -130,6 +132,7 @@ public class ClusterBasedAgentLoadBalancerPlanner implements AgentLoadBalancerPl } } + s_logger.debug("Management server " + msId + " is ready to give away " + hostsToReturn.size() + " hosts"); return hostsToReturn; } diff --git a/server/src/com/cloud/host/dao/HostDao.java b/server/src/com/cloud/host/dao/HostDao.java index 1324a72e073..6f9728b699b 100755 --- a/server/src/com/cloud/host/dao/HostDao.java +++ b/server/src/com/cloud/host/dao/HostDao.java @@ -168,7 +168,7 @@ public interface HostDao extends GenericDao { List listAllSecondaryStorageHosts(long dataCenterId); - List listByManagementServer(long msId); + List listRoutingHostsByManagementServer(long msId); List listSecondaryStorageVM(long dcId); diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index f3d74885fcd..018b1efb49c 100755 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -133,6 +133,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao MsStatusSearch = createSearchBuilder(); MsStatusSearch.and("ms", MsStatusSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ); + MsStatusSearch.and("type", MsStatusSearch.entity().getType(), SearchCriteria.Op.EQ); MsStatusSearch.and("statuses", MsStatusSearch.entity().getStatus(), SearchCriteria.Op.NIN); MsStatusSearch.done(); @@ -995,9 +996,10 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao } @Override - public List listByManagementServer(long msId) { + public List listRoutingHostsByManagementServer(long msId) { SearchCriteria sc = MsStatusSearch.create(); sc.setParameters("ms", msId); + sc.setParameters("type", Type.Routing); return listBy(sc); }