cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aprat...@apache.org
Subject git commit: updated refs/heads/master-6-17-stable to 74c1687
Date Fri, 28 Jun 2013 09:21:01 GMT
Updated Branches:
  refs/heads/master-6-17-stable 6b38d1465 -> 74c168757


Cloudstack-3106 Delete all ips except ipAlias. Cloudstack-3119 Shared network removal doesn't
cleanup corresponding IP ranges

Signed-off-by: Abhinandan Prateek <aprateek@apache.org>


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

Branch: refs/heads/master-6-17-stable
Commit: 74c1687574c4589a75714eaeb5204c07a7372ca1
Parents: 6b38d14
Author: Bharat Kumar <bharat.kumar@citrix.com>
Authored: Fri Jun 28 14:14:43 2013 +0530
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Fri Jun 28 14:49:29 2013 +0530

----------------------------------------------------------------------
 engine/schema/src/com/cloud/dc/VlanVO.java      |   4 +
 .../src/com/cloud/network/dao/IPAddressDao.java |   6 +
 .../com/cloud/network/dao/IPAddressDaoImpl.java |  23 +++
 .../configuration/ConfigurationManagerImpl.java | 144 ++++++-------------
 .../VirtualNetworkApplianceManagerImpl.java     |   2 -
 5 files changed, 77 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74c16875/engine/schema/src/com/cloud/dc/VlanVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/VlanVO.java b/engine/schema/src/com/cloud/dc/VlanVO.java
index af6b5fc..1d28896 100644
--- a/engine/schema/src/com/cloud/dc/VlanVO.java
+++ b/engine/schema/src/com/cloud/dc/VlanVO.java
@@ -193,4 +193,8 @@ public class VlanVO implements Vlan {
 	public void setIp6Range(String ip6Range) {
 		this.ip6Range = ip6Range;
 	}
+
+    public void setIpRange(String ipRange) {
+        this.ip6Range = ipRange;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74c16875/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
index fecd44a..3eba6d8 100755
--- a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
@@ -17,9 +17,11 @@
 package com.cloud.network.dao;
 
 import com.cloud.dc.Vlan.VlanType;
+import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDao;
 import com.cloud.utils.net.Ip;
 
+import java.sql.SQLException;
 import java.util.List;
 
 public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
@@ -72,4 +74,8 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long>
{
     IPAddressVO findByIpAndVlanId(String ipAddress, long vlanid);
 
     long countFreeIpsInVlan(long vlanDbId);
+
+    boolean deletePublicIPRangeExceptAliasIP(long vlanDbId, String aliasIp) throws SQLException;
+
+    boolean deletePublicIPRange(long vlanDbId) throws SQLException;
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74c16875/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
index 886011e..1051b69 100755
--- a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
@@ -40,6 +40,7 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.Date;
 import java.util.List;
 
@@ -365,6 +366,28 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO,
Long> implemen
     }
 
     @Override
+    public boolean deletePublicIPRangeExceptAliasIP(long vlanDbId, String aliasIp) throws
SQLException {
+        Transaction txn = Transaction.currentTxn();
+        String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE vlan_db_id = ? and
public_ip_address!=?";
+
+        txn.start();
+        PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteSql);
+        stmt.setLong(1, vlanDbId);
+        stmt.setString(2, aliasIp);
+        stmt.executeUpdate();
+        txn.commit();
+        return true;
+    }
+
+    @Override
+    public boolean deletePublicIPRange(long vlanDbId) throws SQLException{
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("vlan", vlanDbId);
+        remove(sc);
+        return true;
+    }
+
+    @Override
     @DB
     public boolean remove(Long id) {
         Transaction txn = Transaction.currentTxn();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74c16875/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index cb4f76b..c19f401 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -121,7 +121,6 @@ import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
 import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.PermissionDeniedException;
@@ -141,7 +140,6 @@ import com.cloud.network.NetworkService;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PhysicalNetwork;
-import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.FirewallRulesDao;
 import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.IPAddressVO;
@@ -2948,11 +2946,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
         return vlan;
     }
 
-    public boolean removeFromDb (long  vlanDbId){
-        if (!deletePublicIPRange(vlanDbId)) {
-            return false;
-        }
-        return  _vlanDao.expunge(vlanDbId);
+    @DB
+    public void deleteVLANFromDb(long vlanDbId) throws SQLException {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        _publicIpAddressDao.deletePublicIPRange(vlanDbId);
+        _vlanDao.expunge(vlanDbId);
+        txn.commit();
     }
 
     @Override
@@ -3024,31 +3024,30 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
                             ip.getSystem(), ip.getClass().getName(), ip.getUuid());
                 }
             }
-            if (_networkModel.areServicesSupportedInNetwork(vlanRange.getNetworkId(), Service.Dhcp))
{
-                Network network = _networkDao.findById(vlanRange.getNetworkId());
-                DhcpServiceProvider dhcpServiceProvider = _networkMgr.getDhcpServiceProvider(network);
-                if (!dhcpServiceProvider.getProvider().getName().equalsIgnoreCase(Provider.VirtualRouter.getName()))
{
-                    Transaction txn = Transaction.currentTxn();
-                    txn.start();
-                    if (!removeFromDb(vlanDbId)) {
-                        txn.rollback();
-                        return false;
-                    }
-                    else {
-                        txn.commit();
+            try {
+                if (_networkModel.areServicesSupportedInNetwork(vlanRange.getNetworkId(),
Service.Dhcp)) {
+                    Network network = _networkDao.findById(vlanRange.getNetworkId());
+                    DhcpServiceProvider dhcpServiceProvider = _networkMgr.getDhcpServiceProvider(network);
+                    if (!dhcpServiceProvider.getProvider().getName().equalsIgnoreCase(Provider.VirtualRouter.getName()))
{
+                        deleteVLANFromDb(vlanDbId);
+                    } else {
+                        return  handleIpAliasDeletion(vlanRange, vlanDbId, dhcpServiceProvider,
network);
                     }
-                    txn.close();
                 }
                 else {
-                  return  handleIpAliasDeletion(vlanRange, vlanDbId, dhcpServiceProvider,
network);
+                    deleteVLANFromDb(vlanDbId);
                 }
             }
+            catch ( SQLException e) {
+               throw  new CloudRuntimeException(e.getMessage());
+            }
+
         }
         return true;
     }
 
-    private boolean handleIpAliasDeletion(VlanVO vlanRange, long vlanDbId, DhcpServiceProvider
dhcpServiceProvider, Network network) {
-        boolean result_final = false;
+    @DB
+    private boolean handleIpAliasDeletion(VlanVO vlanRange, long vlanDbId, DhcpServiceProvider
dhcpServiceProvider, Network network) throws SQLException {
         Transaction txn = Transaction.currentTxn();
         txn.start();
         IPAddressVO ip = null;
@@ -3058,84 +3057,48 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
             //search if the vlan has any allocated ips.
             allocIpCount = _publicIpAddressDao.countIPs(vlanRange.getDataCenterId(), vlanDbId,
true);
             if (allocIpCount > 1) {
-                throw  new InvalidParameterValueException ("cannot delete this range as some
of the vlans are in use.");
+                throw  new InvalidParameterValueException ("Cannot delete this range as some
of the vlans are in use.");
             }
-            if (allocIpCount == 0){
-                result_final=true;
+            else if (allocIpCount == 0){
+                deleteVLANFromDb(vlanDbId);
             }
             else {
                 ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(),
vlanRange.getNetworkId(),  NicIpAlias.state.active);
-                ipAlias.setState(NicIpAlias.state.revoked);
-                _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
                 //check if this ip belongs to this vlan and is allocated.
                 ip = _publicIpAddressDao.findByIpAndVlanId(ipAlias.getIp4Address(), vlanDbId);
                 if (ip != null && ip.getState() == IpAddress.State.Allocated) {
                     //check if there any other vlan ranges in the same subnet having free
ips
                     List<VlanVO> vlanRanges = _vlanDao.listVlansByNetworkIdAndGateway(vlanRange.getNetworkId(),
vlanRange.getVlanGateway());
                     //if there is no other vlanrage in this subnet. free the ip and delete
the vlan.
-                    if (vlanRanges.size() == 1){
-                        boolean result = dhcpServiceProvider.removeDhcpSupportForSubnet(network);
-                        if (result == false) {
-                            result_final = false;
+                    if (vlanRanges.size() == 1) {
+                        ipAlias.setState(NicIpAlias.state.revoked);
+                        _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
+                        if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) {
                             s_logger.debug("Failed to delete the vlan range as we could not
free the ip used to provide the dhcp service.");
+                            //setting the state back to active
+                            ipAlias.setState(NicIpAlias.state.active);
+                            _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
                         }
                         else {
                             _publicIpAddressDao.unassignIpAddress(ip.getId());
-                            result_final = true;
+                            deleteVLANFromDb(vlanDbId);
                         }
                     } else {
-                        // if there are more vlans in the subnet check if there are free
ips.
-                        List<Long> vlanDbIdList = new ArrayList<Long>();
-                        for (VlanVO vlanrange : vlanRanges) {
-                            if (vlanrange.getId() != vlanDbId) {
-                                vlanDbIdList.add(vlanrange.getId());
-                            }
-                        }
-                        s_logger.info("vlan Range"+vlanRange.getId()+" id being deleted,
one of the Ips in this range is used to provide the dhcp service, trying to free this ip and
allocate a new one.");
-                        for (VlanVO vlanrange : vlanRanges) {
-                            if (vlanrange.getId() != vlanDbId) {
-                                long freeIpsInsubnet =  _publicIpAddressDao.countFreeIpsInVlan(vlanrange.getId());
-                                if (freeIpsInsubnet > 0){
-                                    //assign one free ip to the router for creating ip Alias.
The ipalias is system managed ip so we are using the system account to allocate the ip not
the caller.
-                                    boolean result = false;
-                                    PublicIp routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(network.getDataCenterId(),
null, _accountDao.findById(Account.ACCOUNT_ID_SYSTEM), Vlan.VlanType.DirectAttached, vlanDbIdList,
network.getId(), null, false);
-                                    s_logger.info("creating a db entry for the new ip alias.");
-                                    NicIpAliasVO newipAlias = new NicIpAliasVO(ipAlias.getNicId(),
routerPublicIP.getAddress().addr(), ipAlias.getVmId(), ipAlias.getAccountId(), network.getDomainId(),
network.getId(), ipAlias.getGateway(), ipAlias.getNetmask());
-                                    newipAlias.setAliasCount(routerPublicIP.getIpMacAddress());
-                                    _nicIpAliasDao.persist(newipAlias);
-                                    //we revoke all the rules and apply all the rules as
a part of the removedhcp config. so the new ip will get configured when we delete the old
ip.
-                                    s_logger.info("removing the old ip alias on router");
-                                    result = dhcpServiceProvider.removeDhcpSupportForSubnet(network);
-                                    if (result == false) {
-                                        s_logger.debug("could't delete the ip alias on the
router");
-                                        result_final = false;
-                                    }
-                                    else {
-                                        _publicIpAddressDao.unassignIpAddress(ip.getId());
-                                        result_final=true;
-                                    }
-                                }
-                            }
-                        }
+                        // if there are more vlans in the subnet, free all the ips in the
range except the ip alias.
+                        s_logger.info("vlan Range"+vlanRange.getId()+" id being deleted,
one of the Ips in this range is used to provide the dhcp service, will free the rest of the
IPs in range.");
+                        _publicIpAddressDao.deletePublicIPRangeExceptAliasIP(vlanDbId, ipAlias.getIp4Address());
+                        VlanVO vlan = _vlanDao.findById(vlanDbId);
+                        vlan.setIpRange(ipAlias.getIp4Address()+"-"+ipAlias.getIp4Address());
+                        _vlanDao.update(vlan.getId(), vlan);
                     }
                 }
             }
-
-        } catch (InsufficientAddressCapacityException e) {
-            throw new InvalidParameterValueException("cannot delete  vlan range"+ vlanRange.getId()+"one
of the ips in this range is benig used to provide dhcp service. Cannot use some other ip as
there are no free ips in this subnet");
-        }
-        finally {
-            if (result_final) {
-                if (!removeFromDb(vlanDbId)) {
-                    txn.rollback();
-                }
-                else {
-                    txn.commit();
-                }
-                txn.close();
-            }
+        } catch (CloudRuntimeException e) {
+            txn.rollback();
+            throw e;
         }
-        return result_final;
+        txn.commit();
+        return true;
     }
 
     @Override
@@ -3349,25 +3312,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
         return tags;
     }
 
-    @DB
-    protected boolean deletePublicIPRange(long vlanDbId) {
-        Transaction txn = Transaction.currentTxn();
-        String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE vlan_db_id = ?";
-
-        txn.start();
-        try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteSql);
-            stmt.setLong(1, vlanDbId);
-            stmt.executeUpdate();
-        } catch (Exception ex) {
-            s_logger.error(ex.getMessage());
-            return false;
-        }
-        txn.commit();
-
-        return true;
-    }
-
 
     @DB
     protected boolean savePublicIPRange(String startIP, String endIP, long zoneId, long vlanDbId,
long sourceNetworkid, long physicalNetworkId) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74c16875/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 4b29eab..e863af4 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -2846,8 +2846,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
                     network.getId(), DataCenter.class, network.getDataCenterId());
         }
 
-        boolean agentResults = true;
-
         for (DomainRouterVO router : routers) {
             if (router.getState() != State.Running) {
                 s_logger.warn("Failed to add/remove VPN users: router not in running state");


Mime
View raw message