diff --git a/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java b/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java index 84c3081bfc1b..d51b42ab17f9 100644 --- a/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java +++ b/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java @@ -74,6 +74,8 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance); private static final List agentValidHostTypes = List.of(Host.Type.Routing, Host.Type.ConsoleProxy, Host.Type.SecondaryStorage, Host.Type.SecondaryStorageVM); + private static final List agentNonRoutingHostTypes = List.of(Host.Type.ConsoleProxy, + Host.Type.SecondaryStorage, Host.Type.SecondaryStorageVM); private static final List agentValidHypervisorTypes = List.of( Hypervisor.HypervisorType.KVM, Hypervisor.HypervisorType.LXC); @@ -136,6 +138,16 @@ List getOrderedHostIdList(final Long dcId) { return hostIdList; } + private List getAllAgentBasedNonRoutingHostsFromDB(final Long zoneId) { + return hostDao.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(zoneId, null, + agentValidResourceStates, agentNonRoutingHostTypes, agentValidHypervisorTypes); + } + + private List getAllAgentBasedRoutingHostsFromDB(final Long zoneId, final Long clusterId) { + return hostDao.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(zoneId, clusterId, + agentValidResourceStates, List.of(Host.Type.Routing), agentValidHypervisorTypes); + } + private List getAllAgentBasedHostsFromDB(final Long zoneId, final Long clusterId) { return hostDao.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(zoneId, clusterId, agentValidResourceStates, agentValidHostTypes, agentValidHypervisorTypes); @@ -158,32 +170,42 @@ private org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm getAgentMSLBAlgo public void propagateMSListToAgents() { logger.debug("Propagating management server list update to agents"); final String lbAlgorithm = getLBAlgorithmName(); + final Long globalLbCheckInterval = getLBPreferredHostCheckInterval(null); List zones = dataCenterDao.listAll(); for (DataCenterVO zone : zones) { List zoneHostIds = new ArrayList<>(); + List nonRoutingHostIds = getAllAgentBasedNonRoutingHostsFromDB(zone.getId()); + zoneHostIds.addAll(nonRoutingHostIds); Map> clusterHostIdsMap = new HashMap<>(); List clusterIds = clusterDao.listAllClusterIds(zone.getId()); for (Long clusterId : clusterIds) { - List hostIds = getAllAgentBasedHostsFromDB(zone.getId(), clusterId); + List hostIds = getAllAgentBasedRoutingHostsFromDB(zone.getId(), clusterId); clusterHostIdsMap.put(clusterId, hostIds); zoneHostIds.addAll(hostIds); } zoneHostIds.sort(Comparator.comparingLong(x -> x)); + for (Long nonRoutingHostId : nonRoutingHostIds) { + setupMSList(nonRoutingHostId, zone.getId(), zoneHostIds, lbAlgorithm, globalLbCheckInterval); + } for (Long clusterId : clusterIds) { - final Long lbCheckInterval = getLBPreferredHostCheckInterval(clusterId); + final Long clusterLbCheckInterval = getLBPreferredHostCheckInterval(clusterId); List hostIds = clusterHostIdsMap.get(clusterId); for (Long hostId : hostIds) { - final List msList = getManagementServerList(hostId, zone.getId(), zoneHostIds); - final SetupMSListCommand cmd = new SetupMSListCommand(msList, lbAlgorithm, lbCheckInterval); - final Answer answer = agentManager.easySend(hostId, cmd); - if (answer == null || !answer.getResult()) { - logger.warn("Failed to setup management servers list to the agent of ID: {}", hostId); - } + setupMSList(hostId, zone.getId(), zoneHostIds, lbAlgorithm, clusterLbCheckInterval); } } } } + private void setupMSList(final Long hostId, final Long dcId, final List orderedHostIdList, final String lbAlgorithm, final Long lbCheckInterval) { + final List msList = getManagementServerList(hostId, dcId, orderedHostIdList); + final SetupMSListCommand cmd = new SetupMSListCommand(msList, lbAlgorithm, lbCheckInterval); + final Answer answer = agentManager.easySend(hostId, cmd); + if (answer == null || !answer.getResult()) { + logger.warn(String.format("Failed to setup management servers list to the agent of ID: %d", hostId)); + } + } + private void configureAlgorithmMap() { final List algorithms = new ArrayList<>(); algorithms.add(new IndirectAgentLBStaticAlgorithm());