cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [31/50] [abbrv] git commit: updated refs/heads/disk-cache to 99d67cb
Date Mon, 02 Sep 2013 20:05:17 GMT
CLOUDSTACK-4023: lock the network during the shutdownNetwork (just the way we do when implement
network)

Conflicts:
	server/src/com/cloud/network/NetworkServiceImpl.java
	server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java


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

Branch: refs/heads/disk-cache
Commit: fc33d69b2ab7bf9aacf77335a0936987741e5539
Parents: b484666
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Fri Aug 2 13:15:07 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Fri Aug 2 13:20:47 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/network/NetworkManagerImpl.java   | 117 +++++++++++--------
 .../VirtualNetworkApplianceManagerImpl.java     |   2 +-
 2 files changed, 69 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fc33d69b/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index ea3d552..9cbe8f0 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -2679,68 +2679,87 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
     @DB
     public boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements)
{
         boolean result = false;
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-        NetworkVO network = _networksDao.lockRow(networkId, true);
-        if (network == null) {
-            s_logger.debug("Unable to find network with id: " + networkId);
-            return false;
-        }
-        if (network.getState() != Network.State.Implemented && network.getState()
!= Network.State.Shutdown) {
-            s_logger.debug("Network is not implemented: " + network);
-            return false;
-        }
+        NetworkVO network = null;
+        try {
+            //do global lock for the network
+            network = _networksDao.acquireInLockTable(networkId, getNetworkLockTimeout());
+            if (network == null) {
+                s_logger.warn("Unable to acquire lock for the network " + network + " as
a part of network shutdown");
+                return false;
+            }
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Lock is acquired for network " + network + " as a part of
network shutdown");
+            }
+            
+            if (network.getState() == Network.State.Allocated) {
+                s_logger.debug("Network is already shutdown: " + network);
+                return true;
+            }
+            
+            if (network.getState() != Network.State.Implemented && network.getState()
!= Network.State.Shutdown) {
+                s_logger.debug("Network is not implemented: " + network);
+                return false;
+            }
 
-        if (isSharedNetworkWithServices(network)) {
-            network.setState(Network.State.Shutdown);
-            _networksDao.update(network.getId(), network);
-        } else {
-            try {
-                stateTransitTo(network, Event.DestroyNetwork);
-            } catch (NoTransitionException e) {
+            if (isSharedNetworkWithServices(network)) {
                 network.setState(Network.State.Shutdown);
                 _networksDao.update(network.getId(), network);
+            } else {
+                try {
+                    stateTransitTo(network, Event.DestroyNetwork);
+                } catch (NoTransitionException e) {
+                    network.setState(Network.State.Shutdown);
+                    _networksDao.update(network.getId(), network);
+                }
             }
-        }
-        txn.commit();
 
-        boolean success = shutdownNetworkElementsAndResources(context, cleanupElements, network);
+            
+            boolean success = shutdownNetworkElementsAndResources(context, cleanupElements,
network);
 
-        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()));
+            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()));
 
-            applyProfileToNetwork(network, profile);
-            DataCenterVO zone = _dcDao.findById(network.getDataCenterId());
-            if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()) &&
(zone.getNetworkType() == NetworkType.Advanced)) {
-                network.setState(Network.State.Setup);
+                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);
+                    }
+                }
+                _networksDao.update(network.getId(), network);
+                _networksDao.clearCheckForGc(networkId);
+                result = true;
             } else {
                 try {
-                    stateTransitTo(network, Event.OperationSucceeded);
+                    stateTransitTo(network, Event.OperationFailed);
                 } catch (NoTransitionException e) {
-                    network.setState(Network.State.Allocated);
-                    network.setRestartRequired(false);
+                    network.setState(Network.State.Implemented);
+                    _networksDao.update(network.getId(), network);
                 }
+                result = false;
             }
-            _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);
+            txn.commit();
+            return result;
+        } finally {
+            if (network != null) {
+                _networksDao.releaseFromLockTable(network.getId());
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Lock is released for network " + network + " as a part
of network shutdown");
+                }
             }
-            result = false;
-        }
-        txn.commit();
-        return result;
+        } 
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fc33d69b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 92da4db..ef7b0e4 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -47,7 +47,6 @@ import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.context.ServerContexts;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
-
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.AgentManager.OnError;
 import com.cloud.agent.Listener;
@@ -255,6 +254,7 @@ import com.cloud.vm.dao.NicIpAliasVO;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
+
 /**
  * VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances
available in the Cloud Stack.
  */


Mime
View raw message