cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [1/2] git commit: updated refs/heads/internallb to ae69f0a
Date Sat, 13 Apr 2013 00:42:05 GMT
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 <alena.prokharchyk@citrix.com>
Authored: Fri Apr 12 15:58:27 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@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);
+    }
+
 }


Mime
View raw message