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

This commit is contained in:
Alena Prokharchyk 2012-07-10 17:03:05 -07:00
parent 663ba8c898
commit 954b937a42
5 changed files with 22 additions and 54 deletions

View File

@ -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;

View File

@ -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<? extends VMInstanceVO> 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<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri)
void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic)
throws ConcurrentOperationException, ResourceUnavailableException;

View File

@ -2263,42 +2263,23 @@ 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 = 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<? 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) {

View File

@ -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<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 {
@ -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;
}

View File

@ -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<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
public void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
// TODO Auto-generated method stub
return null;
}