Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C1658F845 for ; Sat, 13 Apr 2013 00:42:05 +0000 (UTC) Received: (qmail 78599 invoked by uid 500); 13 Apr 2013 00:42:05 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 78569 invoked by uid 500); 13 Apr 2013 00:42:05 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 78552 invoked by uid 99); 13 Apr 2013 00:42:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Apr 2013 00:42:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 3005D81A0E6; Sat, 13 Apr 2013 00:42:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: alena1108@apache.org To: commits@cloudstack.apache.org Date: Sat, 13 Apr 2013 00:42:05 -0000 Message-Id: <6ff0ee8a55794dceaf5347a4c8a43459@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Fri Apr 12 15:58:27 2013 -0700 Committer: Alena Prokharchyk 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 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 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 ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal); + + //2) Start those vms + for (String ip : ips) { + Ip sourceIp = new Ip(ip); + List 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 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 ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(), Scheme.Internal); + + //2) Start those vms + for (String ip : ips) { + Ip sourceIp = new Ip(ip); + List 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 rules) throws ResourceUnavailableException { - Map> rulesToApply = getLbRulesToApply(rules); + //1) Get Internal LB VMs to destroy Set vmsToDestroy = getVmsToDestroy(rules); + //2) Get rules to apply + Map> 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 rules = new ArrayList(); rules.add(rule); - if (canHandle(network, rules)) { + if (canHandle(network, rule.getScheme())) { List 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 listLbIpsBySourceIpNetworkId(long sourceIpNetworkId); long countBySourceIp(Ip sourceIp, long sourceIpNetworkId); List listBySourceIpAndNotRevoked(Ip sourceIp, long sourceNetworkId); + List 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 listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme scheme) { + SearchCriteria sc = listIps.create(); + sc.setParameters("sourceIpNetworkId", sourceIpNetworkId); + sc.setParameters("scheme", scheme); + return customSearch(sc, null); + } + }