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/04/13 02:42:05 UTC
[1/2] git commit: updated refs/heads/internallb to ae69f0a
Updated Branches:
refs/heads/internallb 3b41d5bee -> ae69f0ae5
InternalLb: Start/deploy internal LB vms for the existing LB rules as a part of network implement
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/888a83c2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/888a83c2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/888a83c2
Branch: refs/heads/internallb
Commit: 888a83c22111f3792850e6bb6235d30a93408d1d
Parents: 3b41d5b
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Fri Apr 12 15:58:27 2013 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Fri Apr 12 15:58:27 2013 -0700
----------------------------------------------------------------------
.../element/InternalLoadBalancerElement.java | 81 +++++++++++++--
.../lb/ApplicationLoadBalancerManagerImpl.java | 1 -
.../lb/dao/ApplicationLoadBalancerRuleDao.java | 3 +
.../lb/dao/ApplicationLoadBalancerRuleDaoImpl.java | 10 ++
4 files changed, 85 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/888a83c2/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 29a0f09..9b50e77 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
@@ -30,7 +30,9 @@ import javax.inject.Inject;
import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd;
import org.apache.cloudstack.api.command.admin.internallb.CreateInternalLoadBalancerElementCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLoadBalancerElementsCmd;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
import org.apache.cloudstack.network.lb.InternalLoadBalancerManager;
+import org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDao;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO;
@@ -65,6 +67,7 @@ import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancerContainer;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
@@ -96,6 +99,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
@Inject InternalLoadBalancerManager _internalLbMgr;
@Inject ConfigurationManager _configMgr;
@Inject AccountManager _accountMgr;
+ @Inject ApplicationLoadBalancerRuleDao _appLbDao;
protected InternalLoadBalancerElement() {
}
@@ -107,7 +111,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
return internalLbElement;
}
- private boolean canHandle(Network config, List<LoadBalancingRule> rules) {
+ private boolean canHandle(Network config, Scheme lbScheme) {
//works in Advance zone only
DataCenter dc = _configMgr.getZone(config.getDataCenterId());
if (dc.getNetworkType() != NetworkType.Advanced) {
@@ -122,12 +126,10 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) {
String schemeCaps = lbCaps.get(Capability.LbSchemes);
- if (schemeCaps != null && rules != null && !rules.isEmpty()) {
- for (LoadBalancingRule rule : rules) {
- if (!schemeCaps.contains(rule.getScheme().toString())) {
- s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + this.getName());
- return false;
- }
+ if (schemeCaps != null && lbScheme != null) {
+ if (!schemeCaps.contains(lbScheme.toString())) {
+ s_logger.debug("Scheme " + lbScheme.toString() + " is not supported by the provider " + this.getName());
+ return false;
}
}
}
@@ -154,12 +156,70 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
+
+ if (!canHandle(network, null)) {
+ s_logger.trace("No need to implement " + this.getName());
+ 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.size() == 0)) {
+ throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
+ DataCenter.class, network.getDataCenterId());
+ }
+ }
+
return true;
}
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
+
+ if (!canHandle(network, null)) {
+ s_logger.trace("No need to prepare " + this.getName());
+ 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.size() == 0)) {
+ throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
+ DataCenter.class, network.getDataCenterId());
+ }
+ }
+
return true;
}
@@ -254,9 +314,12 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
- Map<Ip, List<LoadBalancingRule>> rulesToApply = getLbRulesToApply(rules);
+ //1) Get Internal LB VMs to destroy
Set<Ip> vmsToDestroy = getVmsToDestroy(rules);
+ //2) Get rules to apply
+ Map<Ip, List<LoadBalancingRule>> rulesToApply = getLbRulesToApply(rules);
+
for (Ip sourceIp : rulesToApply.keySet()) {
if (vmsToDestroy.contains(sourceIp)) {
//2.1 Destroy internal lb vm
@@ -377,7 +440,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
public boolean validateLBRule(Network network, LoadBalancingRule rule) {
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
rules.add(rule);
- if (canHandle(network, rules)) {
+ if (canHandle(network, rule.getScheme())) {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.INTERNAL_LB_VM);
if (routers == null || routers.isEmpty()) {
return true;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/888a83c2/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
index 8e99bb3..46cef7c 100644
--- a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
+++ b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
@@ -510,5 +510,4 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A
s_logger.debug("No network rule conflicts detected for " + newLbRule + " against " + (lbRules.size() - 1) + " existing rules");
}
}
-
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/888a83c2/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDao.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDao.java b/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDao.java
index c702987..a3ba53e 100644
--- a/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDao.java
+++ b/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDao.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.net.Ip;
@@ -29,4 +30,6 @@ public interface ApplicationLoadBalancerRuleDao extends GenericDao<ApplicationLo
List<String> listLbIpsBySourceIpNetworkId(long sourceIpNetworkId);
long countBySourceIp(Ip sourceIp, long sourceIpNetworkId);
List<ApplicationLoadBalancerRuleVO> listBySourceIpAndNotRevoked(Ip sourceIp, long sourceNetworkId);
+ List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme scheme);
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/888a83c2/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java b/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
index 6bf7868..5caf06a 100644
--- a/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
+++ b/server/src/org/apache/cloudstack/network/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
import org.springframework.stereotype.Component;
import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
@@ -54,6 +55,7 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
listIps = createSearchBuilder(String.class);
listIps.select(null, Func.DISTINCT, listIps.entity().getSourceIp());
listIps.and("sourceIpNetworkId", listIps.entity().getSourceIpNetworkId(), Op.EQ);
+ listIps.and("scheme", listIps.entity().getScheme(), Op.EQ);
listIps.done();
CountBy = createSearchBuilder(Long.class);
@@ -102,4 +104,12 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
return listBy(sc);
}
+ @Override
+ public List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme scheme) {
+ SearchCriteria<String> sc = listIps.create();
+ sc.setParameters("sourceIpNetworkId", sourceIpNetworkId);
+ sc.setParameters("scheme", scheme);
+ return customSearch(sc, null);
+ }
+
}
[2/2] git commit: updated refs/heads/internallb to ae69f0a
Posted by al...@apache.org.
InternalLb: fixed prepare() in InternalLbElement - have to prepare nics of User vms only
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ae69f0ae
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ae69f0ae
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ae69f0ae
Branch: refs/heads/internallb
Commit: ae69f0ae5612834b8bc911bd074cfb050c0b164c
Parents: 888a83c
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Fri Apr 12 17:25:02 2013 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Fri Apr 12 17:34:05 2013 -0700
----------------------------------------------------------------------
.../element/InternalLoadBalancerElement.java | 58 ++++++++-------
.../lb/InternalLoadBalancerManagerImpl.java | 12 ---
2 files changed, 31 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ae69f0ae/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 9b50e77..1ff1cab 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
@@ -197,26 +197,28 @@ 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 (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);
- if ((internalLbVms == null) || (internalLbVms.size() == 0)) {
- throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
- DataCenter.class, network.getDataCenterId());
+ //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.size() == 0)) {
+ throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
+ DataCenter.class, network.getDataCenterId());
+ }
}
}
@@ -324,14 +326,16 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
if (vmsToDestroy.contains(sourceIp)) {
//2.1 Destroy internal lb vm
List<? extends VirtualRouter> vms = _internalLbMgr.findInternalLbVms(network.getId(), sourceIp);
- //only one internal lb per IP exists
- try {
- s_logger.debug("Destroying internal lb vm for ip " + sourceIp.addr() + " as all the rules for this vm are in Revoke state");
- return _internalLbMgr.destroyInternalLbVm(vms.get(0).getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM),
- _accountMgr.getUserIncludingRemoved(User.UID_SYSTEM).getId());
- } catch (ConcurrentOperationException e) {
- s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + " on the element " + this.getName() + " due to:", e);
- return false;
+ if (vms.size() > 0) {
+ //only one internal lb per IP exists
+ try {
+ s_logger.debug("Destroying internal lb vm for ip " + sourceIp.addr() + " as all the rules for this vm are in Revoke state");
+ return _internalLbMgr.destroyInternalLbVm(vms.get(0).getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM),
+ _accountMgr.getUserIncludingRemoved(User.UID_SYSTEM).getId());
+ } catch (ConcurrentOperationException e) {
+ s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + " on the element " + this.getName() + " due to:", e);
+ return false;
+ }
}
} else {
//2.2 Start Internal LB vm per IP address
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ae69f0ae/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManagerImpl.java
index 88b8232..b4b79bc 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManagerImpl.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManagerImpl.java
@@ -56,7 +56,6 @@ import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientServerCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
@@ -887,15 +886,4 @@ InternalLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
}
return result;
}
-
-
- protected VirtualRouter startInternalLbVm(long vmId, Account caller, long callerUserId) throws StorageUnavailableException, InsufficientCapacityException,
- ConcurrentOperationException, ResourceUnavailableException {
- DomainRouterVO vm = _routerDao.findById(vmId);
- if (vm == null || vm.getRole() != VirtualRouter.Role.INTERNAL_LB_VM) {
- throw new InvalidParameterValueException("Unable to find internal lb vm by id");
- }
-
- return startInternalLbVm(vm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), callerUserId, null);
- }
}