You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/07/11 03:08:25 UTC

[2/2] git commit: VPC: unplugNic - release the nic in the DB only after the command is executed succesfully on the backend

VPC: unplugNic - release the nic in the DB only after the command is executed succesfully on the backend

Conflicts:

	api/src/com/cloud/agent/api/routing/SetStaticRouteCommand.java
	server/src/com/cloud/network/NetworkManagerImpl.java
	server/test/com/cloud/network/MockNetworkManagerImpl.java


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

Branch: refs/heads/vpc
Commit: 697aa4589bc4e9b402db979ba8cb3dceee284b38
Parents: f59b935
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Tue Jul 10 17:03:05 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Tue Jul 10 18:07:09 2012 -0700

----------------------------------------------------------------------
 server/src/com/cloud/network/NetworkManager.java   |   18 +-------
 .../src/com/cloud/network/NetworkManagerImpl.java  |   29 +++----------
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   21 +++++----
 .../com/cloud/network/MockNetworkManagerImpl.java  |   32 +++++----------
 4 files changed, 31 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/697aa458/server/src/com/cloud/network/NetworkManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java
index 0e62439..f3a448b 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -16,7 +16,6 @@
 // under the License.
 package com.cloud.network;
 
-import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -388,17 +387,6 @@ public interface NetworkManager extends NetworkService {
 
 
     /**
-     * @param vmProfile
-     * @param network
-     * @return TODO
-     * @throws ConcurrentOperationException
-     * @throws ResourceUnavailableException
-     */
-    NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network) 
-            throws ConcurrentOperationException, ResourceUnavailableException;
-
-
-    /**
      * @param vm
      * @param network
      */
@@ -446,13 +434,11 @@ public interface NetworkManager extends NetworkService {
 
     /**
      * @param vmProfile
-     * @param network
-     * @param broadcastUri
-     * @return
+     * @param nic TODO
      * @throws ConcurrentOperationException
      * @throws ResourceUnavailableException
      */
-    NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri) 
+    void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic) 
             throws ConcurrentOperationException, ResourceUnavailableException;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/697aa458/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 c310919..76b3465 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -2264,37 +2264,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
     		ConcurrentOperationException, ResourceUnavailableException {
         List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
         for (NicVO nic : nics) {
-            NetworkVO network = _networksDao.findById(nic.getNetworkId());
-            releaseNic(vmProfile, nic, network);
+            releaseNic(vmProfile, nic);
         }
     }
-    
-    @Override
-    public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network) 
-            throws ConcurrentOperationException, ResourceUnavailableException {
-        NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vmProfile.getId());
-        releaseNic(vmProfile, nic, network);
-        
-        NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, 
-                isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
-        return profile;
-    }
-    
-    
     @Override
-    public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri) 
+    public void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic) 
             throws ConcurrentOperationException, ResourceUnavailableException {
-        NicVO nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vmProfile.getId(), broadcastUri.toString());
-        releaseNic(vmProfile, nic, network);
-        
-        NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, 
-                isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
-        return profile;
+        NicVO nicVO = _nicDao.findById(nic.getId());
+        releaseNic(vmProfile, nicVO);
     }
 
 
-    protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic, NetworkVO network) 
+    protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic) 
             throws ConcurrentOperationException, ResourceUnavailableException {
+        NetworkVO network = _networksDao.findById(nic.getNetworkId());
         if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
             Nic.State originalState = nic.getState();
             if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/697aa458/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index da2790d..2e75e72 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -2493,7 +2493,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
     @Override
     public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
         VMInstanceVO vmVO = _vmDao.findById(vm.getId());
-        NetworkVO networkVO = _networkDao.findById(network.getId());
         ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), 
                 _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
         
@@ -2503,20 +2502,20 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
         DataCenter dc = _configMgr.getZone(network.getDataCenterId());
         Host host = _hostDao.findById(vm.getHostId()); 
         DeployDestination dest = new DeployDestination(dc, null, null, host);
-        
-        //1) Release the nic
-        NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO, broadcastUri);
-        
-        //2) Convert vmProfile to vmTO
         VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
         HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
         VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
         
-        NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
+        Nic nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
+        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 
+                _networkMgr.getNetworkRate(network.getId(), vm.getId()), 
+                _networkMgr.isSecurityGroupSupportedInNetwork(network), 
+                _networkMgr.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
         
+        //1) Unplug the nic
+        NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
         s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network);
         boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest);
-        //4) Unplug the nic
         if (result) {
             s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network );
         } else {
@@ -2524,7 +2523,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
             return false;
         }
         
-        //6) Remove the nic
+        //2) Release the nic
+        _networkMgr.releaseNic(vmProfile, nic);
+        s_logger.debug("Successfully released nic " + nic +  "for vm " + vm);
+        
+        //3) Remove the nic
         _networkMgr.removeNic(vmProfile, network);
         return result;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/697aa458/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index e245a9a..f8a657c 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -16,7 +16,6 @@
 // under the License.
 package com.cloud.network;
 
-import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -805,15 +804,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
     }
 
     /* (non-Javadoc)
-     * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.NetworkVO)
-     */
-    @Override
-    public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /* (non-Javadoc)
      * @see com.cloud.network.NetworkManager#removeNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network)
      */
     @Override
@@ -962,8 +952,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
      * @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String)
      */
     @Override
-    public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
-            InsufficientAddressCapacityException {
+    public void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
         // TODO Auto-generated method stub
         
     }
@@ -1067,15 +1056,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
     }
 
     /* (non-Javadoc)
-     * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.NetworkVO, java.net.URI)
-     */
-    @Override
-    public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /* (non-Javadoc)
      * @see com.cloud.network.NetworkManager#getPhysicalNtwksSupportingTrafficType(long, com.cloud.network.Networks.TrafficType)
      */
     @Override
@@ -1139,4 +1119,14 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
         // TODO Auto-generated method stub
         return null;
     }
+
+    /* (non-Javadoc)
+     * @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String)
+     */
+    @Override
+    public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
+            InsufficientAddressCapacityException {
+        // TODO Auto-generated method stub
+        
+    }
 }