mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 8412: allow to delete network when it has dhcp/domRs
status 8412: resolved fixed 1) Don't count domR/Dhcp nic in active nics. 2) Removed domR cleanup thread; Network shutdown thread would shutdown domR/dhcp when network has no active vms
This commit is contained in:
parent
78df5ea616
commit
cd90bc7166
@ -39,6 +39,11 @@ public interface Nic {
|
||||
OperationFailed,
|
||||
}
|
||||
|
||||
public enum VmType {
|
||||
System,
|
||||
User;
|
||||
}
|
||||
|
||||
public enum State implements FiniteState<State, Event> {
|
||||
Allocated("Resource is allocated but not reserved"),
|
||||
Reserving("Resource is being reserved right now"),
|
||||
@ -151,4 +156,6 @@ public interface Nic {
|
||||
URI getIsolationUri();
|
||||
|
||||
URI getBroadcastUri();
|
||||
|
||||
VmType getVmType();
|
||||
}
|
||||
|
||||
@ -122,7 +122,6 @@ public enum Config {
|
||||
Port("Advanced", AgentManager.class, Integer.class, "port", "8250", "Port to listen on for agent connection.", null),
|
||||
RouterCpuMHz("Advanced", NetworkManager.class, Integer.class, "router.cpu.mhz", "500", "Default CPU speed (MHz) for router VM.", null),
|
||||
RestartRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "restart.retry.interval", "600", "Time (in seconds) between retries to restart a vm", null),
|
||||
RouterCleanupInterval("Advanced", ManagementServer.class, Integer.class, "router.cleanup.interval", "3600", "Time (in seconds) identifies when to stop router when there are no user vms associated with it", null),
|
||||
RouterStatsInterval("Advanced", NetworkManager.class, Integer.class, "router.stats.interval", "300", "Interval (in seconds) to report router statistics.", null),
|
||||
RouterTemplateId("Advanced", NetworkManager.class, Long.class, "router.template.id", "1", "Default ID for template.", null),
|
||||
StartRetry("Advanced", AgentManager.class, Integer.class, "start.retry", "10", "Number of times to retry create and start commands", null),
|
||||
|
||||
@ -189,7 +189,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
configValuesForValidation.add("migrate.retry.interval");
|
||||
configValuesForValidation.add("network.gc.interval");
|
||||
configValuesForValidation.add("ping.interval");
|
||||
configValuesForValidation.add("router.cleanup.interval");
|
||||
configValuesForValidation.add("router.stats.interval");
|
||||
configValuesForValidation.add("snapshot.poll.interval");
|
||||
configValuesForValidation.add("stop.retry.interval");
|
||||
|
||||
@ -126,10 +126,12 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.Nic.VmType;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.ReservationContextImpl;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
@ -366,11 +368,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
sourceNat = ip.ip();
|
||||
|
||||
markPublicIpAsAllocated(sourceNat);
|
||||
_ipAddressDao.update(sourceNat.getId(), sourceNat);
|
||||
|
||||
|
||||
// Increment the number of public IPs for this accountId in the database
|
||||
|
||||
_ipAddressDao.update(sourceNat.getId(), sourceNat);
|
||||
} else {
|
||||
// Account already has ip addresses
|
||||
for (IPAddressVO addr : addrs) {
|
||||
@ -931,7 +929,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
if (profile == null) {
|
||||
continue;
|
||||
}
|
||||
NicVO vo = new NicVO(concierge.getName(), vm.getId(), config.getId());
|
||||
|
||||
VmType vmType = null;
|
||||
|
||||
if (vm.getType() == Type.User) {
|
||||
vmType = Nic.VmType.User;
|
||||
} else {
|
||||
vmType = Nic.VmType.System;
|
||||
}
|
||||
|
||||
NicVO vo = new NicVO(concierge.getName(), vm.getId(), config.getId(), vmType);
|
||||
|
||||
while (deviceIds[deviceId] && deviceId < deviceIds.length) {
|
||||
deviceId++;
|
||||
@ -1112,7 +1119,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
_nicDao.update(nic.getId(), nic);
|
||||
_networksDao.changeActiveNicsBy(networkId, count);
|
||||
|
||||
if (nic.getVmType() == VmType.User) {
|
||||
_networksDao.changeActiveNicsBy(networkId, count);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
@ -1714,7 +1724,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
throw new InvalidParameterValueException("Unable to remove the network id=" + networkId + " as it has active Nics.");
|
||||
}
|
||||
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
// Verify network id
|
||||
@ -1731,9 +1740,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
throw new PermissionDeniedException("Account " + caller.getAccountName() + " does not own network id=" + networkId + ", permission denied");
|
||||
}
|
||||
} else {
|
||||
|
||||
_accountMgr.checkAccess(caller, owner);
|
||||
}
|
||||
|
||||
//Make sure that there are no user vms in the network that are not Expunged/Error
|
||||
List<UserVmVO> userVms = _vmDao.listByNetworkId(networkId);
|
||||
|
||||
for (UserVmVO vm : userVms) {
|
||||
if (!(vm.getState() == VirtualMachine.State.Error || vm.getState() == VirtualMachine.State.Expunging)) {
|
||||
throw new InvalidParameterValueException("Can't delete the network, not all user vms are expunged");
|
||||
}
|
||||
}
|
||||
|
||||
User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
|
||||
|
||||
@ -20,7 +20,6 @@ package com.cloud.network.router;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.agent.api.to.PortForwardingRuleTO;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
@ -30,7 +29,6 @@ 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.FirewallRule;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
|
||||
@ -281,7 +281,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
String _instance;
|
||||
String _mgmt_host;
|
||||
|
||||
int _routerCleanupInterval = 3600;
|
||||
int _routerStatsInterval = 300;
|
||||
private ServiceOfferingVO _offering;
|
||||
|
||||
@ -551,9 +550,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
value = configs.get("router.stats.interval");
|
||||
_routerStatsInterval = NumbersUtil.parseInt(value, 300);
|
||||
|
||||
value = configs.get("router.cleanup.interval");
|
||||
_routerCleanupInterval = NumbersUtil.parseInt(value, 3600);
|
||||
|
||||
_instance = configs.get("instance.name");
|
||||
if (_instance == null) {
|
||||
_instance = "DEFAULT";
|
||||
@ -588,7 +584,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
_executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS);
|
||||
_executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS);
|
||||
return true;
|
||||
}
|
||||
@ -610,36 +605,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
return VirtualMachineName.getRouterId(vmName);
|
||||
}
|
||||
|
||||
protected class RouterCleanupTask implements Runnable {
|
||||
|
||||
public RouterCleanupTask() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<Long> ids = findLonelyRouters();
|
||||
|
||||
s_logger.trace("Found " + ids.size() + " routers to stop. ");
|
||||
|
||||
for (Long id : ids) {
|
||||
try {
|
||||
DomainRouterVO router = _routerDao.findById(id);
|
||||
if (stop(router, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()) != null) {
|
||||
s_logger.info("Successfully stopped a rather lonely " + router);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to stop router " + id, e);
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.trace("Done my job. Time to rest.");
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to stop routers. Will retry. ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private VmDataCommand generateVmDataCommand(DomainRouterVO router, String vmPrivateIpAddress,
|
||||
String userData, String serviceOffering, String zoneName, String guestIpAddress, String vmName, String vmInstanceName, long vmId, String publicKey) {
|
||||
VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress);
|
||||
@ -1655,43 +1620,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
return sendCommandsToRouter(router, cmds);
|
||||
}
|
||||
|
||||
|
||||
private List<Long> findLonelyRouters() {
|
||||
List<Long> routersToStop = new ArrayList<Long>();
|
||||
List<VMInstanceVO> runningRouters = _instanceDao.listByTypeAndState(State.Running, VirtualMachine.Type.DomainRouter);
|
||||
|
||||
for (VMInstanceVO router : runningRouters) {
|
||||
DataCenter dc = _configMgr.getZone(router.getDataCenterId());
|
||||
if (dc.getNetworkType() == NetworkType.Advanced) {
|
||||
//Only non-system networks should be reviewed as system network can always have other system vms running
|
||||
List<NetworkVO> routerNetworks = _networkMgr.listNetworksUsedByVm(router.getId(), false);
|
||||
List<Network> networksToCheck = new ArrayList<Network>();
|
||||
for (Network routerNetwork : routerNetworks){
|
||||
if ((routerNetwork.getGuestType() == GuestIpType.Direct && routerNetwork.getTrafficType() == TrafficType.Public) || (routerNetwork.getGuestType() == GuestIpType.Virtual && routerNetwork.getTrafficType() == TrafficType.Guest)) {
|
||||
networksToCheck.add(routerNetwork);
|
||||
}
|
||||
}
|
||||
|
||||
boolean toStop = true;
|
||||
for (Network network : networksToCheck) {
|
||||
int count = _networkMgr.getActiveNicsInNetwork(network.getId());
|
||||
if (count > 1) {
|
||||
s_logger.trace("Network id=" + network.getId() + " used by router " + router + " has more than 1 active nic (number of nics is " + count + ")");
|
||||
toStop = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (toStop) {
|
||||
s_logger.trace("Adding router " + router + " to stop list of Router Monitor");
|
||||
routersToStop.add(router.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return routersToStop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouter getRouterForNetwork(long networkId) {
|
||||
return _routerDao.findByNetwork(networkId);
|
||||
|
||||
@ -224,7 +224,6 @@ public class DatabaseConfig {
|
||||
s_configurationComponents.put("consoleproxy.domP.enable", "management-server");
|
||||
s_configurationComponents.put("consoleproxy.port", "management-server");
|
||||
s_configurationComponents.put("consoleproxy.url.port", "management-server");
|
||||
s_configurationComponents.put("router.cleanup.interval", "management-server");
|
||||
s_configurationComponents.put("alert.email.addresses", "management-server");
|
||||
s_configurationComponents.put("alert.smtp.host", "management-server");
|
||||
s_configurationComponents.put("alert.smtp.port", "management-server");
|
||||
|
||||
@ -101,17 +101,22 @@ public class NicVO implements Nic {
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
ReservationStrategy strategy;
|
||||
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name="vm_type")
|
||||
VmType vmType;
|
||||
|
||||
@Column(name=GenericDao.REMOVED_COLUMN)
|
||||
Date removed;
|
||||
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
Date created;
|
||||
|
||||
public NicVO(String reserver, Long instanceId, long configurationId) {
|
||||
public NicVO(String reserver, Long instanceId, long configurationId, VmType vmType) {
|
||||
this.reserver = reserver;
|
||||
this.instanceId = instanceId;
|
||||
this.networkId = configurationId;
|
||||
this.state = State.Allocated;
|
||||
this.vmType = vmType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -300,4 +305,9 @@ public class NicVO implements Nic {
|
||||
public String toString() {
|
||||
return new StringBuilder("Nic[").append(id).append("-").append(instanceId).append("-").append(reservationId).append("-").append(ip4Address).append("]").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VmType getVmType() {
|
||||
return vmType;
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,6 +207,7 @@ CREATE TABLE `cloud`.`nics` (
|
||||
`isolation_uri` varchar(255) COMMENT 'id for isolation',
|
||||
`ip6_address` char(40) COMMENT 'ip6 address',
|
||||
`default_nic` tinyint NOT NULL COMMENT "None",
|
||||
`vm_type` varchar(32) COMMENT 'type of vm: System or User vm',
|
||||
`created` datetime NOT NULL COMMENT 'date created',
|
||||
`removed` datetime COMMENT 'date removed if not null',
|
||||
PRIMARY KEY (`id`),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user