incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mlsoren...@apache.org
Subject [3/50] [abbrv] git commit: Network-refactor: move validateRule to LB manager since it now has access to LB elements. NetworkServiceImpl does not need a cache of system network offerings Ensure mocks build to new APIs.
Date Fri, 18 Jan 2013 22:23:45 GMT
Network-refactor: move validateRule to LB manager since it now has access to LB elements.
NetworkServiceImpl does not need a cache of system network offerings
Ensure mocks build to new APIs.

Signed-off-by: Chiradeep Vittal <chiradeep@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/1776659f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/1776659f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/1776659f

Branch: refs/heads/add_remove_nics
Commit: 1776659fe76bb23003baaa7f3f39a2223cee9fd2
Parents: 745fae9
Author: Chiradeep Vittal <chiradeep@apache.org>
Authored: Wed Jan 9 18:35:06 2013 -0800
Committer: Chiradeep Vittal <chiradeep@apache.org>
Committed: Wed Jan 9 18:36:29 2013 -0800

----------------------------------------------------------------------
 api/src/com/cloud/network/NetworkModel.java        |    9 +++-
 server/src/com/cloud/network/NetworkModelImpl.java |   28 +-----------
 .../src/com/cloud/network/NetworkServiceImpl.java  |   36 +++++----------
 .../network/lb/LoadBalancingRulesManagerImpl.java  |   19 +++++++-
 .../com/cloud/network/MockNetworkManagerImpl.java  |   10 ----
 .../com/cloud/network/MockNetworkModelImpl.java    |    9 +---
 .../test/com/cloud/vpc/MockNetworkManagerImpl.java |   12 -----
 7 files changed, 39 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1776659f/api/src/com/cloud/network/NetworkModel.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkModel.java b/api/src/com/cloud/network/NetworkModel.java
index bd3acbe..ed76c66 100644
--- a/api/src/com/cloud/network/NetworkModel.java
+++ b/api/src/com/cloud/network/NetworkModel.java
@@ -31,7 +31,6 @@ import com.cloud.network.Network.Service;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.UserDataServiceProvider;
-import com.cloud.network.rules.FirewallRule;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.user.Account;
 import com.cloud.vm.Nic;
@@ -39,6 +38,12 @@ import com.cloud.vm.NicProfile;
 import com.cloud.vm.VirtualMachine;
 
 
+/**
+ * The NetworkModel presents a read-only view into the Network data such as L2 networks,
+ * Nics, PublicIps, NetworkOfferings, traffic labels, physical networks and the like
+ * The idea is that only the orchestration core should be able to modify the data, while
other 
+ * participants in the orchestration can use this interface to query the data.
+ */
 public interface NetworkModel {
 
     /**
@@ -60,8 +65,6 @@ public interface NetworkModel {
 
     String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
 
-    boolean validateRule(FirewallRule rule);
-
     PublicIpAddress getPublicIpAddress(long ipAddressId);
 
     List<? extends Vlan> listPodVlans(long podId);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1776659f/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index dcd3c25..2470989 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -65,11 +65,8 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
 import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
 import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao;
 import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
-import com.cloud.network.element.LoadBalancingServiceProvider;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.UserDataServiceProvider;
-import com.cloud.network.lb.LoadBalancingRule;
-import com.cloud.network.rules.FirewallRule;
 import com.cloud.network.rules.FirewallRule.Purpose;
 import com.cloud.network.rules.FirewallRuleVO;
 import com.cloud.network.rules.dao.PortForwardingRulesDao;
@@ -87,9 +84,9 @@ import com.cloud.utils.component.Inject;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
@@ -521,28 +518,7 @@ public class NetworkModelImpl  implements NetworkModel, Manager{
         return hasFreeIps;
     }
 
-    @Override
-    public boolean validateRule(FirewallRule rule) {
-        Network network = _networksDao.findById(rule.getNetworkId());
-        Purpose purpose = rule.getPurpose();
-        for (NetworkElement ne : _networkElements) {
-            boolean validated;
-            switch (purpose) {
-            case LoadBalancing:
-                if (!(ne instanceof LoadBalancingServiceProvider)) {
-                    continue;
-                }
-                validated = ((LoadBalancingServiceProvider) ne).validateLBRule(network, (LoadBalancingRule)
rule);
-                if (!validated)
-                    return false;
-                break;
-            default:
-                s_logger.debug("Unable to validate network rules for purpose: " + purpose.toString());
-                validated = false;
-            }
-        }
-        return true;
-    }
+   
 
     @Override
     public Map<Service, Map<Capability, String>> getNetworkCapabilities(long
networkId) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1776659f/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index be719c2..dc8f549 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -229,8 +229,6 @@ public class NetworkServiceImpl implements  NetworkService, Manager {
     @Inject
     NetworkModel _networkModel;
 
-    private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String,
NetworkOfferingVO>(5);
-
     int _cidrLimit;
     boolean _allowSubdomainNetworkAccess;
 
@@ -467,10 +465,6 @@ public class NetworkServiceImpl implements  NetworkService, Manager {
         return _networkMgr.allocateIp(ipOwner, isSystem, caller, zone);
     }
 
-   
-    
-
-
     @Override
     @DB
     public boolean configure(final String name, final Map<String, Object> params) throws
ConfigurationException {
@@ -479,23 +473,6 @@ public class NetworkServiceImpl implements  NetworkService, Manager {
 
         _cidrLimit = NumbersUtil.parseInt(_configs.get(Config.NetworkGuestCidrLimit.key()),
22);
 
-        NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork,
TrafficType.Public, true);
-        publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering);
-        _systemNetworks.put(NetworkOfferingVO.SystemPublicNetwork, publicNetworkOffering);
-        NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork,
TrafficType.Management, false);
-        managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering);
-        _systemNetworks.put(NetworkOfferingVO.SystemManagementNetwork, managementNetworkOffering);
-        NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork,
TrafficType.Control, false);
-        controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering);
-        _systemNetworks.put(NetworkOfferingVO.SystemControlNetwork, controlNetworkOffering);
-        NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork,
TrafficType.Storage, true);
-        storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
-        _systemNetworks.put(NetworkOfferingVO.SystemStorageNetwork, storageNetworkOffering);
-        NetworkOfferingVO privateGatewayNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPrivateGatewayNetworkOffering,
-                GuestType.Isolated);
-        privateGatewayNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(privateGatewayNetworkOffering);
-        _systemNetworks.put(NetworkOfferingVO.SystemPrivateGatewayNetworkOffering, privateGatewayNetworkOffering);
-
         _allowSubdomainNetworkAccess = Boolean.valueOf(_configs.get(Config.SubDomainNetworkAccess.key()));
 
         s_logger.info("Network Service is configured.");
@@ -2844,7 +2821,7 @@ public class NetworkServiceImpl implements  NetworkService, Manager
{
         Account owner = _accountMgr.getAccount(networkOwnerId);
         
         // Get system network offeirng
-        NetworkOfferingVO ntwkOff = _systemNetworks.get(NetworkOffering.SystemPrivateGatewayNetworkOffering);
+        NetworkOfferingVO ntwkOff = findSystemNetworkOffering(NetworkOffering.SystemPrivateGatewayNetworkOffering);
         
         // Validate physical network
         PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
@@ -2917,4 +2894,15 @@ public class NetworkServiceImpl implements  NetworkService, Manager
{
         return privateNetwork;
     }
 
+    
+    private NetworkOfferingVO findSystemNetworkOffering(String offeringName) {
+        List<NetworkOfferingVO> allOfferings = _networkOfferingDao.listSystemNetworkOfferings();
+        for (NetworkOfferingVO offer: allOfferings){
+            if (offer.getName().equals(offeringName)) {
+                return offer;
+            }
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1776659f/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index eb75d0b..662a2da 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -95,6 +95,7 @@ import com.cloud.network.dao.LoadBalancerVMMapDao;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkServiceMapDao;
 import com.cloud.network.element.LoadBalancingServiceProvider;
+import com.cloud.network.element.NetworkElement;
 import com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy;
 import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup;
 import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile;
@@ -487,7 +488,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
         List<LbStickinessPolicy> policyList = new ArrayList<LbStickinessPolicy>();
         policyList.add(new LbStickinessPolicy(cmd.getStickinessMethodName(), lbpolicy.getParams()));
         LoadBalancingRule lbRule = new LoadBalancingRule(loadBalancer, getExistingDestinations(lbpolicy.getId()),
policyList);
-        if (!_networkModel.validateRule(lbRule)) {
+        if (!validateRule(lbRule)) {
             throw new InvalidParameterValueException("Failed to create Stickiness policy:
Validation Failed " + cmd.getLbRuleId());
         }
 
@@ -498,6 +499,22 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
         return policy;
     }
 
+    
+    private boolean validateRule(LoadBalancingRule lbRule) {
+        Network network = _networkDao.findById(lbRule.getNetworkId());
+        Purpose purpose = lbRule.getPurpose();
+        if (purpose != Purpose.LoadBalancing) {
+            s_logger.debug("Unable to validate network rules for purpose: " + purpose.toString());
+            return false;
+        }
+        for (LoadBalancingServiceProvider ne : _lbProviders) {
+            boolean validated = ne.validateLBRule(network,  lbRule);
+            if (!validated)
+                return false;
+        }
+        return true;
+    }
+    
     @Override
     @DB
     @ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_CREATE, eventDescription
= "Apply Stickinesspolicy to load balancer ", async = true)

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1776659f/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index 0053d4a..cfaa169 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -131,16 +131,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager,
NetworkS
         return null;
     }
 
-   
-    @Override
-    public boolean isNetworkAvailableInDomain(long networkId, long domainId) {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    
-
-   
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1776659f/server/test/com/cloud/network/MockNetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java b/server/test/com/cloud/network/MockNetworkModelImpl.java
index e1113a4..fae5ad3 100644
--- a/server/test/com/cloud/network/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/network/MockNetworkModelImpl.java
@@ -118,14 +118,7 @@ public class MockNetworkModelImpl implements NetworkModel, Manager {
         return null;
     }
 
-    /* (non-Javadoc)
-     * @see com.cloud.network.NetworkModel#validateRule(com.cloud.network.rules.FirewallRule)
-     */
-    @Override
-    public boolean validateRule(FirewallRule rule) {
-        // TODO Auto-generated method stub
-        return false;
-    }
+    
 
     /* (non-Javadoc)
      * @see com.cloud.network.NetworkModel#getPublicIpAddress(long)

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1776659f/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index beb0bd4..1a3cbae 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -273,18 +273,6 @@ public class MockNetworkManagerImpl implements NetworkManager, NetworkService,
M
 
 
 
-    /* (non-Javadoc)
-     * @see com.cloud.network.NetworkService#isNetworkAvailableInDomain(long, long)
-     */
-    @Override
-    public boolean isNetworkAvailableInDomain(long networkId, long domainId) {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-
-
-
 
     /* (non-Javadoc)
      * @see com.cloud.network.NetworkService#updateGuestNetwork(long, java.lang.String, java.lang.String,
com.cloud.user.Account, com.cloud.user.User, java.lang.String, java.lang.Long, java.lang.Boolean)


Mime
View raw message