You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2013/06/20 22:08:46 UTC
git commit: updated refs/heads/master to ae6e8b4
Updated Branches:
refs/heads/master 205722aab -> ae6e8b448
CLOUDSTACK-3085: network implement - deploy internal lb vm for the ip only when:
* the load balancer contains lb rule in state "Active"
* when lb rule has at least one vm assigned to it
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ae6e8b44
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ae6e8b44
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ae6e8b44
Branch: refs/heads/master
Commit: ae6e8b448f61aefbb3a9b0b439e311929abf27c3
Parents: 205722a
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Thu Jun 20 11:34:30 2013 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Thu Jun 20 13:01:32 2013 -0700
----------------------------------------------------------------------
.../lb/dao/ApplicationLoadBalancerRuleDao.java | 1 +
.../dao/ApplicationLoadBalancerRuleDaoImpl.java | 18 +++++
.../element/InternalLoadBalancerElement.java | 74 +++++++++-----------
3 files changed, 52 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ae6e8b44/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
index 47f1d36..aa765ad 100644
--- a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
+++ b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
@@ -32,5 +32,6 @@ public interface ApplicationLoadBalancerRuleDao extends GenericDao<ApplicationLo
List<ApplicationLoadBalancerRuleVO> listBySourceIpAndNotRevoked(Ip sourceIp, long sourceNetworkId);
List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme scheme);
long countBySourceIpAndNotRevoked(Ip sourceIp, long sourceIpNetworkId);
+ long countActiveBySourceIp(Ip sourceIp, long sourceIpNetworkId);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ae6e8b44/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
index 6036b5a..67d0a78 100644
--- a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
+++ b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
@@ -43,6 +43,7 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountBy;
protected final SearchBuilder<ApplicationLoadBalancerRuleVO> NotRevokedSearch;
final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountNotRevoked;
+ final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountActive;
protected ApplicationLoadBalancerRuleDaoImpl() {
@@ -77,6 +78,13 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
CountNotRevoked.and("state", CountNotRevoked.entity().getState(), Op.NEQ);
CountNotRevoked.and("sourceIpNetworkId", CountNotRevoked.entity().getSourceIpNetworkId(), Op.EQ);
CountNotRevoked.done();
+
+ CountActive = createSearchBuilder(Long.class);
+ CountActive.select(null, Func.COUNT, CountActive.entity().getId());
+ CountActive.and("sourceIp", CountActive.entity().getSourceIp(), Op.EQ);
+ CountActive.and("state", CountActive.entity().getState(), Op.EQ);
+ CountActive.and("sourceIpNetworkId", CountActive.entity().getSourceIpNetworkId(), Op.EQ);
+ CountActive.done();
}
@Override
@@ -129,5 +137,15 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
List<Long> results = customSearch(sc, null);
return results.get(0);
}
+
+ @Override
+ public long countActiveBySourceIp(Ip sourceIp, long sourceIpNetworkId) {
+ SearchCriteria<Long> sc = CountActive.create();
+ sc.setParameters("sourceIp", sourceIp);
+ sc.setParameters("sourceIpNetworkId", sourceIpNetworkId);
+ sc.setParameters("state", State.Active);
+ List<Long> results = customSearch(sc, null);
+ return results.get(0);
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ae6e8b44/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
index 14b616c..18ac13b 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
@@ -165,30 +165,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
return true;
}
- //1) Get all the Ips from the network having LB rules assigned
- List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal);
-
- //2) Start those vms
- for (String ip : ips) {
- Ip sourceIp = new Ip(ip);
- List<? extends VirtualRouter> internalLbVms;
- try {
- internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
- } catch (InsufficientCapacityException e) {
- s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e);
- return false;
- } catch (ConcurrentOperationException e) {
- s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e);
- return false;
- }
-
- if (internalLbVms == null || internalLbVms.isEmpty()) {
- throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
- DataCenter.class, network.getDataCenterId());
- }
- }
-
- return true;
+ return implementInternalLbVms(network, dest);
}
@@ -202,12 +179,23 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
}
if (vm.getType() == VirtualMachine.Type.User) {
- //1) Get all the Ips from the network having LB rules assigned
- List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal);
-
- //2) Start those vms
- for (String ip : ips) {
- Ip sourceIp = new Ip(ip);
+ return implementInternalLbVms(network, dest);
+ }
+ return true;
+ }
+
+
+ protected boolean implementInternalLbVms(Network network, DeployDestination dest) throws ResourceUnavailableException {
+ //1) Get all the Ips from the network having LB rules assigned
+ List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal);
+
+ //2) Start internal lb vms for the ips having active rules
+ for (String ip : ips) {
+ Ip sourceIp = new Ip(ip);
+ long active = _appLbDao.countActiveBySourceIp(sourceIp, network.getId());
+ if (active > 0) {
+ s_logger.debug("Have to implement internal lb vm for source ip " + sourceIp + " as a part of network " + network
+ + " implement as there are " + active + " internal lb rules exist for this ip");
List<? extends VirtualRouter> internalLbVms;
try {
internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
@@ -223,7 +211,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
DataCenter.class, network.getDataCenterId());
}
- }
+ }
}
return true;
@@ -410,17 +398,21 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
protected Map<Ip, List<LoadBalancingRule>> groupBySourceIp(List<LoadBalancingRule> rules) {
Map<Ip, List<LoadBalancingRule>> groupedRules = new HashMap<Ip, List<LoadBalancingRule>>();
for (LoadBalancingRule rule : rules) {
- Ip sourceIp = rule.getSourceIp();
- if (!groupedRules.containsKey(sourceIp)) {
- groupedRules.put(sourceIp, null);
- }
-
- List<LoadBalancingRule> rulesToApply = groupedRules.get(sourceIp);
- if (rulesToApply == null) {
- rulesToApply = new ArrayList<LoadBalancingRule>();
+ if (rule.getDestinations() != null && !rule.getDestinations().isEmpty()) {
+ Ip sourceIp = rule.getSourceIp();
+ if (!groupedRules.containsKey(sourceIp)) {
+ groupedRules.put(sourceIp, null);
+ }
+
+ List<LoadBalancingRule> rulesToApply = groupedRules.get(sourceIp);
+ if (rulesToApply == null) {
+ rulesToApply = new ArrayList<LoadBalancingRule>();
+ }
+ rulesToApply.add(rule);
+ groupedRules.put(sourceIp, rulesToApply);
+ } else {
+ s_logger.debug("Internal lb rule " + rule + " doesn't have any vms assigned, skipping");
}
- rulesToApply.add(rule);
- groupedRules.put(sourceIp, rulesToApply);
}
return groupedRules;
}