diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 5b84b4787f1..8735a029450 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -137,7 +137,6 @@ public enum Config { SystemVMAutoReserveCapacity("Advanced", ManagementServer.class, Boolean.class, "system.vm.auto.reserve.capacity", "true", "Indicates whether or not to automatically reserver system VM standby capacity.", null), CPUOverprovisioningFactor("Advanced", ManagementServer.class, String.class, "cpu.overprovisioning.factor", "1", "Used for CPU overprovisioning calculation; available CPU will be (actualCpuCapacity * cpu.overprovisioning.factor)", null), LinkLocalIpNums("Advanced", ManagementServer.class, Integer.class, "linkLocalIp.nums", "10", "The number of link local ip that needed by domR(in power of 2)", null), - HypervisorDefaultType("Advanced", ManagementServer.class, String.class, "hypervisor.type", HypervisorType.KVM.toString(), "The type of hypervisor that this deployment will use.", "kvm,xenserver,vmware"), HypervisorList("Advanced", ManagementServer.class, String.class, "hypervisor.list", HypervisorType.KVM + "," + HypervisorType.XenServer + "," + HypervisorType.VMware, "The list of hypervisors that this deployment will use.", "hypervisorList"), ManagementHostIPAdr("Advanced", ManagementServer.class, String.class, "host", "localhost", "The ip address of management server", null), EventPurgeDelay("Advanced", ManagementServer.class, Integer.class, "event.purge.delay", "0", "Events older than specified number days will be purged", null), diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 081273fe4ea..451e3b6ebca 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -197,7 +197,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx private ConsoleProxyListener _listener; private ServiceOfferingVO _serviceOffering; - private VMTemplateVO _template; NetworkOfferingVO _publicNetworkOffering; NetworkOfferingVO _managementNetworkOffering; @@ -597,9 +596,16 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx for (NetworkOfferingVO offering : offerings) { networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null)); } - ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getHypervisorType(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0); + + VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId); + if (template == null) { + s_logger.debug("Can't find a template to start"); + throw new CloudRuntimeException("Insufficient capacity exception"); + } + + ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0); try { - proxy = _itMgr.allocate(proxy, _template, _serviceOffering, networks, plan, null, systemAcct); + proxy = _itMgr.allocate(proxy, template, _serviceOffering, networks, plan, null, systemAcct); } catch (InsufficientCapacityException e) { s_logger.warn("InsufficientCapacity", e); throw new CloudRuntimeException("Insufficient capacity exception", e); @@ -1084,7 +1090,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx public boolean isZoneReady(Map zoneHostInfoMap, long dataCenterId) { ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId); if (zoneHostInfo != null && isZoneHostReady(zoneHostInfo)) { - VMTemplateVO template = _templateDao.findConsoleProxyTemplate(); + VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId); HostVO secondaryStorageHost = _storageMgr.getSecondaryStorageHost(dataCenterId); boolean templateReady = false; @@ -1384,11 +1390,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-ConsoleProxy"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); - _template = _templateDao.findConsoleProxyTemplate(); - if (_template == null) { - throw new ConfigurationException("Unable to find the template for console proxy VMs"); - } - + _capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), STARTUP_DELAY, _capacityScanInterval, TimeUnit.MILLISECONDS); if (s_logger.isInfoEnabled()) { diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 97a1221f3ba..695cc890d87 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -285,12 +285,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Inject OvsTunnelManager _ovsTunnelMgr; - long _routerTemplateId = -1; int _routerRamSize; int _retry = 2; String _domain; String _instance; - String _defaultHypervisorType; String _mgmt_host; int _routerCleanupInterval = 3600; @@ -298,8 +296,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian private ServiceOfferingVO _offering; String _networkDomain; - private VMTemplateVO _template; - ScheduledExecutorService _executor; Account _systemAcct; @@ -571,8 +567,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian String value = configs.get("start.retry"); _retry = NumbersUtil.parseInt(value, 2); - _defaultHypervisorType = _configDao.getValue(Config.HypervisorDefaultType.key()); - value = configs.get("router.stats.interval"); _routerStatsInterval = NumbersUtil.parseInt(value, 300); @@ -591,7 +585,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _networkDomain = configs.get("guest.domain.suffix"); - s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize + "; templateId=" + _routerTemplateId); + s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize); final UserStatisticsDao statsDao = locator.getDao(UserStatisticsDao.class); if (statsDao == null) { @@ -607,12 +601,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian Network.GuestIpType.Virtual, useLocalStorage, true, null, true); _offering.setUniqueName("Cloud.Com-SoftwareRouter"); _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering); - _template = _templateDao.findRoutingTemplate(); - if (_template == null) { - s_logger.error("Unable to find system vm template."); - } else { - _routerTemplateId = _template.getId(); - } _systemAcct = _accountService.getSystemAccount(); @@ -930,10 +918,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr)); networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); networks.add(new Pair(controlConfig, null)); - - router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), _template.getId(), - _template.getHypervisorType(), _template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), _offering.getOfferHA(), guestNetwork.getNetworkDomain()); - router = _itMgr.allocate(router, _template, _offering, networks, plan, null, owner); + + /*Before starting router, already know the hypervisor type*/ + VMTemplateVO template = _templateDao.findRoutingTemplate(dest.getCluster().getHypervisorType()); + router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), + template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), _offering.getOfferHA(), guestNetwork.getNetworkDomain()); + router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner); } State state = router.getState(); @@ -983,10 +973,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); networks.add(new Pair(controlConfig, null)); - router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), _template.getId(), - _template.getHypervisorType(), _template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), _offering.getOfferHA(), guestNetwork.getNetworkDomain()); + /*Before starting router, already know the hypervisor type*/ + VMTemplateVO template = _templateDao.findRoutingTemplate(dest.getCluster().getHypervisorType()); + + router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), + template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), _offering.getOfferHA(), guestNetwork.getNetworkDomain()); router.setRole(Role.DHCP_USERDATA); - router = _itMgr.allocate(router, _template, _offering, networks, plan, null, owner); + router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner); } State state = router.getState(); if (state != State.Starting && state != State.Running) { diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index a37339f8dc1..4e3e1ca1794 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -168,11 +168,6 @@ public class ConfigurationServerImpl implements ConfigurationServer { // Default value is set as KVM because of FOSS build, when we are // running under premium, autoset to XenServer if we know it is from FOSS settings - String value = _configDao.getValue(Config.HypervisorDefaultType.key()); - if (value == null || value.equalsIgnoreCase(HypervisorType.KVM.toString())) { - _configDao.update("hypervisor.type", "xenserver"); - s_logger.debug("ConfigurationServer changed the hypervisor type to \"xenserver\"."); - } _configDao.update("secondary.storage.vm", "true"); s_logger.debug("ConfigurationServer made secondary storage vm required."); diff --git a/server/src/com/cloud/storage/dao/VMTemplateDao.java b/server/src/com/cloud/storage/dao/VMTemplateDao.java index bd39bb433d1..d3c44b350d8 100644 --- a/server/src/com/cloud/storage/dao/VMTemplateDao.java +++ b/server/src/com/cloud/storage/dao/VMTemplateDao.java @@ -50,9 +50,9 @@ public interface VMTemplateDao extends GenericDao { public VMTemplateVO findByTemplateNameAccountId(String templateName, Long accountId); //public void update(VMTemplateVO template); - public VMTemplateVO findRoutingTemplate(); - public List listAllRoutingTemplates(); - public VMTemplateVO findConsoleProxyTemplate(); + + public List listAllSystemVMTemplates(); + public List listDefaultBuiltinTemplates(); public String getRoutingTemplateUniqueName(); public List findIsosByIdAndPath(Long domainId, Long accountId, String path); @@ -66,5 +66,7 @@ public interface VMTemplateDao extends GenericDao { public List listByHypervisorType(HypervisorType hyperType); public List publicIsoSearch(); + VMTemplateVO findSystemVMTemplate(long zoneId); + VMTemplateVO findRoutingTemplate(HypervisorType type); } diff --git a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java index 8dd374ece38..6e5eba33744 100755 --- a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -22,6 +22,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.LinkedList; @@ -36,6 +37,9 @@ import org.apache.log4j.Logger; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.domain.DomainVO; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Storage; import com.cloud.storage.VMTemplateVO; @@ -61,7 +65,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem @Inject VMTemplateZoneDao _templateZoneDao; @Inject - ConfigurationDao _configDao; + ConfigurationDao _configDao; + @Inject + HostDao _hostDao; private final String SELECT_ALL = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t"; @@ -128,22 +134,12 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem } @Override - public List listAllRoutingTemplates() { + public List listAllSystemVMTemplates() { SearchCriteria sc = tmpltTypeSearch.create(); sc.setParameters("templateType", Storage.TemplateType.SYSTEM); return listBy(sc); } - @Override - public VMTemplateVO findRoutingTemplate() { - return findSystemVMTemplate(); - } - - @Override - public VMTemplateVO findConsoleProxyTemplate() { - return findSystemVMTemplate(); - } - @Override public List listReadyTemplates() { SearchCriteria sc = createSearchCriteria(); @@ -215,7 +211,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem tmpltTypeHyperSearch = createSearchBuilder(); tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); - tmpltTypeHyperSearch.and("hypervisor_type", tmpltTypeHyperSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ); + SearchBuilder hostHyperSearch = _hostDao.createSearchBuilder(); + hostHyperSearch.and("type", hostHyperSearch.entity().getType(), SearchCriteria.Op.EQ); + hostHyperSearch.and("zoneId", hostHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + hostHyperSearch.groupBy(hostHyperSearch.entity().getHypervisorType()); + + tmpltTypeHyperSearch.join("tmplHyper", hostHyperSearch, hostHyperSearch.entity().getHypervisorType(), tmpltTypeHyperSearch.entity().getHypervisorType(), JoinBuilder.JoinType.INNER); + hostHyperSearch.done(); + tmpltTypeHyperSearch.done(); tmpltTypeSearch = createSearchBuilder(); tmpltTypeSearch.and("templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); @@ -431,29 +434,26 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem return listBy(sc); } - private VMTemplateVO findSystemVMTemplate() { + @Override + public VMTemplateVO findSystemVMTemplate(long zoneId) { SearchCriteria sc = tmpltTypeHyperSearch.create(); sc.setParameters("templateType", Storage.TemplateType.SYSTEM); - sc.setParameters("hypervisor_type", _defaultHyperType.toString()); - VMTemplateVO tmplt = findOneBy(sc); - - if (tmplt == null) { - /*Can't find it? We'd like to prefer xenserver */ - if (_defaultHyperType != HypervisorType.XenServer) { - sc = tmpltTypeHyperSearch.create(); - sc.setParameters("templateType", Storage.TemplateType.SYSTEM); - sc.setParameters("hypervisor_type", HypervisorType.XenServer.toString()); - tmplt = findOneBy(sc); - - /*Still can't find it? return a random one*/ - if (tmplt == null) { - sc = tmpltTypeSearch.create(); - sc.setParameters("templateType", Storage.TemplateType.SYSTEM); - tmplt = findOneBy(sc); - } - } - } - - return tmplt; + sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing); + sc.setJoinParameters("tmplHyper", "zoneId", zoneId); + + List tmplts = listBy(sc); + Collections.shuffle(tmplts); + return tmplts.get(0); + } + + @Override + public VMTemplateVO findRoutingTemplate(HypervisorType type) { + List templates = listAllSystemVMTemplates(); + for (VMTemplateVO template : templates) { + if (template.getHypervisorType() == type) { + return template; + } + } + return null; } } diff --git a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java index b6efd9e0e2f..0cfb1dc7724 100755 --- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java +++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java @@ -392,7 +392,7 @@ public class DownloadMonitorImpl implements DownloadMonitor { Set toBeDownloaded = new HashSet(); List allTemplates = _templateDao.listAllInZone(storageHost.getDataCenterId()); - List rtngTmplts = _templateDao.listAllRoutingTemplates(); + List rtngTmplts = _templateDao.listAllSystemVMTemplates(); List defaultBuiltin = _templateDao.listDefaultBuiltinTemplates(); if (rtngTmplts != null) { diff --git a/server/src/com/cloud/storage/resource/DummySecondaryStorageResource.java b/server/src/com/cloud/storage/resource/DummySecondaryStorageResource.java index 3c9f2669a90..f4ff10e4c71 100644 --- a/server/src/com/cloud/storage/resource/DummySecondaryStorageResource.java +++ b/server/src/com/cloud/storage/resource/DummySecondaryStorageResource.java @@ -173,7 +173,7 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements } public Map getDefaultSystemVmTemplateInfo() { - List tmplts = _tmpltDao.listAllRoutingTemplates(); + List tmplts = _tmpltDao.listAllSystemVMTemplates(); Map tmpltInfo = new HashMap(); if (tmplts != null) { for (VMTemplateVO tmplt : tmplts) { diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 4e95731e8c8..6053ba39924 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -179,7 +179,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V private SecondaryStorageListener _listener; private ServiceOfferingVO _serviceOffering; - private VMTemplateVO _template; + @Inject private ConfigurationDao _configDao; @Inject @@ -431,10 +431,17 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V s_logger.info("Unable to setup due to concurrent operation. " + e); return new HashMap(); } - SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, _template.getId(), - _template.getHypervisorType(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId()); + + VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId); + if (template == null) { + s_logger.debug("Can't find a template to start"); + throw new CloudRuntimeException("Insufficient capacity exception"); + } + + SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), + template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId()); try { - secStorageVm = _itMgr.allocate(secStorageVm, _template, _serviceOffering, networks, plan, null, systemAcct); + secStorageVm = _itMgr.allocate(secStorageVm, template, _serviceOffering, networks, plan, null, systemAcct); } catch (InsufficientCapacityException e) { s_logger.warn("InsufficientCapacity", e); throw new CloudRuntimeException("Insufficient capacity exception", e); @@ -667,7 +674,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V public boolean isZoneReady(Map zoneHostInfoMap, long dataCenterId) { ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId); if (zoneHostInfo != null && (zoneHostInfo.getFlags() & RunningHostInfoAgregator.ZoneHostInfo.ROUTING_HOST_MASK) != 0) { - VMTemplateVO template = _templateDao.findConsoleProxyTemplate(); + VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId); HostVO secHost = _hostDao.findSecondaryStorageHost(dataCenterId); if (secHost == null) { if (s_logger.isDebugEnabled()) { @@ -815,10 +822,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V Network.GuestIpType.Virtual, _useLocalStorage, true, null, true); _serviceOffering.setUniqueName("Cloud.com-SecondaryStorage"); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); - _template = _templateDao.findConsoleProxyTemplate(); - if (_template == null && _useServiceVM) { - throw new ConfigurationException("Unable to find the template for secondary storage vm VMs"); - } if (_useServiceVM) { _capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), STARTUP_DELAY, _capacityScanInterval, TimeUnit.MILLISECONDS); diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index f6aeb863f96..8fb9abd29ee 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -415,9 +415,12 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe throw new IllegalArgumentException("Please specify a valid zone."); } } - VMTemplateVO systemvmTmplt = _tmpltDao.findRoutingTemplate(); - if (systemvmTmplt.getName().equalsIgnoreCase(name) || systemvmTmplt.getDisplayText().equalsIgnoreCase(displayText)) { - throw new IllegalArgumentException("Cannot use reserved names for templates"); + + List systemvmTmplts = _tmpltDao.listAllSystemVMTemplates(); + for (VMTemplateVO template : systemvmTmplts) { + if (template.getName().equalsIgnoreCase(name) || template.getDisplayText().equalsIgnoreCase(displayText)) { + throw new IllegalArgumentException("Cannot use reserved names for templates"); + } } return create(userId, accountId, zoneId, name, displayText, isPublic, featured, isExtractable, imgfmt, diskType, uri, chksum, requiresHvm, bits, enablePassword, guestOSId, bootable, hypervisorType);