cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From likit...@apache.org
Subject [5/7] git commit: updated refs/heads/dedicate-guest-vlan-ranges to 5f15f38
Date Thu, 25 Apr 2013 23:25:46 GMT
guest-vlan: network creation


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

Branch: refs/heads/dedicate-guest-vlan-ranges
Commit: 84395f530e87ceca671666af53e10ccc2c618511
Parents: 576d839
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Thu Apr 25 05:53:49 2013 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
Committed: Thu Apr 25 05:53:49 2013 +0530

----------------------------------------------------------------------
 server/src/com/cloud/dc/dao/DataCenterVnetDao.java |    3 +
 .../com/cloud/dc/dao/DataCenterVnetDaoImpl.java    |   47 ++++++++++++++-
 .../src/com/cloud/network/NetworkManagerImpl.java  |   35 ++++++++++-
 3 files changed, 81 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/84395f53/server/src/com/cloud/dc/dao/DataCenterVnetDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/dc/dao/DataCenterVnetDao.java b/server/src/com/cloud/dc/dao/DataCenterVnetDao.java
index 9479284..17c7634 100755
--- a/server/src/com/cloud/dc/dao/DataCenterVnetDao.java
+++ b/server/src/com/cloud/dc/dao/DataCenterVnetDao.java
@@ -41,4 +41,7 @@ public interface DataCenterVnetDao extends GenericDao<DataCenterVnetVO,
Long> {
 
     public void release(String vnet, long physicalNetworkId, long accountId, String reservationId);
 
+    public int countVnetsAllocatedToAccount(long dcId, long accountId);
+
+    public int countVnetsDedicatedToAccount(long dcId, long accountId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/84395f53/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java b/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
index 8b710e4..27d692b 100755
--- a/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
+++ b/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
@@ -20,8 +20,10 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 import javax.inject.Inject;
+import javax.naming.ConfigurationException;
 
 import com.cloud.exception.InvalidParameterValueException;
 import org.springframework.stereotype.Component;
@@ -58,6 +60,10 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
     private final GenericSearchBuilder<DataCenterVnetVO, Integer> countZoneVlans;
     private final GenericSearchBuilder<DataCenterVnetVO, Integer> countAllocatedZoneVlans;
     private final SearchBuilder<DataCenterVnetVO> SearchRange;
+    private final GenericSearchBuilder<DataCenterVnetVO, Integer> countVnetsAllocatedToAccount;
+
+    protected GenericSearchBuilder<DataCenterVnetVO, Integer> countVnetsDedicatedToAccount;
+    protected SearchBuilder<AccountGuestVlanMapVO> AccountGuestVlanMapSearch;
 
     @Inject protected AccountGuestVlanMapDao _accountGuestVlanMapDao;
     
@@ -194,6 +200,40 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
         update(vo.getId(), vo);
     }
 
+    @Override
+    public int countVnetsAllocatedToAccount(long dcId, long accountId) {
+        SearchCriteria<Integer> sc = countVnetsAllocatedToAccount.create();
+        sc.setParameters("dc", dcId);
+        sc.setParameters("accountId", accountId);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public int countVnetsDedicatedToAccount(long dcId, long accountId) {
+        SearchCriteria<Integer> sc = countVnetsDedicatedToAccount.create();
+        sc.setParameters("dc", dcId);
+        sc.setParameters("accountId", accountId);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
+        boolean result = super.configure(name, params);
+
+        countVnetsDedicatedToAccount = createSearchBuilder(Integer.class);
+        countVnetsDedicatedToAccount.and("dc", countVnetsDedicatedToAccount.entity().getDataCenterId(),
SearchCriteria.Op.EQ);
+        countVnetsDedicatedToAccount.and("accountGuestVlanMapId", countVnetsDedicatedToAccount.entity().getAccountGuestVlanMapId(),
Op.NNULL);
+        AccountGuestVlanMapSearch = _accountGuestVlanMapDao.createSearchBuilder();
+        AccountGuestVlanMapSearch.and("accountId", AccountGuestVlanMapSearch.entity().getAccountId(),
SearchCriteria.Op.EQ);
+        countVnetsDedicatedToAccount.join("AccountGuestVlanMapSearch", AccountGuestVlanMapSearch,
countVnetsDedicatedToAccount.entity().getAccountGuestVlanMapId(),
+                AccountGuestVlanMapSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+        countVnetsDedicatedToAccount.select(null, Func.COUNT, countVnetsDedicatedToAccount.entity().getId());
+        countVnetsDedicatedToAccount.done();
+        AccountGuestVlanMapSearch.done();
+
+        return result;
+    }
+
     public DataCenterVnetDaoImpl() {
     	super();
         DcSearchAllocated = createSearchBuilder();
@@ -253,6 +293,11 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
         VnetDcSearchAllocated.and("account", VnetDcSearchAllocated.entity().getAccountId(),
SearchCriteria.Op.EQ);
         VnetDcSearchAllocated.and("reservation", VnetDcSearchAllocated.entity().getReservationId(),
SearchCriteria.Op.EQ);
         VnetDcSearchAllocated.done();
-        
+
+        countVnetsAllocatedToAccount = createSearchBuilder(Integer.class);
+        countVnetsAllocatedToAccount.and("dc", countVnetsAllocatedToAccount.entity().getDataCenterId(),
SearchCriteria.Op.EQ);
+        countVnetsAllocatedToAccount.and("accountId", countVnetsAllocatedToAccount.entity().getAccountId(),
SearchCriteria.Op.EQ);
+        countVnetsAllocatedToAccount.select(null, Func.COUNT, countVnetsAllocatedToAccount.entity().getId());
+        countVnetsAllocatedToAccount.done();
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/84395f53/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 72ccac0..bc57668 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -31,6 +31,7 @@ import com.cloud.dc.DataCenter.NetworkType;
 import com.cloud.dc.Vlan.VlanType;
 import com.cloud.dc.dao.AccountVlanMapDao;
 import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.DataCenterVnetDao;
 import com.cloud.dc.dao.PodVlanMapDao;
 import com.cloud.dc.dao.VlanDao;
 import com.cloud.deploy.DataCenterDeployment;
@@ -153,6 +154,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
     RemoteAccessVpnService _vpnMgr;
     @Inject
     PodVlanMapDao _podVlanMapDao;
+    @Inject
+    AccountGuestVlanMapDao _accountGuestVlanMapDao;
+    @Inject
+    DataCenterVnetDao _datacenterVnetDao;
 
     List<NetworkGuru> _networkGurus;
     public List<NetworkGuru> getNetworkGurus() {
@@ -1988,8 +1993,29 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
             // For Isolated networks, don't allow to create network with vlan that already
exists in the zone
             if (ntwkOff.getGuestType() == GuestType.Isolated) {
                 if (_networksDao.countByZoneAndUri(zoneId, uri) > 0) {
-                throw new InvalidParameterValueException("Network with vlan " + vlanId +
" already exists in zone " + zoneId);
-            }
+                    throw new InvalidParameterValueException("Network with vlan " + vlanId
+ " already exists in zone " + zoneId);
+                } else {
+                    DataCenterVnetVO dcVnet = _datacenterVnetDao.findVnet(zoneId, vlanId.toString()).get(0);
+                    // Fail network creation if specified vlan is dedicated to a different
account
+                    if (dcVnet.getAccountGuestVlanMapId() != null) {
+                        Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId();
+                        AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId);
+                        if (map.getAccountId() != owner.getAccountId()) {
+                            throw new InvalidParameterValueException("Vlan " + vlanId + "
is dedicated to a different account");
+                        }
+                    // Fail network creation if owner has a dedicated range of vlans but
the specified vlan belongs to the system pool
+                    } else {
+                        List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId());
+                        if (maps != null && !maps.isEmpty()) {
+                            int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId,
owner.getAccountId());
+                            int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId,
owner.getAccountId());
+                            if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) {
+                                throw new InvalidParameterValueException("Specified vlan
" + vlanId + " doesn't belong" +
+                                        " to the vlan range dedicated to the owner "+ owner.getAccountName());
+                            }
+                        }
+                    }
+                }
             } else {
                 // don't allow to creating shared network with given Vlan ID, if there already
exists a isolated network or
                 // shared network with same Vlan ID in the zone
@@ -1998,7 +2024,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
                     throw new InvalidParameterValueException("There is a isolated/shared
network with vlan id: " +
                             vlanId + " already exists " + "in zone " + zoneId);
                 }
-        }
+            }
+
+
+
         }
 
         // If networkDomain is not specified, take it from the global configuration


Mime
View raw message