cloudstack-commits mailing list archives

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


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

Branch: refs/heads/dedicate-guest-vlan-ranges
Commit: 576d8391430007305e48006ea6b8a86e8a2a532f
Parents: e168204
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Thu Apr 25 00:53:32 2013 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
Committed: Thu Apr 25 00:53:32 2013 +0530

----------------------------------------------------------------------
 server/src/com/cloud/dc/DataCenterVnetVO.java      |   11 +++++
 server/src/com/cloud/dc/dao/DataCenterDaoImpl.java |   17 +++++++-
 server/src/com/cloud/dc/dao/DataCenterVnetDao.java |    2 +-
 .../com/cloud/dc/dao/DataCenterVnetDaoImpl.java    |   30 +++++++++++++-
 .../src/com/cloud/network/NetworkServiceImpl.java  |   15 +++++--
 setup/db/db/schema-410to420.sql                    |    2 +
 6 files changed, 66 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/576d8391/server/src/com/cloud/dc/DataCenterVnetVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/dc/DataCenterVnetVO.java b/server/src/com/cloud/dc/DataCenterVnetVO.java
index 52d7ad2..5321441 100755
--- a/server/src/com/cloud/dc/DataCenterVnetVO.java
+++ b/server/src/com/cloud/dc/DataCenterVnetVO.java
@@ -56,6 +56,9 @@ public class DataCenterVnetVO implements InternalIdentity {
     
     @Column(name="reservation_id")
     protected String reservationId;
+
+    @Column(name="account_guest_vlan_map_id")
+    protected Long accountGuestVlanMapId;
     
     public Date getTakenAt() {
         return takenAt;
@@ -103,6 +106,14 @@ public class DataCenterVnetVO implements InternalIdentity {
     public long getPhysicalNetworkId() {
         return physicalNetworkId;
     }
+
+    public void setAccountGuestVlanMapId(Long accountGuestVlanMapId) {
+        this.accountGuestVlanMapId = accountGuestVlanMapId;
+    }
+
+    public Long getAccountGuestVlanMapId() {
+        return accountGuestVlanMapId;
+    }
     
     protected DataCenterVnetVO() {
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/576d8391/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java b/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java
index 4afd640..4d9d010 100755
--- a/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java
+++ b/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java
@@ -16,6 +16,7 @@
 // under the License.
 package com.cloud.dc.dao;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
@@ -33,6 +34,8 @@ import com.cloud.dc.DataCenterLinkLocalIpAddressVO;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.DataCenterVnetVO;
 import com.cloud.dc.PodVlanVO;
+import com.cloud.network.dao.AccountGuestVlanMapDao;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
 import com.cloud.org.Grouping;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
@@ -68,6 +71,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long>
implem
     @Inject protected DataCenterVnetDao _vnetAllocDao = null;
     @Inject protected PodVlanDao _podVlanAllocDao = null;
     @Inject protected DcDetailsDao _detailsDao = null;
+    @Inject protected AccountGuestVlanMapDao _accountGuestVlanMapDao = null;
 
     protected long _prefix;
     protected Random _rand = new Random(System.currentTimeMillis());
@@ -189,11 +193,20 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO,
Long> implem
 
     @Override
     public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId,
String reservationId) {
-        DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId);
+        ArrayList<Long> dedicatedVlanDbIds = new ArrayList<Long>();
+        List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId);
+        for (AccountGuestVlanMapVO map : maps) {
+            dedicatedVlanDbIds.add(map.getId());
+        }
+        if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
+            DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId,
dedicatedVlanDbIds);
+            if (vo != null)
+                return vo.getVnet();
+        }
+        DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId,
null);
         if (vo == null) {
             return null;
         }
-
         return vo.getVnet();
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/576d8391/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
old mode 100644
new mode 100755
index 7fb68dc..9479284
--- a/server/src/com/cloud/dc/dao/DataCenterVnetDao.java
+++ b/server/src/com/cloud/dc/dao/DataCenterVnetDao.java
@@ -37,7 +37,7 @@ public interface DataCenterVnetDao extends GenericDao<DataCenterVnetVO,
Long> {
 
     public void lockRange(long dcId, long physicalNetworkId, Integer start, Integer end);
 
-    public DataCenterVnetVO take(long physicalNetworkId, long accountId, String reservationId);
+    public DataCenterVnetVO take(long physicalNetworkId, long accountId, String reservationId,
List<Long> vlanDbIds);
 
     public void release(String vnet, long physicalNetworkId, long accountId, String reservationId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/576d8391/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 2e04439..8b710e4 100755
--- a/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
+++ b/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
@@ -21,14 +21,19 @@ import java.sql.SQLException;
 import java.util.Date;
 import java.util.List;
 
+import javax.inject.Inject;
+
 import com.cloud.exception.InvalidParameterValueException;
 import org.springframework.stereotype.Component;
 
 import com.cloud.dc.DataCenterVnetVO;
+import com.cloud.network.dao.AccountGuestVlanMapDao;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDao;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
@@ -43,7 +48,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
 @Component
 @DB(txn=false)
 public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO, Long> implements
DataCenterVnetDao {
+
     private final SearchBuilder<DataCenterVnetVO> FreeVnetSearch;
+    private final SearchBuilder<DataCenterVnetVO> FreeDedicatedVnetSearch;
     private final SearchBuilder<DataCenterVnetVO> VnetDcSearch;
     private final SearchBuilder<DataCenterVnetVO> VnetDcSearchAllocated;
     private final SearchBuilder<DataCenterVnetVO> DcSearchAllocated;
@@ -51,6 +58,8 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
     private final GenericSearchBuilder<DataCenterVnetVO, Integer> countZoneVlans;
     private final GenericSearchBuilder<DataCenterVnetVO, Integer> countAllocatedZoneVlans;
     private final SearchBuilder<DataCenterVnetVO> SearchRange;
+
+    @Inject protected AccountGuestVlanMapDao _accountGuestVlanMapDao;
     
     public List<DataCenterVnetVO> listAllocatedVnets(long physicalNetworkId) {
         SearchCriteria<DataCenterVnetVO> sc = DcSearchAllocated.create();
@@ -141,9 +150,15 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
     }
 
     @DB
-    public DataCenterVnetVO take(long physicalNetworkId, long accountId, String reservationId)
{
-        SearchCriteria<DataCenterVnetVO> sc = FreeVnetSearch.create();
-        sc.setParameters("physicalNetworkId", physicalNetworkId);        
+    public DataCenterVnetVO take(long physicalNetworkId, long accountId, String reservationId,
List<Long> vlanDbIds) {
+        SearchCriteria<DataCenterVnetVO> sc;
+        if (vlanDbIds != null) {
+            sc = FreeDedicatedVnetSearch.create();
+            sc.setParameters("accountGuestVlanMapId", vlanDbIds.toArray());
+        } else {
+            sc = FreeVnetSearch.create();
+        }
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
         Date now = new Date();
         Transaction txn = Transaction.currentTxn();
         txn.start();
@@ -160,6 +175,7 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
         return vo;
     }
 
+
     public void release(String vnet, long physicalNetworkId, long accountId, String reservationId)
{
         SearchCriteria<DataCenterVnetVO> sc = VnetDcSearchAllocated.create();
         sc.setParameters("vnet", vnet);
@@ -202,7 +218,15 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
         FreeVnetSearch.and("dc", FreeVnetSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
         FreeVnetSearch.and("physicalNetworkId", FreeVnetSearch.entity().getPhysicalNetworkId(),
SearchCriteria.Op.EQ);
         FreeVnetSearch.and("taken", FreeVnetSearch.entity().getTakenAt(), SearchCriteria.Op.NULL);
+        FreeVnetSearch.and("accountGuestVlanMapId", FreeVnetSearch.entity().getAccountGuestVlanMapId(),
SearchCriteria.Op.NULL);
         FreeVnetSearch.done();
+
+        FreeDedicatedVnetSearch = createSearchBuilder();
+        FreeDedicatedVnetSearch.and("dc", FreeDedicatedVnetSearch.entity().getDataCenterId(),
SearchCriteria.Op.EQ);
+        FreeDedicatedVnetSearch.and("physicalNetworkId", FreeDedicatedVnetSearch.entity().getPhysicalNetworkId(),
SearchCriteria.Op.EQ);
+        FreeDedicatedVnetSearch.and("taken", FreeDedicatedVnetSearch.entity().getTakenAt(),
SearchCriteria.Op.NULL);
+        FreeDedicatedVnetSearch.and("accountGuestVlanMapId", FreeDedicatedVnetSearch.entity().getAccountGuestVlanMapId(),
SearchCriteria.Op.IN);
+        FreeDedicatedVnetSearch.done();
         
         VnetDcSearch = createSearchBuilder();
         VnetDcSearch.and("vnet", VnetDcSearch.entity().getVnet(), SearchCriteria.Op.EQ);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/576d8391/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 0e3624c..0b38367 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -2800,23 +2800,28 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             }
         }
 
-
+        AccountGuestVlanMapVO accountGuestVlanMapVO;
         if (updatedVlanRange != null) {
             if (guestVlanMapAccountId != vlanOwner.getAccountId()) {
                 throw new InvalidParameterValueException("Vlan range is partially dedicated
to another account. Cannot dedicate guest vlan range " + vlan);
             }
-            AccountGuestVlanMapVO accountGuestVlanMapVO = _accountGuestVlanMapDao.findById(guestVlanMapId);
+            accountGuestVlanMapVO = _accountGuestVlanMapDao.findById(guestVlanMapId);
             accountGuestVlanMapVO.setGuestVlanRange(updatedVlanRange);
             _accountGuestVlanMapDao.update(guestVlanMapId, accountGuestVlanMapVO);
-            return accountGuestVlanMapVO;
         } else {
             Transaction txn = Transaction.currentTxn();
-            AccountGuestVlanMapVO accountGuestVlanMapVO = new AccountGuestVlanMapVO(vlanOwner.getAccountId(),
physicalNetworkId);
+            accountGuestVlanMapVO = new AccountGuestVlanMapVO(vlanOwner.getAccountId(), physicalNetworkId);
             accountGuestVlanMapVO.setGuestVlanRange(startVlan + "-" +  endVlan);
             _accountGuestVlanMapDao.persist(accountGuestVlanMapVO);
             txn.commit();
-            return accountGuestVlanMapVO;
         }
+        // For every guest vlan set the corresponding account guest vlan map id
+        for (int i = startVlan; i <= endVlan; i++) {
+            List<DataCenterVnetVO> dataCenterVnet = _datacneter_vnet.findVnet(physicalNetwork.getDataCenterId(),((Integer)i).toString());
+            dataCenterVnet.get(0).setAccountGuestVlanMapId(accountGuestVlanMapVO.getId());
+            _datacneter_vnet.update(dataCenterVnet.get(0).getId(), dataCenterVnet.get(0));
+        }
+        return accountGuestVlanMapVO;
     }
 
     private List<Integer> getVlanFromRange(String vlanRange) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/576d8391/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
old mode 100644
new mode 100755

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/576d8391/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index c5b4d8f..317cdc9 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -1125,3 +1125,5 @@ CREATE TABLE `cloud`.`account_guest_vlan_map` (
   INDEX `i_account_guest_vlan_map__account_id`(`account_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD COLUMN account_guest_vlan_map_id bigint unsigned;
+ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD CONSTRAINT `fk_op_dc_vnet_alloc__account_guest_vlan_map_id`
FOREIGN KEY `fk_op_dc_vnet_alloc__account_guest_vlan_map_id` (`account_guest_vlan_map_id`)
REFERENCES `account_guest_vlan_map` (`id`) ON DELETE CASCADE;


Mime
View raw message