You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/06/20 09:20:22 UTC

[49/50] [abbrv] git commit: updated refs/heads/master to 97f8c52

merge to master


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

Branch: refs/heads/master
Commit: 5f28dcc6bbd3dec9b89e2482072560298e4f48de
Parents: 9aec9c6 febe7d9
Author: Edison Su <ed...@citrix.com>
Authored: Wed Jun 19 22:41:13 2013 -0700
Committer: Edison Su <ed...@citrix.com>
Committed: Wed Jun 19 22:41:13 2013 -0700

----------------------------------------------------------------------
 .../debian/config/root/createIpAlias.sh         |   5 +-
 .../configuration/ConfigurationManagerImpl.java | 168 +++++++++----------
 .../com/cloud/network/NetworkManagerImpl.java   |   2 +-
 .../VirtualNetworkApplianceManagerImpl.java     |   3 +-
 ui/scripts/system.js                            |  34 ++--
 5 files changed, 102 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5f28dcc6/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 8fc0229,13c821e..f7440c0
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@@ -3096,9 -2931,16 +3096,16 @@@ public class ConfigurationManagerImpl e
          return vlan;
      }
  
+     public boolean removeFromDb (long  vlanDbId){
+         if (!deletePublicIPRange(vlanDbId)) {
+             return false;
+         }
+         return  _vlanDao.expunge(vlanDbId);
+     }
+ 
      @Override
      @DB
 -    public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller)  {
 +    public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller) {
          VlanVO vlanRange = _vlanDao.findById(vlanDbId);
          if (vlanRange == null) {
              throw new InvalidParameterValueException("Please specify a valid IP range id.");
@@@ -3181,103 -3011,83 +3188,88 @@@
                  Network network = _networkDao.findById(vlanRange.getNetworkId());
                  DhcpServiceProvider dhcpServiceProvider = _networkMgr.getDhcpServiceProvider(network);
                  if (!dhcpServiceProvider.getProvider().getName().equalsIgnoreCase(Provider.VirtualRouter.getName())) {
-                     if (!deletePublicIPRange(vlanDbId)) {
+                     Transaction txn = Transaction.currentTxn();
+                     txn.start();
+                     if (!removeFromDb(vlanDbId)) {
+                         txn.rollback();
+                         txn.close();
                          return false;
                      }
-                     _vlanDao.expunge(vlanDbId);
-                     return true;
-                 }
-                 // search if the vlan has any allocated ips.
-                 boolean aliasIpBelongsToThisVlan = false;
-                 long freeIpsInsubnet = 0;
-                 NicIpAliasVO ipAlias = null;
-                 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.");
-                 }
-                 if (allocIpCount == 0) {
-                     // remove the vlan range.
-                     if (!deletePublicIPRange(vlanDbId)) {
-                         return false;
++
+                     else {
+                         txn.commit();
                      }
-                     _vlanDao.expunge(vlanDbId);
-                     return true;
-                 }
-                 // check if this allocated ip is being used as an ipAlias on the
-                 // router.
-                 ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(),
-                         vlanRange.getNetworkId(), NicIpAlias.state.active);
-                 // check if this ip belongs to this vlan and is allocated.
-                 IPAddressVO ip = _publicIpAddressDao.findByIpAndVlanId(ipAlias.getIp4Address(), vlanDbId);
+                     txn.close();
+                 }
++
+                 else {
+                   return  handleIpAliasDeletion(vlanRange, vlanDbId, dhcpServiceProvider, network);
+                 }
+             }
+         }
+         return true;
+     }
+ 
+     private boolean handleIpAliasDeletion(VlanVO vlanRange, long vlanDbId, DhcpServiceProvider dhcpServiceProvider, Network network) {
+         boolean result_final = false;
+         Transaction txn = Transaction.currentTxn();
+         txn.start();
+         IPAddressVO ip = null;
+         NicIpAliasVO ipAlias = null;
+         try{
+             Integer allocIpCount=0;
+             //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.");
+             }
+             if (allocIpCount == 0){
+                 result_final=true;
+             }
+             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) {
-                     aliasIpBelongsToThisVlan = true;
-                     // 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) {
+                     //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;
                              s_logger.debug("Failed to delete the vlan range as we could not free the ip used to provide the dhcp service.");
 -                        }
 -                        else {
 +                        } else {
                              _publicIpAddressDao.unassignIpAddress(ip.getId());
-                             if (!deletePublicIPRange(vlanDbId)) {
-                                 return false;
-                             }
-                             _vlanDao.expunge(vlanDbId);
-                             _nicIpAliasDao.expunge(ipAlias.getId());
+                             result_final = true;
                          }
                      } else {
 -                        // if there are more vlans in the subnet check if there are free ips.
 +                        // 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.");
 +                        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) {
-                                 freeIpsInsubnet = _publicIpAddressDao.countFreeIpsInVlan(vlanrange.getId());
-                                 if (freeIpsInsubnet > 0) {
-                                     // assign one free ip to the router for
-                                     // creating ip Alias.
-                                     Transaction txn = Transaction.currentTxn();
-                                     // changing the state to revoked so that
-                                     // removeDhcpSupport for subnet sses it.
-                                     ipAlias.setState(NicIpAlias.state.revoked);
-                                     _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
++
+                                 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;
-                                     try {
-                                         PublicIp routerPublicIP = _networkMgr.assignPublicIpAddressFromVlans(
-                                                 network.getDataCenterId(), null, caller, 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.
- 
-                                     } catch (InsufficientAddressCapacityException e) {
-                                         txn.rollback();
-                                         txn.close();
-                                         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");
-                                     }
+                                     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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5f28dcc6/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5f28dcc6/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5f28dcc6/ui/scripts/system.js
----------------------------------------------------------------------