From 954b937a42556824d917b0f2d1c9e59ae7370322 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 10 Jul 2012 17:03:05 -0700 Subject: [PATCH] VPC: unplugNic - release the nic in the DB only after the command is executed succesfully on the backend --- .../api/routing/SetStaticRouteCommand.java | 1 - .../src/com/cloud/network/NetworkManager.java | 18 ++-------- .../com/cloud/network/NetworkManagerImpl.java | 33 ++++--------------- .../cloud/vm/VirtualMachineManagerImpl.java | 21 +++++++----- .../cloud/network/MockNetworkManagerImpl.java | 3 +- 5 files changed, 22 insertions(+), 54 deletions(-) diff --git a/api/src/com/cloud/agent/api/routing/SetStaticRouteCommand.java b/api/src/com/cloud/agent/api/routing/SetStaticRouteCommand.java index 4f335af7fdd..561ab37a3fa 100644 --- a/api/src/com/cloud/agent/api/routing/SetStaticRouteCommand.java +++ b/api/src/com/cloud/agent/api/routing/SetStaticRouteCommand.java @@ -16,7 +16,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import com.cloud.agent.api.to.NetworkACLTO; import com.cloud.network.vpc.StaticRoute; import com.cloud.network.vpc.StaticRouteProfile; diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 78fb983a38a..3d450a9ac45 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -12,7 +12,6 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network; -import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -379,17 +378,6 @@ public interface NetworkManager extends NetworkService { InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - /** - * @param vmProfile - * @param network - * @return TODO - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ - NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) - throws ConcurrentOperationException, ResourceUnavailableException; - - /** * @param vm * @param network @@ -438,13 +426,11 @@ public interface NetworkManager extends NetworkService { /** * @param vmProfile - * @param network - * @param broadcastUri - * @return + * @param nic TODO * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network, URI broadcastUri) + void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException; diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 9f7bf2bc450..37824af84e7 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2263,42 +2263,23 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag ConcurrentOperationException, ResourceUnavailableException { List 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 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 vmProfile, NetworkVO network, URI broadcastUri) + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { - NicVO nic = null; - if (broadcastUri != null) { - nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vmProfile.getId(), broadcastUri.toString()); - } else { - 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; + + NicVO nicVO = _nicDao.findById(nic.getId()); + releaseNic(vmProfile, nicVO); } - protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nic, NetworkVO network) + protected void releaseNic(VirtualMachineProfile 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) { diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index ff059bce65b..51aacbd72d3 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2494,7 +2494,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)); @@ -2504,20 +2503,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 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 { @@ -2525,7 +2524,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; } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 7ce527f9f69..2b94ee7733f 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -12,7 +12,6 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network; -import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -991,7 +990,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.NetworkVO, java.net.URI) */ @Override - public NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException { + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub return null; }