Skip to content

Commit 5a0d6d8

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 80c39f1 commit 5a0d6d8

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
@@ -137,6 +137,11 @@ public String getCidrList() {
137137
return cidrList;
138138
}
139139

140+
/**
141+
* Sets the CIDR list associated with this load balancer rule.
142+
*
143+
* @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
144+
*/
140145
public void setCidrList(String cidrList) {
141146
this.cidrList = cidrList;
142147
}

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

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

22732273
// Check if algorithm or cidrlist has changed, and reapply the lb config if needed
22742274
boolean algorithmChanged = (algorithm != null) && (tmplbVo.getAlgorithm().compareTo(algorithm) != 0);
2275-
boolean cidrListChanged = (tmplbVo.getCidrList() == null && lb.getCidrList() != null) ||
2276-
(tmplbVo.getCidrList() != null && lb.getCidrList() == null) ||
2277-
(tmplbVo.getCidrList() != null && lb.getCidrList() != null &&
2278-
!tmplbVo.getCidrList().equals(lb.getCidrList()));
2275+
boolean cidrListChanged = !Objects.equals(tmplbVo.getCidrList(), lb.getCidrList());
22792276

22802277
if (algorithmChanged || cidrListChanged) {
22812278
try {
@@ -2298,9 +2295,7 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22982295
if (lbBackup.getAlgorithm() != null) {
22992296
lb.setAlgorithm(lbBackup.getAlgorithm());
23002297
}
2301-
if (lbBackup.getCidrList() != null || lb.getCidrList() != null) { // Added for cidrlist rollback
2302-
lb.setCidrList(lbBackup.getCidrList());
2303-
}
2298+
lb.setCidrList(lbBackup.getCidrList());
23042299
lb.setState(lbBackup.getState());
23052300
_lbDao.update(lb.getId(), lb);
23062301
_lbDao.persist(lb);

0 commit comments

Comments
 (0)