Skip to content

Commit cd90bc7

Browse files
committed
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
1 parent 78df5ea commit cd90bc7

9 files changed

Lines changed: 45 additions & 87 deletions

File tree

api/src/com/cloud/vm/Nic.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ enum Event {
3939
OperationFailed,
4040
}
4141

42+
public enum VmType {
43+
System,
44+
User;
45+
}
46+
4247
public enum State implements FiniteState<State, Event> {
4348
Allocated("Resource is allocated but not reserved"),
4449
Reserving("Resource is being reserved right now"),
@@ -151,4 +156,6 @@ public enum ReservationStrategy {
151156
URI getIsolationUri();
152157

153158
URI getBroadcastUri();
159+
160+
VmType getVmType();
154161
}

server/src/com/cloud/configuration/Config.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public enum Config {
122122
Port("Advanced", AgentManager.class, Integer.class, "port", "8250", "Port to listen on for agent connection.", null),
123123
RouterCpuMHz("Advanced", NetworkManager.class, Integer.class, "router.cpu.mhz", "500", "Default CPU speed (MHz) for router VM.", null),
124124
RestartRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "restart.retry.interval", "600", "Time (in seconds) between retries to restart a vm", null),
125-
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),
126125
RouterStatsInterval("Advanced", NetworkManager.class, Integer.class, "router.stats.interval", "300", "Interval (in seconds) to report router statistics.", null),
127126
RouterTemplateId("Advanced", NetworkManager.class, Long.class, "router.template.id", "1", "Default ID for template.", null),
128127
StartRetry("Advanced", AgentManager.class, Integer.class, "start.retry", "10", "Number of times to retry create and start commands", null),

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ private void populateConfigValuesForValidationSet(){
189189
configValuesForValidation.add("migrate.retry.interval");
190190
configValuesForValidation.add("network.gc.interval");
191191
configValuesForValidation.add("ping.interval");
192-
configValuesForValidation.add("router.cleanup.interval");
193192
configValuesForValidation.add("router.stats.interval");
194193
configValuesForValidation.add("snapshot.poll.interval");
195194
configValuesForValidation.add("stop.retry.interval");

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@
126126
import com.cloud.utils.net.Ip;
127127
import com.cloud.utils.net.NetUtils;
128128
import com.cloud.vm.Nic;
129+
import com.cloud.vm.Nic.VmType;
129130
import com.cloud.vm.NicProfile;
130131
import com.cloud.vm.NicVO;
131132
import com.cloud.vm.ReservationContext;
132133
import com.cloud.vm.ReservationContextImpl;
134+
import com.cloud.vm.UserVmVO;
133135
import com.cloud.vm.VMInstanceVO;
134136
import com.cloud.vm.VirtualMachine;
135137
import com.cloud.vm.VirtualMachine.Type;
@@ -366,11 +368,7 @@ public PublicIp assignSourceNatIpAddress(Account owner, Network network, long ca
366368
sourceNat = ip.ip();
367369

368370
markPublicIpAsAllocated(sourceNat);
369-
_ipAddressDao.update(sourceNat.getId(), sourceNat);
370-
371-
372-
// Increment the number of public IPs for this accountId in the database
373-
371+
_ipAddressDao.update(sourceNat.getId(), sourceNat);
374372
} else {
375373
// Account already has ip addresses
376374
for (IPAddressVO addr : addrs) {
@@ -931,7 +929,16 @@ public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair
931929
if (profile == null) {
932930
continue;
933931
}
934-
NicVO vo = new NicVO(concierge.getName(), vm.getId(), config.getId());
932+
933+
VmType vmType = null;
934+
935+
if (vm.getType() == Type.User) {
936+
vmType = Nic.VmType.User;
937+
} else {
938+
vmType = Nic.VmType.System;
939+
}
940+
941+
NicVO vo = new NicVO(concierge.getName(), vm.getId(), config.getId(), vmType);
935942

936943
while (deviceIds[deviceId] && deviceId < deviceIds.length) {
937944
deviceId++;
@@ -1112,7 +1119,10 @@ protected void updateNic(NicVO nic, long networkId, int count) {
11121119
Transaction txn = Transaction.currentTxn();
11131120
txn.start();
11141121
_nicDao.update(nic.getId(), nic);
1115-
_networksDao.changeActiveNicsBy(networkId, count);
1122+
1123+
if (nic.getVmType() == VmType.User) {
1124+
_networksDao.changeActiveNicsBy(networkId, count);
1125+
}
11161126
txn.commit();
11171127
}
11181128

@@ -1714,7 +1724,6 @@ public boolean deleteNetwork(long networkId){
17141724
throw new InvalidParameterValueException("Unable to remove the network id=" + networkId + " as it has active Nics.");
17151725
}
17161726

1717-
Long userId = UserContext.current().getCallerUserId();
17181727
Account caller = UserContext.current().getCaller();
17191728

17201729
// Verify network id
@@ -1731,9 +1740,17 @@ public boolean deleteNetwork(long networkId){
17311740
throw new PermissionDeniedException("Account " + caller.getAccountName() + " does not own network id=" + networkId + ", permission denied");
17321741
}
17331742
} else {
1734-
17351743
_accountMgr.checkAccess(caller, owner);
17361744
}
1745+
1746+
//Make sure that there are no user vms in the network that are not Expunged/Error
1747+
List<UserVmVO> userVms = _vmDao.listByNetworkId(networkId);
1748+
1749+
for (UserVmVO vm : userVms) {
1750+
if (!(vm.getState() == VirtualMachine.State.Error || vm.getState() == VirtualMachine.State.Expunging)) {
1751+
throw new InvalidParameterValueException("Can't delete the network, not all user vms are expunged");
1752+
}
1753+
}
17371754

17381755
User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
17391756
ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);

server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23-
import com.cloud.agent.api.to.PortForwardingRuleTO;
2423
import com.cloud.deploy.DeployDestination;
2524
import com.cloud.exception.ConcurrentOperationException;
2625
import com.cloud.exception.InsufficientCapacityException;
@@ -30,7 +29,6 @@
3029
import com.cloud.network.RemoteAccessVpn;
3130
import com.cloud.network.VirtualNetworkApplianceService;
3231
import com.cloud.network.VpnUser;
33-
import com.cloud.network.lb.LoadBalancingRule;
3432
import com.cloud.network.rules.FirewallRule;
3533
import com.cloud.user.Account;
3634
import com.cloud.user.User;

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
281281
String _instance;
282282
String _mgmt_host;
283283

284-
int _routerCleanupInterval = 3600;
285284
int _routerStatsInterval = 300;
286285
private ServiceOfferingVO _offering;
287286

@@ -551,9 +550,6 @@ public boolean configure(final String name, final Map<String, Object> params) th
551550
value = configs.get("router.stats.interval");
552551
_routerStatsInterval = NumbersUtil.parseInt(value, 300);
553552

554-
value = configs.get("router.cleanup.interval");
555-
_routerCleanupInterval = NumbersUtil.parseInt(value, 3600);
556-
557553
_instance = configs.get("instance.name");
558554
if (_instance == null) {
559555
_instance = "DEFAULT";
@@ -588,7 +584,6 @@ public String getName() {
588584

589585
@Override
590586
public boolean start() {
591-
_executor.scheduleAtFixedRate(new RouterCleanupTask(), _routerCleanupInterval, _routerCleanupInterval, TimeUnit.SECONDS);
592587
_executor.scheduleAtFixedRate(new NetworkUsageTask(), _routerStatsInterval, _routerStatsInterval, TimeUnit.SECONDS);
593588
return true;
594589
}
@@ -610,36 +605,6 @@ public Long convertToId(final String vmName) {
610605
return VirtualMachineName.getRouterId(vmName);
611606
}
612607

613-
protected class RouterCleanupTask implements Runnable {
614-
615-
public RouterCleanupTask() {
616-
}
617-
618-
@Override
619-
public void run() {
620-
try {
621-
List<Long> ids = findLonelyRouters();
622-
623-
s_logger.trace("Found " + ids.size() + " routers to stop. ");
624-
625-
for (Long id : ids) {
626-
try {
627-
DomainRouterVO router = _routerDao.findById(id);
628-
if (stop(router, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()) != null) {
629-
s_logger.info("Successfully stopped a rather lonely " + router);
630-
}
631-
} catch (Exception e) {
632-
s_logger.warn("Unable to stop router " + id, e);
633-
}
634-
}
635-
636-
s_logger.trace("Done my job. Time to rest.");
637-
} catch (Exception e) {
638-
s_logger.warn("Unable to stop routers. Will retry. ", e);
639-
}
640-
}
641-
}
642-
643608
private VmDataCommand generateVmDataCommand(DomainRouterVO router, String vmPrivateIpAddress,
644609
String userData, String serviceOffering, String zoneName, String guestIpAddress, String vmName, String vmInstanceName, long vmId, String publicKey) {
645610
VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress);
@@ -1655,43 +1620,6 @@ protected boolean applyStaticNatRules(DomainRouterVO router, List<StaticNatRule>
16551620
return sendCommandsToRouter(router, cmds);
16561621
}
16571622

1658-
1659-
private List<Long> findLonelyRouters() {
1660-
List<Long> routersToStop = new ArrayList<Long>();
1661-
List<VMInstanceVO> runningRouters = _instanceDao.listByTypeAndState(State.Running, VirtualMachine.Type.DomainRouter);
1662-
1663-
for (VMInstanceVO router : runningRouters) {
1664-
DataCenter dc = _configMgr.getZone(router.getDataCenterId());
1665-
if (dc.getNetworkType() == NetworkType.Advanced) {
1666-
//Only non-system networks should be reviewed as system network can always have other system vms running
1667-
List<NetworkVO> routerNetworks = _networkMgr.listNetworksUsedByVm(router.getId(), false);
1668-
List<Network> networksToCheck = new ArrayList<Network>();
1669-
for (Network routerNetwork : routerNetworks){
1670-
if ((routerNetwork.getGuestType() == GuestIpType.Direct && routerNetwork.getTrafficType() == TrafficType.Public) || (routerNetwork.getGuestType() == GuestIpType.Virtual && routerNetwork.getTrafficType() == TrafficType.Guest)) {
1671-
networksToCheck.add(routerNetwork);
1672-
}
1673-
}
1674-
1675-
boolean toStop = true;
1676-
for (Network network : networksToCheck) {
1677-
int count = _networkMgr.getActiveNicsInNetwork(network.getId());
1678-
if (count > 1) {
1679-
s_logger.trace("Network id=" + network.getId() + " used by router " + router + " has more than 1 active nic (number of nics is " + count + ")");
1680-
toStop = false;
1681-
break;
1682-
}
1683-
}
1684-
1685-
if (toStop) {
1686-
s_logger.trace("Adding router " + router + " to stop list of Router Monitor");
1687-
routersToStop.add(router.getId());
1688-
}
1689-
}
1690-
}
1691-
1692-
return routersToStop;
1693-
}
1694-
16951623
@Override
16961624
public VirtualRouter getRouterForNetwork(long networkId) {
16971625
return _routerDao.findByNetwork(networkId);

server/src/com/cloud/test/DatabaseConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ public class DatabaseConfig {
224224
s_configurationComponents.put("consoleproxy.domP.enable", "management-server");
225225
s_configurationComponents.put("consoleproxy.port", "management-server");
226226
s_configurationComponents.put("consoleproxy.url.port", "management-server");
227-
s_configurationComponents.put("router.cleanup.interval", "management-server");
228227
s_configurationComponents.put("alert.email.addresses", "management-server");
229228
s_configurationComponents.put("alert.smtp.host", "management-server");
230229
s_configurationComponents.put("alert.smtp.port", "management-server");

server/src/com/cloud/vm/NicVO.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ protected NicVO() {
101101
@Enumerated(value=EnumType.STRING)
102102
ReservationStrategy strategy;
103103

104+
@Enumerated(value=EnumType.STRING)
105+
@Column(name="vm_type")
106+
VmType vmType;
107+
104108
@Column(name=GenericDao.REMOVED_COLUMN)
105109
Date removed;
106110

107111
@Column(name=GenericDao.CREATED_COLUMN)
108112
Date created;
109113

110-
public NicVO(String reserver, Long instanceId, long configurationId) {
114+
public NicVO(String reserver, Long instanceId, long configurationId, VmType vmType) {
111115
this.reserver = reserver;
112116
this.instanceId = instanceId;
113117
this.networkId = configurationId;
114118
this.state = State.Allocated;
119+
this.vmType = vmType;
115120
}
116121

117122
@Override
@@ -300,4 +305,9 @@ public void setCreated(Date created) {
300305
public String toString() {
301306
return new StringBuilder("Nic[").append(id).append("-").append(instanceId).append("-").append(reservationId).append("-").append(ip4Address).append("]").toString();
302307
}
308+
309+
@Override
310+
public VmType getVmType() {
311+
return vmType;
312+
}
303313
}

setup/db/create-schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ CREATE TABLE `cloud`.`nics` (
207207
`isolation_uri` varchar(255) COMMENT 'id for isolation',
208208
`ip6_address` char(40) COMMENT 'ip6 address',
209209
`default_nic` tinyint NOT NULL COMMENT "None",
210+
`vm_type` varchar(32) COMMENT 'type of vm: System or User vm',
210211
`created` datetime NOT NULL COMMENT 'date created',
211212
`removed` datetime COMMENT 'date removed if not null',
212213
PRIMARY KEY (`id`),

0 commit comments

Comments
 (0)