Skip to content

Commit 90df4e4

Browse files
author
Alena Prokharchyk
committed
CLOUDSTACK-2840: get the latest information from the DB about the number of rules in non-revoked state for the ip address when figuring out if the internal lb vm needs to be destroyed. Instead of relying on the information passed down by the NetworkManager as the network manager might pass only rules in transition state omitting the Active rules
1 parent 7e8d199 commit 90df4e4

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ public interface ApplicationLoadBalancerRuleDao extends GenericDao<ApplicationLo
3131
long countBySourceIp(Ip sourceIp, long sourceIpNetworkId);
3232
List<ApplicationLoadBalancerRuleVO> listBySourceIpAndNotRevoked(Ip sourceIp, long sourceNetworkId);
3333
List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme scheme);
34+
long countBySourceIpAndNotRevoked(Ip sourceIp, long sourceIpNetworkId);
3435

3536
}

engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.stereotype.Component;
2626

2727
import com.cloud.network.rules.FirewallRule;
28+
import com.cloud.network.rules.FirewallRule.State;
2829
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
2930
import com.cloud.utils.db.GenericDaoBase;
3031
import com.cloud.utils.db.GenericSearchBuilder;
@@ -41,8 +42,8 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
4142
final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, String> listIps;
4243
final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountBy;
4344
protected final SearchBuilder<ApplicationLoadBalancerRuleVO> NotRevokedSearch;
44-
45-
45+
final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountNotRevoked;
46+
4647

4748
protected ApplicationLoadBalancerRuleDaoImpl() {
4849
AllFieldsSearch = createSearchBuilder();
@@ -69,6 +70,13 @@ protected ApplicationLoadBalancerRuleDaoImpl() {
6970
NotRevokedSearch.and("sourceIpNetworkId", NotRevokedSearch.entity().getSourceIpNetworkId(), SearchCriteria.Op.EQ);
7071
NotRevokedSearch.and("state", NotRevokedSearch.entity().getState(), SearchCriteria.Op.NEQ);
7172
NotRevokedSearch.done();
73+
74+
CountNotRevoked = createSearchBuilder(Long.class);
75+
CountNotRevoked.select(null, Func.COUNT, CountNotRevoked.entity().getId());
76+
CountNotRevoked.and("sourceIp", CountNotRevoked.entity().getSourceIp(), Op.EQ);
77+
CountNotRevoked.and("state", CountNotRevoked.entity().getState(), Op.NEQ);
78+
CountNotRevoked.and("sourceIpNetworkId", CountNotRevoked.entity().getSourceIpNetworkId(), Op.EQ);
79+
CountNotRevoked.done();
7280
}
7381

7482
@Override
@@ -112,4 +120,14 @@ public List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId
112120
return customSearch(sc, null);
113121
}
114122

123+
@Override
124+
public long countBySourceIpAndNotRevoked(Ip sourceIp, long sourceIpNetworkId) {
125+
SearchCriteria<Long> sc = CountNotRevoked.create();
126+
sc.setParameters("sourceIp", sourceIp);
127+
sc.setParameters("sourceIpNetworkId", sourceIpNetworkId);
128+
sc.setParameters("state", State.Revoke);
129+
List<Long> results = customSearch(sc, null);
130+
return results.get(0);
131+
}
132+
115133
}

plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import com.cloud.network.lb.LoadBalancingRule;
6565
import com.cloud.network.router.VirtualRouter;
6666
import com.cloud.network.router.VirtualRouter.Role;
67-
import com.cloud.network.rules.FirewallRule;
6867
import com.cloud.network.rules.LoadBalancerContainer;
6968
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
7069
import com.cloud.offering.NetworkOffering;
@@ -394,23 +393,16 @@ protected Set<Ip> getVmsToDestroy(List<LoadBalancingRule> rules) {
394393
//1) Group rules by the source ip address as NetworkManager always passes the entire network lb config to the element
395394
Map<Ip, List<LoadBalancingRule>> groupedRules = groupBySourceIp(rules);
396395

397-
//2) Count rules in revoke state
398396
Set<Ip> vmsToDestroy = new HashSet<Ip>();
399397

400398
for (Ip sourceIp : groupedRules.keySet()) {
399+
//2) Check if there are non revoked rules for the source ip address
401400
List<LoadBalancingRule> rulesToCheck = groupedRules.get(sourceIp);
402-
int revoke = 0;
403-
for (LoadBalancingRule ruleToCheck : rulesToCheck) {
404-
if (ruleToCheck.getState() == FirewallRule.State.Revoke){
405-
revoke++;
406-
}
407-
}
408-
409-
if (revoke == rulesToCheck.size()) {
410-
s_logger.debug("Have to destroy internal lb vm for source ip " + sourceIp);
401+
if (_appLbDao.countBySourceIpAndNotRevoked(sourceIp, rulesToCheck.get(0).getNetworkId()) == 0) {
402+
s_logger.debug("Have to destroy internal lb vm for source ip " + sourceIp + " as it has 0 rules in non-Revoke state");
411403
vmsToDestroy.add(sourceIp);
412-
}
413-
}
404+
}
405+
}
414406
return vmsToDestroy;
415407
}
416408

0 commit comments

Comments
 (0)