bug 8087: default hypervisor type is gone: when creating cpvm/ssvm, randomly choose one hypervisor type, which got from host table. When creating domR, as we already know the hypervisor type at that time, so domR and user vm are always created as the same hypervisor type.

status 8087: resolved fixed
This commit is contained in:
Edison Su 2011-02-01 11:26:02 -05:00
parent 447153f570
commit 5b073cd370
10 changed files with 84 additions and 87 deletions

View File

@ -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),

View File

@ -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<NetworkVO, NicProfile>(_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<Long, ZoneHostInfo> 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()) {

View File

@ -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, NicProfile>((NetworkVO) guestNetwork, gatewayNic));
networks.add(new Pair<NetworkVO, NicProfile>(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, NicProfile>((NetworkVO) guestNetwork, gatewayNic));
networks.add(new Pair<NetworkVO, NicProfile>(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) {

View File

@ -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.");

View File

@ -50,9 +50,9 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
public VMTemplateVO findByTemplateNameAccountId(String templateName, Long accountId);
//public void update(VMTemplateVO template);
public VMTemplateVO findRoutingTemplate();
public List<VMTemplateVO> listAllRoutingTemplates();
public VMTemplateVO findConsoleProxyTemplate();
public List<VMTemplateVO> listAllSystemVMTemplates();
public List<VMTemplateVO> listDefaultBuiltinTemplates();
public String getRoutingTemplateUniqueName();
public List<VMTemplateVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
@ -66,5 +66,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
public List<VMTemplateVO> listByHypervisorType(HypervisorType hyperType);
public List<VMTemplateVO> publicIsoSearch();
VMTemplateVO findSystemVMTemplate(long zoneId);
VMTemplateVO findRoutingTemplate(HypervisorType type);
}

View File

@ -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<VMTemplateVO, Long> 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<VMTemplateVO, Long> implem
}
@Override
public List<VMTemplateVO> listAllRoutingTemplates() {
public List<VMTemplateVO> listAllSystemVMTemplates() {
SearchCriteria<VMTemplateVO> 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<VMTemplateVO> listReadyTemplates() {
SearchCriteria<VMTemplateVO> sc = createSearchCriteria();
@ -215,7 +211,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
tmpltTypeHyperSearch = createSearchBuilder();
tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
tmpltTypeHyperSearch.and("hypervisor_type", tmpltTypeHyperSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
SearchBuilder<HostVO> 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<VMTemplateVO, Long> implem
return listBy(sc);
}
private VMTemplateVO findSystemVMTemplate() {
@Override
public VMTemplateVO findSystemVMTemplate(long zoneId) {
SearchCriteria<VMTemplateVO> 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<VMTemplateVO> tmplts = listBy(sc);
Collections.shuffle(tmplts);
return tmplts.get(0);
}
@Override
public VMTemplateVO findRoutingTemplate(HypervisorType type) {
List<VMTemplateVO> templates = listAllSystemVMTemplates();
for (VMTemplateVO template : templates) {
if (template.getHypervisorType() == type) {
return template;
}
}
return null;
}
}

View File

@ -392,7 +392,7 @@ public class DownloadMonitorImpl implements DownloadMonitor {
Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
List<VMTemplateVO> allTemplates = _templateDao.listAllInZone(storageHost.getDataCenterId());
List<VMTemplateVO> rtngTmplts = _templateDao.listAllRoutingTemplates();
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
if (rtngTmplts != null) {

View File

@ -173,7 +173,7 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements
}
public Map<String, TemplateInfo> getDefaultSystemVmTemplateInfo() {
List<VMTemplateVO> tmplts = _tmpltDao.listAllRoutingTemplates();
List<VMTemplateVO> tmplts = _tmpltDao.listAllSystemVMTemplates();
Map<String, TemplateInfo> tmpltInfo = new HashMap<String, TemplateInfo>();
if (tmplts != null) {
for (VMTemplateVO tmplt : tmplts) {

View File

@ -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<String, Object>();
}
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<Long, ZoneHostInfo> 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);

View File

@ -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<VMTemplateVO> 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);