From 9bcb2affff96b3b5c74231f3edadd2630c893fb5 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Tue, 10 Jan 2012 15:09:10 -0800 Subject: [PATCH] bug 12139: add a way to specifiy which hypervisor used to start system vm: Admin can either configure system.vm.default.hypervisor which is a global configuration for all zones, or call updatezone add defaultSystemVMHypervisorType status 12139: resolved fixed --- .../src/com/cloud/configuration/Config.java | 3 +- .../consoleproxy/ConsoleProxyManagerImpl.java | 4 +- .../VirtualNetworkApplianceManagerImpl.java | 4 ++ .../com/cloud/resource/ResourceManager.java | 4 ++ .../cloud/resource/ResourceManagerImpl.java | 63 +++++++++++++++++++ .../com/cloud/storage/StorageManagerImpl.java | 2 + .../SecondaryStorageManagerImpl.java | 4 +- 7 files changed, 80 insertions(+), 4 deletions(-) diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 97419d55e0b..14703286fda 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -184,7 +184,8 @@ public enum Config { // UpgradeURL("Advanced", ManagementServer.class, String.class, "upgrade.url", "http://example.com:8080/client/agent/update.zip", "The upgrade URL is the URL of the management server that agents will connect to in order to automatically upgrade.", null), SystemVMUseLocalStorage("Advanced", ManagementServer.class, Boolean.class, "system.vm.use.local.storage", "false", "Indicates whether to use local storage pools or shared storage pools for system VMs.", null), 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), + SystemVMDefaultHypervisor("Advanced", ManagementServer.class, String.class, "system.vm.default.hypervisor", null, "Hypervisor type used to create system vm", 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), MemOverprovisioningFactor("Advanced", ManagementServer.class, String.class, "mem.overprovisioning.factor", "1", "Used for memory overprovisioning calculation", 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), HypervisorList("Advanced", ManagementServer.class, String.class, "hypervisor.list", HypervisorType.KVM + "," + HypervisorType.XenServer + "," + HypervisorType.VMware + "," + HypervisorType.BareMetal + "," + HypervisorType.Ovm, "The list of hypervisors that this deployment will use.", "hypervisorList"), diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index da6d83414f3..26ff82b89af 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -527,9 +527,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit"); return null; } - HypervisorType currentHyp = currentHypervisorType(dataCenterId); + HypervisorType defaultHype = _resourceMgr.getAvailableHypervisor(dataCenterId); - Map context = createProxyInstance(dataCenterId, currentHyp); + Map context = createProxyInstance(dataCenterId, defaultHype); long proxyVmId = (Long) context.get("proxyVmId"); if (proxyVmId == 0) { diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index e31b4c5c4a0..b010124ec01 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1317,6 +1317,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Router is the network element, we don't know the hypervisor type yet. //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up List supportedHypervisors = new ArrayList(); + HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId()); + if (defaults != HypervisorType.None) { + supportedHypervisors.add(defaults); + } if (dest.getCluster() != null) { if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) { diff --git a/server/src/com/cloud/resource/ResourceManager.java b/server/src/com/cloud/resource/ResourceManager.java index f54b5d7c802..53bb21258b0 100755 --- a/server/src/com/cloud/resource/ResourceManager.java +++ b/server/src/com/cloud/resource/ResourceManager.java @@ -133,4 +133,8 @@ public interface ResourceManager extends ResourceService{ List listByDataCenter(long dcId); List listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId); + + HypervisorType getDefaultHypervisor(long zoneId); + + HypervisorType getAvailableHypervisor(long zoneId); } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index a4e86c87b02..262e287f527 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -64,6 +64,7 @@ import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; import com.cloud.cluster.ClusterManager; import com.cloud.cluster.ManagementServerNode; +import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterVO; @@ -109,9 +110,11 @@ import com.cloud.storage.StoragePoolVO; import com.cloud.storage.StorageService; import com.cloud.storage.Swift; import com.cloud.storage.SwiftVO; +import com.cloud.storage.VMTemplateVO; import com.cloud.storage.dao.GuestOSCategoryDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; +import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.storage.swift.SwiftManager; import com.cloud.template.VirtualMachineTemplate; @@ -199,12 +202,15 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma protected StoragePoolHostDao _storagePoolHostDao; @Inject(adapter = PodAllocator.class) protected Adapters _podAllocators = null; + @Inject + protected VMTemplateDao _templateDao; protected long _nodeId = ManagementServerNode.getManagementServerId(); protected HashMap _resourceStateAdapters = new HashMap(); protected HashMap> _lifeCycleListeners = new HashMap>(); + private HypervisorType _defaultSystemVMHypervisor; private void insertListener(Integer event, ResourceListener listener) { List lst = _lifeCycleListeners.get(event); @@ -1199,6 +1205,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; + _defaultSystemVMHypervisor = HypervisorType.getType(_configDao.getValue(Config.SystemVMDefaultHypervisor.toString())); return true; } @@ -1237,6 +1244,62 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma return hypervisorTypes; } + + @Override + public HypervisorType getDefaultHypervisor(long zoneId) { + HypervisorType defaultHyper = HypervisorType.None; + if (_defaultSystemVMHypervisor != HypervisorType.None) { + defaultHyper = _defaultSystemVMHypervisor; + } + + DataCenterVO dc = _dcDao.findById(zoneId); + if (dc == null) { + return HypervisorType.None; + } + _dcDao.loadDetails(dc); + String defaultHypervisorInZone = dc.getDetail("defaultSystemVMHypervisorType"); + if (defaultHypervisorInZone != null) { + defaultHyper = HypervisorType.getType(defaultHypervisorInZone); + } + + List systemTemplates = _templateDao.listAllSystemVMTemplates(); + boolean isValid = false; + for (VMTemplateVO template : systemTemplates) { + if (template.getHypervisorType() == defaultHyper) { + isValid = true; + break; + } + } + + if (isValid) { + List clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString()); + if (clusters.size() <= 0) { + isValid = false; + } + } + + if (isValid) { + return defaultHyper; + } else { + return HypervisorType.None; + } + } + + @Override + public HypervisorType getAvailableHypervisor(long zoneId) { + HypervisorType defaultHype = getDefaultHypervisor(zoneId); + if (defaultHype == HypervisorType.None) { + List supportedHypes = getSupportedHypervisorTypes(zoneId, false, null); + if (supportedHypes.size() > 0) { + defaultHype = supportedHypes.get(0); + } + } + + if (defaultHype == HypervisorType.None) { + defaultHype = HypervisorType.Any; + } + return defaultHype; + } @Override public void registerResourceStateAdapter(String name, ResourceStateAdapter adapter) { diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 2ccaffe7c5b..f8b7ef8c6f3 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -875,6 +875,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag String time = configs.get("storage.cleanup.interval"); _storageCleanupInterval = NumbersUtil.parseInt(time, 86400); + + s_logger.info("Storage cleanup enabled: " + _storageCleanupEnabled + ", interval: " + _storageCleanupInterval + ", template cleanup enabled: " + _templateCleanupEnabled); String workers = configs.get("expunge.workers"); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 9c8b2a3d42c..34a4f4c9929 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -540,7 +540,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V return new HashMap(); } - VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId); + HypervisorType hypeType = _resourceMgr.getAvailableHypervisor(dataCenterId); + + VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId, hypeType); if (template == null) { s_logger.debug("Can't find a template to start"); throw new CloudRuntimeException("Insufficient capacity exception");