cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/4.2 to 8fe4c24
Date Fri, 02 Aug 2013 20:29:12 GMT
Updated Branches:
  refs/heads/4.2 922f902b3 -> 8fe4c240b


CLOUDSTACK-4023: lock the network during the shutdownNetwork (just the way we do when implement
network)


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

Branch: refs/heads/4.2
Commit: 8fe4c240bf25063491c44c55015a24bd19f831fd
Parents: 922f902
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:15:07 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/network/NetworkManagerImpl.java   | 117 +++++++++++--------
 .../com/cloud/network/NetworkServiceImpl.java   |  20 +---
 .../VirtualNetworkApplianceManagerImpl.java     |  58 +++++----
 3 files changed, 98 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8fe4c240/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 b5a1ca7..effee96 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -2756,68 +2756,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/8fe4c240/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 90368be..739f5cc 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -18,8 +18,6 @@ package com.cloud.network;
 
 import java.net.Inet6Address;
 import java.net.InetAddress;
-import java.net.InetAddress;
-import java.net.Inet6Address;
 import java.net.UnknownHostException;
 import java.security.InvalidParameterException;
 import java.sql.PreparedStatement;
@@ -41,19 +39,11 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import com.cloud.network.vpc.dao.VpcDao;
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
-import org.apache.cloudstack.acl.SecurityChecker;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
 import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
 import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
-import org.apache.cloudstack.api.command.user.network.*;
-import com.cloud.network.vpc.NetworkACL;
-import com.cloud.network.vpc.dao.NetworkACLDao;
-import org.apache.cloudstack.acl.ControlledEntity.ACLType;
-import org.apache.cloudstack.acl.SecurityChecker.AccessType;
-import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
 import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
 import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
 import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
@@ -62,11 +52,6 @@ import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-import org.apache.cloudstack.api.command.user.vm.ListNicsCmd;
-import org.bouncycastle.util.IPAddress;
-
 import com.cloud.api.ApiDBUtils;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
@@ -133,13 +118,15 @@ import com.cloud.network.element.VpcVirtualRouterElement;
 import com.cloud.network.guru.NetworkGuru;
 import com.cloud.network.rules.FirewallRule.Purpose;
 import com.cloud.network.rules.FirewallRuleVO;
-import com.cloud.network.rules.PortForwardingRuleVO;
 import com.cloud.network.rules.RulesManager;
 import com.cloud.network.rules.dao.PortForwardingRulesDao;
+import com.cloud.network.vpc.NetworkACL;
 import com.cloud.network.vpc.PrivateIpVO;
 import com.cloud.network.vpc.Vpc;
 import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.dao.NetworkACLDao;
 import com.cloud.network.vpc.dao.PrivateIpDao;
+import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.NetworkOfferingVO;
 import com.cloud.offerings.dao.NetworkOfferingDao;
@@ -160,7 +147,6 @@ import com.cloud.user.UserContext;
 import com.cloud.user.UserVO;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.UserDao;
-import com.cloud.utils.AnnotationHelper;
 import com.cloud.utils.Journal;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8fe4c240/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 7a1a05b..a143c0c 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -17,6 +17,33 @@
 
 package com.cloud.network.router;
 
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.AgentManager.OnError;
 import com.cloud.agent.Listener;
@@ -146,8 +173,6 @@ import com.cloud.network.dao.Site2SiteVpnGatewayDao;
 import com.cloud.network.dao.UserIpv6AddressDao;
 import com.cloud.network.dao.VirtualRouterProviderDao;
 import com.cloud.network.dao.VpnUserDao;
-import com.cloud.network.guru.NetworkGuru;
-import com.cloud.network.guru.PublicNetworkGuru;
 import com.cloud.network.lb.LoadBalancingRule;
 import com.cloud.network.lb.LoadBalancingRule.LbDestination;
 import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
@@ -171,10 +196,8 @@ import com.cloud.offerings.NetworkOfferingVO;
 import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.resource.ResourceManager;
 import com.cloud.server.ConfigurationServer;
-import com.cloud.server.ManagementServer;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.storage.GuestOSVO;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.Volume.Type;
 import com.cloud.storage.VolumeVO;
@@ -196,7 +219,6 @@ import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.PasswordGenerator;
 import com.cloud.utils.StringUtils;
-import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
@@ -233,32 +255,6 @@ import com.cloud.vm.dao.NicIpAliasVO;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
-import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TimeZone;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
 
 /**
  * VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances
available in the Cloud Stack.


Mime
View raw message