From d0687f663f88b8cb344b8fa9987c4e1af7f6353f Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 7 Jan 2011 16:43:08 -0800 Subject: [PATCH] bug 7863: fixed router cleanup thread status 7863: resolved fixed Router cleanp thread is fixed, here is functionality description: * Runs every "router.cleanup.interval" period of time (1 day by default) * Stops only domRs running in Advance zone * Thread Flow: - gets all Running domRs/dhcps, get their networks, select network that has to be checked (see criteria below): - checks that there is only one nic in the op_networks table for the network, and this nic belongs to domR/dhcp - Stops domR/dhcp * Criteria to choose the network: - Network has to be non-system. - Network should be one of the following: Guest Virtual (TrafficType=Guest; GuestType=Virtual); Direct Tagged (TrafficType=Public; GuestType=Direct) Couple of other fixes: * Added isShared parameter to listNetworks command * Moved guestType from NetworkOffering to Network --- .../cloud/api/commands/ListNetworksCmd.java | 7 ++ api/src/com/cloud/network/Network.java | 6 +- .../com/cloud/offering/NetworkOffering.java | 5 -- .../com/cloud/offering/ServiceOffering.java | 4 +- .../impl/UserConcentratedAllocator.java | 10 +-- .../configuration/ConfigurationManager.java | 7 +- .../ConfigurationManagerImpl.java | 17 ++-- .../consoleproxy/ConsoleProxyManagerImpl.java | 4 +- .../migration/Db20to21MigrationUtil.java | 8 +- .../migration/Db21to22MigrationUtil.java | 5 +- .../cloud/migration/ServiceOffering20VO.java | 13 ++- .../cloud/migration/ServiceOffering21VO.java | 10 +-- .../src/com/cloud/network/NetworkManager.java | 6 +- .../com/cloud/network/NetworkManagerImpl.java | 39 +++++++-- server/src/com/cloud/network/NetworkVO.java | 1 - .../src/com/cloud/network/dao/NetworkDao.java | 2 +- .../com/cloud/network/dao/NetworkDaoImpl.java | 2 +- .../cloud/network/element/DhcpElement.java | 2 +- .../network/element/VirtualRouterElement.java | 2 +- .../cloud/network/guru/DirectNetworkGuru.java | 2 +- .../cloud/network/guru/GuestNetworkGuru.java | 2 +- .../VirtualNetworkApplianceManagerImpl.java | 81 +++++++++++++++---- .../cloud/network/rules/RulesManagerImpl.java | 2 +- .../cloud/offerings/NetworkOfferingVO.java | 3 +- .../cloud/server/ConfigurationServerImpl.java | 14 ++-- .../com/cloud/service/ServiceOfferingVO.java | 12 +-- .../allocator/LocalStoragePoolAllocator.java | 18 ++--- .../SecondaryStorageManagerImpl.java | 4 +- server/src/com/cloud/test/DatabaseConfig.java | 8 +- .../src/com/cloud/vm/UserVmManagerImpl.java | 6 +- .../src/com/cloud/vm/dao/DomainRouterDao.java | 3 - .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 20 ----- .../src/com/cloud/vm/dao/VMInstanceDao.java | 2 + .../com/cloud/vm/dao/VMInstanceDaoImpl.java | 14 ++++ 34 files changed, 209 insertions(+), 132 deletions(-) diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java index 0b959f55098..614fc56a1c6 100644 --- a/api/src/com/cloud/api/commands/ListNetworksCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java @@ -57,6 +57,9 @@ public class ListNetworksCmd extends BaseListCmd { @Parameter(name=ApiConstants.IS_SYSTEM, type=CommandType.BOOLEAN, description="true if network is system, false otherwise") private Boolean isSystem; + + @Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true if network is shared, false otherwise") + private Boolean isShared; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -86,6 +89,10 @@ public class ListNetworksCmd extends BaseListCmd { return isSystem; } + public Boolean getIsShared() { + return isShared; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index ed62bb57b6d..a3355ff28fe 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -11,7 +11,6 @@ import com.cloud.acl.ControlledEntity; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.utils.fsm.FiniteState; import com.cloud.utils.fsm.StateMachine; @@ -21,6 +20,11 @@ import com.cloud.utils.fsm.StateMachine; */ public interface Network extends ControlledEntity { + public enum GuestIpType { + Virtual, + Direct, + } + public static class Service { public static final Service Vpn = new Service("Vpn", Capability.SupportedVpnTypes); diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 9f4b70ba245..62bbaa221f6 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -25,11 +25,6 @@ import com.cloud.network.Networks.TrafficType; */ public interface NetworkOffering { - public enum GuestIpType { - Virtual, - Direct, - } - public enum Availability { Required, Optional, diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index aa9c97c1b8c..c9ca5ba3272 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -19,6 +19,8 @@ package com.cloud.offering; import java.util.Date; +import com.cloud.network.Network; + /** * ServiceOffering models the different types of service contracts to be * offered. @@ -70,7 +72,7 @@ public interface ServiceOffering { /** * @return the type of IP address to allocate as the primary ip address to a guest */ - NetworkOffering.GuestIpType getGuestIpType(); + Network.GuestIpType getGuestIpType(); /** * @return whether or not the service offering requires local storage diff --git a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java index 6dcab9892d8..a45e8891551 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java @@ -38,7 +38,7 @@ import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.Pod; import com.cloud.dc.dao.HostPodDao; -import com.cloud.offering.NetworkOffering; +import com.cloud.network.Network; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; @@ -250,14 +250,14 @@ public class UserConcentratedAllocator implements PodAllocator { so = _offeringDao.findById(userVm.getServiceOfferingId()); } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { so = new ServiceOfferingVO("Fake Offering For DomP", 1, - _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + _proxyRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.DomainRouter) { - so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else { assert(false) : "Unsupported system vm type"; - so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) { diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 6716340941f..a9163cbeb63 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -32,7 +32,6 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.network.Networks.TrafficType; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering.Availability; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.service.ServiceOfferingVO; @@ -172,15 +171,14 @@ public interface ConfigurationManager extends Manager { * Creates a new network offering * @param name * @param displayText - * @param type * @param trafficType * @param tags * @param maxConnections * @param id - * @param specifyVlan; + * @param specifyVlan; * @return network offering object */ - NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability); + NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability); Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; @@ -188,4 +186,5 @@ public interface ConfigurationManager extends Manager { Long saveConfigurationEvent(long userId, Long accountId, String type, String description, String... paramsList); + DataCenterVO getZone(long id); } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 8edd2c78c9e..c98834cd1b6 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -91,6 +91,8 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IPAddressVO; +import com.cloud.network.Network; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.BroadcastDomainType; @@ -100,7 +102,6 @@ import com.cloud.network.dao.NetworkDao; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; @@ -1360,7 +1361,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); - NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtual : NetworkOffering.GuestIpType.Direct; + Network.GuestIpType guestIpType = useVirtualNetwork ? Network.GuestIpType.Virtual : Network.GuestIpType.Direct; tags = cleanupTags(tags); ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags, false,domainId); @@ -1442,7 +1443,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (_serviceOfferingDao.update(id, offering)) { offering = _serviceOfferingDao.findById(id); saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully updated service offering with name: " + offering.getName() + ".", "soId=" + offering.getId(), "name=" + offering.getName(), - "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtual), "tags=" + offering.getTags(), "domainId=" + offering.getDomainId()); + "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == Network.GuestIpType.Virtual), "tags=" + offering.getTags(), "domainId=" + offering.getDomainId()); return offering; } else { return null; @@ -2684,7 +2685,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String availabilityStr = cmd.getAvailability(); TrafficType trafficType = null; - GuestIpType type = null; Availability availability = null; @@ -2710,11 +2710,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } Integer maxConnections = cmd.getMaxconnections(); - return createNetworkOffering(userId, name, displayText, type, trafficType, tags, maxConnections, specifyVlan, availability); + return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability); } @Override - public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability) { + public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability) { String networkRateStr = _configDao.getValue("network.throttling.rate"); String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); @@ -2882,4 +2882,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } } + + @Override + public DataCenterVO getZone(long id){ + return _zoneDao.findById(id); + } } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 129cd3f90a2..0ee83f41d04 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -104,11 +104,11 @@ import com.cloud.info.RunningHostInfoAgregator; import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.maid.StackMaid; import com.cloud.network.IpAddrAllocator; +import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.NetworkDao; -import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; @@ -1911,7 +1911,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _itMgr.registerGuru(VirtualMachine.Type.ConsoleProxy, this); boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); - _serviceOffering = new ServiceOfferingVO("System Offering For Console Proxy", 1, _proxyRamSize, 0, 0, 0, true, null, NetworkOffering.GuestIpType.Virtual, + _serviceOffering = new ServiceOfferingVO("System Offering For Console Proxy", 1, _proxyRamSize, 0, 0, 0, true, null, Network.GuestIpType.Virtual, useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-ConsoleProxy"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); diff --git a/server/src/com/cloud/migration/Db20to21MigrationUtil.java b/server/src/com/cloud/migration/Db20to21MigrationUtil.java index d95036a9a7e..9d141fef251 100644 --- a/server/src/com/cloud/migration/Db20to21MigrationUtil.java +++ b/server/src/com/cloud/migration/Db20to21MigrationUtil.java @@ -38,7 +38,7 @@ import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.migration.DiskOffering21VO.Type; -import com.cloud.offering.NetworkOffering; +import com.cloud.network.Network; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.Volume.VolumeType; @@ -306,7 +306,7 @@ public class Db20to21MigrationUtil { _configDao.getValue(Config.ConsoleProxyRamSize.key()), ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); ServiceOffering21VO soConsoleProxy = new ServiceOffering21VO("Fake Offering For DomP", 1, - proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, + proxyRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, useLocalStorage, true, null); soConsoleProxy.setId(seq++); soConsoleProxy.setUniqueName("Cloud.com-ConsoleProxy"); @@ -317,7 +317,7 @@ public class Db20to21MigrationUtil { _configDao.getValue(Config.SecStorageVmRamSize.key()), SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE); ServiceOffering21VO soSecondaryVm = new ServiceOffering21VO("Fake Offering For Secondary Storage VM", 1, - secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, useLocalStorage, true, null); + secStorageVmRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, useLocalStorage, true, null); soSecondaryVm.setId(seq++); soSecondaryVm.setUniqueName("Cloud.com-SecondaryStorage"); soSecondaryVm = _serviceOffering21Dao.persist(soSecondaryVm); @@ -325,7 +325,7 @@ public class Db20to21MigrationUtil { int routerRamSize = NumbersUtil.parseInt(_configDao.getValue("router.ram.size"), 128); ServiceOffering21VO soDomainRouter = new ServiceOffering21VO("Fake Offering For DomR", 1, - routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, useLocalStorage, true, null); + routerRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, useLocalStorage, true, null); soDomainRouter.setId(seq++); soDomainRouter.setUniqueName("Cloud.Com-SoftwareRouter"); soDomainRouter = _serviceOffering21Dao.persist(soDomainRouter); diff --git a/server/src/com/cloud/migration/Db21to22MigrationUtil.java b/server/src/com/cloud/migration/Db21to22MigrationUtil.java index 78007068c3c..3216e28f3e3 100644 --- a/server/src/com/cloud/migration/Db21to22MigrationUtil.java +++ b/server/src/com/cloud/migration/Db21to22MigrationUtil.java @@ -1,7 +1,6 @@ package com.cloud.migration; import java.io.File; -import java.net.InetAddress; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.List; @@ -9,13 +8,12 @@ import java.util.List; import org.apache.log4j.xml.DOMConfigurator; import com.cloud.configuration.ResourceCount.ResourceType; -import com.cloud.configuration.ConfigurationVO; import com.cloud.configuration.ResourceCountVO; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ResourceCountDao; import com.cloud.dc.ClusterVO; -import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.domain.DomainVO; @@ -28,7 +26,6 @@ import com.cloud.user.Account; import com.cloud.user.dao.AccountDao; import com.cloud.utils.PropertiesUtil; import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.db.DB; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; diff --git a/server/src/com/cloud/migration/ServiceOffering20VO.java b/server/src/com/cloud/migration/ServiceOffering20VO.java index 7d31fbb7ede..60e8115b8fa 100644 --- a/server/src/com/cloud/migration/ServiceOffering20VO.java +++ b/server/src/com/cloud/migration/ServiceOffering20VO.java @@ -11,8 +11,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; -import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; +import com.cloud.network.Network; import com.cloud.utils.db.GenericDao; @Entity @@ -52,7 +51,7 @@ public class ServiceOffering20VO { @Column(name="guest_ip_type") @Enumerated(EnumType.STRING) - private NetworkOffering.GuestIpType guestIpType = NetworkOffering.GuestIpType.Virtual; + private Network.GuestIpType guestIpType = Network.GuestIpType.Virtual; @Column(name="use_local_storage") private boolean useLocalStorage; @@ -67,10 +66,10 @@ public class ServiceOffering20VO { } public ServiceOffering20VO(Long id, String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, boolean localStorageRequired) { - this(id, name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, NetworkOffering.GuestIpType.Virtual, localStorageRequired); + this(id, name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, Network.GuestIpType.Virtual, localStorageRequired); } - public ServiceOffering20VO(Long id, String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage) { + public ServiceOffering20VO(Long id, String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, Network.GuestIpType guestIpType, boolean useLocalStorage) { this.id = id; this.name = name; this.cpu = cpu; @@ -168,11 +167,11 @@ public class ServiceOffering20VO { return multicastRateMbps; } - public void setGuestIpType(NetworkOffering.GuestIpType guestIpType) { + public void setGuestIpType(Network.GuestIpType guestIpType) { this.guestIpType = guestIpType; } - public NetworkOffering.GuestIpType getGuestIpType() { + public Network.GuestIpType getGuestIpType() { return guestIpType; } diff --git a/server/src/com/cloud/migration/ServiceOffering21VO.java b/server/src/com/cloud/migration/ServiceOffering21VO.java index 95b4fee3584..12385fbf30f 100644 --- a/server/src/com/cloud/migration/ServiceOffering21VO.java +++ b/server/src/com/cloud/migration/ServiceOffering21VO.java @@ -9,7 +9,7 @@ import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; import javax.persistence.Transient; -import com.cloud.offering.NetworkOffering; +import com.cloud.network.Network; import com.cloud.offering.ServiceOffering; @Entity @@ -37,13 +37,13 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe @Column(name="guest_ip_type") @Enumerated(EnumType.STRING) - private NetworkOffering.GuestIpType guestIpType; + private Network.GuestIpType guestIpType; protected ServiceOffering21VO() { super(); } - public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags) { + public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, Network.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags) { super(name, displayText, false, tags, recreatable, useLocalStorage); this.cpu = cpu; this.ramSize = ramSize; @@ -119,12 +119,12 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe return multicastRateMbps; } - public void setGuestIpType(NetworkOffering.GuestIpType guestIpType) { + public void setGuestIpType(Network.GuestIpType guestIpType) { this.guestIpType = guestIpType; } @Override - public NetworkOffering.GuestIpType getGuestIpType() { + public Network.GuestIpType getGuestIpType() { return guestIpType; } public String gethypervisorType() { diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 6d3896751de..a5019883e2c 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -120,7 +120,7 @@ public interface NetworkManager extends NetworkService { void cleanupNics(VirtualMachineProfile vm); - List getNics (VirtualMachine vm); + List getNics(VirtualMachine vm); List getAccountsUsingNetwork(long configurationId); AccountVO getNetworkOwner(long configurationId); @@ -140,6 +140,8 @@ public interface NetworkManager extends NetworkService { PublicIpAddress getPublicIpAddress(Ip ipAddress); List listPodVlans(long podId); - + Pair implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + List listNetworksUsedByVm(long vmId, boolean isSystem); + } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 6020d0efc0a..d19f59a9da6 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -79,6 +79,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network.Capability; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.Service; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; @@ -96,7 +97,6 @@ import com.cloud.network.rules.RulesManager; import com.cloud.network.vpn.RemoteAccessVpnElement; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.resource.Resource; @@ -685,19 +685,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _networkGcWait = NumbersUtil.parseInt(_configs.get(Config.NetworkGcWait.key()), 600); _networkGcInterval = NumbersUtil.parseInt(_configs.get(Config.NetworkGcInterval.key()), 600); - NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public, null); + NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public); publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemPublicNetwork, publicNetworkOffering); - NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management, null); + NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management); managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemManagementNetwork, managementNetworkOffering); - NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control, null); + NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control); controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemControlNetwork, controlNetworkOffering); - NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, null); + NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage); storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SystemStorageNetwork, storageNetworkOffering); - NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SysteGuestNetwork, TrafficType.Guest, null); + NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SysteGuestNetwork, TrafficType.Guest); guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering); _systemNetworks.put(NetworkOfferingVO.SysteGuestNetwork, guestNetworkOffering); @@ -1424,12 +1424,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String accountName = cmd.getAccountName(); String type = cmd.getType(); Boolean isSystem = cmd.getIsSystem(); + Boolean isShared = cmd.getIsShared(); Long accountId = null; if (isSystem == null) { isSystem = false; } + if (isShared == null) { + isShared = false; + } + //Account/domainId parameters and isSystem are mutually exclusive if (isSystem && (accountName != null || domainId != null)) { throw new InvalidParameterValueException("System network belongs to system, account and domainId parameters can't be specified"); @@ -1502,6 +1507,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); } + if (isShared != null) { + sc.addAnd("isShared", SearchCriteria.Op.EQ, isShared); + } + List networks = _networksDao.search(sc, searchFilter); return networks; @@ -1844,4 +1853,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return vlans; } + @Override + public List listNetworksUsedByVm(long vmId, boolean isSystem) { + List networks = new ArrayList(); + + List nics = _nicDao.listBy(vmId); + if (nics != null) { + for (Nic nic : nics) { + NetworkVO network = _networksDao.findByIdIncludingRemoved(nic.getNetworkId()); + NetworkOffering no = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId()); + if (no.isSystemOnly() == isSystem) { + networks.add(network); + } + } + } + + return networks; + } + } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 955f6f6aac5..ecf08519a7a 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -32,7 +32,6 @@ import javax.persistence.Transient; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; import com.cloud.utils.net.NetUtils; diff --git a/server/src/com/cloud/network/dao/NetworkDao.java b/server/src/com/cloud/network/dao/NetworkDao.java index d4596841c03..6deeccbef5c 100644 --- a/server/src/com/cloud/network/dao/NetworkDao.java +++ b/server/src/com/cloud/network/dao/NetworkDao.java @@ -19,9 +19,9 @@ package com.cloud.network.dao; import java.util.List; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.NetworkAccountVO; import com.cloud.network.NetworkVO; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.SearchBuilder; diff --git a/server/src/com/cloud/network/dao/NetworkDaoImpl.java b/server/src/com/cloud/network/dao/NetworkDaoImpl.java index aa455af6523..533cbab5916 100644 --- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java @@ -23,13 +23,13 @@ import java.util.Random; import javax.ejb.Local; import javax.persistence.TableGenerator; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.NetworkAccountDaoImpl; import com.cloud.network.NetworkAccountVO; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; diff --git a/server/src/com/cloud/network/element/DhcpElement.java b/server/src/com/cloud/network/element/DhcpElement.java index 2ef447d66e2..433f4cb9063 100644 --- a/server/src/com/cloud/network/element/DhcpElement.java +++ b/server/src/com/cloud/network/element/DhcpElement.java @@ -33,6 +33,7 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.Network.Capability; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; @@ -42,7 +43,6 @@ import com.cloud.network.dao.NetworkDao; import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.rules.FirewallRule; import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.uservm.UserVm; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.Inject; diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 7a366601982..0e59a7363cc 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -35,6 +35,7 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.LoadBalancerVO; import com.cloud.network.Network; import com.cloud.network.Network.Capability; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; @@ -52,7 +53,6 @@ import com.cloud.network.rules.FirewallRule.Purpose; import com.cloud.network.rules.PortForwardingRule; import com.cloud.network.vpn.RemoteAccessVpnElement; import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.uservm.UserVm; import com.cloud.utils.component.AdapterBase; diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java index d26426d524d..54890e5320c 100644 --- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java @@ -33,6 +33,7 @@ import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; @@ -44,7 +45,6 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.IPAddressDao; import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.resource.Resource.ReservationStrategy; import com.cloud.user.Account; diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index ffdeb6abc86..e2b3d9595e6 100644 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -36,6 +36,7 @@ import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; @@ -44,7 +45,6 @@ import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.resource.Resource.ReservationStrategy; import com.cloud.user.Account; import com.cloud.utils.component.AdapterBase; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f059f412a6a..0f90aaa5344 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -105,6 +105,7 @@ import com.cloud.network.IPAddressVO; import com.cloud.network.IpAddress; import com.cloud.network.LoadBalancerVO; import com.cloud.network.Network; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.BroadcastDomainType; @@ -134,8 +135,6 @@ import com.cloud.network.rules.PortForwardingRule; import com.cloud.network.rules.PortForwardingRuleVO; import com.cloud.network.rules.RulesManager; import com.cloud.network.rules.dao.PortForwardingRulesDao; -import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; @@ -174,6 +173,7 @@ import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; import com.cloud.vm.UserVmVO; +import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineGuru; @@ -183,6 +183,7 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.dao.VMInstanceDao; /** * VirtualNetworkApplianceManagerImpl manages the different types of @@ -291,6 +292,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian PortForwardingRulesDao _pfRulesDao; @Inject RemoteAccessVpnDao _vpnDao; + @Inject + VMInstanceDao _instanceDao; long _routerTemplateId = -1; int _routerRamSize; @@ -564,7 +567,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian userStats.setNetBytesSent(userStats.getNetBytesSent() + netBytes); userStats.setCurrentBytesSent(0); _userStatsDao.update(userStats.getId(), userStats); - s_logger.debug("Successfully updated user statistics as a part of domR id=" + router.getId() + " reboot/stop"); + s_logger.debug("Successfully updated user statistics as a part of domR " + router + " reboot/stop"); } else { s_logger.warn("User stats were not created for account " + router.getAccountId() + " and dc " + router.getDataCenterId()); } @@ -620,12 +623,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId()); } - s_logger.debug("Stopping and starting router id=" + router.getId() + " as a part of router reboot"); + s_logger.debug("Stopping and starting router " + router + " as a part of router reboot"); if (stopRouter(routerId) != null) { return startRouter(routerId); } else { - throw new CloudRuntimeException("Failed to reboot router id=" + router.getId()); + throw new CloudRuntimeException("Failed to reboot router " + router); } } @@ -682,7 +685,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); _multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, 0, 0, 0, true, null, - NetworkOffering.GuestIpType.Virtual, useLocalStorage, true, null, true); + Network.GuestIpType.Virtual, useLocalStorage, true, null, true); _offering.setUniqueName("Cloud.Com-SoftwareRouter"); _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering); _template = _templateDao.findRoutingTemplate(); @@ -903,12 +906,22 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public void run() { try { - final List ids = _routerDao.findLonelyRouters(); - s_logger.info("Found " + ids.size() + " routers to stop. "); - - for (final Long id : ids) { - stopRouterInternal(id); + final List ids = findLonelyRouters(); + Long size; + if (ids == null || ids.isEmpty()) { + size = 0L; + } else { + size = Long.valueOf(ids.size()); } + + s_logger.info("Found " + size + " routers to stop. "); + + if (ids != null) { + for (final Long id : ids) { + stopRouterInternal(id); + } + } + s_logger.info("Done my job. Time to rest."); } catch (Exception e) { s_logger.warn("Unable to stop routers. Will retry. ", e); @@ -1415,7 +1428,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian private DomainRouterVO start(DomainRouterVO router, User user, Account caller) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { - s_logger.debug("Starting router id=" + router.getId()); + s_logger.debug("Starting router " + router); if (_itMgr.start(router, null, user, caller, null) != null) { return _routerDao.findById(router.getId()); } else { @@ -1424,7 +1437,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } private DomainRouterVO stop(DomainRouterVO router, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.debug("Stopping router id=" + router.getId()); + s_logger.debug("Stopping router " + router); if (_itMgr.stop(router, user, caller)) { return _routerDao.findById(router.getId()); } else { @@ -1692,7 +1705,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (vm.getUserData() != null) { NicVO nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId()); if (nic != null) { - s_logger.debug("Creating user data entry for vm id=" + vm.getId() + " on domR " + router.getId()); + s_logger.debug("Creating user data entry for vm " + vm + " on domR " + router); String serviceOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId()).getDisplayText(); String zoneName = _dcDao.findById(router.getDataCenterId()).getName(); cmds.addCommand( @@ -1712,7 +1725,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian for (UserVmVO vm : vms) { NicVO nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId()); if (nic != null) { - s_logger.debug("Creating dhcp entry for vm id=" + vm.getId() + " on domR " + router.getId()); + s_logger.debug("Creating dhcp entry for vm " + vm + " on domR " + router); DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getName()); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, router.getPrivateIpAddress()); @@ -1814,4 +1827,42 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian // TODO Auto-generated method stub return false; } + + + private List findLonelyRouters() { + List routersToStop = new ArrayList(); + List 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 routerNetworks = _networkMgr.listNetworksUsedByVm(router.getId(), false); + List networksToCheck = new ArrayList(); + 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; + } + } diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index b420f1b0f85..29e4fe2364d 100644 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -36,13 +36,13 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IPAddressVO; import com.cloud.network.IpAddress; import com.cloud.network.Network; +import com.cloud.network.Network.GuestIpType; import com.cloud.network.NetworkManager; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.rules.FirewallRule.Purpose; import com.cloud.network.rules.FirewallRule.State; import com.cloud.network.rules.dao.PortForwardingRulesDao; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.user.Account; import com.cloud.user.AccountManager; import com.cloud.user.UserContext; diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index a31decb0165..a7cdeb9628b 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -323,9 +323,8 @@ public class NetworkOfferingVO implements NetworkOffering { * Network Offering for all system vms. * @param name * @param trafficType - * @param type */ - public NetworkOfferingVO(String name, TrafficType trafficType, GuestIpType type) { + public NetworkOfferingVO(String name, TrafficType trafficType) { this(name, "System Offering for " + name, trafficType, true, false, null, null, null, false, Availability.Required, false, false, false, false, false, false, false); } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index d9ba64972f2..90efd4d745b 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -56,6 +56,7 @@ import com.cloud.domain.dao.DomainDao; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.Network; import com.cloud.network.Network.State; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.BroadcastDomainType; @@ -667,7 +668,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); - NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtual : NetworkOffering.GuestIpType.Direct; + Network.GuestIpType guestIpType = useVirtualNetwork ? Network.GuestIpType.Virtual : Network.GuestIpType.Direct; tags = cleanupTags(tags); ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags, false); @@ -696,15 +697,15 @@ public class ConfigurationServerImpl implements ConfigurationServer { Integer rateMbps = getIntegerConfigValue(Config.NetworkThrottlingRate.key(), null); Integer multicastRateMbps = getIntegerConfigValue(Config.MulticastThrottlingRate.key(), null); - NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public, null); + NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public); publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering); - NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management, null); + NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management); managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering); - NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control, null); + NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control); controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering); - NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, null); + NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage); storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering); - NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SysteGuestNetwork, TrafficType.Guest, null); + NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SysteGuestNetwork, TrafficType.Guest); guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering); NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false); @@ -732,7 +733,6 @@ public class ConfigurationServerImpl implements ConfigurationServer { guruNames.put(TrafficType.Storage, PodBasedNetworkGuru.class.getSimpleName()); guruNames.put(TrafficType.Guest, DirectPodBasedNetworkGuru.class.getSimpleName()); - for (DataCenterVO zone : zones) { long zoneId = zone.getId(); long accountId = 1L; diff --git a/server/src/com/cloud/service/ServiceOfferingVO.java b/server/src/com/cloud/service/ServiceOfferingVO.java index 9591f6c8b57..d50c4513b8c 100644 --- a/server/src/com/cloud/service/ServiceOfferingVO.java +++ b/server/src/com/cloud/service/ServiceOfferingVO.java @@ -27,7 +27,7 @@ import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; import javax.persistence.Transient; -import com.cloud.offering.NetworkOffering; +import com.cloud.network.Network; import com.cloud.offering.ServiceOffering; import com.cloud.storage.DiskOfferingVO; @@ -56,13 +56,13 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering @Column(name="guest_ip_type") @Enumerated(EnumType.STRING) - private NetworkOffering.GuestIpType guestIpType; + private Network.GuestIpType guestIpType; protected ServiceOfferingVO() { super(); } - public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse) { + public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, Network.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse) { super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse,false); this.cpu = cpu; this.ramSize = ramSize; @@ -73,7 +73,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering this.guestIpType = guestIpType; } - public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId) { + public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, Network.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId) { super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse,false,domainId); this.cpu = cpu; this.ramSize = ramSize; @@ -149,12 +149,12 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering return multicastRateMbps; } - public void setGuestIpType(NetworkOffering.GuestIpType guestIpType) { + public void setGuestIpType(Network.GuestIpType guestIpType) { this.guestIpType = guestIpType; } @Override - public NetworkOffering.GuestIpType getGuestIpType() { + public Network.GuestIpType getGuestIpType() { return guestIpType; } diff --git a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java index 255461e3b8f..2e8d3f3fa1c 100644 --- a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java @@ -32,7 +32,7 @@ import com.cloud.capacity.dao.CapacityDao; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; -import com.cloud.offering.NetworkOffering; +import com.cloud.network.Network; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; @@ -150,14 +150,14 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator { } } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { so = new ServiceOfferingVO("Fake Offering For DomP", 1, - _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + _proxyRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.DomainRouter) { - so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else { assert(false) : "Unsupported system vm type"; - so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, false); + so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, false); } long usedMemory = calcHostAllocatedCpuMemoryCapacity(vmOnHost, CapacityVO.CAPACITY_TYPE_MEMORY); @@ -256,14 +256,14 @@ public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator { so = _offeringDao.findById(userVm.getServiceOfferingId()); } else if(vm.getType() == VirtualMachine.Type.ConsoleProxy) { so = new ServiceOfferingVO("Fake Offering For DomP", 1, - _proxyRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + _proxyRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else if(vm.getType() == VirtualMachine.Type.DomainRouter) { - so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, true); } else { assert(false) : "Unsupported system vm type"; - so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, NetworkOffering.GuestIpType.Virtual, false, true, null, false); + so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, 0, 0, false, null, Network.GuestIpType.Virtual, false, true, null, false); } if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) { diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index ace1022cd41..65ed6246a4d 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -82,12 +82,12 @@ import com.cloud.info.RunningHostCountInfo; import com.cloud.info.RunningHostInfoAgregator; import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo; import com.cloud.network.IpAddrAllocator; +import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.NetworkDao; -import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; @@ -943,7 +943,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); - _serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, true, null, NetworkOffering.GuestIpType.Virtual, useLocalStorage, true, null, true); + _serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, 0, 0, true, null, Network.GuestIpType.Virtual, useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-SecondaryStorage"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); _template = _templateDao.findConsoleProxyTemplate(); diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java index fe2d292d826..b41cbee93a2 100644 --- a/server/src/com/cloud/test/DatabaseConfig.java +++ b/server/src/com/cloud/test/DatabaseConfig.java @@ -51,7 +51,7 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import com.cloud.host.Status; -import com.cloud.offering.NetworkOffering; +import com.cloud.network.Network; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDaoImpl; import com.cloud.storage.DiskOfferingVO; @@ -751,11 +751,11 @@ public class DatabaseConfig { boolean ha = Boolean.parseBoolean(_currentObjectParams.get("enableHA")); boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored")); String guestIpType = _currentObjectParams.get("guestIpType"); - NetworkOffering.GuestIpType type = null; + Network.GuestIpType type = null; if (guestIpType == null) { - type = NetworkOffering.GuestIpType.Virtual; + type = Network.GuestIpType.Virtual; } else { - type = NetworkOffering.GuestIpType.valueOf(guestIpType); + type = Network.GuestIpType.valueOf(guestIpType); } boolean useLocalStorage; diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index bc064d9269f..bb8b5b115bc 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -122,7 +122,6 @@ import com.cloud.network.IpAddrAllocator; import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; -import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; @@ -134,7 +133,6 @@ import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.rules.RulesManager; import com.cloud.network.security.SecurityGroupManager; import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offering.ServiceOffering; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.server.Criteria; @@ -933,7 +931,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager public void releaseGuestIpAddress(UserVmVO userVm) { ServiceOffering offering = _offeringDao.findById(userVm.getServiceOfferingId()); - if (offering.getGuestIpType() != NetworkOffering.GuestIpType.Virtual) { + if (offering.getGuestIpType() != Network.GuestIpType.Virtual) { IPAddressVO guestIP = (userVm.getGuestIpAddress() == null) ? null : _ipAddressDao.findById(new Ip(userVm.getGuestIpAddress())); if (guestIP != null && guestIP.getAllocatedTime() != null) { _ipAddressDao.unassignIpAddress(new Ip(userVm.getGuestIpAddress())); @@ -2672,7 +2670,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } if (useVirtualNetwork != null) { - sc.setJoinParameters("serviceSearch", "guestIpType", NetworkOffering.GuestIpType.Virtual.toString()); + sc.setJoinParameters("serviceSearch", "guestIpType", Network.GuestIpType.Virtual.toString()); } if (keyword != null) { diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index 94ed2bce5f3..0c4e68c1416 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -92,9 +92,6 @@ public interface DomainRouterDao extends GenericDao, State * @return DomainRouterVO or null if not found. */ public DomainRouterVO findByPublicIpAddress(String ipAddress); - - - public List findLonelyRouters(); /** * Gets the next dhcp ip address to be used for vms from this domain router. diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index 4dd2aa65f74..5811186c8f3 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -20,7 +20,6 @@ package com.cloud.vm.dao; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -46,7 +45,6 @@ import com.cloud.vm.VirtualMachine.State; public class DomainRouterDaoImpl extends GenericDaoBase implements DomainRouterDao { private static final Logger s_logger = Logger.getLogger(DomainRouterDaoImpl.class); - private static final String FindLonelyRoutersSql = "SELECT dr.id FROM domain_router dr, vm_instance vm WHERE dr.id=vm.id AND vm.state = 'Running' AND dr.id NOT IN (SELECT DISTINCT domain_router_id FROM user_vm uvm, vm_instance vmi WHERE (vmi.state = 'Running' OR vmi.state = 'Starting' OR vmi.state='Stopping' OR vmi.state = 'Migrating') AND vmi.id = uvm.id)"; private static final String GetNextDhcpAddressSql = "UPDATE domain_router set dhcp_ip_address = (@LAST_DHCP:=dhcp_ip_address) + 1 WHERE id = ?"; private static final String GetLastDhcpSql = "SELECT @LAST_DHCP"; @@ -255,24 +253,6 @@ public class DomainRouterDaoImpl extends GenericDaoBase im return listBy(sc); } - @Override - public List findLonelyRouters() { - ArrayList ids = new ArrayList(); - PreparedStatement pstmt = null; - Transaction txn = Transaction.currentTxn(); - try { - pstmt = txn.prepareAutoCloseStatement(FindLonelyRoutersSql); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - ids.add(rs.getLong(1)); - } - - } catch (SQLException e) { - throw new CloudRuntimeException("Problem finding routers: " + pstmt.toString(), e); - } - return ids; - } - @Override public long getNextDhcpIpAddress(long id) { Transaction txn = Transaction.currentTxn(); diff --git a/server/src/com/cloud/vm/dao/VMInstanceDao.java b/server/src/com/cloud/vm/dao/VMInstanceDao.java index 9babfaabdf6..d5675245bcd 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDao.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDao.java @@ -84,4 +84,6 @@ public interface VMInstanceDao extends GenericDao, StateDao< List listByZoneIdAndType(long zoneId, VirtualMachine.Type type); List listUpByHostId(Long hostId); List listByLastHostId(Long hostId); + + List listByTypeAndState(State state, VirtualMachine.Type type); } diff --git a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java index 3c7adce640d..bd70da428e7 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -62,6 +62,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem protected final SearchBuilder HostIdTypesSearch; protected final SearchBuilder HostIdUpTypesSearch; protected final SearchBuilder HostUpSearch; + protected final SearchBuilder TypeStateSearch; protected final Attribute _updateTimeAttr; @@ -136,6 +137,11 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem HostUpSearch.and("states", HostUpSearch.entity().getState(), SearchCriteria.Op.IN); HostUpSearch.done(); + TypeStateSearch = createSearchBuilder(); + TypeStateSearch.and("type", TypeStateSearch.entity().getType(), SearchCriteria.Op.EQ); + TypeStateSearch.and("state", TypeStateSearch.entity().getState(), SearchCriteria.Op.EQ); + TypeStateSearch.done(); + _updateTimeAttr = _allAttributes.get("updateTime"); assert _updateTimeAttr != null : "Couldn't get this updateTime attribute"; } @@ -282,6 +288,14 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem sc.setParameters("types", (Object[]) types); return listBy(sc); } + + @Override + public List listByTypeAndState(State state, VirtualMachine.Type type) { + SearchCriteria sc = TypeStateSearch.create(); + sc.setParameters("type", type); + sc.setParameters("state", state); + return listBy(sc); + } @Override public VMInstanceVO findByIdTypes(long id, Type... types) {