cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dar...@apache.org
Subject [33/47] New Transaction API
Date Wed, 23 Oct 2013 19:43:50 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f62e28c1/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java
index 8debe2e..65abae3 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java
@@ -54,7 +54,7 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.db.UpdateBuilder;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -336,7 +336,7 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
 
     @Override @DB
     public List<EngineHostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) {
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
         txn.start();
         SearchCriteria<EngineHostVO> sc = UnmanagedDirectConnectSearch.create();
         sc.setParameters("lastPinged", lastPingSecondsAfter);
@@ -356,7 +356,7 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
 
     @Override @DB
     public List<EngineHostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId) {
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
 
         txn.start();
         SearchCriteria<EngineHostVO> sc = UnmanagedApplianceSearch.create();
@@ -495,7 +495,7 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
     @DB
     @Override
     public List<EngineHostVO> findLostHosts(long timeout) {
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
         PreparedStatement pstmt = null;
         List<EngineHostVO> result = new ArrayList<EngineHostVO>();
         ResultSet rs = null;
@@ -546,7 +546,7 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
     public EngineHostVO persist(EngineHostVO host) {
         final String InsertSequenceSql = "INSERT INTO op_host(id) VALUES(?)";
 
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
         txn.start();
 
         EngineHostVO dbHost = super.persist(host);
@@ -572,7 +572,7 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
     @Override
     @DB
     public boolean update(Long hostId, EngineHostVO host) {
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
         txn.start();
 
         boolean persisted = super.update(hostId, host);
@@ -598,7 +598,7 @@ public class EngineHostDaoImpl extends GenericDaoBase<EngineHostVO, Long> implem
 
         ArrayList<RunningHostCountInfo> l = new ArrayList<RunningHostCountInfo>();
 
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
         ;
         PreparedStatement pstmt = null;
         try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f62e28c1/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java
index 7bf85d5..2bcfdd1 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java
@@ -41,7 +41,7 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.UpdateBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
 
 @Component(value="EngineHostPodDao")
 @Local(value={EngineHostPodDao.class})
@@ -97,7 +97,7 @@ public class EngineHostPodDaoImpl extends GenericDaoBase<EngineHostPodVO, Long>
 		HashMap<Long, List<Object>> currentPodCidrSubnets = new HashMap<Long, List<Object>>();
 
 		String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + zoneId +" and removed IS NULL";
-		Transaction txn = Transaction.currentTxn();
+		TransactionLegacy txn = TransactionLegacy.currentTxn();
 		try {
 		PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
 		ResultSet rs = stmt.executeQuery();
@@ -123,7 +123,7 @@ public class EngineHostPodDaoImpl extends GenericDaoBase<EngineHostPodVO, Long>
 
     @Override
     public boolean remove(Long id) {
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
         txn.start();
         EngineHostPodVO pod = createForUpdate();
         pod.setName(null);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f62e28c1/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
index e0ae778..e0a6dce 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java
@@ -31,7 +31,7 @@ import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 @Component(value="EngineHostDetailsDao")
@@ -96,7 +96,7 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
     public void persist(long hostId, Map<String, String> details) {
         final String InsertOrUpdateSql = "INSERT INTO `cloud`.`host_details` (host_id, name, value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE value=?";
 
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
         txn.start();
 
         for (Map.Entry<String, String> detail : details.entrySet()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f62e28c1/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
index a70b7d1..17d6f81 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java
@@ -27,7 +27,7 @@ import com.cloud.host.HostTagVO;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
 
 @Component(value="EngineHostTagsDao")
 @Local(value=HostTagsDao.class)
@@ -56,7 +56,7 @@ public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> implements
     
     @Override
     public void persist(long hostId, List<String> hostTags) {
-        Transaction txn = Transaction.currentTxn();
+        TransactionLegacy txn = TransactionLegacy.currentTxn();
 
         txn.start();
         SearchCriteria<HostTagVO> sc = HostSearch.create();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f62e28c1/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 3c4b1ed..7ba9b1b 100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -167,6 +167,10 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.EntityManager;
 import com.cloud.utils.db.GlobalLock;
+import com.cloud.utils.db.TransactionCallback;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionCallbackWithException;
+import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
@@ -346,7 +350,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
     @DB
     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
         // populate providers
-        Map<Network.Service, Set<Network.Provider>> defaultSharedNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
+        final Map<Network.Service, Set<Network.Provider>> defaultSharedNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
         Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
 
         defaultProviders.add(Network.Provider.VirtualRouter);
@@ -354,7 +358,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         defaultSharedNetworkOfferingProviders.put(Service.Dns, defaultProviders);
         defaultSharedNetworkOfferingProviders.put(Service.UserData, defaultProviders);
 
-        Map<Network.Service, Set<Network.Provider>> defaultIsolatedNetworkOfferingProviders = defaultSharedNetworkOfferingProviders;
+        final Map<Network.Service, Set<Network.Provider>> defaultIsolatedNetworkOfferingProviders = defaultSharedNetworkOfferingProviders;
         defaultIsolatedNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
         defaultIsolatedNetworkOfferingProviders.put(Service.Dns, defaultProviders);
         defaultIsolatedNetworkOfferingProviders.put(Service.UserData, defaultProviders);
@@ -365,7 +369,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         defaultIsolatedNetworkOfferingProviders.put(Service.PortForwarding, defaultProviders);
         defaultIsolatedNetworkOfferingProviders.put(Service.Vpn, defaultProviders);
 
-        Map<Network.Service, Set<Network.Provider>> defaultSharedSGEnabledNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
+        final Map<Network.Service, Set<Network.Provider>> defaultSharedSGEnabledNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
         defaultSharedSGEnabledNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
         defaultSharedSGEnabledNetworkOfferingProviders.put(Service.Dns, defaultProviders);
         defaultSharedSGEnabledNetworkOfferingProviders.put(Service.UserData, defaultProviders);
@@ -373,7 +377,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         sgProviders.add(Provider.SecurityGroupProvider);
         defaultSharedSGEnabledNetworkOfferingProviders.put(Service.SecurityGroup, sgProviders);
 
-        Map<Network.Service, Set<Network.Provider>> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
+        final Map<Network.Service, Set<Network.Provider>> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
         defaultProviders.clear();
         defaultProviders.add(Network.Provider.VirtualRouter);
         defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
@@ -387,7 +391,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.PortForwarding, defaultProviders);
         defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Vpn, defaultProviders);
 
-        Map<Network.Service, Set<Network.Provider>> defaultVPCOffProviders = new HashMap<Network.Service, Set<Network.Provider>>();
+        final Map<Network.Service, Set<Network.Provider>> defaultVPCOffProviders = new HashMap<Network.Service, Set<Network.Provider>>();
         defaultProviders.clear();
         defaultProviders.add(Network.Provider.VPCVirtualRouter);
         defaultVPCOffProviders.put(Service.Dhcp, defaultProviders);
@@ -401,133 +405,134 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         defaultVPCOffProviders.put(Service.PortForwarding, defaultProviders);
         defaultVPCOffProviders.put(Service.Vpn, defaultProviders);
 
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-
-        NetworkOfferingVO offering = null;
-        //#1 - quick cloud network offering
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.QuickCloudNoServices) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices, "Offering for QuickCloud with no services", TrafficType.Guest, null, true,
-                Availability.Optional, null, new HashMap<Network.Service, Set<Network.Provider>>(), true, Network.GuestType.Shared, false, null, true, null, true, false, null,
-                false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        //#2 - SG enabled network offering
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks",
-                TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true,
-                false, null, false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        //#3 - shared network offering with no SG service
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true,
-                Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        //#4 - default isolated offering with Source nat service
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
-                "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null,
-                defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false, false, null, false, null);
-
-            offering.setState(NetworkOffering.State.Enabled);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        //#5 - default vpc offering with LB service
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
-                "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Optional, null, defaultVPCOffProviders, true,
-                Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        //#6 - default vpc offering with no LB service
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB) == null) {
-            //remove LB service
-            defaultVPCOffProviders.remove(Service.Lb);
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB,
-                "Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest, null, false, Availability.Optional, null,
-                defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        //#7 - isolated offering with source nat disabled
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service",
-                TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null,
-                true, false, null, false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        //#8 - network offering with internal lb service
-        Map<Network.Service, Set<Network.Provider>> internalLbOffProviders = new HashMap<Network.Service, Set<Network.Provider>>();
-        Set<Network.Provider> defaultVpcProvider = new HashSet<Network.Provider>();
-        defaultVpcProvider.add(Network.Provider.VPCVirtualRouter);
-
-        Set<Network.Provider> defaultInternalLbProvider = new HashSet<Network.Provider>();
-        defaultInternalLbProvider.add(Network.Provider.InternalLbVm);
-
-        internalLbOffProviders.put(Service.Dhcp, defaultVpcProvider);
-        internalLbOffProviders.put(Service.Dns, defaultVpcProvider);
-        internalLbOffProviders.put(Service.UserData, defaultVpcProvider);
-        internalLbOffProviders.put(Service.NetworkACL, defaultVpcProvider);
-        internalLbOffProviders.put(Service.Gateway, defaultVpcProvider);
-        internalLbOffProviders.put(Service.Lb, defaultInternalLbProvider);
-        internalLbOffProviders.put(Service.SourceNat, defaultVpcProvider);
-
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB,
-                "Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, null, false, Availability.Optional, null, internalLbOffProviders, true,
-                Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            offering.setInternalLb(true);
-            offering.setPublicLb(false);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        Map<Network.Service, Set<Network.Provider>> netscalerServiceProviders = new HashMap<Network.Service, Set<Network.Provider>>();
-        Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
-        vrProvider.add(Provider.VirtualRouter);
-        Set<Network.Provider> sgProvider = new HashSet<Network.Provider>();
-        sgProvider.add(Provider.SecurityGroupProvider);
-        Set<Network.Provider> nsProvider = new HashSet<Network.Provider>();
-        nsProvider.add(Provider.Netscaler);
-        netscalerServiceProviders.put(Service.Dhcp, vrProvider);
-        netscalerServiceProviders.put(Service.Dns, vrProvider);
-        netscalerServiceProviders.put(Service.UserData, vrProvider);
-        netscalerServiceProviders.put(Service.SecurityGroup, sgProvider);
-        netscalerServiceProviders.put(Service.StaticNat, nsProvider);
-        netscalerServiceProviders.put(Service.Lb, nsProvider);
-
-        Map<Service, Map<Capability, String>> serviceCapabilityMap = new HashMap<Service, Map<Capability, String>>();
-        Map<Capability, String> elb = new HashMap<Capability, String>();
-        elb.put(Capability.ElasticLb, "true");
-        Map<Capability, String> eip = new HashMap<Capability, String>();
-        eip.put(Capability.ElasticIp, "true");
-        serviceCapabilityMap.put(Service.Lb, elb);
-        serviceCapabilityMap.put(Service.StaticNat, eip);
-
-        if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) {
-            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering,
-                "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, Availability.Optional, null, netscalerServiceProviders,
-                true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null);
-            offering.setState(NetworkOffering.State.Enabled);
-            offering.setDedicatedLB(false);
-            _networkOfferingDao.update(offering.getId(), offering);
-        }
-
-        txn.commit();
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
+            public void doInTransactionWithoutResult(TransactionStatus status) {
+                NetworkOfferingVO offering = null;
+                //#1 - quick cloud network offering
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.QuickCloudNoServices) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices, "Offering for QuickCloud with no services", TrafficType.Guest, null, true,
+                        Availability.Optional, null, new HashMap<Network.Service, Set<Network.Provider>>(), true, Network.GuestType.Shared, false, null, true, null, true, false, null,
+                        false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                //#2 - SG enabled network offering
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks",
+                        TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true,
+                        false, null, false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                //#3 - shared network offering with no SG service
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true,
+                        Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                //#4 - default isolated offering with Source nat service
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
+                        "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null,
+                        defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false, false, null, false, null);
+        
+                    offering.setState(NetworkOffering.State.Enabled);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                //#5 - default vpc offering with LB service
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
+                        "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Optional, null, defaultVPCOffProviders, true,
+                        Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                //#6 - default vpc offering with no LB service
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB) == null) {
+                    //remove LB service
+                    defaultVPCOffProviders.remove(Service.Lb);
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB,
+                        "Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest, null, false, Availability.Optional, null,
+                        defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                //#7 - isolated offering with source nat disabled
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service",
+                        TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null,
+                        true, false, null, false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                //#8 - network offering with internal lb service
+                Map<Network.Service, Set<Network.Provider>> internalLbOffProviders = new HashMap<Network.Service, Set<Network.Provider>>();
+                Set<Network.Provider> defaultVpcProvider = new HashSet<Network.Provider>();
+                defaultVpcProvider.add(Network.Provider.VPCVirtualRouter);
+        
+                Set<Network.Provider> defaultInternalLbProvider = new HashSet<Network.Provider>();
+                defaultInternalLbProvider.add(Network.Provider.InternalLbVm);
+        
+                internalLbOffProviders.put(Service.Dhcp, defaultVpcProvider);
+                internalLbOffProviders.put(Service.Dns, defaultVpcProvider);
+                internalLbOffProviders.put(Service.UserData, defaultVpcProvider);
+                internalLbOffProviders.put(Service.NetworkACL, defaultVpcProvider);
+                internalLbOffProviders.put(Service.Gateway, defaultVpcProvider);
+                internalLbOffProviders.put(Service.Lb, defaultInternalLbProvider);
+                internalLbOffProviders.put(Service.SourceNat, defaultVpcProvider);
+        
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB,
+                        "Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, null, false, Availability.Optional, null, internalLbOffProviders, true,
+                        Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    offering.setInternalLb(true);
+                    offering.setPublicLb(false);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+        
+                Map<Network.Service, Set<Network.Provider>> netscalerServiceProviders = new HashMap<Network.Service, Set<Network.Provider>>();
+                Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
+                vrProvider.add(Provider.VirtualRouter);
+                Set<Network.Provider> sgProvider = new HashSet<Network.Provider>();
+                sgProvider.add(Provider.SecurityGroupProvider);
+                Set<Network.Provider> nsProvider = new HashSet<Network.Provider>();
+                nsProvider.add(Provider.Netscaler);
+                netscalerServiceProviders.put(Service.Dhcp, vrProvider);
+                netscalerServiceProviders.put(Service.Dns, vrProvider);
+                netscalerServiceProviders.put(Service.UserData, vrProvider);
+                netscalerServiceProviders.put(Service.SecurityGroup, sgProvider);
+                netscalerServiceProviders.put(Service.StaticNat, nsProvider);
+                netscalerServiceProviders.put(Service.Lb, nsProvider);
+        
+                Map<Service, Map<Capability, String>> serviceCapabilityMap = new HashMap<Service, Map<Capability, String>>();
+                Map<Capability, String> elb = new HashMap<Capability, String>();
+                elb.put(Capability.ElasticLb, "true");
+                Map<Capability, String> eip = new HashMap<Capability, String>();
+                eip.put(Capability.ElasticIp, "true");
+                serviceCapabilityMap.put(Service.Lb, elb);
+                serviceCapabilityMap.put(Service.StaticNat, eip);
+        
+                if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) {
+                    offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering,
+                        "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, Availability.Optional, null, netscalerServiceProviders,
+                        true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null);
+                    offering.setState(NetworkOffering.State.Enabled);
+                    offering.setDedicatedLB(false);
+                    _networkOfferingDao.update(offering.getId(), offering);
+                }
+            }
+        });
+
 
         AssignIpAddressSearch = _ipAddressDao.createSearchBuilder();
         AssignIpAddressSearch.and("dc", AssignIpAddressSearch.entity().getDataCenterId(), Op.EQ);
@@ -590,8 +595,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
 
     @Override
     @DB
-    public List<? extends Network> setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan plan, String name, String displayText,
-        boolean errorIfAlreadySetup, Long domainId, ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException {
+    public List<? extends Network> setupNetwork(final Account owner, final NetworkOffering offering, final Network predefined, final DeploymentPlan plan, final String name, final String displayText,
+        boolean errorIfAlreadySetup, final Long domainId, final ACLType aclType, final Boolean subdomainAccess, final Long vpcId, final Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException {
 
         Account locked = _accountDao.acquireInLockTable(owner.getId());
         if (locked == null) {
@@ -622,12 +627,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
                 }
             }
 
-            List<NetworkVO> networks = new ArrayList<NetworkVO>();
+            final List<NetworkVO> networks = new ArrayList<NetworkVO>();
 
             long related = -1;
 
-            for (NetworkGuru guru : _networkGurus) {
-                Network network = guru.design(offering, plan, predefined, owner);
+            for (final NetworkGuru guru : _networkGurus) {
+                final Network network = guru.design(offering, plan, predefined, owner);
                 if (network == null) {
                     continue;
                 }
@@ -641,28 +646,26 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
                     continue;
                 }
 
-                long id = _networksDao.getNextInSequence(Long.class, "id");
+                final long id = _networksDao.getNextInSequence(Long.class, "id");
                 if (related == -1) {
                     related = id;
                 }
 
-                Transaction txn = Transaction.currentTxn();
-                txn.start();
-
-                NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText,
-                    predefined.getNetworkDomain(), offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId);
-                vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled);
-                networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
-                    finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
-
-                if (domainId != null && aclType == ACLType.Domain) {
-                    if (subdomainAccess == null) {
-                        subdomainAccess = true;
+                final long relatedFile = related;
+                Transaction.execute(new TransactionCallbackNoReturn() {
+                    @Override
+                    public void doInTransactionWithoutResult(TransactionStatus status) {
+                        NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), relatedFile, name, displayText,
+                            predefined.getNetworkDomain(), offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId);
+                        vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled);
+                        networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
+                            finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
+        
+                        if (domainId != null && aclType == ACLType.Domain) {
+                            _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess);
+                        }
                     }
-                    _networksDao.addDomainToNetwork(id, domainId, subdomainAccess);
-                }
-
-                txn.commit();
+                });
             }
 
             if (networks.size() < 1) {
@@ -681,73 +684,76 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
 
     @Override
     @DB
-    public void allocate(VirtualMachineProfile vm, LinkedHashMap<? extends Network, ? extends NicProfile> networks) throws InsufficientCapacityException,
+    public void allocate(final VirtualMachineProfile vm, final LinkedHashMap<? extends Network, ? extends NicProfile> networks) throws InsufficientCapacityException,
         ConcurrentOperationException {
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-
-        int deviceId = 0;
-
-        boolean[] deviceIds = new boolean[networks.size()];
-        Arrays.fill(deviceIds, false);
-
-        List<NicProfile> nics = new ArrayList<NicProfile>(networks.size());
-        NicProfile defaultNic = null;
-
-        for (Map.Entry<? extends Network, ? extends NicProfile> network : networks.entrySet()) {
-            Network config = network.getKey();
-            NicProfile requested = network.getValue();
-
-            Boolean isDefaultNic = false;
-            if (vm != null && (requested != null && requested.isDefaultNic())) {
-                isDefaultNic = true;
-            }
-
-            while (deviceIds[deviceId] && deviceId < deviceIds.length) {
-                deviceId++;
-            }
 
-            Pair<NicProfile, Integer> vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm);
-
-            NicProfile vmNic = vmNicPair.first();
-            if (vmNic == null) {
-                continue;
-            }
-
-            deviceId = vmNicPair.second();
-
-            int devId = vmNic.getDeviceId();
-            if (devId > deviceIds.length) {
-                throw new IllegalArgumentException("Device id for nic is too large: " + vmNic);
-            }
-            if (deviceIds[devId]) {
-                throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic);
-            }
-
-            deviceIds[devId] = true;
-
-            if (vmNic.isDefaultNic()) {
-                if (defaultNic != null) {
-                    throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic);
+        Transaction.executeWithException(new TransactionCallbackWithException<Object>() {
+            @Override
+            public Object doInTransaction(TransactionStatus status) throws InsufficientCapacityException {
+                int deviceId = 0;
+        
+                boolean[] deviceIds = new boolean[networks.size()];
+                Arrays.fill(deviceIds, false);
+        
+                List<NicProfile> nics = new ArrayList<NicProfile>(networks.size());
+                NicProfile defaultNic = null;
+        
+                for (Map.Entry<? extends Network, ? extends NicProfile> network : networks.entrySet()) {
+                    Network config = network.getKey();
+                    NicProfile requested = network.getValue();
+        
+                    Boolean isDefaultNic = false;
+                    if (vm != null && (requested != null && requested.isDefaultNic())) {
+                        isDefaultNic = true;
+                    }
+        
+                    while (deviceIds[deviceId] && deviceId < deviceIds.length) {
+                        deviceId++;
+                    }
+        
+                    Pair<NicProfile, Integer> vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm);
+        
+                    NicProfile vmNic = vmNicPair.first();
+                    if (vmNic == null) {
+                        continue;
+                    }
+        
+                    deviceId = vmNicPair.second();
+        
+                    int devId = vmNic.getDeviceId();
+                    if (devId > deviceIds.length) {
+                        throw new IllegalArgumentException("Device id for nic is too large: " + vmNic);
+                    }
+                    if (deviceIds[devId]) {
+                        throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic);
+                    }
+        
+                    deviceIds[devId] = true;
+        
+                    if (vmNic.isDefaultNic()) {
+                        if (defaultNic != null) {
+                            throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic);
+                        }
+                        defaultNic = vmNic;
+                    }
+        
+                    nics.add(vmNic);
+                    vm.addNic(vmNic);
+        
                 }
-                defaultNic = vmNic;
+        
+                if (nics.size() != networks.size()) {
+                    s_logger.warn("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size());
+                    throw new CloudRuntimeException("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size());
+                }
+        
+                if (nics.size() == 1) {
+                    nics.get(0).setDefaultNic(true);
+                }
+                
+                return null;
             }
-
-            nics.add(vmNic);
-            vm.addNic(vmNic);
-
-        }
-
-        if (nics.size() != networks.size()) {
-            s_logger.warn("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size());
-            throw new CloudRuntimeException("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size());
-        }
-
-        if (nics.size() == 1) {
-            nics.get(0).setDefaultNic(true);
-        }
-
-        txn.commit();
+        }, InsufficientCapacityException.class);
     }
 
     @DB
@@ -900,7 +906,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
     @DB
     public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
         ResourceUnavailableException, InsufficientCapacityException {
-        Transaction.currentTxn();
         Pair<NetworkGuru, NetworkVO> implemented = new Pair<NetworkGuru, NetworkVO>(null, null);
 
         NetworkVO network = _networksDao.findById(networkId);
@@ -1176,22 +1181,23 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
     }
 
     @DB
-    protected void updateNic(NicVO nic, long networkId, int count) {
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-        _nicDao.update(nic.getId(), nic);
-
-        if (nic.getVmType() == VirtualMachine.Type.User) {
-            s_logger.debug("Changing active number of nics for network id=" + networkId + " on " + count);
-            _networksDao.changeActiveNicsBy(networkId, count);
-        }
-
-        if (nic.getVmType() == VirtualMachine.Type.User ||
-            (nic.getVmType() == VirtualMachine.Type.DomainRouter && _networksDao.findById(networkId).getTrafficType() == TrafficType.Guest)) {
-            _networksDao.setCheckForGc(networkId);
-        }
-
-        txn.commit();
+    protected void updateNic(final NicVO nic, final long networkId, final int count) {
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
+            public void doInTransactionWithoutResult(TransactionStatus status) {
+                _nicDao.update(nic.getId(), nic);
+        
+                if (nic.getVmType() == VirtualMachine.Type.User) {
+                    s_logger.debug("Changing active number of nics for network id=" + networkId + " on " + count);
+                    _networksDao.changeActiveNicsBy(networkId, count);
+                }
+        
+                if (nic.getVmType() == VirtualMachine.Type.User ||
+                    (nic.getVmType() == VirtualMachine.Type.DomainRouter && _networksDao.findById(networkId).getTrafficType() == TrafficType.Guest)) {
+                    _networksDao.setCheckForGc(networkId);
+                }
+            }
+        });
     }
 
     @Override
@@ -1414,59 +1420,63 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
     }
 
     @DB
-    protected void releaseNic(VirtualMachineProfile vmProfile, long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
-        //lock the nic
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-
-        NicVO nic = _nicDao.lockRow(nicId, true);
-        if (nic == null) {
-            throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
-        }
+    protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
+        Pair<Network,NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<Pair<Network,NicProfile>>() {
+            @Override
+            public Pair<Network,NicProfile> doInTransaction(TransactionStatus status) {
+                NicVO nic = _nicDao.lockRow(nicId, true);
+                if (nic == null) {
+                    throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
+                }
 
-        Nic.State originalState = nic.getState();
-        NetworkVO network = _networksDao.findById(nic.getNetworkId());
+                Nic.State originalState = nic.getState();
+                NetworkVO network = _networksDao.findById(nic.getNetworkId());
 
-        if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
-            if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
-                NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
-                nic.setState(Nic.State.Releasing);
-                _nicDao.update(nic.getId(), nic);
-                NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network),
-                    _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
-                if (guru.release(profile, vmProfile, nic.getReservationId())) {
-                    applyProfileToNicForRelease(nic, profile);
-                    nic.setState(Nic.State.Allocated);
-                    if (originalState == Nic.State.Reserved) {
-                        updateNic(nic, network.getId(), -1);
-                    } else {
+                if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
+                    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
+                        NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
+                        nic.setState(Nic.State.Releasing);
                         _nicDao.update(nic.getId(), nic);
+                        NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network),
+                            _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
+                        if (guru.release(profile, vmProfile, nic.getReservationId())) {
+                            applyProfileToNicForRelease(nic, profile);
+                            nic.setState(Nic.State.Allocated);
+                            if (originalState == Nic.State.Reserved) {
+                                updateNic(nic, network.getId(), -1);
+                            } else {
+                                _nicDao.update(nic.getId(), nic);
+                            }
+                        }
+                        // Perform release on network elements
+                        return new Pair<Network,NicProfile>(network, profile);
+                    } else {
+                        nic.setState(Nic.State.Allocated);
+                        updateNic(nic, network.getId(), -1);
                     }
                 }
-                //commit the transaction before proceeding releasing nic profile on the network elements
-                txn.commit();
 
-                // Perform release on network elements
-                List<Provider> providersToImplement = getNetworkProviders(network.getId());
-                for (NetworkElement element : _networkElements) {
-                    if (providersToImplement.contains(element.getProvider())) {
-                        if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
-                            throw new CloudRuntimeException("Service provider " + element.getProvider().getName() +
-                                                            " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
-                        }
-                        if (s_logger.isDebugEnabled()) {
-                            s_logger.debug("Asking " + element.getName() + " to release " + nic);
-                        }
-                        //NOTE: Context appear to never be used in release method
-                        //implementations. Consider removing it from interface Element
-                        element.release(network, profile, vmProfile, null);
+                return null;
+            }
+        });
+
+        if (networkToRelease != null) {
+            Network network = networkToRelease.first();
+            NicProfile profile = networkToRelease.second();
+            List<Provider> providersToImplement = getNetworkProviders(network.getId());
+            for (NetworkElement element : _networkElements) {
+                if (providersToImplement.contains(element.getProvider())) {
+                    if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
+                        throw new CloudRuntimeException("Service provider " + element.getProvider().getName() +
+                                                        " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
                     }
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Asking " + element.getName() + " to release " + profile);
+                    }
+                    //NOTE: Context appear to never be used in release method
+                    //implementations. Consider removing it from interface Element
+                    element.release(network, profile, vmProfile, null);
                 }
-
-            } else {
-                nic.setState(Nic.State.Allocated);
-                updateNic(nic, network.getId(), -1);
-                txn.commit();
             }
         }
     }
@@ -1563,15 +1573,17 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         Network network = _networksDao.findById(nic.getNetworkId());
         DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
         try {
-            NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(nic.getGateway(), network.getId(), NicIpAlias.state.active);
+            final NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(nic.getGateway(), network.getId(), NicIpAlias.state.active);
             if (ipAlias != null) {
                 ipAlias.setState(NicIpAlias.state.revoked);
-                Transaction txn = Transaction.currentTxn();
-                txn.start();
-                _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
-                IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address());
-                _publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId());
-                txn.commit();
+                Transaction.execute(new TransactionCallbackNoReturn() {
+                    @Override
+                    public void doInTransactionWithoutResult(TransactionStatus status) {
+                    _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
+                    IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address());
+                    _publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId());
+                    }
+                });
                 if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) {
                     s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address());
                 }
@@ -1593,18 +1605,18 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
 
     @Override
     @DB
-    public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner,
-        Long domainId, PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr,
-        Boolean isDisplayNetworkEnabled, String isolatedPvlan) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
+    public Network createGuestNetwork(long networkOfferingId, final String name, final String displayText, final String gateway, final String cidr, String vlanId, String networkDomain, final Account owner,
+        final Long domainId, final PhysicalNetwork pNtwk, final long zoneId, final ACLType aclType, Boolean subdomainAccess, final Long vpcId, final String ip6Gateway, final String ip6Cidr,
+        final Boolean isDisplayNetworkEnabled, final String isolatedPvlan) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
 
-        NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
+        final NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
         // this method supports only guest network creation
         if (ntwkOff.getTrafficType() != TrafficType.Guest) {
             s_logger.warn("Only guest networks can be created using this method");
             return null;
         }
 
-        boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, aclType);
+        final boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, aclType);
         //check resource limits
         if (updateResourceCount) {
             _resourceLimitMgr.checkResourceLimit(owner, ResourceType.network);
@@ -1632,7 +1644,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
             ipv6 = true;
         }
         // Validate zone
-        DataCenterVO zone = _dcDao.findById(zoneId);
+        final DataCenterVO zone = _dcDao.findById(zoneId);
         if (zone.getNetworkType() == NetworkType.Basic) {
             if (ipv6) {
                 throw new InvalidParameterValueException("IPv6 is not supported in Basic zone");
@@ -1819,79 +1831,84 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
             }
         }
 
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-
-        Long physicalNetworkId = null;
-        if (pNtwk != null) {
-            physicalNetworkId = pNtwk.getId();
-        }
-        DataCenterDeployment plan = new DataCenterDeployment(zoneId, null, null, null, null, physicalNetworkId);
-        NetworkVO userNetwork = new NetworkVO();
-        userNetwork.setNetworkDomain(networkDomain);
-
-        if (cidr != null && gateway != null) {
-            userNetwork.setCidr(cidr);
-            userNetwork.setGateway(gateway);
-        }
-
-        if (ip6Cidr != null && ip6Gateway != null) {
-            userNetwork.setIp6Cidr(ip6Cidr);
-            userNetwork.setIp6Gateway(ip6Gateway);
-        }
-
-        if (vlanId != null) {
-        	if (isolatedPvlan == null) {
-                URI uri = BroadcastDomainType.fromString(vlanId);
-                userNetwork.setBroadcastUri(uri);
-        		if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
-        			userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
-        		} else {
-        			userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
-        		}
-        	} else {
-        		if (vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
-        			throw new InvalidParameterValueException("Cannot support pvlan with untagged primary vlan!");
-        		}
-        		userNetwork.setBroadcastUri(NetUtils.generateUriForPvlan(vlanId, isolatedPvlan));
-        		userNetwork.setBroadcastDomainType(BroadcastDomainType.Pvlan);
-        	}
-        }
+        final String networkDomainFinal = networkDomain;
+        final String vlanIdFinal = vlanId;
+        final Boolean subdomainAccessFinal = subdomainAccess;
+        Network network = Transaction.execute(new TransactionCallback<Network>() {
+            @Override
+            public Network doInTransaction(TransactionStatus status) {
+                Long physicalNetworkId = null;
+                if (pNtwk != null) {
+                    physicalNetworkId = pNtwk.getId();
+                }
+                DataCenterDeployment plan = new DataCenterDeployment(zoneId, null, null, null, null, physicalNetworkId);
+                NetworkVO userNetwork = new NetworkVO();
+                userNetwork.setNetworkDomain(networkDomainFinal);
         
-        List<? extends Network> networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, aclType, subdomainAccess, vpcId,
-            isDisplayNetworkEnabled);
-
-        Network network = null;
-        if (networks == null || networks.isEmpty()) {
-            throw new CloudRuntimeException("Fail to create a network");
-        } else {
-            if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && networks.get(0).getTrafficType() == TrafficType.Guest) {
-                Network defaultGuestNetwork = networks.get(0);
-                for (Network nw : networks) {
-                    if (nw.getCidr() != null && nw.getCidr().equals(zone.getGuestNetworkCidr())) {
-                        defaultGuestNetwork = nw;
+                if (cidr != null && gateway != null) {
+                    userNetwork.setCidr(cidr);
+                    userNetwork.setGateway(gateway);
+                }
+        
+                if (ip6Cidr != null && ip6Gateway != null) {
+                    userNetwork.setIp6Cidr(ip6Cidr);
+                    userNetwork.setIp6Gateway(ip6Gateway);
+                }
+        
+                if (vlanIdFinal != null) {
+                	if (isolatedPvlan == null) {
+                        URI uri = BroadcastDomainType.fromString(vlanIdFinal);
+                        userNetwork.setBroadcastUri(uri);
+                		if (!vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) {
+                			userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
+                		} else {
+                			userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
+                		}
+                	} else {
+                		if (vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) {
+                			throw new InvalidParameterValueException("Cannot support pvlan with untagged primary vlan!");
+                		}
+                		userNetwork.setBroadcastUri(NetUtils.generateUriForPvlan(vlanIdFinal, isolatedPvlan));
+                		userNetwork.setBroadcastDomainType(BroadcastDomainType.Pvlan);
+                	}
+                }
+                
+                List<? extends Network> networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, aclType, subdomainAccessFinal, vpcId,
+                    isDisplayNetworkEnabled);
+        
+                Network network = null;
+                if (networks == null || networks.isEmpty()) {
+                    throw new CloudRuntimeException("Fail to create a network");
+                } else {
+                    if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && networks.get(0).getTrafficType() == TrafficType.Guest) {
+                        Network defaultGuestNetwork = networks.get(0);
+                        for (Network nw : networks) {
+                            if (nw.getCidr() != null && nw.getCidr().equals(zone.getGuestNetworkCidr())) {
+                                defaultGuestNetwork = nw;
+                            }
+                        }
+                        network = defaultGuestNetwork;
+                    } else {
+                        // For shared network
+                        network = networks.get(0);
                     }
                 }
-                network = defaultGuestNetwork;
-            } else {
-                // For shared network
-                network = networks.get(0);
+        
+                if (updateResourceCount) {
+                    _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network);
+                }
+                
+                return network;
             }
-        }
-
-        if (updateResourceCount) {
-            _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network);
-        }
+        });
 
-        txn.commit();
         CallContext.current().setEventDetails("Network Id: " + network.getId());
         return network;
     }
 
     @Override
     @DB
-    public boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements) {
-        boolean result = false;
+    public boolean shutdownNetwork(final long networkId, ReservationContext context, boolean cleanupElements) {
         NetworkVO network = _networksDao.findById(networkId);
         if (network.getState() == Network.State.Allocated) {
             s_logger.debug("Network is already shutdown: " + network);
@@ -1936,43 +1953,51 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
                 }
             }
 
-            boolean success = shutdownNetworkElementsAndResources(context, cleanupElements, network);
+            final boolean success = shutdownNetworkElementsAndResources(context, cleanupElements, network);
 
-            Transaction txn = Transaction.currentTxn();
-            txn.start();
-            if (success) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
-                }
-                NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
-                NetworkProfile profile = convertNetworkToNetworkProfile(network.getId());
-                guru.shutdown(profile, _networkOfferingDao.findById(network.getNetworkOfferingId()));
+            final NetworkVO networkFinal = network;
+            boolean result = Transaction.execute(new TransactionCallback<Boolean>() {
+                @Override
+                public Boolean doInTransaction(TransactionStatus status) {
+                    boolean result = false;
 
-                applyProfileToNetwork(network, profile);
-                DataCenterVO zone = _dcDao.findById(network.getDataCenterId());
-                if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()) && (zone.getNetworkType() == NetworkType.Advanced)) {
-                    network.setState(Network.State.Setup);
-                } else {
-                    try {
-                        stateTransitTo(network, Event.OperationSucceeded);
-                    } catch (NoTransitionException e) {
-                        network.setState(Network.State.Allocated);
-                        network.setRestartRequired(false);
+                    if (success) {
+                        if (s_logger.isDebugEnabled()) {
+                            s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
+                        }
+                        NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, networkFinal.getGuruName());
+                        NetworkProfile profile = convertNetworkToNetworkProfile(networkFinal.getId());
+                        guru.shutdown(profile, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
+        
+                        applyProfileToNetwork(networkFinal, profile);
+                        DataCenterVO zone = _dcDao.findById(networkFinal.getDataCenterId());
+                        if (isSharedNetworkOfferingWithServices(networkFinal.getNetworkOfferingId()) && (zone.getNetworkType() == NetworkType.Advanced)) {
+                            networkFinal.setState(Network.State.Setup);
+                        } else {
+                            try {
+                                stateTransitTo(networkFinal, Event.OperationSucceeded);
+                            } catch (NoTransitionException e) {
+                                networkFinal.setState(Network.State.Allocated);
+                                networkFinal.setRestartRequired(false);
+                            }
+                        }
+                        _networksDao.update(networkFinal.getId(), networkFinal);
+                        _networksDao.clearCheckForGc(networkId);
+                        result = true;
+                    } else {
+                        try {
+                            stateTransitTo(networkFinal, Event.OperationFailed);
+                        } catch (NoTransitionException e) {
+                            networkFinal.setState(Network.State.Implemented);
+                            _networksDao.update(networkFinal.getId(), networkFinal);
+                        }
+                        result = false;
                     }
+
+                    return result;
                 }
-                _networksDao.update(network.getId(), network);
-                _networksDao.clearCheckForGc(networkId);
-                result = true;
-            } else {
-                try {
-                    stateTransitTo(network, Event.OperationFailed);
-                } catch (NoTransitionException e) {
-                    network.setState(Network.State.Implemented);
-                    _networksDao.update(network.getId(), network);
-                }
-                result = false;
-            }
-            txn.commit();
+            });
+
             return result;
         } finally {
             if (network != null) {
@@ -2036,8 +2061,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
 
     @Override
     @DB
-    public boolean destroyNetwork(long networkId, ReservationContext context) {
-        Account callerAccount = context.getAccount();
+    public boolean destroyNetwork(long networkId, final ReservationContext context) {
+        final Account callerAccount = context.getAccount();
 
         NetworkVO network = _networksDao.findById(networkId);
         if (network == null) {
@@ -2126,38 +2151,48 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now.");
             }
-            NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
-
-            Transaction txn = Transaction.currentTxn();
-            txn.start();
-            guru.trash(network, _networkOfferingDao.findById(network.getNetworkOfferingId()));
 
-            if (!deleteVlansInNetwork(network.getId(), context.getCaller().getId(), callerAccount)) {
-                success = false;
-                s_logger.warn("Failed to delete network " + network + "; was unable to cleanup corresponding ip ranges");
-            } else {
-                // commit transaction only when ips and vlans for the network are released successfully
-                try {
-                    stateTransitTo(network, Event.DestroyNetwork);
-                } catch (NoTransitionException e) {
-                    s_logger.debug(e.getMessage());
-                }
-                if (_networksDao.remove(network.getId())) {
-                    NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(network.getId());
-                    if (networkDomain != null)
-                        _networkDomainDao.remove(networkDomain.getId());
-
-                    NetworkAccountVO networkAccount = _networkAccountDao.getAccountNetworkMapByNetworkId(network.getId());
-                    if (networkAccount != null)
-                        _networkAccountDao.remove(networkAccount.getId());
-                }
-
-                NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
-                boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, network.getAclType());
-                if (updateResourceCount) {
-                    _resourceLimitMgr.decrementResourceCount(network.getAccountId(), ResourceType.network);
-                }
-                txn.commit();
+            final NetworkVO networkFinal = network;
+            try {
+                Transaction.execute(new TransactionCallbackNoReturn() {
+                    @Override
+                    public void doInTransactionWithoutResult(TransactionStatus status) {
+                        NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, networkFinal.getGuruName());
+    
+                        guru.trash(networkFinal, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
+    
+                        if (!deleteVlansInNetwork(networkFinal.getId(), context.getCaller().getId(), callerAccount)) {
+                            s_logger.warn("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
+                            throw new CloudRuntimeException("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges");
+                        } else {
+                            // commit transaction only when ips and vlans for the network are released successfully
+                            try {
+                                stateTransitTo(networkFinal, Event.DestroyNetwork);
+                            } catch (NoTransitionException e) {
+                                s_logger.debug(e.getMessage());
+                            }
+                            if (_networksDao.remove(networkFinal.getId())) {
+                                NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(networkFinal.getId());
+                                if (networkDomain != null)
+                                    _networkDomainDao.remove(networkDomain.getId());
+    
+                                NetworkAccountVO networkAccount = _networkAccountDao.getAccountNetworkMapByNetworkId(networkFinal.getId());
+                                if (networkAccount != null)
+                                    _networkAccountDao.remove(networkAccount.getId());
+                            }
+    
+                            NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, networkFinal.getNetworkOfferingId());
+                            boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, networkFinal.getAclType());
+                            if (updateResourceCount) {
+                                _resourceLimitMgr.decrementResourceCount(networkFinal.getAccountId(), ResourceType.network);
+                            }
+                        }
+                    }
+                });
+                return false;
+            } catch ( CloudRuntimeException e ) {
+                s_logger.error("Failed to delete network", e);
+                return false;
             }
         }
 
@@ -2426,24 +2461,24 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
 
     @DB
     @Override
-    public boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException {
+    public boolean reallocate(final VirtualMachineProfile vm, DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException {
         VMInstanceVO vmInstance = _vmDao.findById(vm.getId());
         DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId());
         if (dc.getNetworkType() == NetworkType.Basic) {
             List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
             NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
-            LinkedHashMap<Network, NicProfile> profiles = new LinkedHashMap<Network, NicProfile>();
+            final LinkedHashMap<Network, NicProfile> profiles = new LinkedHashMap<Network, NicProfile>();
             profiles.put(network, null);
 
-            Transaction txn = Transaction.currentTxn();
-            txn.start();
+            Transaction.executeWithException(new TransactionCallbackWithException<Object>() {
+                @Override
+                public Object doInTransaction(TransactionStatus status) throws Exception {
+                    cleanupNics(vm);
+                    allocate(vm, profiles);
 
-            try {
-                cleanupNics(vm);
-                allocate(vm, profiles);
-            } finally {
-                txn.commit();
-            }
+                    return null;
+                }
+            }, InsufficientCapacityException.class);
         }
         return true;
     }
@@ -3050,17 +3085,20 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         return nic.getSecondaryIp();
     }
 
-    private boolean removeVmSecondaryIpsOfNic(long nicId) {
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-        List<NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId);
-        if (ipList != null) {
-            for (NicSecondaryIpVO ip : ipList) {
-                _nicSecondaryIpDao.remove(ip.getId());
+    private boolean removeVmSecondaryIpsOfNic(final long nicId) {
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
+            public void doInTransactionWithoutResult(TransactionStatus status) {
+                List<NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId);
+                if (ipList != null) {
+                    for (NicSecondaryIpVO ip : ipList) {
+                        _nicSecondaryIpDao.remove(ip.getId());
+                    }
+                    s_logger.debug("Revoving nic secondary ip entry ...");
+                }
             }
-            s_logger.debug("Revoving nic secondary ip entry ...");
-        }
-        txn.commit();
+        });
+
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f62e28c1/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
index 0817393..7d81232 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
@@ -31,7 +31,6 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@ -97,6 +96,9 @@ import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.EntityManager;
 import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallback;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.utils.fsm.StateMachine2;
@@ -681,9 +683,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
     }
 
     @DB
-    protected VolumeVO switchVolume(VolumeVO existingVolume, VirtualMachineProfile vm) throws StorageUnavailableException {
-        Transaction txn = Transaction.currentTxn();
-
+    protected VolumeVO switchVolume(final VolumeVO existingVolume, final VirtualMachineProfile vm) throws StorageUnavailableException {
         Long templateIdToUse = null;
         Long volTemplateId = existingVolume.getTemplateId();
         long vmTemplateId = vm.getTemplateId();
@@ -695,22 +695,26 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
             templateIdToUse = vmTemplateId;
         }
 
-        txn.start();
-        VolumeVO newVolume = allocateDuplicateVolumeVO(existingVolume, templateIdToUse);
-        // In case of Vmware if vm reference is not removed then during root
-        // disk cleanup
-        // the vm also gets deleted, so remove the reference
-        if (vm.getHypervisorType() == HypervisorType.VMware) {
-            _volsDao.detachVolume(existingVolume.getId());
-        }
-        try {
-            stateTransitTo(existingVolume, Volume.Event.DestroyRequested);
-        } catch (NoTransitionException e) {
-            s_logger.debug("Unable to destroy existing volume: " + e.toString());
-        }
-        txn.commit();
-        return newVolume;
-
+        final Long templateIdToUseFinal = templateIdToUse; 
+        return Transaction.execute(new TransactionCallback<VolumeVO>() {
+            @Override
+            public VolumeVO doInTransaction(TransactionStatus status) {
+                VolumeVO newVolume = allocateDuplicateVolumeVO(existingVolume, templateIdToUseFinal);
+                // In case of Vmware if vm reference is not removed then during root
+                // disk cleanup
+                // the vm also gets deleted, so remove the reference
+                if (vm.getHypervisorType() == HypervisorType.VMware) {
+                    _volsDao.detachVolume(existingVolume.getId());
+                }
+                try {
+                    stateTransitTo(existingVolume, Volume.Event.DestroyRequested);
+                } catch (NoTransitionException e) {
+                    s_logger.debug("Unable to destroy existing volume: " + e.toString());
+                }
+                
+                return newVolume;
+            }
+        });
     }
 
     @Override
@@ -724,28 +728,32 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Cleaning storage for vm: " + vmId);
         }
-        List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId);
-        List<VolumeVO> toBeExpunged = new ArrayList<VolumeVO>();
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-        for (VolumeVO vol : volumesForVm) {
-            if (vol.getVolumeType().equals(Type.ROOT)) {
-                // Destroy volume if not already destroyed
-                boolean volumeAlreadyDestroyed = (vol.getState() == Volume.State.Destroy || vol.getState() == Volume.State.Expunged || vol.getState() == Volume.State.Expunging);
-                if (!volumeAlreadyDestroyed) {
-                    volService.destroyVolume(vol.getId());
-                } else {
-                    s_logger.debug("Skipping destroy for the volume " + vol + " as its in state " + vol.getState().toString());
-                }
-                toBeExpunged.add(vol);
-            } else {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Detaching " + vol);
+        final List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId);
+        final List<VolumeVO> toBeExpunged = new ArrayList<VolumeVO>();
+
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
+            public void doInTransactionWithoutResult(TransactionStatus status) {
+                for (VolumeVO vol : volumesForVm) {
+                    if (vol.getVolumeType().equals(Type.ROOT)) {
+                        // Destroy volume if not already destroyed
+                        boolean volumeAlreadyDestroyed = (vol.getState() == Volume.State.Destroy || vol.getState() == Volume.State.Expunged || vol.getState() == Volume.State.Expunging);
+                        if (!volumeAlreadyDestroyed) {
+                            volService.destroyVolume(vol.getId());
+                        } else {
+                            s_logger.debug("Skipping destroy for the volume " + vol + " as its in state " + vol.getState().toString());
+                        }
+                        toBeExpunged.add(vol);
+                    } else {
+                        if (s_logger.isDebugEnabled()) {
+                            s_logger.debug("Detaching " + vol);
+                        }
+                        _volsDao.detachVolume(vol.getId());
+                    }
                 }
-                _volsDao.detachVolume(vol.getId());
             }
-        }
-        txn.commit();
+        });
+
         AsyncCallFuture<VolumeApiResult> future = null;
         for (VolumeVO expunge : toBeExpunged) {
             future = volService.expungeVolumeAsync(volFactory.getVolume(expunge.getId()));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f62e28c1/engine/schema/src/com/cloud/alert/dao/AlertDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/alert/dao/AlertDaoImpl.java b/engine/schema/src/com/cloud/alert/dao/AlertDaoImpl.java
index 7c0a562..57102cb 100755
--- a/engine/schema/src/com/cloud/alert/dao/AlertDaoImpl.java
+++ b/engine/schema/src/com/cloud/alert/dao/AlertDaoImpl.java
@@ -29,7 +29,7 @@ import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
 
 @Component
 @Local(value = { AlertDao.class })
@@ -116,7 +116,7 @@ public class AlertDaoImpl extends GenericDaoBase<AlertVO, Long> implements Alert
             return result;
         }
         if (alerts != null && !alerts.isEmpty()) {
-            Transaction txn = Transaction.currentTxn();
+            TransactionLegacy txn = TransactionLegacy.currentTxn();
             txn.start();
             for (AlertVO alert : alerts) {
                 alert = lockRow(alert.getId(), true);


Mime
View raw message