cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [45/50] [abbrv] Merge branch 'master' into rbac.
Date Fri, 01 Nov 2013 00:21:56 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ef4d520/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/NetworkServiceImpl.java
index aa14a1d,7e971bd..690365f
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@@ -714,26 -720,29 +720,29 @@@ public class NetworkServiceImpl extend
              return null;
          }
  
-         NicSecondaryIpVO secondaryIpVO;
          if (ipaddr != null) {
              // we got the ip addr so up the nics table and secodary ip
-             Transaction txn = Transaction.currentTxn();
-             txn.start();
- 
+             final String addrFinal = ipaddr;
+             long id = Transaction.execute(new TransactionCallback<Long>() {
+                 @Override
+                 public Long doInTransaction(TransactionStatus status) {
 -                    boolean nicSecondaryIpSet = nicVO.getSecondaryIp();
 -                    if (!nicSecondaryIpSet) {
 -                        nicVO.setSecondaryIp(true);
 -                        // commit when previously set ??
 -                        s_logger.debug("Setting nics table ...");
 -                        _nicDao.update(nicId, nicVO);
 -                    }
 -        
 -                    s_logger.debug("Setting nic_secondary_ip table ...");
 +            boolean nicSecondaryIpSet = nicVO.getSecondaryIp();
 +            if (!nicSecondaryIpSet) {
 +                nicVO.setSecondaryIp(true);
 +                // commit when previously set ??
 +                s_logger.debug("Setting nics table ...");
 +                _nicDao.update(nicId, nicVO);
 +            }
 +
 +            s_logger.debug("Setting nic_secondary_ip table ...");
-             vmId = nicVO.getInstanceId();
-             secondaryIpVO = new NicSecondaryIpVO(nicId, ipaddr, vmId, accountId, domainId, networkId);
+                     Long vmId = nicVO.getInstanceId();
+                     NicSecondaryIpVO secondaryIpVO = new NicSecondaryIpVO(nicId, addrFinal, vmId, accountId, domainId, networkId);
 -                    _nicSecondaryIpDao.persist(secondaryIpVO);
 +            _nicSecondaryIpDao.persist(secondaryIpVO);
-             txn.commit();
-            return  getNicSecondaryIp(secondaryIpVO.getId());
+                     return secondaryIpVO.getId();
+                 }
+             });
+ 
+            return getNicSecondaryIp(id);
          } else {
              return null;
          }
@@@ -803,13 -812,15 +812,15 @@@
                  throw new InvalidParameterValueException("Can' remove the ip " + secondaryIp + "is associate with static NAT rule public IP address id " + publicIpVO.getId());
              }
          } else if (dc.getNetworkType() == NetworkType.Basic || ntwkOff.getGuestType()  == Network.GuestType.Shared) {
-             IPAddressVO ip = _ipAddressDao.findByIpAndNetworkId(secIpVO.getNetworkId(), secIpVO.getIp4Address());
+             final IPAddressVO ip = _ipAddressDao.findByIpAndNetworkId(secIpVO.getNetworkId(), secIpVO.getIp4Address());
              if (ip != null) {
-                 Transaction txn = Transaction.currentTxn();
-                 txn.start();
+                 Transaction.execute(new TransactionCallbackNoReturn() {
+                     @Override
+                     public void doInTransactionWithoutResult(TransactionStatus status) {
 -                        _ipAddrMgr.markIpAsUnavailable(ip.getId());
 -                        _ipAddressDao.unassignIpAddress(ip.getId());
 +                _ipAddrMgr.markIpAsUnavailable(ip.getId());
 +                _ipAddressDao.unassignIpAddress(ip.getId());
-                 txn.commit();
+                     }
+                 });
              }
          } else {
              throw new InvalidParameterValueException("Not supported for this network now");
@@@ -819,22 -830,24 +830,24 @@@
          return success;
      }
  
-     boolean removeNicSecondaryIP(NicSecondaryIpVO ipVO, boolean lastIp) {
-         Transaction txn = Transaction.currentTxn();
-         long nicId = ipVO.getNicId();
-         NicVO nic = _nicDao.findById(nicId);
- 
-         txn.start();
+     boolean removeNicSecondaryIP(final NicSecondaryIpVO ipVO, final boolean lastIp) {
+         final long nicId = ipVO.getNicId();
+         final NicVO nic = _nicDao.findById(nicId);
  
+         Transaction.execute(new TransactionCallbackNoReturn() {
+             @Override
+             public void doInTransactionWithoutResult(TransactionStatus status) {
 -                if (lastIp) {
 -                    nic.setSecondaryIp(false);
 -                    s_logger.debug("Setting nics secondary ip to false ...");
 -                    _nicDao.update(nicId, nic);
 -                }
 +        if (lastIp) {
 +            nic.setSecondaryIp(false);
 +            s_logger.debug("Setting nics secondary ip to false ...");
 +            _nicDao.update(nicId, nic);
 +        }
  
 -                s_logger.debug("Revoving nic secondary ip entry ...");
 -                _nicSecondaryIpDao.remove(ipVO.getId());
 +        s_logger.debug("Revoving nic secondary ip entry ...");
 +        _nicSecondaryIpDao.remove(ipVO.getId());
-         txn.commit();
+             }
+         });
+ 
          return true;
      }
  
@@@ -1253,93 -1266,117 +1266,117 @@@
              throw ex;
          }
  
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
+         Network network = commitNetwork(networkOfferingId, gateway, startIP, endIP, netmask, networkDomain, vlanId,
+                 name, displayText, caller, physicalNetworkId, zoneId, domainId, isDomainSpecific, subdomainAccess,
+                 vpcId, startIPv6, endIPv6, ip6Gateway, ip6Cidr, displayNetwork, aclId, isolatedPvlan, ntwkOff, pNtwk,
+                 aclType, owner, cidr, createVlan);
+ 
+         // if the network offering has persistent set to true, implement the network
+         if ( ntwkOff.getIsPersistent() ) {
+             try {
+                 if ( network.getState() == Network.State.Setup ) {
+                     s_logger.debug("Network id=" + network.getId() + " is already provisioned");
+                     return network;
+                 }
+                 DeployDestination dest = new DeployDestination(zone, null, null, null);
+                 UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId());
+                 Journal journal = new Journal.LogJournal("Implementing " + network, s_logger);
+                 ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, caller);
+                 s_logger.debug("Implementing network " + network + " as a part of network provision for persistent network");
+                 Pair<? extends NetworkGuru, ? extends Network> implementedNetwork = _networkMgr.implementNetwork(network.getId(), dest, context);
+                 if (implementedNetwork.first() == null) {
+                     s_logger.warn("Failed to provision the network " + network);
+                 }
+                 network = implementedNetwork.second();
+             } catch (ResourceUnavailableException ex) {
+                 s_logger.warn("Failed to implement persistent guest network " + network + "due to ", ex);
+                 CloudRuntimeException e = new CloudRuntimeException("Failed to implement persistent guest network");
+                 e.addProxyObject(network.getUuid(), "networkId");
+                 throw e;
+             }
+         }
+         return network;
+     }
+ 
+     private Network commitNetwork(final Long networkOfferingId, final String gateway, final String startIP, final String endIP, final String netmask,
+             final String networkDomain, final String vlanId, final String name, final String displayText, final Account caller,
+             final Long physicalNetworkId, final Long zoneId, final Long domainId, final boolean isDomainSpecific, final Boolean subdomainAccessFinal,
+             final Long vpcId, final String startIPv6, final String endIPv6, final String ip6Gateway, final String ip6Cidr, final Boolean displayNetwork,
+             final Long aclId, final String isolatedPvlan, final NetworkOfferingVO ntwkOff, final PhysicalNetwork pNtwk, final ACLType aclType,
+             final Account ownerFinal, final String cidr, final boolean createVlan) throws InsufficientCapacityException,
+             ResourceAllocationException {
+         try {
+             return Transaction.execute(new TransactionCallbackWithException<Network,Exception>() {
+                 @Override
+                 public Network doInTransaction(TransactionStatus status) throws InsufficientCapacityException, ResourceAllocationException {
+                     Account owner = ownerFinal;
+                     Boolean subdomainAccess = subdomainAccessFinal;
 -                    
 -                    Long sharedDomainId = null;
 -                    if (isDomainSpecific) {
 -                        if (domainId != null) {
 -                            sharedDomainId = domainId;
 -                        } else {
 -                            sharedDomainId = _domainMgr.getDomain(Domain.ROOT_DOMAIN).getId();
 -                            subdomainAccess = true;
 -                        }
 -                    }
 -            
 -                    // default owner to system if network has aclType=Domain
 -                    if (aclType == ACLType.Domain) {
 -                        owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
 -                    }
 -            
 -                    //Create guest network
 -                    Network network = null;
 -                    if (vpcId != null) {
 -                        if (!_configMgr.isOfferingForVpc(ntwkOff)){
 -                            throw new InvalidParameterValueException("Network offering can't be used for VPC networks");
 -                        }
 -            
 -                        if(aclId != null){
 -                            NetworkACL acl = _networkACLDao.findById(aclId);
 -                            if(acl == null){
 -                                throw new InvalidParameterValueException("Unable to find specified NetworkACL");
 -                            }
 -            
 -                            if(aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) {
 -                                //ACL is not default DENY/ALLOW
 -                                // ACL should be associated with a VPC
 -                                if(!vpcId.equals(acl.getVpcId())){
 -                                    throw new InvalidParameterValueException("ACL: "+aclId+" do not belong to the VPC");
 -                                }
 -                            }
 -                        }
 -                        network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
 -                                networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork);
 -                    } else {
 -                        if (_configMgr.isOfferingForVpc(ntwkOff)){
 -                            throw new InvalidParameterValueException("Network offering can be used for VPC networks only");
 -                        }
 -                        if (ntwkOff.getInternalLb()) {
 -                            throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only");
 -                        }
 -            
 -                        network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
 -                        		networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId,
 -                        		ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan);
 -                    }
 -            
 -                    if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) {
 -                        // Create vlan ip range
 -                        _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId,
 -                                false, null, startIP, endIP, gateway, netmask, vlanId, null, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
 +
 +        Long sharedDomainId = null;
 +        if (isDomainSpecific) {
 +            if (domainId != null) {
 +                sharedDomainId = domainId;
 +            } else {
 +                sharedDomainId = _domainMgr.getDomain(Domain.ROOT_DOMAIN).getId();
 +                subdomainAccess = true;
 +            }
 +        }
 +
 +        // default owner to system if network has aclType=Domain
 +        if (aclType == ACLType.Domain) {
 +            owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
 +        }
 +
 +        //Create guest network
 +        Network network = null;
 +        if (vpcId != null) {
 +            if (!_configMgr.isOfferingForVpc(ntwkOff)){
 +                throw new InvalidParameterValueException("Network offering can't be used for VPC networks");
 +            }
 +
 +            if(aclId != null){
 +                NetworkACL acl = _networkACLDao.findById(aclId);
 +                if(acl == null){
 +                    throw new InvalidParameterValueException("Unable to find specified NetworkACL");
 +                }
 +
 +                if(aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) {
 +                    //ACL is not default DENY/ALLOW
 +                    // ACL should be associated with a VPC
 +                    if(!vpcId.equals(acl.getVpcId())){
 +                        throw new InvalidParameterValueException("ACL: "+aclId+" do not belong to the VPC");
                      }
 +                }
 +            }
 +            network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
 +                    networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork);
 +        } else {
 +            if (_configMgr.isOfferingForVpc(ntwkOff)){
 +                throw new InvalidParameterValueException("Network offering can be used for VPC networks only");
 +            }
 +            if (ntwkOff.getInternalLb()) {
 +                throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only");
 +            }
 +
 +            network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
 +            		networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId,
 +            		ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan);
 +        }
 +
 +        if (_accountMgr.isRootAdmin(caller.getId()) && createVlan) {
 +            // Create vlan ip range
 +            _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId,
 +                    false, null, startIP, endIP, gateway, netmask, vlanId, null, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
 +        }
- 
-         txn.commit();
- 
-         // if the network offering has persistent set to true, implement the network
-         if ( ntwkOff.getIsPersistent() ) {
-             try {
-                 if ( network.getState() == Network.State.Setup ) {
-                     s_logger.debug("Network id=" + network.getId() + " is already provisioned");
                      return network;
                  }
-                 DeployDestination dest = new DeployDestination(zone, null, null, null);
-                 UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId());
-                 Journal journal = new Journal.LogJournal("Implementing " + network, s_logger);
-                 ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, caller);
-                 s_logger.debug("Implementing network " + network + " as a part of network provision for persistent network");
-                 Pair<? extends NetworkGuru, ? extends Network> implementedNetwork = _networkMgr.implementNetwork(network.getId(), dest, context);
-                 if (implementedNetwork.first() == null) {
-                     s_logger.warn("Failed to provision the network " + network);
-                 }
-                 network = implementedNetwork.second();
-             } catch (ResourceUnavailableException ex) {
-                 s_logger.warn("Failed to implement persistent guest network " + network + "due to ", ex);
-                 CloudRuntimeException e = new CloudRuntimeException("Failed to implement persistent guest network");
-                 e.addProxyObject(network.getUuid(), "networkId");
-                 throw e;
-             }
+             });
+         } catch (Exception e) {
+             ExceptionUtil.rethrowRuntime(e);
+             ExceptionUtil.rethrow(e, InsufficientCapacityException.class);
+             ExceptionUtil.rethrow(e, ResourceAllocationException.class);
+             throw new IllegalStateException(e);
          }
-         return network;
      }
  
      @Override
@@@ -2199,29 -2234,31 +2234,31 @@@
  
          if (networkOfferingId != null) {
              if (networkOfferingChanged) {
-                 Transaction txn = Transaction.currentTxn();
-                 txn.start();
+                 Transaction.execute(new TransactionCallbackNoReturn() {
+                     @Override
+                     public void doInTransactionWithoutResult(TransactionStatus status) {
 -                        network.setNetworkOfferingId(networkOfferingId);
 -                        _networksDao.update(networkId, network, newSvcProviders);
 -                        // get all nics using this network
 -                        // log remove usage events for old offering
 -                        // log assign usage events for new offering
 -                        List<NicVO> nics = _nicDao.listByNetworkId(networkId);
 -                        for (NicVO nic : nics) {
 -                            long vmId = nic.getInstanceId();
 -                            VMInstanceVO vm = _vmDao.findById(vmId);
 -                            if (vm == null) {
 -                                s_logger.error("Vm for nic " + nic.getId() + " not found with Vm Id:" + vmId);
 -                                continue;
 -                            }
 -                            long isDefault = (nic.isDefaultNic()) ? 1 : 0;
 -                            String nicIdString = Long.toString(nic.getId());
 -                            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(),
 -                                    vm.getId(), nicIdString, oldNetworkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
 -                            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(),
 -                                    vm.getId(), nicIdString, networkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
 -                        }
 +                network.setNetworkOfferingId(networkOfferingId);
 +                _networksDao.update(networkId, network, newSvcProviders);
 +                // get all nics using this network
 +                // log remove usage events for old offering
 +                // log assign usage events for new offering
 +                List<NicVO> nics = _nicDao.listByNetworkId(networkId);
 +                for (NicVO nic : nics) {
 +                    long vmId = nic.getInstanceId();
 +                    VMInstanceVO vm = _vmDao.findById(vmId);
 +                    if (vm == null) {
 +                        s_logger.error("Vm for nic " + nic.getId() + " not found with Vm Id:" + vmId);
 +                        continue;
 +                    }
 +                    long isDefault = (nic.isDefaultNic()) ? 1 : 0;
 +                    String nicIdString = Long.toString(nic.getId());
 +                    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(),
 +                            vm.getId(), nicIdString, oldNetworkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
 +                    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(),
 +                            vm.getId(), nicIdString, networkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
 +                }
-                 txn.commit();
+                     }
+                 });
              }   else {
                  network.setNetworkOfferingId(networkOfferingId);
                  _networksDao.update(networkId, network, _networkMgr.finalizeServicesAndProvidersForNetwork(_entityMgr.findById(NetworkOffering.class, networkOfferingId), network.getPhysicalNetworkId()));
@@@ -2443,39 -2480,42 +2480,42 @@@
              }
          }
  
-         Transaction txn = Transaction.currentTxn();
          try {
-             txn.start();
+             final BroadcastDomainRange broadcastDomainRangeFinal = broadcastDomainRange;
+             return Transaction.execute(new TransactionCallback<PhysicalNetworkVO>() {
+                 @Override
+                 public PhysicalNetworkVO doInTransaction(TransactionStatus status) {
 -                    // Create the new physical network in the database
 -                    long id = _physicalNetworkDao.getNextInSequence(Long.class, "id");
 +            // Create the new physical network in the database
 +            long id = _physicalNetworkDao.getNextInSequence(Long.class, "id");
-             PhysicalNetworkVO pNetwork = new PhysicalNetworkVO(id, zoneId, vnetRange, networkSpeed, domainId, broadcastDomainRange, name);
+                     PhysicalNetworkVO pNetwork = new PhysicalNetworkVO(id, zoneId, vnetRange, networkSpeed, domainId, broadcastDomainRangeFinal, name);
 -                    pNetwork.setTags(tags);
 -                    pNetwork.setIsolationMethods(isolationMethods);
 +            pNetwork.setTags(tags);
 +            pNetwork.setIsolationMethods(isolationMethods);
  
 -                    pNetwork = _physicalNetworkDao.persist(pNetwork);
 +            pNetwork = _physicalNetworkDao.persist(pNetwork);
  
 -                    // Add vnet entries for the new zone if zone type is Advanced
 -                    if (vnetRange != null) {
 -                        addOrRemoveVnets(vnetRange.split(","), pNetwork);
 -                    }
 +            // Add vnet entries for the new zone if zone type is Advanced
 +            if (vnetRange != null) {
 +                addOrRemoveVnets(vnetRange.split(","), pNetwork);
 +            }
 +
 +            // add VirtualRouter as the default network service provider
 +            addDefaultVirtualRouterToPhysicalNetwork(pNetwork.getId());
  
 -                    // add VirtualRouter as the default network service provider
 -                    addDefaultVirtualRouterToPhysicalNetwork(pNetwork.getId());
 +            // add security group provider to the physical network
 +            addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId());
  
 -                    // add security group provider to the physical network
 -                    addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId());
 +            // add VPCVirtualRouter as the defualt network service provider
 +            addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId());
  
 -                    // add VPCVirtualRouter as the defualt network service provider
 -                    addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId());
 +            // add baremetal as the defualt network service provider
 +            addDefaultBaremetalProvidersToPhysicalNetwork(pNetwork.getId());
  
 -                    // add baremetal as the defualt network service provider
 -                    addDefaultBaremetalProvidersToPhysicalNetwork(pNetwork.getId());
 +            //Add Internal Load Balancer element as a default network service provider
 +            addDefaultInternalLbProviderToPhysicalNetwork(pNetwork.getId());
  
-             txn.commit();
 -                    //Add Internal Load Balancer element as a default network service provider
 -                    addDefaultInternalLbProviderToPhysicalNetwork(pNetwork.getId());
 -                    
 -                    return pNetwork;
 +            return pNetwork;
+                 }
+             });
          } catch (Exception ex) {
              s_logger.warn("Exception: ", ex);
              throw new CloudRuntimeException("Fail to create a physical network");
@@@ -2609,22 -2649,27 +2649,27 @@@
              }
              network.setVnet(comaSeperatedStingOfVnetRanges);
  
-             Transaction txn = Transaction.currentTxn();
-             txn.start();
-             if (addVnets != null) {
-                 s_logger.debug("Adding vnet range " + addVnets.toString()+ " for the physicalNetwork id= " + network.getId() + " and zone id=" + network.getDataCenterId()
+             final List<String> addVnetsFinal = addVnets;
+             final List<String> removeVnetsFinal = removeVnets;
+             Transaction.execute(new TransactionCallbackNoReturn() {
+                 @Override
+                 public void doInTransactionWithoutResult(TransactionStatus status) {
+                     if (addVnetsFinal != null) {
+                         s_logger.debug("Adding vnet range " + addVnetsFinal.toString()+ " for the physicalNetwork id= " + network.getId() + " and zone id=" + network.getDataCenterId()
 -                                + " as a part of updatePhysicalNetwork call");
 -                        //add vnet takes a list of strings to be added. each string is a vnet.
 +                        + " as a part of updatePhysicalNetwork call");
 +                //add vnet takes a list of strings to be added. each string is a vnet.
-                 _dcDao.addVnet(network.getDataCenterId(), network.getId(), addVnets);
+                         _dcDao.addVnet(network.getDataCenterId(), network.getId(), addVnetsFinal);
 -                    }
 +            }
-             if (removeVnets != null) {
-                 s_logger.debug("removing vnet range " + removeVnets.toString()+ " for the physicalNetwork id= " + network.getId() + " and zone id=" + network.getDataCenterId()
+                     if (removeVnetsFinal != null) {
+                         s_logger.debug("removing vnet range " + removeVnetsFinal.toString()+ " for the physicalNetwork id= " + network.getId() + " and zone id=" + network.getDataCenterId()
 -                                + " as a part of updatePhysicalNetwork call");
 -                        //deleteVnets  takes a list of strings to be removed. each string is a vnet.
 +                        + " as a part of updatePhysicalNetwork call");
 +                //deleteVnets  takes a list of strings to be removed. each string is a vnet.
-                 _datacneter_vnet.deleteVnets(txn, network.getDataCenterId(), network.getId(), removeVnets);
+                         _datacneter_vnet.deleteVnets(TransactionLegacy.currentTxn(), network.getDataCenterId(), network.getId(), removeVnetsFinal);
 -                    }
 -                    _physicalNetworkDao.update(network.getId(), network);
 +            }
 +            _physicalNetworkDao.update(network.getId(), network);
-             txn.commit();
+                 }
+             });
+ 
              _physicalNetworkDao.releaseFromLockTable(network.getId());
          }
      }
@@@ -2778,48 -2840,47 +2840,47 @@@
  
          checkIfPhysicalNetworkIsDeletable(physicalNetworkId);
  
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
+         return Transaction.execute(new TransactionCallback<Boolean>() {
+             @Override
+             public Boolean doInTransaction(TransactionStatus status) {
 -                // delete vlans for this zone
 -                List<VlanVO> vlans = _vlanDao.listVlansByPhysicalNetworkId(physicalNetworkId);
 -                for (VlanVO vlan : vlans) {
 -                    _vlanDao.remove(vlan.getId());
 -                }
 -        
 -                // Delete networks
 -                List<NetworkVO> networks = _networksDao.listByPhysicalNetwork(physicalNetworkId);
 -                if (networks != null && !networks.isEmpty()) {
 -                    for (NetworkVO network : networks) {
 -                        _networksDao.remove(network.getId());
 -                    }
 -                }
 -        
 -                // delete vnets
 -                _dcDao.deleteVnet(physicalNetworkId);
 -        
 -                // delete service providers
 -                List<PhysicalNetworkServiceProviderVO> providers = _pNSPDao.listBy(physicalNetworkId);
 -        
 -                for(PhysicalNetworkServiceProviderVO provider : providers){
 -                    try {
 -                        deleteNetworkServiceProvider(provider.getId());
 -                    }catch (ResourceUnavailableException e) {
 -                        s_logger.warn("Unable to complete destroy of the physical network provider: " + provider.getProviderName() + ", id: "+ provider.getId(), e);
 -                        return false;
 -                    } catch (ConcurrentOperationException e) {
 -                        s_logger.warn("Unable to complete destroy of the physical network provider: " + provider.getProviderName() + ", id: "+ provider.getId(), e);
 -                        return false;
 -                    }
 -                }
 -        
 -                // delete traffic types
 -                _pNTrafficTypeDao.deleteTrafficTypes(physicalNetworkId);
 -        
 +        // delete vlans for this zone
 +        List<VlanVO> vlans = _vlanDao.listVlansByPhysicalNetworkId(physicalNetworkId);
 +        for (VlanVO vlan : vlans) {
 +            _vlanDao.remove(vlan.getId());
 +        }
 +
 +        // Delete networks
 +        List<NetworkVO> networks = _networksDao.listByPhysicalNetwork(physicalNetworkId);
 +        if (networks != null && !networks.isEmpty()) {
 +            for (NetworkVO network : networks) {
 +                _networksDao.remove(network.getId());
 +            }
 +        }
 +
 +        // delete vnets
 +        _dcDao.deleteVnet(physicalNetworkId);
 +
 +        // delete service providers
 +        List<PhysicalNetworkServiceProviderVO> providers = _pNSPDao.listBy(physicalNetworkId);
 +
 +        for(PhysicalNetworkServiceProviderVO provider : providers){
 +            try {
 +                deleteNetworkServiceProvider(provider.getId());
 +            }catch (ResourceUnavailableException e) {
 +                s_logger.warn("Unable to complete destroy of the physical network provider: " + provider.getProviderName() + ", id: "+ provider.getId(), e);
 +                return false;
 +            } catch (ConcurrentOperationException e) {
 +                s_logger.warn("Unable to complete destroy of the physical network provider: " + provider.getProviderName() + ", id: "+ provider.getId(), e);
 +                return false;
 +            }
 +        }
 +
 +        // delete traffic types
 +        _pNTrafficTypeDao.deleteTrafficTypes(physicalNetworkId);
 +
-         boolean success = _physicalNetworkDao.remove(physicalNetworkId);
- 
-         txn.commit();
- 
-         return success;
+                 return _physicalNetworkDao.remove(physicalNetworkId);
+             }
+         });
      }
  
      @DB
@@@ -3861,50 -3912,59 +3912,59 @@@
              throw new InvalidParameterValueException("unsupported type of broadcastUri specified: " + broadcastUriString);
          }
  
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
- 
+         final NetworkOfferingVO ntwkOffFinal = ntwkOff; 
+         try {
+             return Transaction.execute(new TransactionCallbackWithException<Network,Exception>() {
+                 @Override
+                 public Network doInTransaction(TransactionStatus status) throws ResourceAllocationException, InsufficientCapacityException {
 -                    //lock datacenter as we need to get mac address seq from there
 -                    DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true);
 -            
 -                    //check if we need to create guest network
 -                    Network privateNetwork = _networksDao.getPrivateNetwork(uriString, cidr,
 +        //lock datacenter as we need to get mac address seq from there
 +        DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true);
 +
 +        //check if we need to create guest network
 +        Network privateNetwork = _networksDao.getPrivateNetwork(uriString, cidr,
-                 networkOwnerId, pNtwk.getDataCenterId(), null);
+                             networkOwnerId, pNtwk.getDataCenterId(), networkOfferingId);
 -                    if (privateNetwork == null) {
 -                        //create Guest network
 +        if (privateNetwork == null) {
 +            //create Guest network
-             privateNetwork = _networkMgr.createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, uriString,
+                         privateNetwork = _networkMgr.createGuestNetwork(ntwkOffFinal.getId(), networkName, displayText, gateway, cidr, uriString,
 -                                null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, vpcId, null, null, true, null);
 -                        s_logger.debug("Created private network " + privateNetwork);
 -                    } else {
 -                        s_logger.debug("Private network already exists: " + privateNetwork);
 -                        //Do not allow multiple private gateways with same Vlan within a VPC
 -                        if(vpcId.equals(privateNetwork.getVpcId())){
 -                            throw new InvalidParameterValueException("Private network for the vlan: " + uriString + " and cidr  "+ cidr +"  already exists " +
 -                                    "for Vpc "+vpcId+" in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
 -                        }
 -                    }
 -            
 -                    //add entry to private_ip_address table
 -                    PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(), startIp, vpcId);
 -                    if (privateIp != null) {
 -                        throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" +
 -                                " in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
 -                    }
 -            
 -                    Long mac = dc.getMacAddress();
 -                    Long nextMac = mac + 1;
 -                    dc.setMacAddress(nextMac);
 -            
 -                    privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac, vpcId, sourceNat);
 -                    _privateIpDao.persist(privateIp);
 -            
 -                    _dcDao.update(dc.getId(), dc);
 -            
 -                    s_logger.debug("Private network " + privateNetwork + " is created");
 -            
 -                    return privateNetwork;
 -                }
 +                    null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, vpcId, null, null, true, null);
 +            s_logger.debug("Created private network " + privateNetwork);
 +        } else {
 +            s_logger.debug("Private network already exists: " + privateNetwork);
 +            //Do not allow multiple private gateways with same Vlan within a VPC
 +            if(vpcId.equals(privateNetwork.getVpcId())){
 +                throw new InvalidParameterValueException("Private network for the vlan: " + uriString + " and cidr  "+ cidr +"  already exists " +
 +                        "for Vpc "+vpcId+" in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
 +            }
 +        }
 +
 +        //add entry to private_ip_address table
 +        PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(), startIp, vpcId);
 +        if (privateIp != null) {
 +            throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" +
 +                    " in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
 +        }
 +
 +        Long mac = dc.getMacAddress();
 +        Long nextMac = mac + 1;
 +        dc.setMacAddress(nextMac);
 +
 +        privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac, vpcId, sourceNat);
 +        _privateIpDao.persist(privateIp);
 +
 +        _dcDao.update(dc.getId(), dc);
 +
-         txn.commit();
 +        s_logger.debug("Private network " + privateNetwork + " is created");
 +
 +        return privateNetwork;
 +    }
+             });
+         } catch (Exception e) {
+             ExceptionUtil.rethrowRuntime(e);
+             ExceptionUtil.rethrow(e, ResourceAllocationException.class);
+             ExceptionUtil.rethrow(e, InsufficientCapacityException.class);
+             throw new IllegalStateException(e);
+         }
+     }
  
  
      private NetworkOfferingVO findSystemNetworkOffering(String offeringName) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ef4d520/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/firewall/FirewallManagerImpl.java
index 195f93e,ccceb8d..89f24c6
--- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
+++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
@@@ -222,26 -229,28 +229,28 @@@ public class FirewallManagerImpl extend
                  domainId = network.getDomainId();
          }
  
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
- 
+         final Long accountIdFinal = accountId;
+         final Long domainIdFinal = domainId;
+         return Transaction.execute(new TransactionCallbackWithException<FirewallRuleVO,NetworkRuleConflictException>() {
+             @Override
+             public FirewallRuleVO doInTransaction(TransactionStatus status) throws NetworkRuleConflictException {
 -                FirewallRuleVO newRule = new FirewallRuleVO(xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), networkId,
 +        FirewallRuleVO newRule = new FirewallRuleVO(xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), networkId,
-                 accountId, domainId, Purpose.Firewall, sourceCidrList, icmpCode, icmpType, relatedRuleId, trafficType);
+                         accountIdFinal, domainIdFinal, Purpose.Firewall, sourceCidrList, icmpCode, icmpType, relatedRuleId, trafficType);
 -                newRule.setType(type);
 -                newRule = _firewallDao.persist(newRule);
 -        
 -                if (type == FirewallRuleType.User)
 -                    detectRulesConflict(newRule);
 -        
 -                if (!_firewallDao.setStateToAdd(newRule)) {
 -                    throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
 -                }
 -                CallContext.current().setEventDetails("Rule Id: " + newRule.getId());
 -                
 -                return newRule;
 -            }
 +        newRule.setType(type);
 +        newRule = _firewallDao.persist(newRule);
 +
 +        if (type == FirewallRuleType.User)
 +            detectRulesConflict(newRule);
 +
 +        if (!_firewallDao.setStateToAdd(newRule)) {
 +            throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
 +        }
 +        CallContext.current().setEventDetails("Rule Id: " + newRule.getId());
 +
-         txn.commit();
- 
 +        return newRule;
 +    }
+         });
+     }
  
      @Override
      public Pair<List<? extends FirewallRule>, Integer> listFirewallRules(ListFirewallRulesCmd cmd) {
@@@ -739,28 -738,29 +738,29 @@@
              _accountMgr.checkAccess(caller, null, true, rule);
          }
  
-         Transaction txn = Transaction.currentTxn();
+         Transaction.execute(new TransactionCallbackNoReturn() {
+             @Override
+             public void doInTransactionWithoutResult(TransactionStatus status) {
 -                boolean generateUsageEvent = false;
 +        boolean generateUsageEvent = false;
  
-         txn.start();
 -                if (rule.getState() == State.Staged) {
 -                    if (s_logger.isDebugEnabled()) {
 -                        s_logger.debug("Found a rule that is still in stage state so just removing it: " + rule);
 -                    }
 -                    removeRule(rule);
 -                    generateUsageEvent = true;
 -                } else if (rule.getState() == State.Add || rule.getState() == State.Active) {
 -                    rule.setState(State.Revoke);
 -                    _firewallDao.update(rule.getId(), rule);
 -                    generateUsageEvent = true;
 -                }
 +        if (rule.getState() == State.Staged) {
 +            if (s_logger.isDebugEnabled()) {
 +                s_logger.debug("Found a rule that is still in stage state so just removing it: " + rule);
 +            }
 +            removeRule(rule);
 +            generateUsageEvent = true;
 +        } else if (rule.getState() == State.Add || rule.getState() == State.Active) {
 +            rule.setState(State.Revoke);
 +            _firewallDao.update(rule.getId(), rule);
 +            generateUsageEvent = true;
 +        }
  
 -                if (generateUsageEvent && needUsageEvent) {
 -                    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_RULE_DELETE, rule.getAccountId(), 0, rule.getId(),
 -                            null, rule.getClass().getName(), rule.getUuid());
 -                }
 +        if (generateUsageEvent && needUsageEvent) {
 +            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_RULE_DELETE, rule.getAccountId(), 0, rule.getId(),
 +                    null, rule.getClass().getName(), rule.getUuid());
 +        }
- 
-         txn.commit();
+             }
+         });
      }
  
      @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ef4d520/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 6d3223e,6e0b54d..0b9d306
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@@ -206,50 -212,50 +212,50 @@@ public class VpcManagerImpl extends Man
      @DB
      public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
          //configure default vpc offering
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
-         
+         Transaction.execute(new TransactionCallbackNoReturn() {
+             @Override
+             public void doInTransactionWithoutResult(TransactionStatus status) {
 -                if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) {
 -                    s_logger.debug("Creating default VPC offering " + VpcOffering.defaultVPCOfferingName);
 -                    
 -                    Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
 -                    Set<Provider> defaultProviders = new HashSet<Provider>();
 -                    defaultProviders.add(Provider.VPCVirtualRouter);
 -                    for (Service svc : getSupportedServices()) {
 -                        if (svc == Service.Lb) {
 -                            Set<Provider> lbProviders = new HashSet<Provider>();
 -                            lbProviders.add(Provider.VPCVirtualRouter);
 -                            lbProviders.add(Provider.InternalLbVm);
 -                            svcProviderMap.put(svc, lbProviders);
 -                        } else {
 -                            svcProviderMap.put(svc, defaultProviders);
 -                        }
 -                    }
 -                    createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap,
 -                            true, State.Enabled);
 +        if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) {
 +            s_logger.debug("Creating default VPC offering " + VpcOffering.defaultVPCOfferingName);
 +            
 +            Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
 +            Set<Provider> defaultProviders = new HashSet<Provider>();
 +            defaultProviders.add(Provider.VPCVirtualRouter);
 +            for (Service svc : getSupportedServices()) {
 +                if (svc == Service.Lb) {
 +                    Set<Provider> lbProviders = new HashSet<Provider>();
 +                    lbProviders.add(Provider.VPCVirtualRouter);
 +                    lbProviders.add(Provider.InternalLbVm);
 +                    svcProviderMap.put(svc, lbProviders);
 +                } else {
 +                    svcProviderMap.put(svc, defaultProviders);
                  }
 -        
 -                //configure default vpc offering with Netscaler as LB Provider
 -                if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCNSOfferingName ) == null) {
 -                    s_logger.debug("Creating default VPC offering with Netscaler as LB Provider" + VpcOffering.defaultVPCNSOfferingName);
 -                    Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
 -                    Set<Provider> defaultProviders = new HashSet<Provider>();
 -                    defaultProviders.add(Provider.VPCVirtualRouter);
 -                    for (Service svc : getSupportedServices()) {
 -                        if (svc == Service.Lb) {
 -                            Set<Provider> lbProviders = new HashSet<Provider>();
 -                            lbProviders.add(Provider.Netscaler);
 -                            lbProviders.add(Provider.InternalLbVm);
 -                            svcProviderMap.put(svc, lbProviders);
 -                        } else {
 -                            svcProviderMap.put(svc, defaultProviders);
 -                        }
 -                    }
 -                    createVpcOffering(VpcOffering.defaultVPCNSOfferingName, VpcOffering.defaultVPCNSOfferingName,
 -                            svcProviderMap, false, State.Enabled);
 +            }
 +            createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap,
 +                    true, State.Enabled);
 +        }
 +
 +        //configure default vpc offering with Netscaler as LB Provider
 +        if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCNSOfferingName ) == null) {
 +            s_logger.debug("Creating default VPC offering with Netscaler as LB Provider" + VpcOffering.defaultVPCNSOfferingName);
 +            Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
 +            Set<Provider> defaultProviders = new HashSet<Provider>();
 +            defaultProviders.add(Provider.VPCVirtualRouter);
 +            for (Service svc : getSupportedServices()) {
 +                if (svc == Service.Lb) {
 +                    Set<Provider> lbProviders = new HashSet<Provider>();
 +                    lbProviders.add(Provider.Netscaler);
 +                    lbProviders.add(Provider.InternalLbVm);
 +                    svcProviderMap.put(svc, lbProviders);
 +                } else {
 +                    svcProviderMap.put(svc, defaultProviders);
                  }
              }
 +            createVpcOffering(VpcOffering.defaultVPCNSOfferingName, VpcOffering.defaultVPCNSOfferingName,
 +                    svcProviderMap, false, State.Enabled);
 +        }
- 
-         txn.commit();
++            }
+         });
          
          Map<String, String> configs = _configDao.getConfiguration(params);
          String value = configs.get(Config.VpcCleanupInterval.key());
@@@ -375,37 -381,39 +381,39 @@@
  
      
      @DB
-     protected VpcOffering createVpcOffering(String name, String displayText, Map<Network.Service,
-             Set<Network.Provider>> svcProviderMap, boolean isDefault, State state) {
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
+     protected VpcOffering createVpcOffering(final String name, final String displayText, final Map<Network.Service,
+             Set<Network.Provider>> svcProviderMap, final boolean isDefault, final State state) {
+         return Transaction.execute(new TransactionCallback<VpcOffering>() {
+             @Override
+             public VpcOffering doInTransaction(TransactionStatus status) {
 -                // create vpc offering object
 -                VpcOfferingVO offering  = new VpcOfferingVO(name, displayText, isDefault, null);
 -
 -                if (state != null) {
 -                    offering.setState(state);
 -                }
 -                s_logger.debug("Adding vpc offering " + offering);
 -                offering = _vpcOffDao.persist(offering);
 -                // populate services and providers
 -                if (svcProviderMap != null) {
 -                    for (Network.Service service : svcProviderMap.keySet()) {
 -                        Set<Provider> providers = svcProviderMap.get(service);
 -                        if (providers != null && !providers.isEmpty()) {
 -                            for (Network.Provider provider : providers) {
 -                                VpcOfferingServiceMapVO offService = new VpcOfferingServiceMapVO(offering.getId(), service, provider);
 -                                _vpcOffSvcMapDao.persist(offService);
 -                                s_logger.trace("Added service for the vpc offering: " + offService + " with provider " + provider.getName());
 -                            }
 -                        } else {
 -                            throw new InvalidParameterValueException("Provider is missing for the VPC offering service " + service.getName());
 -                        }
 +        // create vpc offering object
 +        VpcOfferingVO offering  = new VpcOfferingVO(name, displayText, isDefault, null);
 +        
 +        if (state != null) {
 +            offering.setState(state);
 +        }
 +        s_logger.debug("Adding vpc offering " + offering);
 +        offering = _vpcOffDao.persist(offering);
 +        // populate services and providers
 +        if (svcProviderMap != null) {
 +            for (Network.Service service : svcProviderMap.keySet()) {
 +                Set<Provider> providers = svcProviderMap.get(service);
 +                if (providers != null && !providers.isEmpty()) {
 +                    for (Network.Provider provider : providers) {
 +                        VpcOfferingServiceMapVO offService = new VpcOfferingServiceMapVO(offering.getId(), service, provider);
 +                        _vpcOffSvcMapDao.persist(offService);
 +                        s_logger.trace("Added service for the vpc offering: " + offService + " with provider " + provider.getName());
                      }
 +                } else {
 +                    throw new InvalidParameterValueException("Provider is missing for the VPC offering service " + service.getName());
                  }
 -
 -                return offering;
              }
 +        }
-         txn.commit();
 +
 +        return offering;
 +    }
+         });
+     }
      
      @Override
      public Vpc getActiveVpc(long vpcId) {
@@@ -635,9 -643,9 +643,9 @@@
  
      
      @DB
-     protected Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr,
-             String networkDomain) {
+     protected Vpc createVpc(final long zoneId, final long vpcOffId, final Account vpcOwner, final String vpcName, final String displayText, final String cidr,
+             final String networkDomain) {
 -
 +        
          //Validate CIDR
          if (!NetUtils.isValidCIDR(cidr)) {
              throw new InvalidParameterValueException("Invalid CIDR specified " + cidr);
@@@ -657,22 -665,23 +665,23 @@@
                              + "and the hyphen ('-'); can't start or end with \"-\"");
          }
  
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
+         return Transaction.execute(new TransactionCallback<VpcVO>() {
+             @Override
+             public VpcVO doInTransaction(TransactionStatus status) {
 -                VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr,
 -                        networkDomain);
 -                vpc = _vpcDao.persist(vpc, finalizeServicesAndProvidersForVpc(zoneId, vpcOffId));
 -                _resourceLimitMgr.incrementResourceCount(vpcOwner.getId(), ResourceType.vpc);
 +        VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr,
 +                networkDomain);
 +        vpc = _vpcDao.persist(vpc, finalizeServicesAndProvidersForVpc(zoneId, vpcOffId));
 +        _resourceLimitMgr.incrementResourceCount(vpcOwner.getId(), ResourceType.vpc);
-         txn.commit();
  
 -                s_logger.debug("Created VPC " + vpc);
 +        s_logger.debug("Created VPC " + vpc);
  
 -                return vpc;
 -            }
 +        return vpc;
 +    }
+         });
+     }
  
-     private Map<String, String> finalizeServicesAndProvidersForVpc(long zoneId, long offeringId) {
-         Map<String, String> svcProviders = new HashMap<String, String>();
-         Map<String, List<String>> providerSvcs = new HashMap<String, List<String>>();
+     private Map<String, List<String>> finalizeServicesAndProvidersForVpc(long zoneId, long offeringId) {
+         Map<String, List<String>> svcProviders = new HashMap<String, List<String>>();
          List<VpcOfferingServiceMapVO> servicesMap = _vpcOffSvcMapDao.listByVpcOffId(offeringId);
  
          for (VpcOfferingServiceMapVO serviceMap : servicesMap) {
@@@ -695,13 -698,15 +698,15 @@@
                  throw new InvalidParameterValueException("Provider " + provider +
                          " should be enabled in at least one physical network of the zone specified");
              }
 -            
 +
-             svcProviders.put(service, provider);
-             List<String> l = providerSvcs.get(provider);
-             if (l == null) {
-                 providerSvcs.put(provider, l = new ArrayList<String>());
+             List<String> providers = null;
+             if (svcProviders.get(service) == null) {
+                 providers = new ArrayList<String>();
+             } else {
+                 providers = svcProviders.get(service);
              }
-             l.add(service);
+             providers.add(provider);
+             svcProviders.put(service, providers);
          }
  
          return svcProviders;
@@@ -740,16 -745,18 +745,18 @@@
          //mark VPC as inactive
          if (vpc.getState() != Vpc.State.Inactive) {
              s_logger.debug("Updating VPC " + vpc + " with state " + Vpc.State.Inactive + " as a part of vpc delete");
-             VpcVO vpcVO = _vpcDao.findById(vpc.getId());
+             final VpcVO vpcVO = _vpcDao.findById(vpc.getId());
              vpcVO.setState(Vpc.State.Inactive);
              
-             Transaction txn = Transaction.currentTxn();
-             txn.start();
+             Transaction.execute(new TransactionCallbackNoReturn() {
+                 @Override
+                 public void doInTransactionWithoutResult(TransactionStatus status) {
 -                    _vpcDao.update(vpc.getId(), vpcVO);
 -
 -                    //decrement resource count
 -                    _resourceLimitMgr.decrementResourceCount(vpc.getAccountId(), ResourceType.vpc);
 +            _vpcDao.update(vpc.getId(), vpcVO);
 +            
 +            //decrement resource count
 +            _resourceLimitMgr.decrementResourceCount(vpc.getAccountId(), ResourceType.vpc);
-             txn.commit();
+                 }
+             });
          }
          
          //shutdown VPC
@@@ -1145,71 -1152,72 +1152,72 @@@
      }
  
      @DB
-     protected void validateNewVpcGuestNetwork(String cidr, String gateway, Account networkOwner, Vpc vpc, String networkDomain) {
+     protected void validateNewVpcGuestNetwork(final String cidr, final String gateway, final Account networkOwner, final Vpc vpc, final String networkDomain) {
          
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
+         Transaction.execute(new TransactionCallbackNoReturn() {
+             @Override
+             public void doInTransactionWithoutResult(TransactionStatus status) {
 -                Vpc locked = _vpcDao.acquireInLockTable(vpc.getId());
 -                if (locked == null) {
 -                    throw new CloudRuntimeException("Unable to acquire lock on " + vpc);
 -                }
 +        Vpc locked = _vpcDao.acquireInLockTable(vpc.getId());
 +        if (locked == null) {
 +            throw new CloudRuntimeException("Unable to acquire lock on " + vpc);
 +        }
 +        
 +        try {
 +            //check number of active networks in vpc
 +            if (_ntwkDao.countVpcNetworks(vpc.getId()) >= _maxNetworks) {
 +                throw new CloudRuntimeException("Number of networks per VPC can't extend "
 +                        + _maxNetworks + "; increase it using global config " + Config.VpcMaxNetworks);
 +            }
 +            
 +            
 +            //1) CIDR is required
 +            if (cidr == null) {
 +                throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC");
 +            }
 +            
 +            //2) Network cidr should be within vpcCidr
 +            if (!NetUtils.isNetworkAWithinNetworkB(cidr, vpc.getCidr())) {
 +                throw new InvalidParameterValueException("Network cidr " + cidr + " is not within vpc " + vpc + " cidr");
 +            }
 +            
 +            //3) Network cidr shouldn't cross the cidr of other vpc network cidrs
 +            List<? extends Network> ntwks = _ntwkDao.listByVpc(vpc.getId());
 +            for (Network ntwk : ntwks) {
 +                assert (cidr != null) : "Why the network cidr is null when it belongs to vpc?";
                  
 -                try {
 -                    //check number of active networks in vpc
 -                    if (_ntwkDao.countVpcNetworks(vpc.getId()) >= _maxNetworks) {
 -                        throw new CloudRuntimeException("Number of networks per VPC can't extend "
 -                                + _maxNetworks + "; increase it using global config " + Config.VpcMaxNetworks);
 -                    }
 -                    
 -                    
 -                    //1) CIDR is required
 -                    if (cidr == null) {
 -                        throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC");
 -                    }
 -                    
 -                    //2) Network cidr should be within vpcCidr
 -                    if (!NetUtils.isNetworkAWithinNetworkB(cidr, vpc.getCidr())) {
 -                        throw new InvalidParameterValueException("Network cidr " + cidr + " is not within vpc " + vpc + " cidr");
 -                    }
 -                    
 -                    //3) Network cidr shouldn't cross the cidr of other vpc network cidrs
 -                    List<? extends Network> ntwks = _ntwkDao.listByVpc(vpc.getId());
 -                    for (Network ntwk : ntwks) {
 -                        assert (cidr != null) : "Why the network cidr is null when it belongs to vpc?";
 -                        
 -                        if (NetUtils.isNetworkAWithinNetworkB(ntwk.getCidr(), cidr)
 -                                || NetUtils.isNetworkAWithinNetworkB(cidr, ntwk.getCidr())) {
 -                            throw new InvalidParameterValueException("Network cidr " + cidr + " crosses other network cidr " + ntwk +
 -                                    " belonging to the same vpc " + vpc);
 -                        }
 -                    }
 -                    
 -                    //4) vpc and network should belong to the same owner
 -                    if (vpc.getAccountId() != networkOwner.getId()) {
 -                        throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner "
 -                                + networkOwner);
 -                    }
 -                    
 -                    //5) network domain should be the same as VPC's
 -                    if (!networkDomain.equalsIgnoreCase(vpc.getNetworkDomain())) {
 -                        throw new InvalidParameterValueException("Network domain of the new network should match network" +
 -                        		" domain of vpc " + vpc);
 -                    }
 -                    
 -                    //6) gateway should never be equal to the cidr subnet
 -                    if (NetUtils.getCidrSubNet(cidr).equalsIgnoreCase(gateway)) {
 -                        throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr subnet value");
 -                    }
 -                } finally {
 -                    s_logger.debug("Releasing lock for " + locked);
 -                    _vpcDao.releaseFromLockTable(locked.getId());
 +                if (NetUtils.isNetworkAWithinNetworkB(ntwk.getCidr(), cidr)
 +                        || NetUtils.isNetworkAWithinNetworkB(cidr, ntwk.getCidr())) {
 +                    throw new InvalidParameterValueException("Network cidr " + cidr + " crosses other network cidr " + ntwk +
 +                            " belonging to the same vpc " + vpc);
                  }
              }
 +            
 +            //4) vpc and network should belong to the same owner
 +            if (vpc.getAccountId() != networkOwner.getId()) {
 +                throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner "
 +                        + networkOwner);
 +            }
 +            
 +            //5) network domain should be the same as VPC's
 +            if (!networkDomain.equalsIgnoreCase(vpc.getNetworkDomain())) {
 +                throw new InvalidParameterValueException("Network domain of the new network should match network" +
 +                		" domain of vpc " + vpc);
 +            }
 +            
 +            //6) gateway should never be equal to the cidr subnet
 +            if (NetUtils.getCidrSubNet(cidr).equalsIgnoreCase(gateway)) {
 +                throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr subnet value");
 +            }
- 
-             txn.commit();
 +        } finally {
 +            s_logger.debug("Releasing lock for " + locked);
 +            _vpcDao.releaseFromLockTable(locked.getId());
 +        }
 +    }
+         });
+     }
  
  
-     protected List<VpcProvider> getVpcElements() {
+     public List<VpcProvider> getVpcElements() {
          if (vpcElements == null) {
              vpcElements = new ArrayList<VpcProvider>();
              vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCVirtualRouter.getName()));
@@@ -1392,66 -1400,79 +1400,79 @@@
          if (physNet == null) {
              physNet = _entityMgr.findById(PhysicalNetwork.class,physicalNetworkId);
          }
-         Long dcId = physNet.getDataCenterId();
+         final Long dcId = physNet.getDataCenterId();
          
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
+         final Long physicalNetworkIdFinal = physicalNetworkId;
+         final PhysicalNetwork physNetFinal = physNet;
+         VpcGatewayVO gatewayVO = null;
+         try {
+             gatewayVO = Transaction.execute(new TransactionCallbackWithException<VpcGatewayVO,Exception>() {
+                 @Override
+                 public VpcGatewayVO doInTransaction(TransactionStatus status) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
 -                    s_logger.debug("Creating Private gateway for VPC " + vpc);
 -                    //1) create private network unless it is existing and lswitch'd
 -                    Network privateNtwk = null;
 -                    if (BroadcastDomainType.getSchemeValue(BroadcastDomainType.fromString(broadcastUri)) == BroadcastDomainType.Lswitch) {
 -                        String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
 -            
 -                        privateNtwk = _ntwkDao.getPrivateNetwork(broadcastUri, cidr,
 -                                gatewayOwnerId, dcId, networkOfferingId);
 -                        s_logger.info("found and using existing network for vpc " + vpc + ": " + broadcastUri);
 -                    }
 -                    if (privateNtwk == null) {
 -                        s_logger.info("creating new network for vpc " + vpc + " using broadcast uri: " + broadcastUri);
 -                        String networkName = "vpc-" + vpc.getName() + "-privateNetwork";
 +        s_logger.debug("Creating Private gateway for VPC " + vpc);
 +        //1) create private network unless it is existing and lswitch'd
 +        Network privateNtwk = null;
 +        if (BroadcastDomainType.getSchemeValue(BroadcastDomainType.fromString(broadcastUri)) == BroadcastDomainType.Lswitch) {
 +            String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
 +
 +            privateNtwk = _ntwkDao.getPrivateNetwork(broadcastUri, cidr,
 +                    gatewayOwnerId, dcId, networkOfferingId);
 +            s_logger.info("found and using existing network for vpc " + vpc + ": " + broadcastUri);
 +        }
 +        if (privateNtwk == null) {
 +            s_logger.info("creating new network for vpc " + vpc + " using broadcast uri: " + broadcastUri);
 +            String networkName = "vpc-" + vpc.getName() + "-privateNetwork";
-             privateNtwk = _ntwkSvc.createPrivateNetwork(networkName, networkName, physicalNetworkId, 
+                         privateNtwk = _ntwkSvc.createPrivateNetwork(networkName, networkName, physicalNetworkIdFinal, 
 -                            broadcastUri, ipAddress, null, gateway, netmask, gatewayOwnerId, vpcId, isSourceNat, networkOfferingId);
 -                    } else { // create the nic/ip as createPrivateNetwork doesn''t do that work for us now
 +                broadcastUri, ipAddress, null, gateway, netmask, gatewayOwnerId, vpcId, isSourceNat, networkOfferingId);
 +        } else { // create the nic/ip as createPrivateNetwork doesn''t do that work for us now
-             DataCenterVO dc = _dcDao.lockRow(physNet.getDataCenterId(), true);
+                         DataCenterVO dc = _dcDao.lockRow(physNetFinal.getDataCenterId(), true);
 -            
 -                        //add entry to private_ip_address table
 -                        PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkId(privateNtwk.getId(), ipAddress);
 -                        if (privateIp != null) {
 -                            throw new InvalidParameterValueException("Private ip address " + ipAddress + " already used for private gateway" +
 -                                    " in zone " + _entityMgr.findById(DataCenter.class,dcId).getName());
 -                        }
 -            
 -                        Long mac = dc.getMacAddress();
 -                        Long nextMac = mac + 1;
 -                        dc.setMacAddress(nextMac);
 -            
 -                        privateIp = new PrivateIpVO(ipAddress, privateNtwk.getId(), nextMac, vpcId, true);
 -                        _privateIpDao.persist(privateIp);
 -            
 -                        _dcDao.update(dc.getId(), dc);
 -                    }
 -            
 -                    long networkAclId = NetworkACL.DEFAULT_DENY;
 -                    if (aclId != null) {
 -                        NetworkACLVO aclVO = _networkAclDao.findById(aclId);
 -                        if ( aclVO == null) {
 -                            throw new InvalidParameterValueException("Invalid network acl id passed ");
 -                        }
 -                        if ((aclVO.getVpcId() != vpcId) && !(aclId == NetworkACL.DEFAULT_DENY || aclId == NetworkACL.DEFAULT_ALLOW)) {
 -                            throw new InvalidParameterValueException("Private gateway and network acl are not in the same vpc");
 -                        }
 -            
 -                        networkAclId = aclId;
 -                    }
 -            
 -                    //2) create gateway entry
 -                    VpcGatewayVO gatewayVO = new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(),
 -                            privateNtwk.getId(), broadcastUri, gateway, netmask, vpc.getAccountId(), vpc.getDomainId(), isSourceNat, networkAclId);
 -                    _vpcGatewayDao.persist(gatewayVO);
 -                    
 -                    s_logger.debug("Created vpc gateway entry " + gatewayVO);
 -                    
 +
 +            //add entry to private_ip_address table
 +            PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkId(privateNtwk.getId(), ipAddress);
 +            if (privateIp != null) {
 +                throw new InvalidParameterValueException("Private ip address " + ipAddress + " already used for private gateway" +
 +                        " in zone " + _entityMgr.findById(DataCenter.class,dcId).getName());
 +            }
 +
 +            Long mac = dc.getMacAddress();
 +            Long nextMac = mac + 1;
 +            dc.setMacAddress(nextMac);
 +
 +            privateIp = new PrivateIpVO(ipAddress, privateNtwk.getId(), nextMac, vpcId, true);
 +            _privateIpDao.persist(privateIp);
 +
 +            _dcDao.update(dc.getId(), dc);
 +        }
 +
 +        long networkAclId = NetworkACL.DEFAULT_DENY;
 +        if (aclId != null) {
 +            NetworkACLVO aclVO = _networkAclDao.findById(aclId);
 +            if ( aclVO == null) {
 +                throw new InvalidParameterValueException("Invalid network acl id passed ");
 +            }
 +            if ((aclVO.getVpcId() != vpcId) && !(aclId == NetworkACL.DEFAULT_DENY || aclId == NetworkACL.DEFAULT_ALLOW)) {
 +                throw new InvalidParameterValueException("Private gateway and network acl are not in the same vpc");
 +            }
 +
 +            networkAclId = aclId;
 +        }
 +
 +        //2) create gateway entry
 +        VpcGatewayVO gatewayVO = new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(),
 +                privateNtwk.getId(), broadcastUri, gateway, netmask, vpc.getAccountId(), vpc.getDomainId(), isSourceNat, networkAclId);
 +        _vpcGatewayDao.persist(gatewayVO);
 +        
 +        s_logger.debug("Created vpc gateway entry " + gatewayVO);
 +        
-         txn.commit();
+                     return gatewayVO;
+                 }
+             });
+         } catch (Exception e) {
+             ExceptionUtil.rethrowRuntime(e);
+             ExceptionUtil.rethrow(e, InsufficientCapacityException.class);
+             ExceptionUtil.rethrow(e, ResourceAllocationException.class);
+             throw new IllegalStateException(e);
+         }
          
          return getVpcPrivateGateway(gatewayVO.getId());
      }
@@@ -1509,18 -1528,22 +1528,22 @@@
          }
  
          try {
+             Transaction.execute(new TransactionCallbackNoReturn() {
+                 @Override
+                 public void doInTransactionWithoutResult(TransactionStatus status) {
 -                    //don't allow to remove gateway when there are static routes associated with it
 -                    long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId());
 -                    if (routeCount > 0) {
 -                        throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount +
 -                                " static routes applied. Remove the routes first");
 -                    }
 -
 -                    gatewayVO.setState(VpcGateway.State.Deleting);
 -                    _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
 -                    s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting);
 +            //don't allow to remove gateway when there are static routes associated with it
 +            long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId());
 +            if (routeCount > 0) {
 +                throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount +
 +                        " static routes applied. Remove the routes first");
 +            }
 +            
 +            gatewayVO.setState(VpcGateway.State.Deleting);
 +            _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
 +            s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting);
+                 }
+             });
 -
 +            
-             txn.commit();
  
              //1) delete the gateway on the backend
              PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
@@@ -1555,27 -1578,31 +1578,31 @@@
              deleteNetwork = false;
          }
          
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
-         
+         //TODO: Clean this up, its bad.  There is a DB transaction wrapping calls to NetworkElements (destroyNetwork will
+         // call network elements).
+         final boolean deleteNetworkFinal = deleteNetwork;
+         Transaction.execute(new TransactionCallbackNoReturn() {
+             @Override
+             public void doInTransactionWithoutResult(TransactionStatus status) {
 -                PrivateIpVO ip = _privateIpDao.findByIpAndVpcId(gateway.getVpcId(), gateway.getIp4Address());
 -                if (ip != null) {
 -                    _privateIpDao.remove(ip.getId());
 -                    s_logger.debug("Deleted private ip " + ip);
 -                }
 -                
 +        PrivateIpVO ip = _privateIpDao.findByIpAndVpcId(gateway.getVpcId(), gateway.getIp4Address());
 +        if (ip != null) {
 +            _privateIpDao.remove(ip.getId());
 +            s_logger.debug("Deleted private ip " + ip);
 +        }
 +        
-         if (deleteNetwork) {
+                 if (deleteNetworkFinal) {
 -                    User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
 -                    Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
 -                    ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
 -                    _ntwkMgr.destroyNetwork(networkId, context);
 -                    s_logger.debug("Deleted private network id=" + networkId);
 -                }
 -                
 -                _vpcGatewayDao.remove(gateway.getId());
 -                s_logger.debug("Deleted private gateway " + gateway);
 +            User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
 +            Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
 +            ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
 +            _ntwkMgr.destroyNetwork(networkId, context);
 +            s_logger.debug("Deleted private network id=" + networkId);
 +        }
 +        
 +        _vpcGatewayDao.remove(gateway.getId());
 +        s_logger.debug("Deleted private gateway " + gateway);
+             }
+         });
          
-         txn.commit();
          return true;
      }
  
@@@ -1740,12 -1767,14 +1767,14 @@@
          s_logger.debug("Found " + routes.size() + " to revoke for the vpc " + vpcId);
          if (!routes.isEmpty()) {
              //mark all of them as revoke
-             Transaction txn = Transaction.currentTxn();
-             txn.start();
+             Transaction.execute(new TransactionCallbackNoReturn() {
+                 @Override
+                 public void doInTransactionWithoutResult(TransactionStatus status) {
 -                    for (StaticRouteVO route : routes) {
 -                        markStaticRouteForRevoke(route, caller);
 -                    }
 +            for (StaticRouteVO route : routes) {
 +                markStaticRouteForRevoke(route, caller);
 +            }
-             txn.commit();
+                 }
+             });
              return applyStaticRoutes(vpcId);
          }
          
@@@ -1794,24 -1823,24 +1823,24 @@@
              throw new InvalidParameterValueException("The static gateway cidr overlaps with one of the blacklisted routes of the zone the VPC belongs to");
          }
  
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
-         
+         return Transaction.execute(new TransactionCallbackWithException<StaticRouteVO, NetworkRuleConflictException>() {
+             @Override
+             public StaticRouteVO doInTransaction(TransactionStatus status) throws NetworkRuleConflictException {
 -                StaticRouteVO newRoute = new StaticRouteVO(gateway.getId(), cidr, vpc.getId(), vpc.getAccountId(), vpc.getDomainId());
 -                s_logger.debug("Adding static route " + newRoute);
 -                newRoute = _staticRouteDao.persist(newRoute);
 -                
 -                detectRoutesConflict(newRoute);
 +        StaticRouteVO newRoute = new StaticRouteVO(gateway.getId(), cidr, vpc.getId(), vpc.getAccountId(), vpc.getDomainId());
 +        s_logger.debug("Adding static route " + newRoute);
 +        newRoute = _staticRouteDao.persist(newRoute);
          
 -                if (!_staticRouteDao.setStateToAdd(newRoute)) {
 -                    throw new CloudRuntimeException("Unable to update the state to add for " + newRoute);
 -                }
 -                CallContext.current().setEventDetails("Static route Id: " + newRoute.getId());
 -                
 -                return newRoute;
 -            }
 +        detectRoutesConflict(newRoute);
 +
 +        if (!_staticRouteDao.setStateToAdd(newRoute)) {
 +            throw new CloudRuntimeException("Unable to update the state to add for " + newRoute);
 +        }
 +        CallContext.current().setEventDetails("Static route Id: " + newRoute.getId());
 +        
-         txn.commit();
- 
 +        return newRoute;
 +    }
+         });
+     }
  
      protected boolean isCidrBlacklisted(String cidr, long zoneId) {
          String routesStr = NetworkOrchestrationService.GuestDomainSuffix.valueIn(zoneId);
@@@ -1952,17 -1981,19 +1981,19 @@@
                      return;
                  }
  
-                 Transaction txn = null;
                  try {
-                     txn = Transaction.open(Transaction.CLOUD_DB);
- 
+                     Transaction.execute(new TransactionCallbackWithExceptionNoReturn<Exception>() {
+                         @Override
+                         public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {
 -                            // Cleanup inactive VPCs
 -                            List<VpcVO> inactiveVpcs = _vpcDao.listInactiveVpcs();
 -                            s_logger.info("Found " + inactiveVpcs.size() + " removed VPCs to cleanup");
 -                            for (VpcVO vpc : inactiveVpcs) {
 -                                s_logger.debug("Cleaning up " + vpc);
 -                                destroyVpc(vpc, _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM);
 -                            }
 +                    // Cleanup inactive VPCs
 +                    List<VpcVO> inactiveVpcs = _vpcDao.listInactiveVpcs();
 +                    s_logger.info("Found " + inactiveVpcs.size() + " removed VPCs to cleanup");
 +                    for (VpcVO vpc : inactiveVpcs) {
 +                        s_logger.debug("Cleaning up " + vpc);
 +                        destroyVpc(vpc, _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM);
 +                    }
+                         }
+                     });
                  } catch (Exception e) {
                      s_logger.error("Exception ", e);
                  } finally {
@@@ -2010,17 -2038,20 +2038,20 @@@
  
          s_logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc);
  
-         Transaction txn = Transaction.currentTxn();
-         txn.start();
+         final boolean isSourceNatFinal = isSourceNat; 
+         Transaction.execute(new TransactionCallbackNoReturn() {
+             @Override
+             public void doInTransactionWithoutResult(TransactionStatus status) {
 -                IPAddressVO ip = _ipAddressDao.findById(ipId);
 -                //update ip address with networkId
 -                ip.setVpcId(vpcId);
 +        IPAddressVO ip = _ipAddressDao.findById(ipId);
 +        //update ip address with networkId
 +        ip.setVpcId(vpcId);
-         ip.setSourceNat(isSourceNat);
+                 ip.setSourceNat(isSourceNatFinal);
 -                _ipAddressDao.update(ipId, ip);
 +        _ipAddressDao.update(ipId, ip);
  
 -                //mark ip as allocated
 -                _ipAddrMgr.markPublicIpAsAllocated(ip);
 +        //mark ip as allocated
 +        _ipAddrMgr.markPublicIpAsAllocated(ip);
-         txn.commit();
+             }
+         });
  
          s_logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc);
  


Mime
View raw message