cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject git commit: updated refs/heads/master-6-17-stable to e8b2d74
Date Fri, 28 Jun 2013 21:55:24 GMT
Updated Branches:
  refs/heads/master-6-17-stable 75f98eea4 -> e8b2d74a0


Revert "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"

This reverts commit 53b40d2337fe3f1ecfee982ecd99896118448fb0.


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

Branch: refs/heads/master-6-17-stable
Commit: e8b2d74a00348c25d6810d6e0078bfeb9d76cdea
Parents: 75f98ee
Author: Prachi Damle <prachi@cloud.com>
Authored: Fri Jun 28 14:35:18 2013 -0700
Committer: Prachi Damle <prachi@cloud.com>
Committed: Fri Jun 28 14:35:18 2013 -0700

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


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e8b2d74a/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 a2f7cde..e97f2c6 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 IGNORE INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id,
physical_network_id) VALUES ( ?, ?, ?)";
+        String insertVnet = "INSERT 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/e8b2d74a/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 04815ff..f88f600 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);
-            removeVlanRange(network, tokens.get(0), tokens.get(1));
+            boolean result = removeVlanRange(network, tokens.get(0), tokens.get(1));
         }
 
         if (tags != null && tags.size() > 1) {
@@ -2589,6 +2589,7 @@ 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>>();
 
@@ -2605,6 +2606,7 @@ 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.");
                     }
@@ -2628,62 +2630,79 @@ 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));
-                j= existingRanges.size()-1;
+                    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);
             }
+
             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++){
-                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());
+                 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);
                     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);
                 }
             }
 
 
-            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);
+
+            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);
             }
-            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();
         }
 
-        return  network;
-    }
+        _physicalNetworkDao.update(id, network);
 
+        return network;
+    }
 
     private List<Integer> processVlanRange(PhysicalNetworkVO network, String removeVlan)
{
         Integer StartVnet;


Mime
View raw message