cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaya...@apache.org
Subject [1/5] git commit: updated refs/heads/master to 1c924e5
Date Fri, 28 Jun 2013 13:37:32 GMT
Updated Branches:
  refs/heads/master 9e474d018 -> 1c924e5ab


Cloudstack-2150 DB table entries of phisical network is not proper.Shows Duplicate entries
Cloudstack-2980 Adding a VLAN range that overlaps with two existing ranges results in inconsistent
DB entries

Signed-off-by: Jayapal <jayapal@apache.org>


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

Branch: refs/heads/master
Commit: 7f2f25d640b47c8e72381bfc318a7bbbb1ca2bfd
Parents: 3096261
Author: Bharat Kumar <bharat.kumar@citrix.com>
Authored: Wed Jun 26 20:55:30 2013 +0530
Committer: Jayapal <jayapal@apache.org>
Committed: Fri Jun 28 19:05:54 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/dc/dao/DataCenterVnetDaoImpl.java |  2 +-
 .../com/cloud/network/NetworkServiceImpl.java   | 85 ++++++++------------
 2 files changed, 34 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f2f25d6/engine/schema/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
index e97f2c6..a2f7cde 100755
--- a/engine/schema/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java
@@ -113,7 +113,7 @@ public class DataCenterVnetDaoImpl extends GenericDaoBase<DataCenterVnetVO,
Long
     
     @DB
     public void add(long dcId, long physicalNetworkId, int start, int end) {
-        String insertVnet = "INSERT INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id,
physical_network_id) VALUES ( ?, ?, ?)";
+        String insertVnet = "INSERT IGNORE INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id,
physical_network_id) VALUES ( ?, ?, ?)";
         
         Transaction txn = Transaction.currentTxn();
         try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f2f25d6/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 5e900bb..ac5d949 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -2561,7 +2561,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
 
         if (removeVlan != null){
             List<Integer> tokens = processVlanRange(network,removeVlan);
-            boolean result = removeVlanRange(network, tokens.get(0), tokens.get(1));
+            removeVlanRange(network, tokens.get(0), tokens.get(1));
         }
 
         if (tags != null && tags.size() > 1) {
@@ -2589,7 +2589,6 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             network.setSpeed(networkSpeed);
         }
 
-        // Vnet range can be extended only
         boolean AddVnet = true;
         List<Pair<Integer, Integer>> vnetsToAdd = new ArrayList<Pair<Integer,
Integer>>();
 
@@ -2606,7 +2605,6 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
                     int existingStartVnet = existingRanges.get(j).first();
                     int existingEndVnet = existingRanges.get(j).second();
 
-                    // check if vnet is being extended
                     if (newStartVnet.intValue() >= existingStartVnet & newEndVnet.intValue()
<= existingEndVnet) {
                         throw new InvalidParameterValueException("The vlan range you trying
to add already exists.");
                     }
@@ -2630,80 +2628,63 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
                         vnetsToAdd.add(new Pair<Integer, Integer>(existingEndVnet+1,newEndVnet));
                         existingRanges.get(j).first(newStartVnet);
                         existingRanges.get(j).second(newEndVnet);
+                        AddVnet = false;
                         break;
                     }
                 }
 
             }
             if (AddVnet){
-                    vnetsToAdd.add(new Pair<Integer, Integer>(newStartVnet, newEndVnet));
-                    existingRanges.add(new Pair<Integer, Integer>(newStartVnet,newEndVnet));
-            }
-
-            Map <Integer,Integer> vnetMap = new HashMap<Integer, Integer>(existingRanges.size());
-            Map <Integer, Integer> IndexMap = new HashMap<Integer, Integer>(existingRanges.size());
-            for (int i=0; i< existingRanges.size(); i++){
-                 vnetMap.put(existingRanges.get(i).first(),existingRanges.get(i).second());
-                 IndexMap.put(existingRanges.get(i).first(),i);
+                vnetsToAdd.add(new Pair<Integer, Integer>(newStartVnet, newEndVnet));
+                existingRanges.add(new Pair<Integer, Integer>(newStartVnet,newEndVnet));
+                j= existingRanges.size()-1;
             }
-
             Integer value;
-            Integer index;
             String vnetString = "";
+
+            Integer changed_entry_start = existingRanges.get(j).first();
+            Integer changed_entry_end = existingRanges.get(j).second();
             for (int i=0; i < existingRanges.size(); i++){
-                 value = vnetMap.get((existingRanges.get(i).second()+1));
-                 if (value != null) {
-                     vnetMap.remove((existingRanges.get(i).second()+1));
-                     vnetMap.remove(existingRanges.get(i).first());
-                     vnetMap.put(existingRanges.get(i).first(),value);
-                     existingRanges.add(new Pair<Integer,Integer>(existingRanges.get(i).first(),value));
-                     index = IndexMap.get(existingRanges.get(i).second()+1);
-                     existingRanges.get(index).first(-1);
-                     existingRanges.get(index).second(-1);
-                     existingRanges.get(i).first(-1);
-                     existingRanges.get(i).second(-1);
-                 }
-                value = vnetMap.get((existingRanges.get(i).second()));
-                if (value != null && ( (existingRanges.get(i).second()) != (existingRanges.get(i).first())
)) {
-                    vnetMap.remove((existingRanges.get(i).second()));
-                    vnetMap.remove(existingRanges.get(i).first());
-                    vnetMap.put(existingRanges.get(i).first(),value);
-                    existingRanges.add(new Pair<Integer,Integer>(existingRanges.get(i).first(),value));
-                    index = IndexMap.get(existingRanges.get(i).second());
-                    existingRanges.get(index).first(-1);
-                    existingRanges.get(index).second(-1);
+                if (i !=j  && existingRanges.get(i).first()<=changed_entry_end
&& existingRanges.get(i).second() >= changed_entry_end) {
+                    existingRanges.get(j).second(existingRanges.get(i).second());
                     existingRanges.get(i).first(-1);
                     existingRanges.get(i).second(-1);
+                } else if ((i !=j  && changed_entry_end > existingRanges.get(i).second())
&& changed_entry_start <= existingRanges.get(i).first()) {
+                    existingRanges.get(i).first(-1);
+                    existingRanges.get(i).second(-1);
+                }else if ((i != j ) &&  changed_entry_end > existingRanges.get(i).second()
&& changed_entry_start <= existingRanges.get(i).second() &&  existingRanges.get(i).first()
<= changed_entry_start) {
+                    existingRanges.get(j).first(existingRanges.get(i).first());
+                    existingRanges.get(i).first(-1);
+                    existingRanges.get(i).first(-1);
                 }
             }
 
 
-
-            if (newVnetRangeString != null) {
-               for (Pair<Integer,Integer> vnetRange : existingRanges ){
-                    value=vnetMap.get(vnetRange.first());
-                    if (value != null){
-                        vnetString = vnetString+vnetRange.first().toString()+"-"+value.toString()+";";
-                    }
-               }
-               if (vnetString.length() > 0 && vnetString.charAt(vnetString.length()-1)==';')
{
-                   vnetString = vnetString.substring(0, vnetString.length()-1);
-               }
-               network.setVnet(vnetString);
+            for (Pair<Integer,Integer> vnetRange : existingRanges ){
+                value=vnetRange.first();
+                if (value != -1){
+                    vnetString = vnetString+vnetRange.first().toString()+"-"+vnetRange.second().toString()+";";
+                }
             }
-
+            if (vnetString.length() > 0 && vnetString.charAt(vnetString.length()-1)==';')
{
+                vnetString = vnetString.substring(0, vnetString.length()-1);
+            }
+            network.setVnet(vnetString);
+            Transaction txn = Transaction.currentTxn();
+            txn.start();
             for (Pair<Integer, Integer> vnetToAdd : vnetsToAdd) {
                 s_logger.debug("Adding vnet range " + vnetToAdd.first() + "-" + vnetToAdd.second()
+ " for the physicalNetwork id= " + id + " and zone id=" + network.getDataCenterId()
-                    + " as a part of updatePhysicalNetwork call");
+                        + " as a part of updatePhysicalNetwork call");
                 _dcDao.addVnet(network.getDataCenterId(), network.getId(), vnetToAdd.first(),
vnetToAdd.second());
             }
+            _physicalNetworkDao.update(id, network);
+            txn.commit();
         }
 
-        _physicalNetworkDao.update(id, network);
-
-        return network;
+        return  network;
     }
 
+
     private List<Integer> processVlanRange(PhysicalNetworkVO network, String removeVlan)
{
         Integer StartVnet;
         Integer EndVnet;


Mime
View raw message