Skip to content

Commit 019567b

Browse files
committed
Refactor LB CIDR list comparison & rollback code
- Replace manual null-check comparison with Objects.equals for clarity and null safety - Simplify CIDR list rollback to always restore backup value unconditionally - Add JavaDoc for setCidrList method for improved documentation
1 parent b59d525 commit 019567b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ public String toString() {
145145
this, "id", "uuid", "name", "purpose", "state"));
146146
}
147147

148+
/**
149+
* Sets the CIDR list associated with this load balancer rule.
150+
*
151+
* @param cidrList a comma-separated list of CIDR strings, e.g. "1.2.3.4/24,1.2.3.5/24" or and empty string e.g. "" to clear the restrictions
152+
*/
148153
public void setCidrList(String cidrList) {
149154
this.cidrList = cidrList;
150155
}

server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,10 +2270,7 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22702270

22712271
// Check if algorithm or cidrlist has changed, and reapply the lb config if needed
22722272
boolean algorithmChanged = (algorithm != null) && (tmplbVo.getAlgorithm().compareTo(algorithm) != 0);
2273-
boolean cidrListChanged = (tmplbVo.getCidrList() == null && lb.getCidrList() != null) ||
2274-
(tmplbVo.getCidrList() != null && lb.getCidrList() == null) ||
2275-
(tmplbVo.getCidrList() != null && lb.getCidrList() != null &&
2276-
!tmplbVo.getCidrList().equals(lb.getCidrList()));
2273+
boolean cidrListChanged = !Objects.equals(tmplbVo.getCidrList(), lb.getCidrList());
22772274

22782275
if (algorithmChanged || cidrListChanged) {
22792276
try {
@@ -2296,9 +2293,7 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22962293
if (lbBackup.getAlgorithm() != null) {
22972294
lb.setAlgorithm(lbBackup.getAlgorithm());
22982295
}
2299-
if (lbBackup.getCidrList() != null || lb.getCidrList() != null) { // Added for cidrlist rollback
2300-
lb.setCidrList(lbBackup.getCidrList());
2301-
}
2296+
lb.setCidrList(lbBackup.getCidrList());
23022297
lb.setState(lbBackup.getState());
23032298
_lbDao.update(lb.getId(), lb);
23042299
_lbDao.persist(lb);

0 commit comments

Comments
 (0)