cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [65/68] [abbrv] git commit: updated refs/heads/planner_reserve to ed8ff40
Date Thu, 16 May 2013 18:22:30 GMT
CLOUDSTACK-2517: fixed private gateway creation. Following fixes went in:

1) Only PrivateNetworkGuru handles network creation for the private gateway. Exluded Guest
Network Guru from this list (was mistakenly included as a part of merge for Nicira integration)
2) Pass vpc_id to createNetwork call when the network is created as a part of private gateway
creation
3) Fixed VPC restart when there are multiple private gateways present (have to grab all the
private gateways when creating nic profiles for the VPC router that is being re-created)
4) 41-42 db upgarde: set vpc_id for the private networks of the existing VPCs


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

Branch: refs/heads/planner_reserve
Commit: 9f59c618e277f4b9ce7e3cdd4156012b1d538471
Parents: 73030f4
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Wed May 15 12:08:34 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Wed May 15 13:12:51 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/network/dao/NetworkDao.java      |    2 +
 .../src/com/cloud/network/dao/NetworkDaoImpl.java  |   13 +++++++
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |   27 ++++++++++++++-
 .../src/com/cloud/network/NetworkServiceImpl.java  |    2 +-
 .../network/guru/ExternalGuestNetworkGuru.java     |    2 +-
 .../VpcVirtualNetworkApplianceManagerImpl.java     |   14 ++++---
 server/src/com/cloud/network/vpc/VpcManager.java   |    2 +-
 .../src/com/cloud/network/vpc/VpcManagerImpl.java  |   11 +++---
 server/test/com/cloud/vpc/MockVpcManagerImpl.java  |    2 +-
 .../test/com/cloud/vpc/dao/MockNetworkDaoImpl.java |    5 +++
 10 files changed, 64 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/engine/schema/src/com/cloud/network/dao/NetworkDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDao.java b/engine/schema/src/com/cloud/network/dao/NetworkDao.java
index 43cabe7..d0a1a25 100644
--- a/engine/schema/src/com/cloud/network/dao/NetworkDao.java
+++ b/engine/schema/src/com/cloud/network/dao/NetworkDao.java
@@ -113,4 +113,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long>
, StateDao<State
     List<NetworkVO> listRedundantNetworks();
 
     List<NetworkVO> listByAclId(long aclId);
+
+    int getNonSystemNetworkCountByVpcId(long vpcId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java
index 5b3b526..c55cf28 100644
--- a/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java
+++ b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java
@@ -162,6 +162,9 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>
implements N
         CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ);
         CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ);
         CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL);
+        SearchBuilder<NetworkOfferingVO> ntwkOffJoin = _ntwkOffDao.createSearchBuilder();
+        ntwkOffJoin.and("isSystem", ntwkOffJoin.entity().isSystemOnly(), Op.EQ);
+        CountBy.join("offerings", ntwkOffJoin, CountBy.entity().getNetworkOfferingId(), ntwkOffJoin.entity().getId(),
JoinBuilder.JoinType.INNER);
         CountBy.done();
 
         PhysicalNetworkSearch = createSearchBuilder();
@@ -627,4 +630,14 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>
implements N
 
         return listBy(sc, null);
     }
+    
+    
+    @Override
+    public int getNonSystemNetworkCountByVpcId(long vpcId) {
+        SearchCriteria<Integer> sc = CountBy.create();
+        sc.setParameters("vpcId", vpcId);
+        sc.setJoinParameters("offerings", "isSystem", false);
+        List<Integer> results = customSearch(sc, null);
+        return results.get(0);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index ff5e0fb..1d35c89 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -74,6 +74,7 @@ public class Upgrade410to420 implements DbUpgrade {
         upgradePhysicalNtwksWithInternalLbProvider(conn);
         updateNetworkACLs(conn);
         addHostDetailsIndex(conn);
+        updateNetworksForPrivateGateways(conn);
     }
 
     private void updateSystemVmTemplates(Connection conn) {
@@ -564,7 +565,6 @@ public class Upgrade410to420 implements DbUpgrade {
 
 
     private void upgradeDefaultVpcOffering(Connection conn) {
-
         PreparedStatement pstmt = null;
         ResultSet rs = null;
 
@@ -678,4 +678,29 @@ public class Upgrade410to420 implements DbUpgrade {
             }
         }
     }
+    
+    
+    private void updateNetworksForPrivateGateways(Connection conn) {
+
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            //1) get all non removed gateways
+            pstmt = conn.prepareStatement("SELECT network_id, vpc_id FROM `cloud`.`vpc_gateways`
WHERE type='Private' AND removed IS null");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                Long networkId = rs.getLong(1);
+                Long vpcId = rs.getLong(2);
+                //2) Update networks with vpc_id if its set to NULL
+                pstmt = conn.prepareStatement("UPDATE `cloud`.`networks` set vpc_id=? where
id=? and vpc_id is NULL and removed is NULL");
+                pstmt.setLong(1, vpcId);
+                pstmt.setLong(2, networkId);
+                pstmt.executeUpdate();
+                
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Failed to update private networks with VPC id.",
e);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/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 5f51a30..8b11819 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -3813,7 +3813,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
         if (privateNetwork == null) {
             //create Guest network
             privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName,
displayText, gateway, cidr, vlan,
-                    null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null,
null, null, null, true);
+                    null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null,
vpcId, null, null, true);
 
             s_logger.debug("Created private network " + privateNetwork);
         } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
index fe9e01f..eb1b3dc 100644
--- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
@@ -83,7 +83,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
         if (networkType == NetworkType.Advanced
                 && isMyTrafficType(offering.getTrafficType())
                 && offering.getGuestType() == Network.GuestType.Isolated
-                && isMyIsolationMethod(physicalNetwork)) {
+                && isMyIsolationMethod(physicalNetwork) && !offering.isSystemOnly())
{
             return true;
         } else {
             s_logger.trace("We only take care of Guest networks of type   "

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 915e2d8..7007374 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -1236,12 +1236,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         //1) allocate nic for control and source nat public ip
         networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
 
-        //2) allocate nic for private gateway if needed
-        PrivateGateway privateGateway = _vpcMgr.getVpcPrivateGateway(vpcId);
-        if (privateGateway != null) {
-            NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
-            Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
-            networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork,
privateNic));
+        //2) allocate nic for private gateways if needed
+        List<PrivateGateway> privateGateways = _vpcMgr.getVpcPrivateGateways(vpcId);
+        if (privateGateways != null && !privateGateways.isEmpty()) {
+            for (PrivateGateway privateGateway : privateGateways) {
+                NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
+                Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
+                networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork,
privateNic));
+            }
         }
         
         //3) allocate nic for guest gateway if needed

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/server/src/com/cloud/network/vpc/VpcManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java
index e8db8d3..f22e7e4 100644
--- a/server/src/com/cloud/network/vpc/VpcManager.java
+++ b/server/src/com/cloud/network/vpc/VpcManager.java
@@ -166,5 +166,5 @@ public interface VpcManager extends VpcService{
      */
     void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String
newNetworkDomain, Vpc vpc, String gateway, Account networkOwner);
 
-    List<PrivateGateway> getVpcPrivateGateways(long id);
+    List<PrivateGateway> getVpcPrivateGateways(long vpcId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index f01d81b..2335416 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -711,8 +711,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager,
VpcProvis
     public boolean destroyVpc(Vpc vpc, Account caller, Long callerUserId) throws ConcurrentOperationException,
ResourceUnavailableException {
         s_logger.debug("Destroying vpc " + vpc);
         
-        //don't allow to delete vpc if it's in use by existing networks
-        int networksCount = _ntwkDao.getNetworkCountByVpcId(vpc.getId());
+        //don't allow to delete vpc if it's in use by existing non system networks (system
networks are networks of a private gateway of the VPC,
+        //and they will get removed as a part of VPC cleanup
+        int networksCount = _ntwkDao.getNonSystemNetworkCountByVpcId(vpc.getId());
         if (networksCount > 0) {
             throw new InvalidParameterValueException("Can't delete VPC " + vpc + " as its
used by " + networksCount + " networks");
         }
@@ -1235,7 +1236,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager,
VpcProvis
             return false;
         }
 
-        //4) Delete private gateway
+        //4) Delete private gateways
         List<PrivateGateway> gateways = getVpcPrivateGateways(vpcId);
         if (gateways != null) {
             for (PrivateGateway gateway: gateways) {
@@ -1299,8 +1300,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager,
VpcProvis
     
 
     @Override
-    public List<PrivateGateway> getVpcPrivateGateways(long id) {
-        List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(id, VpcGateway.Type.Private);
+    public List<PrivateGateway> getVpcPrivateGateways(long vpcId) {
+        List<VpcGatewayVO> gateways = _vpcGatewayDao.listByVpcIdAndType(vpcId, VpcGateway.Type.Private);
 
         if (gateways != null) {
             List<PrivateGateway> pvtGateway = new ArrayList();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/server/test/com/cloud/vpc/MockVpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockVpcManagerImpl.java b/server/test/com/cloud/vpc/MockVpcManagerImpl.java
index 9812750..921321f 100644
--- a/server/test/com/cloud/vpc/MockVpcManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockVpcManagerImpl.java
@@ -379,7 +379,7 @@ public class MockVpcManagerImpl extends ManagerBase implements VpcManager
{
     }
 
     @Override
-    public List<PrivateGateway> getVpcPrivateGateways(long id) {
+    public List<PrivateGateway> getVpcPrivateGateways(long vpcId) {
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9f59c618/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java b/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
index 4747e70..ec1a017 100644
--- a/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
+++ b/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
@@ -367,4 +367,9 @@ public class MockNetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>
implemen
         return null;
     }
 
+    
+    @Override
+    public int getNonSystemNetworkCountByVpcId(long vpcId) {
+        return 0;
+    }
 }


Mime
View raw message