Skip to content
Open
Changes from all commits
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 @@ -696,6 +696,41 @@ List<LBPoolMember> getLbPoolMembers(List<NsxLoadBalancerMember> memberList, Stri
}
return members;
}

/**
* Builds the final list of active monitor paths to set on the pool:
* any monitor already attached to the pool that was NOT created by
* this codebase (its id does not contain the pool name - consistent
* with the check already used in deleteNsxLbResources) is preserved
* as-is, plus the monitor path managed by this codebase. Without
* this, every pool update (e.g. on member list change) would
* silently detach any monitor attached outside of this plugin.
*/
private List<String> mergeWithForeignActiveMonitorPaths(Optional<LBPool> existingPool, String lbServerPoolName,
String activeMonitorPath) {
List<String> result = new ArrayList<>();
List<String> existingMonitorPaths = existingPool
.map(LBPool::getActiveMonitorPaths)
.orElseGet(List::of);
for (String path : existingMonitorPaths) {
if (!isMonitorOwnedByThisPool(path, lbServerPoolName)) {
result.add(path);
}
}
if (activeMonitorPath != null && !result.contains(activeMonitorPath)) {
result.add(activeMonitorPath);
}
return result;
}

private boolean isMonitorOwnedByThisPool(String monitorPath, String lbServerPoolName) {
if (monitorPath == null) {
return false;
}
String monitorId = monitorPath.substring(monitorPath.lastIndexOf('/') + 1);
return monitorId.contains(lbServerPoolName);
}

public void createNsxLbServerPool(List<NsxLoadBalancerMember> memberList, String tier1GatewayName, String lbServerPoolName,
String algorithm, String privatePort, String protocol) {
try {
Expand All @@ -712,13 +747,15 @@ public void createNsxLbServerPool(List<NsxLoadBalancerMember> memberList, String
}
}
String activeMonitorPath = getLbActiveMonitorPath(lbServerPoolName, privatePort, protocol);
List<String> activeMonitorPaths = mergeWithForeignActiveMonitorPaths(
nsxLbServerPool, lbServerPoolName, activeMonitorPath);
LBPool lbPool = new LBPool.Builder()
.setId(lbServerPoolName)
.setDisplayName(lbServerPoolName)
.setAlgorithm(getLoadBalancerAlgorithm(algorithm))
.setMembers(members)
.setPassiveMonitorPath(NSX_LB_PASSIVE_MONITOR)
.setActiveMonitorPaths(List.of(activeMonitorPath))
.setActiveMonitorPaths(activeMonitorPaths)
.build();
lbPools.patch(lbServerPoolName, lbPool);
} catch (Error error) {
Expand Down
Loading