Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance);
private static final List<Host.Type> agentValidHostTypes = List.of(Host.Type.Routing, Host.Type.ConsoleProxy,
Host.Type.SecondaryStorage, Host.Type.SecondaryStorageVM);
private static final List<Host.Type> agentNonRoutingHostTypes = List.of(Host.Type.ConsoleProxy,
Host.Type.SecondaryStorage, Host.Type.SecondaryStorageVM);
private static final List<Hypervisor.HypervisorType> agentValidHypervisorTypes = List.of(
Hypervisor.HypervisorType.KVM, Hypervisor.HypervisorType.LXC);

Expand Down Expand Up @@ -136,6 +138,16 @@
return hostIdList;
}

private List<Long> getAllAgentBasedNonRoutingHostsFromDB(final Long zoneId) {
return hostDao.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(zoneId, null,

Check warning on line 142 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L141-L142

Added lines #L141 - L142 were not covered by tests
agentValidResourceStates, agentNonRoutingHostTypes, agentValidHypervisorTypes);
}

Check warning on line 144 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L144

Added line #L144 was not covered by tests

private List<Long> getAllAgentBasedRoutingHostsFromDB(final Long zoneId, final Long clusterId) {
return hostDao.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(zoneId, clusterId,
agentValidResourceStates, List.of(Host.Type.Routing), agentValidHypervisorTypes);
}

Check warning on line 149 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L146-L149

Added lines #L146 - L149 were not covered by tests

private List<Long> getAllAgentBasedHostsFromDB(final Long zoneId, final Long clusterId) {
return hostDao.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(zoneId, clusterId,
agentValidResourceStates, agentValidHostTypes, agentValidHypervisorTypes);
Expand All @@ -161,29 +173,40 @@
List<DataCenterVO> zones = dataCenterDao.listAll();
for (DataCenterVO zone : zones) {
List<Long> zoneHostIds = new ArrayList<>();
List<Long> nonRoutingHostIds = getAllAgentBasedNonRoutingHostsFromDB(zone.getId());
zoneHostIds.addAll(nonRoutingHostIds);

Check warning on line 177 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L176-L177

Added lines #L176 - L177 were not covered by tests
Map<Long, List<Long>> clusterHostIdsMap = new HashMap<>();
List<Long> clusterIds = clusterDao.listAllClusterIds(zone.getId());
for (Long clusterId : clusterIds) {
List<Long> hostIds = getAllAgentBasedHostsFromDB(zone.getId(), clusterId);
List<Long> hostIds = getAllAgentBasedRoutingHostsFromDB(zone.getId(), clusterId);

Check warning on line 181 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L181

Added line #L181 was not covered by tests
clusterHostIdsMap.put(clusterId, hostIds);
zoneHostIds.addAll(hostIds);
}
zoneHostIds.sort(Comparator.comparingLong(x -> x));
Long lbCheckInterval = getLBPreferredHostCheckInterval(null);

Check warning on line 186 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L186

Added line #L186 was not covered by tests
for (Long nonRoutingHostId : nonRoutingHostIds) {
setupMSList(nonRoutingHostId, zone.getId(), zoneHostIds, lbCheckInterval);
}

Check warning on line 189 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L188-L189

Added lines #L188 - L189 were not covered by tests
for (Long clusterId : clusterIds) {
final Long lbCheckInterval = getLBPreferredHostCheckInterval(clusterId);
lbCheckInterval = getLBPreferredHostCheckInterval(clusterId);

Check warning on line 191 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L191

Added line #L191 was not covered by tests
List<Long> hostIds = clusterHostIdsMap.get(clusterId);
for (Long hostId : hostIds) {
final List<String> 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, lbCheckInterval);

Check warning on line 194 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L194

Added line #L194 was not covered by tests
}
}
}
}

private void setupMSList(final Long hostId, final Long dcId, final List<Long> orderedHostIdList, final Long lbCheckInterval) {
final List<String> msList = getManagementServerList(hostId, dcId, orderedHostIdList);
final String lbAlgorithm = getLBAlgorithmName();
final SetupMSListCommand cmd = new SetupMSListCommand(msList, lbAlgorithm, lbCheckInterval);
final Answer answer = agentManager.easySend(hostId, cmd);

Check warning on line 204 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L200-L204

Added lines #L200 - L204 were not covered by tests
if (answer == null || !answer.getResult()) {
logger.warn(String.format("Failed to setup management servers list to the agent of ID: %d", hostId));

Check warning on line 206 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L206

Added line #L206 was not covered by tests
}
}

Check warning on line 208 in server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java#L208

Added line #L208 was not covered by tests

private void configureAlgorithmMap() {
final List<org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm> algorithms = new ArrayList<>();
algorithms.add(new IndirectAgentLBStaticAlgorithm());
Expand Down