mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 6689: release source nat ip address as a part of domR/dhcp destroy
status 6689: resolved fixed Changes to destroyNetwork process. Here are the steps: * shutdown network - shutdowns all network elements (domRs/Dhcps) * delete network - destroy all network elements, cleanup network's resources (vlans, ip ranges), mark network with Destroyed state and set Removed field
This commit is contained in:
parent
23cf2e048a
commit
632d3c67f1
@ -119,7 +119,9 @@ public interface Network extends ControlledEntity {
|
||||
Setup("Indicates the network configuration is setup"),
|
||||
Implementing("Indicates the network configuration is being implemented"),
|
||||
Implemented("Indicates the network configuration is in use"),
|
||||
Destroying("Indicates the network configuration is being destroyed");
|
||||
Shutdown("Indicates the network configuration is being destroyed"),
|
||||
Destroy("Indicates that the network is destroyed");
|
||||
|
||||
|
||||
@Override
|
||||
public StateMachine<State, Event> getStateMachine() {
|
||||
@ -156,10 +158,10 @@ public interface Network extends ControlledEntity {
|
||||
static {
|
||||
s_fsm.addTransition(State.Allocated, Event.ImplementNetwork, State.Implementing);
|
||||
s_fsm.addTransition(State.Implementing, Event.OperationSucceeded, State.Implemented);
|
||||
s_fsm.addTransition(State.Implementing, Event.OperationFailed, State.Destroying);
|
||||
s_fsm.addTransition(State.Implemented, Event.DestroyNetwork, State.Destroying);
|
||||
s_fsm.addTransition(State.Destroying, Event.OperationSucceeded, State.Allocated);
|
||||
s_fsm.addTransition(State.Destroying, Event.OperationFailed, State.Implemented);
|
||||
s_fsm.addTransition(State.Implementing, Event.OperationFailed, State.Shutdown);
|
||||
s_fsm.addTransition(State.Implemented, Event.DestroyNetwork, State.Shutdown);
|
||||
s_fsm.addTransition(State.Shutdown, Event.OperationSucceeded, State.Allocated);
|
||||
s_fsm.addTransition(State.Shutdown, Event.OperationFailed, State.Implemented);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
|
||||
public interface VirtualNetworkApplianceService {
|
||||
public interface VirtualNetworkApplianceService{
|
||||
/**
|
||||
* Starts domain router
|
||||
* @param cmd the command specifying router's id
|
||||
|
||||
@ -77,7 +77,16 @@ public interface NetworkElement extends Adapter {
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean shutdown(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The network is being destroyed.
|
||||
* @param network
|
||||
* @return
|
||||
* @throws ConcurrentOperationException
|
||||
*/
|
||||
boolean destroy(Network network) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
|
||||
/**
|
||||
* Apply ip addresses to this network
|
||||
|
||||
@ -148,5 +148,7 @@ public interface AccountService {
|
||||
Account getActiveAccount(Long accountId);
|
||||
|
||||
Account getAccount(Long accountId);
|
||||
|
||||
User getActiveUser(long userId);
|
||||
|
||||
}
|
||||
|
||||
@ -146,6 +146,8 @@ public interface NetworkManager extends NetworkService {
|
||||
|
||||
<T extends VMInstanceVO> void prepareNicForMigration(VirtualMachineProfile<T> vm, DeployDestination dest);
|
||||
|
||||
void resetBroadcastUri(long networkId);
|
||||
void shutdownNetwork(long networkId);
|
||||
|
||||
boolean destroyNetwork(long networkId, long callerUserId);
|
||||
|
||||
}
|
||||
|
||||
@ -104,6 +104,7 @@ import com.cloud.resource.Resource.ReservationStrategy;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.UserStatisticsVO;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
@ -1009,7 +1010,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
try {
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
Network.State state = network.getState();
|
||||
if (state == Network.State.Implemented || state == Network.State.Setup) {
|
||||
if (state == Network.State.Implemented || state == Network.State.Setup || state == Network.State.Implementing) {
|
||||
implemented.set(guru, network);
|
||||
return implemented;
|
||||
}
|
||||
@ -1019,6 +1020,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
}
|
||||
|
||||
NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
|
||||
network.setReservationId(context.getReservationId());
|
||||
network.setState(Network.State.Implementing);
|
||||
|
||||
_networksDao.update(networkId, network);
|
||||
@ -1038,8 +1040,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
}
|
||||
element.implement(network, offering, dest, context);
|
||||
}
|
||||
|
||||
network.setReservationId(context.getReservationId());
|
||||
|
||||
network.setState(Network.State.Implemented);
|
||||
_networksDao.update(network.getId(), network);
|
||||
implemented.set(guru, network);
|
||||
@ -1599,10 +1600,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
throw new InvalidParameterValueException("unable to find network " + networkId);
|
||||
}
|
||||
|
||||
Long ownerId = network.getAccountId();
|
||||
Long zoneId = network.getDataCenterId();
|
||||
String name = network.getName();
|
||||
|
||||
//Perform permission check
|
||||
if (!_accountMgr.isAdmin(caller.getType())) {
|
||||
if (network.getAccountId() != caller.getId()) {
|
||||
@ -1613,50 +1610,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
_accountMgr.checkAccess(caller, owner);
|
||||
}
|
||||
|
||||
//Don't allow to remove network if there are non-destroyed vms using it
|
||||
List<NicVO> nics = _nicDao.listByNetworkId(networkId);
|
||||
for (NicVO nic : nics) {
|
||||
UserVm vm = _vmDao.findById(nic.getId());
|
||||
if (vm != null && (vm.getState() != State.Destroyed || vm.getState() != State.Expunging || vm.getState() != State.Error)) {
|
||||
throw new CloudRuntimeException("Can't delete a network; make sure that all vms using the network are destroyed");
|
||||
}
|
||||
}
|
||||
|
||||
//remove all the vlans associated with the network
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
txn.start();
|
||||
//remove corresponding vlans
|
||||
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
|
||||
for (VlanVO vlan : vlans) {
|
||||
boolean result = _configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId());
|
||||
if (result == false) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to delete a network: failed to delete corresponding vlan with id " + vlan.getId());
|
||||
}
|
||||
}
|
||||
|
||||
//remove networks
|
||||
_networksDao.remove(networkId);
|
||||
|
||||
txn.commit();
|
||||
|
||||
String eventMsg = "Successfully deleted network " + name + " (id=" + networkId + ")";
|
||||
_configMgr.saveConfigurationEvent(userId, ownerId, EventTypes.EVENT_NETWORK_DELETE, eventMsg, "id=" + networkId, "dcId=" + zoneId, "accountId=" + ownerId);
|
||||
|
||||
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
s_logger.warn("Unexpected exception during deleting a network ", ex);
|
||||
return false;
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
|
||||
return this.destroyNetwork(networkId, userId);
|
||||
}
|
||||
|
||||
@DB
|
||||
@Override @DB
|
||||
public void shutdownNetwork(long networkId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
@ -1665,11 +1622,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
s_logger.debug("Unable to find network with id: " + networkId);
|
||||
return;
|
||||
}
|
||||
if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Destroying) {
|
||||
if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
|
||||
s_logger.debug("Network is not implemented: " + network);
|
||||
return;
|
||||
}
|
||||
network.setState(Network.State.Destroying);
|
||||
network.setState(Network.State.Shutdown);
|
||||
_networksDao.update(network.getId(), network);
|
||||
txn.commit();
|
||||
|
||||
@ -1697,8 +1654,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
|
||||
}
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
guru.destroy(network, _networkOfferingDao.findById(network.getNetworkOfferingId()));
|
||||
network.setBroadcastUri(null);
|
||||
network.setState(Network.State.Allocated);
|
||||
_networksDao.update(network.getId(), network);
|
||||
_networksDao.clearCheckForGc(networkId);
|
||||
@ -1707,8 +1665,84 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
_networksDao.update(network.getId(), network);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
@DB @Override
|
||||
public boolean destroyNetwork(long networkId, long callerUserId) {
|
||||
NetworkVO network = _networksDao.findById(networkId);
|
||||
if (network == null) {
|
||||
s_logger.debug("Unable to find network with id: " + networkId);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Shutdown network first
|
||||
shutdownNetwork(networkId);
|
||||
|
||||
//get updated state for the network
|
||||
network = _networksDao.findById(networkId);
|
||||
if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup) {
|
||||
s_logger.debug("Network is not not in the correct state to be destroyed: " + network.getState());
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean success = true;
|
||||
for (NetworkElement element : _networkElements) {
|
||||
try {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Sending destroy to " + element);
|
||||
}
|
||||
element.destroy(network);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
|
||||
success = false;
|
||||
} catch (ConcurrentOperationException e) {
|
||||
s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
|
||||
success = false;
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now.");
|
||||
}
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
Account owner = _accountMgr.getAccount(network.getAccountId());
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
guru.trash(network, _networkOfferingDao.findById(network.getNetworkOfferingId()), owner);
|
||||
if (!deleteVlansInNetwork(network.getId(), callerUserId)) {
|
||||
success = false;
|
||||
s_logger.warn("Failed to delete network " + network + "; was unable to cleanup corresponding ip ranges");
|
||||
} else {
|
||||
//commit transaction only when ips and vlans for the network are released successfully
|
||||
network.setState(Network.State.Destroy);
|
||||
_networksDao.update(network.getId(), network);
|
||||
_networksDao.remove(network.getId());
|
||||
txn.commit();
|
||||
String eventMsg = "Successfully deleted network " + network.getName() + " (id=" + networkId + ")";
|
||||
_configMgr.saveConfigurationEvent(callerUserId, network.getAccountId(), EventTypes.EVENT_NETWORK_DELETE, eventMsg, "id=" + networkId, "dcId=" + network.getDataCenterId(), "accountId=" + network.getAccountId());
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
private boolean deleteVlansInNetwork(long networkId, long userId) {
|
||||
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
|
||||
boolean result = true;
|
||||
for (VlanVO vlan : vlans) {
|
||||
if (!_configMgr.deleteVlanAndPublicIpRange(_accountMgr.getSystemUser().getId(), vlan.getId())) {
|
||||
s_logger.warn("Failed to delete vlan " + vlan.getId() + ");");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1941,12 +1975,5 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBroadcastUri(long networkId) {
|
||||
NetworkVO network = _networksDao.findById(networkId);
|
||||
network.setBroadcastUri(null);
|
||||
_networksDao.update(networkId, network);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -121,7 +121,16 @@ public class DhcpElement extends AdapterBase implements NetworkElement{
|
||||
if (router == null) {
|
||||
return true;
|
||||
}
|
||||
return _routerMgr.stopRouterInternal(router.getId());
|
||||
return (_routerMgr.stopRouter(router.getId()) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
DomainRouterVO router = _routerDao.findByNetworkConfiguration(config.getId());
|
||||
if (router == null) {
|
||||
return true;
|
||||
}
|
||||
return _routerMgr.destroyRouter(router.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -55,6 +55,7 @@ import com.cloud.network.rules.FirewallRule.Purpose;
|
||||
import com.cloud.network.vpn.RemoteAccessVpnElement;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.Inject;
|
||||
@ -86,6 +87,7 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement,
|
||||
@Inject DomainRouterDao _routerDao;
|
||||
@Inject DataCenterDao _dataCenterDao;
|
||||
@Inject LoadBalancerDao _lbDao;
|
||||
@Inject AccountManager _accountMgr;
|
||||
|
||||
private boolean canHandle(GuestIpType ipType, DataCenter dc) {
|
||||
String provider = dc.getGatewayProvider();
|
||||
@ -154,7 +156,20 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement,
|
||||
if (router == null) {
|
||||
return true;
|
||||
}
|
||||
return _routerMgr.stopRouterInternal(router.getId());
|
||||
if (_routerMgr.stopRouter(router.getId()) != null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
DomainRouterVO router = _routerDao.findByNetworkConfiguration(config.getId());
|
||||
if (router == null) {
|
||||
return true;
|
||||
}
|
||||
return _routerMgr.destroyRouter(router.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -243,7 +243,6 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
public void destroy(Network network, NetworkOffering offering) {
|
||||
s_logger.debug("Releasing vnet for the network id=" + network.getId());
|
||||
_dcDao.releaseVnet(network.getBroadcastUri().getHost(), network.getDataCenterId(), network.getAccountId(), network.getReservationId());
|
||||
_networkMgr.resetBroadcastUri(network.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -31,6 +31,7 @@ import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.RemoteAccessVpn;
|
||||
import com.cloud.network.VirtualNetworkApplianceService;
|
||||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.rules.PortForwardingRule;
|
||||
@ -46,7 +47,7 @@ import com.cloud.vm.VirtualMachineProfile;
|
||||
* NetworkManager manages the network for the different end users.
|
||||
*
|
||||
*/
|
||||
public interface VirtualNetworkApplianceManager extends Manager {
|
||||
public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkApplianceService{
|
||||
public static final int DEFAULT_ROUTER_VM_RAMSIZE = 128; // 128M
|
||||
public static final boolean USE_POD_VLAN = false;
|
||||
/**
|
||||
@ -67,9 +68,7 @@ public interface VirtualNetworkApplianceManager extends Manager {
|
||||
*/
|
||||
boolean savePasswordToRouter(long routerId, String vmIpAddress, String password);
|
||||
|
||||
boolean destroyRouterInternal(long routerId) throws ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
boolean stopRouterInternal(long routerId) throws ResourceUnavailableException, ConcurrentOperationException;
|
||||
boolean destroyRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
boolean getRouterStatistics(long vmId, Map<String, long[]> netStats, Map<String, long[]> diskStats);
|
||||
|
||||
|
||||
@ -58,10 +58,7 @@ import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.commands.UpgradeRouterCmd;
|
||||
import com.cloud.async.AsyncJobExecutor;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.async.BaseAsyncJobExecutor;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
@ -157,6 +154,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
@ -329,7 +327,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroyRouterInternal(final long routerId) throws ResourceUnavailableException, ConcurrentOperationException{
|
||||
public boolean destroyRouter(final long routerId) throws ResourceUnavailableException, ConcurrentOperationException{
|
||||
UserContext context = UserContext.current();
|
||||
User user = _accountMgr.getActiveUser(context.getCallerUserId());
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Attempting to destroy router " + routerId);
|
||||
@ -339,7 +339,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
if (router == null) {
|
||||
return true;
|
||||
}
|
||||
return _itMgr.expunge(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
boolean result = _itMgr.expunge(router, user, _accountMgr.getAccount(router.getAccountId()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -443,44 +445,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
return this.stop(router, user, account);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean stopRouterInternal(long routerId) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
|
||||
DomainRouterVO router = _routerDao.findById(routerId);
|
||||
if (router == null) {
|
||||
throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
|
||||
}
|
||||
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
if (asyncExecutor != null) {
|
||||
AsyncJobVO job = asyncExecutor.getJob();
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Stop router " + routerId + ", update async job-" + job.getId());
|
||||
}
|
||||
_asyncMgr.updateAsyncJobAttachment(job.getId(), "domain_router", routerId);
|
||||
}
|
||||
|
||||
long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, router.getAccountId(), EventTypes.EVENT_ROUTER_STOP, "Starting to stop router : " + router.getName());
|
||||
|
||||
Account account = _accountDao.findById(router.getAccountId());
|
||||
|
||||
//If domR is stopped, not need to stop it again
|
||||
if (router.getState() == State.Stopped) {
|
||||
s_logger.debug("domR is already stopped: " + router);
|
||||
return true;
|
||||
} else {
|
||||
if (this.stop(router, _accountService.getSystemUser(), account) == null) {
|
||||
EventUtils.saveEvent(User.UID_SYSTEM, router.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_STOP, "Unable to stop router: " + router.getName(), startEventId);
|
||||
return false;
|
||||
} else {
|
||||
EventUtils.saveEvent(User.UID_SYSTEM, router.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_STOP, "successfully stopped router : " + router.getName(), startEventId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DB
|
||||
public void processStopOrRebootAnswer(final DomainRouterVO router, Answer answer) {
|
||||
final Transaction txn = Transaction.currentTxn();
|
||||
@ -809,7 +773,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
|
||||
if (ids != null) {
|
||||
for (final Long id : ids) {
|
||||
stopRouterInternal(id);
|
||||
stopRouter(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2184,7 +2184,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
//if the instance is of type domain router vm, call the network manager
|
||||
if(vmInstance.getType().equals(VirtualMachine.Type.DomainRouter))
|
||||
{
|
||||
if(!_routerMgr.stopRouterInternal(vmInstance.getId()))
|
||||
if(_routerMgr.stopRouter(vmInstance.getId()) == null)
|
||||
{
|
||||
String errorMsg = "There was an error stopping the domain router id: "+vmInstance.getId()+" ,cannot enable primary storage maintenance";
|
||||
s_logger.warn(errorMsg);
|
||||
@ -2194,7 +2194,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
else if(restart)
|
||||
{
|
||||
if(!_routerMgr.stopRouterInternal(vmInstance.getId()))
|
||||
if(_routerMgr.stopRouter(vmInstance.getId()) == null)
|
||||
{
|
||||
String errorMsg = "There was an error starting the domain router id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance";
|
||||
s_logger.warn(errorMsg);
|
||||
|
||||
@ -49,17 +49,11 @@ import com.cloud.api.commands.UpdateAccountCmd;
|
||||
import com.cloud.api.commands.UpdateResourceLimitCmd;
|
||||
import com.cloud.api.commands.UpdateUserCmd;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||
import com.cloud.configuration.ResourceLimitVO;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.configuration.dao.ResourceCountDao;
|
||||
import com.cloud.configuration.dao.ResourceLimitDao;
|
||||
import com.cloud.dc.PodVlanMapVO;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.dao.PodVlanMapDao;
|
||||
import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
@ -71,10 +65,8 @@ import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IPAddressVO;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.security.SecurityGroupManager;
|
||||
@ -126,11 +118,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
@Inject private UserAccountDao _userAccountDao;
|
||||
@Inject private VolumeDao _volumeDao;
|
||||
@Inject private UserVmDao _userVmDao;
|
||||
@Inject private IPAddressDao _publicIpAddressDao;
|
||||
@Inject private VlanDao _vlanDao;
|
||||
@Inject private DomainRouterDao _routerDao;
|
||||
@Inject private VMTemplateDao _templateDao;
|
||||
@Inject private PodVlanMapDao _podVlanMapDao;
|
||||
@Inject private NetworkDao _networkDao;
|
||||
@Inject private SecurityGroupDao _securityGroupDao;
|
||||
|
||||
@ -141,7 +130,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
@Inject private UserVmManager _vmMgr;
|
||||
@Inject private StorageManager _storageMgr;
|
||||
@Inject private TemplateManager _tmpltMgr;
|
||||
@Inject private ConfigurationManager _configMgr;
|
||||
@Inject private VirtualNetworkApplianceManager _routerMgr;
|
||||
|
||||
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker"));
|
||||
@ -828,6 +816,23 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
// else, there are no snapshots, hence no directory to delete.
|
||||
|
||||
|
||||
// clean up templates
|
||||
List<VMTemplateVO> userTemplates = _templateDao.listByAccountId(accountId);
|
||||
boolean allTemplatesDeleted = true;
|
||||
for (VMTemplateVO template : userTemplates) {
|
||||
try {
|
||||
allTemplatesDeleted = _tmpltMgr.delete(callerUserId, template.getId(), null);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Failed to delete template while removing account: " + template.getName() + " due to: " + e.getMessage());
|
||||
allTemplatesDeleted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allTemplatesDeleted) {
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
|
||||
// Destroy the account's VMs
|
||||
List<UserVmVO> vms = _userVmDao.listByAccountId(accountId);
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -848,100 +853,25 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
// Mark the account's volumes as destroyed
|
||||
List<VolumeVO> volumes = _volumeDao.findDetachedByAccount(accountId);
|
||||
for (VolumeVO volume : volumes) {
|
||||
// if(volume.getPoolId()==null){
|
||||
// accountCleanupNeeded = true;
|
||||
// }
|
||||
_storageMgr.destroyVolume(volume);
|
||||
}
|
||||
|
||||
// Destroy the account's routers
|
||||
List<DomainRouterVO> routers = _routerDao.listBy(accountId);
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Destroying # of routers (accountId=" + accountId + "): " + routers.size());
|
||||
}
|
||||
|
||||
boolean routersCleanedUp = true;
|
||||
for (DomainRouterVO router : routers) {
|
||||
long startEventId = EventUtils.saveStartedEvent(callerUserId, router.getAccountId(), EventTypes.EVENT_ROUTER_DESTROY, "Starting to destroy router : " + router.getName());
|
||||
if (!_routerMgr.destroyRouterInternal(router.getId())) {
|
||||
s_logger.error("Unable to destroy router: " + router.getId());
|
||||
routersCleanedUp = false;
|
||||
EventUtils.saveEvent(callerUserId, router.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_DESTROY, "Unable to destroy router: " + router.getName(), startEventId);
|
||||
} else {
|
||||
EventUtils.saveEvent(callerUserId, router.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_DESTROY, "successfully destroyed router : " + router.getName(), startEventId);
|
||||
}
|
||||
}
|
||||
|
||||
if (routersCleanedUp) {
|
||||
List<IPAddressVO> ips = _publicIpAddressDao.listByAccount(accountId);
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Found " + ips.size() + " public IP addresses for account with ID " + accountId);
|
||||
}
|
||||
|
||||
for (IPAddressVO ip : ips) {
|
||||
List<PodVlanMapVO> podVlanMaps = _podVlanMapDao.listPodVlanMapsByVlan(ip.getVlanId());
|
||||
if (podVlanMaps != null && podVlanMaps.size() != 0) {
|
||||
Long podId = podVlanMaps.get(0).getPodId();
|
||||
if (podId != null) {
|
||||
continue;//bug 5561 do not release direct attach pod ips until vm is destroyed
|
||||
}
|
||||
}
|
||||
|
||||
if (!_networkMgr.releasePublicIpAddress(ip.getAddress(), account.getId(), User.UID_SYSTEM)) {
|
||||
s_logger.error("Unable to release IP: " + ip.getAddress());
|
||||
accountCleanupNeeded = true;
|
||||
} else {
|
||||
decrementResourceCount(accountId, ResourceType.public_ip);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
|
||||
//Cleanup security groups
|
||||
int numRemoved = _securityGroupDao.removeByAccountId(accountId);
|
||||
s_logger.info("deleteAccount: Deleted " + numRemoved + " network groups for account " + accountId);
|
||||
|
||||
// Delete the account's VLANs
|
||||
List<VlanVO> accountVlans = _vlanDao.listVlansForAccountByType(null, accountId, VlanType.DirectAttached);
|
||||
boolean allVlansDeleted = true;
|
||||
for (VlanVO vlan : accountVlans) {
|
||||
try {
|
||||
allVlansDeleted = _configMgr.deleteVlanAndPublicIpRange(User.UID_SYSTEM, vlan.getId());
|
||||
} catch (InvalidParameterValueException e) {
|
||||
allVlansDeleted = false;
|
||||
}
|
||||
}
|
||||
|
||||
//delete networks
|
||||
//Delete all the networks
|
||||
s_logger.debug("Deleting networks for account " + account.getId());
|
||||
List<NetworkVO> networks = _networkDao.listByOwner(accountId);
|
||||
for (NetworkVO network : networks) {
|
||||
_networkMgr.deleteNetwork(network.getId());
|
||||
s_logger.debug("Network " + network.getId() + " successfully deleted.");
|
||||
}
|
||||
|
||||
if (!allVlansDeleted) {
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
|
||||
// clean up templates
|
||||
List<VMTemplateVO> userTemplates = _templateDao.listByAccountId(accountId);
|
||||
boolean allTemplatesDeleted = true;
|
||||
for (VMTemplateVO template : userTemplates) {
|
||||
try {
|
||||
allTemplatesDeleted = _tmpltMgr.delete(callerUserId, template.getId(), null);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Failed to delete template while removing account: " + template.getName() + " due to: " + e.getMessage());
|
||||
allTemplatesDeleted = false;
|
||||
if (networks != null) {
|
||||
for (NetworkVO network : networks) {
|
||||
if (!_networkMgr.deleteNetwork(network.getId())) {
|
||||
s_logger.warn("Unable to destroy network " + network + " as a part of account cleanup");
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
s_logger.debug("Network " + network.getId() + " successfully deleted.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!allTemplatesDeleted) {
|
||||
accountCleanupNeeded = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
} finally {
|
||||
s_logger.info("Cleanup for account " + account.getId() + (accountCleanupNeeded ? " is needed." : " is not needed."));
|
||||
@ -989,7 +919,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
List<DomainRouterVO> routers = _routerDao.listBy(accountId);
|
||||
for (DomainRouterVO router : routers) {
|
||||
success = (success && _routerMgr.stopRouterInternal(router.getId()));
|
||||
success = (success && (_routerMgr.stopRouter(router.getId()) != null));
|
||||
}
|
||||
|
||||
return success;
|
||||
@ -1635,4 +1565,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
return _accountDao.findByIdIncludingRemoved(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getActiveUser(long userId) {
|
||||
return _userDao.findById(userId);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user