diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java index 426b759d56d..cd0bc4bc36a 100644 --- a/api/src/com/cloud/configuration/ConfigurationService.java +++ b/api/src/com/cloud/configuration/ConfigurationService.java @@ -34,8 +34,6 @@ import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; import com.cloud.user.Account; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachine.Type; public interface ConfigurationService { @@ -184,7 +182,7 @@ public interface ConfigurationService { NetworkOffering getNetworkOffering(long id); - Integer getNetworkRate(long networkOfferingId, Type vmType); + Integer getNetworkOfferingNetworkRate(long networkOfferingId); Account getVlanAccount(long vlanId); @@ -195,5 +193,7 @@ public interface ConfigurationService { ServiceOffering getServiceOffering(long serviceOfferingId); Long getDefaultPageSize(); + + Integer getServiceOfferingNetworkRate(long serviceOfferingId); } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index ba39a3fcc8c..4594ddfd5a6 100644 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -36,6 +36,7 @@ import com.cloud.network.Network.Capability; import com.cloud.network.Network.Service; import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; +import com.cloud.vm.VirtualMachine.Type; public interface NetworkService { @@ -77,4 +78,6 @@ public interface NetworkService { Long getDedicatedNetworkDomain(long networkId); Network updateNetwork(long networkId, String name, String displayText, Account caller); + + Integer getNetworkRate(long networkId, Long vmId); } diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index 7fa98b5e453..8d80248075a 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -60,12 +60,12 @@ public interface ServiceOffering { /** * @return the rate in megabits per sec to which a VM's network interface is throttled to */ - int getRateMbps(); + Integer getRateMbps(); /** * @return the rate megabits per sec to which a VM's multicast&broadcast traffic is throttled to */ - int getMulticastRateMbps(); + Integer getMulticastRateMbps(); /** * @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 660e05f529a..4cdd3b5ba35 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java @@ -251,12 +251,12 @@ public class UserConcentratedAllocator implements PodAllocator { so = new ServiceOfferingVO("Fake Offering For DomP", 1, _proxyRamSize, 0, 0, 0, false, null, 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, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, null, null, false, null, 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, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, null, null, false, null, 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, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, null, null, false, null, false, true, null, true); } if(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) { diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 987b13a84ae..015bc217db1 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -524,7 +524,7 @@ public class ApiDBUtils { } public static Integer getNetworkRate(long networkOfferingId) { - return _configMgr.getNetworkRate(networkOfferingId, null); + return _configMgr.getNetworkOfferingNetworkRate(networkOfferingId); } public static Account getVlanAccount(long vlanId) { diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 3e5be400da7..8462a9781eb 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -60,11 +60,12 @@ public enum Config { GuestNetmask("Network", AgentManager.class, String.class, "guest.netmask", "255.255.255.0", "The netmask of the guest virtual network.", "netmask"), GuestVlanBits("Network", ManagementServer.class, Integer.class, "guest.vlan.bits", "12", "The number of bits to reserve for the VLAN identifier in the guest subnet.", null), //MulticastThrottlingRate("Network", ManagementServer.class, Integer.class, "multicast.throttling.rate", "10", "Default multicast rate in megabits per second allowed.", null), - NetworkThrottlingRate("Network", ManagementServer.class, Integer.class, "network.throttling.rate", "200", "Default data transfer rate in megabits per second allowed.", null), + NetworkThrottlingRate("Network", ManagementServer.class, Integer.class, "network.throttling.rate", "200", "Default data transfer rate in megabits per second allowed in network.", null), GuestDomainSuffix("Network", AgentManager.class, String.class, "guest.domain.suffix", "cloud.internal", "Default domain name for vms inside virtualized networks fronted by router", null), DirectNetworkNoDefaultRoute("Network", ManagementServer.class, Boolean.class, "direct.network.no.default.route", "false", "Direct Network Dhcp Server should not send a default route", "true/false"), OvsNetwork("Network", ManagementServer.class, Boolean.class, "open.vswitch.vlan.network", "false", "enable/disable vlan remapping of open vswitch network", null), OvsTunnelNetwork("Network", ManagementServer.class, Boolean.class, "open.vswitch.tunnel.network", "false", "enable/disable open vswitch tunnel network(no vlan)", null), + VmNetworkThrottlingRate("Network", ManagementServer.class, Integer.class, "vm.network.throttling.rate", "200", "Default data transfer rate in megabits per second allowed in User vm's default network.", null), //VPN RemoteAccessVpnPskLength("Network", AgentManager.class, Integer.class, "remote.access.vpn.psk.length", "24", "The length of the ipsec preshared key (minimum 8, maximum 256)", null), diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 2a519d01083..a114d75d4d3 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -127,8 +127,6 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.SecondaryStorageVmDao; @@ -1450,12 +1448,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Override @ActionEvent (eventType=EventTypes.EVENT_SERVICE_OFFERING_CREATE, eventDescription="creating service offering") public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, String tags, Long domainId, String hostTag) { - String networkRateStr = _configDao.getValue("network.throttling.rate"); - String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); - int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); - int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); tags = cleanupTags(tags); - ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, localStorageRequired, false, tags, false, domainId, hostTag); + ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, displayText, localStorageRequired, false, tags, false, domainId, hostTag); if ((offering = _serviceOfferingDao.persist(offering)) != null) { UserContext.current().setEventDetails("Service offering id=" + offering.getId()); @@ -2851,7 +2845,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } @Override - public Integer getNetworkRate(long networkOfferingId, Type vmType) { + public Integer getNetworkOfferingNetworkRate(long networkOfferingId) { // validate network offering information NetworkOffering no = getNetworkOffering(networkOfferingId); @@ -2859,15 +2853,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Unable to find network offering by id=" + networkOfferingId); } - // For router's public network we use networkRate from guestNetworkOffering - if (vmType != null && vmType == VirtualMachine.Type.DomainRouter && no.getTrafficType() == TrafficType.Public && no.getGuestType() == null) { - List guestOfferings = _networkOfferingDao.listByTrafficTypeAndGuestType(false, TrafficType.Guest, GuestIpType.Virtual); - if (!guestOfferings.isEmpty()) { - // We have one default guest virtual network offering now - no = guestOfferings.get(0); - } - } - Integer networkRate; if (no.getRateMbps() != null) { networkRate = no.getRateMbps(); @@ -2974,4 +2959,29 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura public Long getDefaultPageSize() { return _defaultPageSize; } + + @Override + public Integer getServiceOfferingNetworkRate(long serviceOfferingId) { + + // validate network offering information + ServiceOffering offering = getServiceOffering(serviceOfferingId); + if (offering == null) { + throw new InvalidParameterValueException("Unable to find service offering by id=" + serviceOfferingId); + } + + Integer networkRate; + if (offering.getRateMbps() != null) { + networkRate = offering.getRateMbps(); + } else { + networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key())); + } + + // networkRate is unsigned int in serviceOffering table, and can't be set to -1 + // so 0 means unlimited; we convert it to -1, so we are consistent with all our other resources where -1 means unlimited + if (networkRate == 0) { + networkRate = -1; + } + + return networkRate; + } } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index d7b7807fe37..cec7696dab3 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1187,7 +1187,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, _proxyCpuMHz, 0, 0, true, null, useLocalStorage, true, null, true); + _serviceOffering = new ServiceOfferingVO("System Offering For Console Proxy", 1, _proxyRamSize, _proxyCpuMHz, null, null, true, null, useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-ConsoleProxy"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); diff --git a/server/src/com/cloud/migration/ServiceOffering21VO.java b/server/src/com/cloud/migration/ServiceOffering21VO.java index 3a779df8996..527bad59d8e 100644 --- a/server/src/com/cloud/migration/ServiceOffering21VO.java +++ b/server/src/com/cloud/migration/ServiceOffering21VO.java @@ -27,10 +27,10 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe private int ramSize; @Column(name="nw_rate") - private int rateMbps; + private Integer rateMbps; @Column(name="mc_rate") - private int multicastRateMbps; + private Integer multicastRateMbps; @Column(name="ha_enabled") private boolean offerHA; @@ -46,7 +46,7 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe super(); } - 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) { + public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer 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; @@ -57,7 +57,7 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe this.guestIpType = guestIpType; } - 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, String hostTag) { + public ServiceOffering21VO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, Network.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, String hostTag) { this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, guestIpType, useLocalStorage, recreatable, tags); this.hostTag = hostTag; } @@ -109,21 +109,21 @@ public class ServiceOffering21VO extends DiskOffering21VO implements ServiceOffe return ramSize; } - public void setRateMbps(int rateMbps) { + public void setRateMbps(Integer rateMbps) { this.rateMbps = rateMbps; } @Override - public int getRateMbps() { + public Integer getRateMbps() { return rateMbps; } - public void setMulticastRateMbps(int multicastRateMbps) { + public void setMulticastRateMbps(Integer multicastRateMbps) { this.multicastRateMbps = multicastRateMbps; } @Override - public int getMulticastRateMbps() { + public Integer getMulticastRateMbps() { return multicastRateMbps; } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index b3dfd7e56bd..f4a584dc42d 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -139,6 +139,7 @@ import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.dao.VMInstanceDao; import edu.emory.mathcs.backport.java.util.Collections; @@ -167,7 +168,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Inject ConfigurationDao _configDao; @Inject - UserVmDao _vmDao = null; + UserVmDao _userVmDao = null; @Inject ResourceLimitDao _limitDao = null; @Inject @@ -202,6 +203,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Adapters _networkElements; @Inject NetworkDomainDao _networkDomainDao; + @Inject + VMInstanceDao _vmDao; private HashMap _systemNetworks = new HashMap(5); @@ -981,8 +984,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag deviceIds[devId] = true; nics.add(vo); - NetworkOffering no = _configMgr.getNetworkOffering(config.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); + Integer networkRate = getNetworkRate(config.getId(), vm.getId()); vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate)); } @@ -1075,7 +1077,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag to.setDns2(profile.getDns2()); } - Integer networkRate = _configMgr.getNetworkRate(config.getNetworkOfferingId(), null); + Integer networkRate = getNetworkRate(config.getId(), null); to.setNetworkRateMbps(networkRate); return to; @@ -1195,8 +1197,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); NetworkGuru guru = implemented.first(); NetworkVO network = implemented.second(); - NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId(), vmProfile.getType()); + Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); NicProfile profile = null; if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { nic.setState(Nic.State.Reserving); @@ -1245,8 +1246,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List nics = _nicDao.listByVmId(vm.getId()); for (NicVO nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); - NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); + Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate); @@ -1302,8 +1302,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (nics != null) { for (Nic nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); - NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); + Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate); @@ -1986,7 +1985,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } //Make sure that there are no user vms in the network that are not Expunged/Error - List userVms = _vmDao.listByNetworkId(networkId); + List userVms = _userVmDao.listByNetworkId(networkId); for (UserVmVO vm : userVms) { if (!(vm.getState() == VirtualMachine.State.Error || (vm.getState() == VirtualMachine.State.Expunging && vm.getRemoved() != null))) { @@ -2801,6 +2800,33 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _networksDao.update(networkId, network); return network; - } + + @Override + public Integer getNetworkRate(long networkId, Long vmId) { + VMInstanceVO vm = null; + if (vmId != null) { + vm = _vmDao.findById(vmId); + } + Network network = getNetwork(networkId); + NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); + + //For default vms network offering get rate information from the service offering; for other situations get information from the network offering + if (vm != null && vm.getType() == Type.User && network.isDefault()) { + return _configMgr.getServiceOfferingNetworkRate(vm.getServiceOfferingId()); + } else { + // For router's public network we use networkRate from guestNetworkOffering + if (vm != null && vm.getType() == Type.DomainRouter && networkOffering.getTrafficType() == TrafficType.Public && networkOffering.getGuestType() == null) { + List guestOfferings = _networkOfferingDao.listByTrafficTypeAndGuestType(false, TrafficType.Guest, GuestIpType.Virtual); + if (!guestOfferings.isEmpty()) { + // We have one default guest virtual network offering now + networkOffering = guestOfferings.get(0); + } + } + + return _configMgr.getNetworkOfferingNetworkRate(networkOffering.getId()); + } + + } + } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 3b854fc36f9..c69bc960a61 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -565,7 +565,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this); boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); - _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, 0, 0, true, null, useLocalStorage, true, null, true); + _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null, null, true, null, useLocalStorage, true, null, true); _offering.setUniqueName("Cloud.Com-SoftwareRouter"); _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering); @@ -1415,9 +1415,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String vmGuestAddress = null; //Get network rate - required for IpAssoc - Network network = _networkMgr.getNetwork(ipAddr.getNetworkId()); - NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId(), null); + Integer networkRate = _networkMgr.getNetworkRate(ipAddr.getNetworkId(), null); IpAddressTO ip = new IpAddressTO(ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate); ipsToSend[i++] = ip; diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 530a29982fc..22de8b33b3a 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -53,8 +53,6 @@ import com.cloud.dc.VlanVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.VlanDao; -import com.cloud.domain.DomainVO; -import com.cloud.domain.dao.DomainDao; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network.GuestIpType; @@ -63,7 +61,6 @@ 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.network.dao.IPAddressDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.guru.ControlNetworkGuru; import com.cloud.network.guru.DirectPodBasedNetworkGuru; @@ -77,7 +74,6 @@ import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.dao.DiskOfferingDao; -import com.cloud.storage.dao.SnapshotPolicyDao; import com.cloud.test.IPRangeConfig; import com.cloud.user.Account; import com.cloud.user.User; @@ -94,33 +90,27 @@ public class ConfigurationServerImpl implements ConfigurationServer { public static final Logger s_logger = Logger.getLogger(ConfigurationServerImpl.class.getName()); private final ConfigurationDao _configDao; - private final SnapshotPolicyDao _snapPolicyDao; private final DataCenterDao _zoneDao; private final HostPodDao _podDao; private final DiskOfferingDao _diskOfferingDao; private final ServiceOfferingDao _serviceOfferingDao; - private final DomainDao _domainDao; private final NetworkOfferingDao _networkOfferingDao; private final DataCenterDao _dataCenterDao; private final NetworkDao _networkDao; private final VlanDao _vlanDao; - private final IPAddressDao _ipAddressDao; public ConfigurationServerImpl() { ComponentLocator locator = ComponentLocator.getLocator(Name); _configDao = locator.getDao(ConfigurationDao.class); - _snapPolicyDao = locator.getDao(SnapshotPolicyDao.class); _zoneDao = locator.getDao(DataCenterDao.class); _podDao = locator.getDao(HostPodDao.class); _diskOfferingDao = locator.getDao(DiskOfferingDao.class); _serviceOfferingDao = locator.getDao(ServiceOfferingDao.class); _networkOfferingDao = locator.getDao(NetworkOfferingDao.class); - _domainDao = locator.getDao(DomainDao.class); _dataCenterDao = locator.getDao(DataCenterDao.class); _networkDao = locator.getDao(NetworkDao.class); _vlanDao = locator.getDao(VlanDao.class); - _ipAddressDao = locator.getDao(IPAddressDao.class); } @Override @DB @@ -171,23 +161,18 @@ public class ConfigurationServerImpl implements ConfigurationServer { s_logger.debug("ConfigurationServer made secondary storage copy use realhostip."); - // Save Direct Networking service offerings + // Save default service offerings createServiceOffering(User.UID_SYSTEM, "Small Instance", 1, 512, 500, "Small Instance, $0.05 per hour", false, false, null); createServiceOffering(User.UID_SYSTEM, "Medium Instance", 1, 1024, 1000, "Medium Instance, $0.10 per hour", false, false, null); - // Save Virtual Networking service offerings - //createServiceOffering(User.UID_SYSTEM, "Small Instance", 1, 512, 500, "Small Instance, Virtual Networking, $0.05 per hour", false, false, true, null); - //createServiceOffering(User.UID_SYSTEM, "Medium Instance", 1, 1024, 1000, "Medium Instance, Virtual Networking, $0.10 per hour", false, false, true, null); // Save default disk offerings createDiskOffering(null, "Small", "Small Disk, 5 GB", 5, null); createDiskOffering(null, "Medium", "Medium Disk, 20 GB", 20, null); createDiskOffering(null, "Large", "Large Disk, 100 GB", 100, null); - //_configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Private", "Private Disk", 0, null); // Save the mount parent to the configuration table String mountParent = getMountParent(); if (mountParent != null) { _configDao.update("mount.parent", mountParent); -// _configMgr.updateConfiguration(User.UID_SYSTEM, "mount.parent", mountParent); s_logger.debug("ConfigurationServer saved \"" + mountParent + "\" as mount.parent."); } else { s_logger.debug("ConfigurationServer could not detect mount.parent."); @@ -196,7 +181,6 @@ public class ConfigurationServerImpl implements ConfigurationServer { String hostIpAdr = getHost(); if (hostIpAdr != null) { _configDao.update("host", hostIpAdr); -// _configMgr.updateConfiguration(User.UID_SYSTEM, "host", hostIpAdr); s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host."); } @@ -562,7 +546,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { try { String encodedKey = null; - // Algorithm for SSO Keys is SHA1, should this be configuable? + // Algorithm for SSO Keys is SHA1, should this be configurable? KeyGenerator generator = KeyGenerator.getInstance("HmacSHA1"); SecretKey key = generator.generateKey(); encodedKey = Base64.encodeBase64URLSafeString(key.getEncoded()); @@ -573,48 +557,6 @@ public class ConfigurationServerImpl implements ConfigurationServer { } } - private DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId, NetworkType zoneType) throws InvalidParameterValueException, InternalErrorException { - int vnetStart = 0; - int vnetEnd = 0; - if (vnetRange != null) { - String[] tokens = vnetRange.split("-"); - try { - vnetStart = Integer.parseInt(tokens[0]); - if (tokens.length == 1) { - vnetEnd = vnetStart; - } else { - vnetEnd = Integer.parseInt(tokens[1]); - } - } catch (NumberFormatException e) { - throw new InvalidParameterValueException("Please specify valid integers for the vlan range."); - } - } - - //checking the following params outside checkzoneparams method as we do not use these params for updatezone - //hence the method below is generic to check for common params - if ((guestCidr != null) && !NetUtils.isValidCIDR(guestCidr)) { - throw new InvalidParameterValueException("Please enter a valid guest cidr"); - } - - if(domainId!=null){ - DomainVO domainVo = _domainDao.findById(domainId); - - if(domainVo == null) { - throw new InvalidParameterValueException("Please specify a valid domain id"); - } - } - // Create the new zone in the database - DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId, zoneType, false); - zone = _zoneDao.persist(zone); - - // Add vnet entries for the new zone - if (vnetRange != null){ - _zoneDao.addVnet(zone.getId(), vnetStart, vnetEnd); - } - - return zone; - } - @DB protected HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp) throws InvalidParameterValueException, InternalErrorException { String[] cidrPair = cidr.split("\\/"); @@ -685,12 +627,8 @@ public class ConfigurationServerImpl implements ConfigurationServer { } private ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, String tags) { - String networkRateStr = _configDao.getValue("network.throttling.rate"); - String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); - int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr)); - int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); tags = cleanupTags(tags); - ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, localStorageRequired, false, tags, false); + ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, displayText, localStorageRequired, false, tags, false); if ((offering = _serviceOfferingDao.persist(offering)) != null) { return offering; @@ -754,14 +692,6 @@ public class ConfigurationServerImpl implements ConfigurationServer { defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering); } - private Integer getIntegerConfigValue(String configKey, Integer dflt) { - String value = _configDao.getValue(configKey); - if (value != null) { - return Integer.parseInt(value); - } - return dflt; - } - private void createDefaultNetworks() { List zones = _dataCenterDao.listAll(); long id = 1; diff --git a/server/src/com/cloud/service/ServiceOfferingVO.java b/server/src/com/cloud/service/ServiceOfferingVO.java index a95e0e54c5c..e6f060f2693 100644 --- a/server/src/com/cloud/service/ServiceOfferingVO.java +++ b/server/src/com/cloud/service/ServiceOfferingVO.java @@ -43,10 +43,10 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering private int ramSize; @Column(name="nw_rate") - private int rateMbps; + private Integer rateMbps; @Column(name="mc_rate") - private int multicastRateMbps; + private Integer multicastRateMbps; @Column(name="ha_enabled") private boolean offerHA; @@ -58,7 +58,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering super(); } - public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse) { + public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse) { super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse, true); this.cpu = cpu; this.ramSize = ramSize; @@ -68,7 +68,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering this.offerHA = offerHA; } - public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId) { + public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId) { super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse, true, domainId); this.cpu = cpu; this.ramSize = ramSize; @@ -78,7 +78,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering this.offerHA = offerHA; } - public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId, String hostTag) { + public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId, String hostTag) { this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, displayText, useLocalStorage, recreatable, tags, systemUse, domainId); this.hostTag = hostTag; } @@ -130,21 +130,21 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering return ramSize; } - public void setRateMbps(int rateMbps) { + public void setRateMbps(Integer rateMbps) { this.rateMbps = rateMbps; } @Override - public int getRateMbps() { + public Integer getRateMbps() { return rateMbps; } - public void setMulticastRateMbps(int multicastRateMbps) { + public void setMulticastRateMbps(Integer multicastRateMbps) { this.multicastRateMbps = multicastRateMbps; } @Override - public int getMulticastRateMbps() { + public Integer getMulticastRateMbps() { return multicastRateMbps; } diff --git a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java index 9dbdd98dc01..91a6c9d553c 100644 --- a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java @@ -140,14 +140,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, false, true, null, true); + _proxyRamSize, 0, null, null, false, null, 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, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For Secondary Storage VM", 1, _secStorageVmRamSize, 0, null, null, false, null, 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, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, null, null, false, null, 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, false, true, null, false); + so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, null, null, false, null, false, true, null, false); } long usedMemory = calcHostAllocatedCpuMemoryCapacity(vmOnHost, CapacityVO.CAPACITY_TYPE_MEMORY); @@ -246,14 +246,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, false, true, null, true); + _proxyRamSize, 0, null, null, false, null, 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, 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, false, true, null, true); + so = new ServiceOfferingVO("Fake Offering For DomR", 1, _routerRamSize, 0, null, null, false, null, 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, false, true, null, false); + so = new ServiceOfferingVO("Fake Offering For unknow system VM", 1, 128, 0, null, null, false, null, 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 22bb4f769a2..7cf126f3e94 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -675,7 +675,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V _itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this); _useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); - _serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, _secStorageVmRamSize, _secStorageVmCpuMHz, 0, 0, true, null, _useLocalStorage, true, null, true); + _serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, _secStorageVmRamSize, _secStorageVmCpuMHz, null, null, true, null, _useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-SecondaryStorage"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java index c6297e7aff5..f046973da8b 100755 --- a/server/src/com/cloud/test/DatabaseConfig.java +++ b/server/src/com/cloud/test/DatabaseConfig.java @@ -162,8 +162,6 @@ public class DatabaseConfig { s_configurationDescriptions.put("volume.stats.interval", "the interval in milliseconds when volume stats are retrieved from agents"); s_configurationDescriptions.put("host", "host address to listen on for agent connection"); s_configurationDescriptions.put("port", "port to listen on for agent connection"); - //s_configurationDescriptions.put("guest.ip.network", "ip address for the router"); - //s_configurationDescriptions.put("guest.netmask", "default netmask for the guest network"); s_configurationDescriptions.put("guest.domain.suffix", "domain suffix for users"); s_configurationDescriptions.put("instance.name", "Name of the deployment instance"); s_configurationDescriptions.put("storage.overprovisioning.factor", "Storage Allocator overprovisioning factor"); @@ -211,7 +209,6 @@ public class DatabaseConfig { s_configurationDescriptions.put("snapshot.test.days.per.month", "Set it to a smaller value to take more recurring snapshots"); s_configurationDescriptions.put("snapshot.test.weeks.per.month", "Set it to a smaller value to take more recurring snapshots"); s_configurationDescriptions.put("snapshot.test.months.per.year", "Set it to a smaller value to take more recurring snapshots"); -// s_configurationDescriptions.put("network.type", "The type of network that this deployment will use."); s_configurationDescriptions.put("hypervisor.type", "The type of hypervisor that this deployment will use."); @@ -246,8 +243,6 @@ public class DatabaseConfig { s_configurationComponents.put("expunge.interval", "UserVmManager"); s_configurationComponents.put("host", "AgentManager"); s_configurationComponents.put("port", "AgentManager"); -// s_configurationComponents.put("guest.ip.network", "AgentManager"); -// s_configurationComponents.put("guest.netmask", "AgentManager"); s_configurationComponents.put("domain", "AgentManager"); s_configurationComponents.put("instance.name", "AgentManager"); s_configurationComponents.put("storage.overprovisioning.factor", "StorageAllocator"); @@ -289,7 +284,6 @@ public class DatabaseConfig { s_configurationComponents.put("snapshot.test.days.per.month", "SnapshotManager"); s_configurationComponents.put("snapshot.test.weeks.per.month", "SnapshotManager"); s_configurationComponents.put("snapshot.test.months.per.year", "SnapshotManager"); -// s_configurationComponents.put("network.type", "ManagementServer"); s_configurationComponents.put("hypervisor.type", "ManagementServer"); @@ -300,8 +294,6 @@ public class DatabaseConfig { s_defaultConfigurationValues.put("integration.api.port", "8096"); s_defaultConfigurationValues.put("usage.stats.job.exec.time", "00:15"); // run at 12:15am s_defaultConfigurationValues.put("usage.stats.job.aggregation.range", "1440"); // do a daily aggregation -// s_defaultConfigurationValues.put("guest.ip.network", "10.1.1.1"); -// s_defaultConfigurationValues.put("guest.netmask", "255.255.255.0"); s_defaultConfigurationValues.put("storage.overprovisioning.factor", "2"); s_defaultConfigurationValues.put("retries.per.host", "2"); s_defaultConfigurationValues.put("ping.timeout", "2.5"); @@ -331,13 +323,10 @@ public class DatabaseConfig { s_defaultConfigurationValues.put("restart.retry.interval", "600"); s_defaultConfigurationValues.put("investigate.retry.interval", "60"); s_defaultConfigurationValues.put("migrate.retry.interval", "120"); - // s_defaultConfigurationValues.put("network.throttling.rate", "200"); - // s_defaultConfigurationValues.put("multicast.throttling.rate", "10"); s_defaultConfigurationValues.put("account.cleanup.interval", "86400"); s_defaultConfigurationValues.put("system.vm.use.local.storage", "false"); s_defaultConfigurationValues.put("use.local.storage", "false"); s_defaultConfigurationValues.put("init", "false"); -// s_defaultConfigurationValues.put("network.type", "vnet"); } protected DatabaseConfig() { @@ -431,8 +420,6 @@ public class DatabaseConfig { saveDefaultConfiguations(); txn.commit(); - // Save network.throttling.rate and multicast.throttling.rate for all service offerings, if these values are in the configuration table - saveThrottlingRates(); // Check pod CIDRs against each other, and against the guest ip network/netmask pzc.checkAllPodCidrSubnets(); @@ -776,8 +763,6 @@ public class DatabaseConfig { // int nwRate = Integer.parseInt(_currentObjectParams.get("nwRate")); // int mcRate = Integer.parseInt(_currentObjectParams.get("mcRate")); - int nwRate = 200; - int mcRate = 10; boolean ha = Boolean.parseBoolean(_currentObjectParams.get("enableHA")); boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored")); @@ -792,7 +777,7 @@ public class DatabaseConfig { useLocalStorage = false; } - ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, nwRate, mcRate, ha, displayText, useLocalStorage, false, null, false); + ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, useLocalStorage, false, null, false); ServiceOfferingDaoImpl dao = ComponentLocator.inject(ServiceOfferingDaoImpl.class); try { dao.persist(serviceOffering); diff --git a/server/src/com/cloud/upgrade/dao/Upgrade224to225.java b/server/src/com/cloud/upgrade/dao/Upgrade224to225.java new file mode 100644 index 00000000000..a79fc01acee --- /dev/null +++ b/server/src/com/cloud/upgrade/dao/Upgrade224to225.java @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.upgrade.dao; + +import java.io.File; +import java.sql.Connection; + +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.script.Script; + +public class Upgrade224to225 implements DbUpgrade { + + @Override + public String[] getUpgradableVersionRange() { + return new String[] {"2.2.4"}; + } + + @Override + public String getUpgradedVersion() { + return "2.2.5"; + } + + @Override + public boolean supportsRollingUpgrade() { + return true; + } + + @Override + public File[] getPrepareScripts() { + String script = Script.findScript("", "db/data-224to225.sql"); + if (script == null) { + throw new CloudRuntimeException("Unable to find db/data-224to225.sql"); + } + + return new File[] { new File(script) }; + } + + @Override + public void performDataMigration(Connection conn) { + } + + @Override + public File[] getCleanupScripts() { + return null; + } + +} diff --git a/setup/db/data-224to225.sql b/setup/db/data-224to225.sql new file mode 100644 index 00000000000..7e7011986b9 --- /dev/null +++ b/setup/db/data-224to225.sql @@ -0,0 +1,4 @@ +--; +-- Schema upgrade from 2.2.4 to 2.2.5; +--; +INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) VALUES ('Network', 'DEFAULT', 'management-server', 'vm.network.throttling.rate', 200, 'Default data transfer rate in megabits per second allowed in user vm\'s default network.');