Skip to content

Commit 40e7502

Browse files
Harikrishna Patnalanitinmeh
authored andcommitted
CLOUDSTACK-3228: system vms are not comming up in zone with two cluster xen and kvm CLOUDSTACK-3631: Enhance System vm deployment retry mechanism
Signed off by : Nitin Mehta<nitin.mehta@citrix.com>
1 parent ddf9122 commit 40e7502

4 files changed

Lines changed: 69 additions & 24 deletions

File tree

‎engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
6666

6767
VMTemplateVO findSystemVMTemplate(long zoneId);
6868

69-
VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType);
69+
VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType);
7070

7171
VMTemplateVO findRoutingTemplate(HypervisorType type, String templateName);
7272

‎engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
import java.util.Date;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.Collections;
2627

2728
import javax.ejb.Local;
2829
import javax.inject.Inject;
2930
import javax.naming.ConfigurationException;
3031

32+
import com.cloud.storage.VMTemplateStorageResourceAssoc;
33+
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
34+
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
3135
import org.apache.log4j.Logger;
3236
import org.springframework.stereotype.Component;
3337

@@ -75,6 +79,8 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
7579
DomainDao _domainDao;
7680
@Inject
7781
DataCenterDao _dcDao;
82+
@Inject
83+
TemplateDataStoreDao _templateDataStoreDao;
7884

7985
private static final String SELECT_S3_CANDIDATE_TEMPLATES = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, "
8086
+ "t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, t.checksum, t.display_text, "
@@ -87,6 +93,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
8793
protected SearchBuilder<VMTemplateVO> UniqueNameSearch;
8894
protected SearchBuilder<VMTemplateVO> tmpltTypeSearch;
8995
protected SearchBuilder<VMTemplateVO> tmpltTypeHyperSearch;
96+
protected SearchBuilder<VMTemplateVO> readySystemTemplateSearch;
9097
protected SearchBuilder<VMTemplateVO> tmpltTypeHyperSearch2;
9198

9299
protected SearchBuilder<VMTemplateVO> AccountIdSearch;
@@ -326,6 +333,23 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
326333
hostHyperSearch.done();
327334
tmpltTypeHyperSearch.done();
328335

336+
readySystemTemplateSearch = createSearchBuilder();
337+
readySystemTemplateSearch.and("templateType", readySystemTemplateSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
338+
SearchBuilder<TemplateDataStoreVO> templateDownloadSearch = _templateDataStoreDao.createSearchBuilder();
339+
templateDownloadSearch.and("downloadState", templateDownloadSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
340+
readySystemTemplateSearch.join("vmTemplateJoinTemplateStoreRef", templateDownloadSearch, templateDownloadSearch.entity().getTemplateId(),
341+
readySystemTemplateSearch.entity().getId(), JoinBuilder.JoinType.INNER);
342+
SearchBuilder<HostVO> hostHyperSearch2 = _hostDao.createSearchBuilder();
343+
hostHyperSearch2.and("type", hostHyperSearch2.entity().getType(), SearchCriteria.Op.EQ);
344+
hostHyperSearch2.and("zoneId", hostHyperSearch2.entity().getDataCenterId(), SearchCriteria.Op.EQ);
345+
hostHyperSearch2.and("removed", hostHyperSearch2.entity().getRemoved(), SearchCriteria.Op.NULL);
346+
hostHyperSearch2.groupBy(hostHyperSearch2.entity().getHypervisorType());
347+
348+
readySystemTemplateSearch.join("tmplHyper", hostHyperSearch2, hostHyperSearch2.entity().getHypervisorType(),
349+
readySystemTemplateSearch.entity().getHypervisorType(), JoinBuilder.JoinType.INNER);
350+
hostHyperSearch2.done();
351+
readySystemTemplateSearch.done();
352+
329353
tmpltTypeHyperSearch2 = createSearchBuilder();
330354
tmpltTypeHyperSearch2.and("templateType", tmpltTypeHyperSearch2.entity().getTemplateType(),
331355
SearchCriteria.Op.EQ);
@@ -764,22 +788,27 @@ public VMTemplateVO findSystemVMTemplate(long zoneId) {
764788
}
765789

766790
@Override
767-
public VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType) {
768-
SearchCriteria<VMTemplateVO> sc = tmpltTypeHyperSearch.create();
791+
public VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType) {
792+
SearchCriteria<VMTemplateVO> sc = readySystemTemplateSearch.create();
769793
sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
770794
sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing);
771795
sc.setJoinParameters("tmplHyper", "zoneId", zoneId);
796+
sc.setJoinParameters("vmTemplateJoinTemplateStoreRef", "downloadState", VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
772797

773798
// order by descending order of id
774799
List<VMTemplateVO> tmplts = listBy(sc, new Filter(VMTemplateVO.class, "id", false, null, null));
775800

776-
for (VMTemplateVO tmplt : tmplts) {
777-
if (tmplt.getHypervisorType() == hType) {
778-
return tmplt;
801+
if (tmplts.size() > 0) {
802+
if (hypervisorType == HypervisorType.Any) {
803+
Collections.shuffle(tmplts);
804+
return tmplts.get(0);
779805
}
780-
}
781-
if (tmplts.size() > 0 && hType == HypervisorType.Any) {
782-
return tmplts.get(0);
806+
for (VMTemplateVO tmplt : tmplts) {
807+
if (tmplt.getHypervisorType() == hypervisorType) {
808+
return tmplt;
809+
}
810+
}
811+
783812
}
784813
return null;
785814
}

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,22 @@ public ConsoleProxyVO startNew(long dataCenterId) throws ConcurrentOperationExce
645645
s_logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit");
646646
return null;
647647
}
648-
HypervisorType defaultHype = _resourceMgr.getAvailableHypervisor(dataCenterId);
649648

650-
Map<String, Object> context = createProxyInstance(dataCenterId, defaultHype);
649+
VMTemplateVO template = null;
650+
HypervisorType defaultHypervisor = _resourceMgr.getDefaultHypervisor(dataCenterId);
651+
if (defaultHypervisor != HypervisorType.None) {
652+
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, defaultHypervisor);
653+
if (template == null) {
654+
throw new CloudRuntimeException("Not able to find the System template or not downloaded in zone " + dataCenterId + " corresponding to default System vm hypervisor " + defaultHypervisor);
655+
}
656+
} else {
657+
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
658+
if (template == null) {
659+
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
660+
}
661+
}
662+
663+
Map<String, Object> context = createProxyInstance(dataCenterId, template);
651664

652665
long proxyVmId = (Long) context.get("proxyVmId");
653666
if (proxyVmId == 0) {
@@ -673,7 +686,7 @@ public ConsoleProxyVO startNew(long dataCenterId) throws ConcurrentOperationExce
673686
return null;
674687
}
675688

676-
protected Map<String, Object> createProxyInstance(long dataCenterId, HypervisorType desiredHyp) throws ConcurrentOperationException {
689+
protected Map<String, Object> createProxyInstance(long dataCenterId, VMTemplateVO template) throws ConcurrentOperationException {
677690

678691
long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
679692
String name = VirtualMachineName.getConsoleProxyName(id, _instance);
@@ -716,12 +729,6 @@ protected Map<String, Object> createProxyInstance(long dataCenterId, HypervisorT
716729
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null));
717730
}
718731

719-
VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId, desiredHyp);
720-
if (template == null) {
721-
s_logger.debug("Can't find a template to start");
722-
throw new CloudRuntimeException("Insufficient capacity exception");
723-
}
724-
725732
ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(),
726733
systemAcct.getId(), 0, _serviceOffering.getOfferHA());
727734
proxy.setDynamicallyScalable(template.isDynamicallyScalable());

‎server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
3535
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
3636
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
37+
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
3738
import org.apache.log4j.Logger;
3839

3940
import com.cloud.agent.AgentManager;
@@ -237,6 +238,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
237238
DataStoreManager _dataStoreMgr;
238239
@Inject
239240
ImageStoreDao _imageStoreDao;
241+
@Inject
242+
TemplateDataStoreDao _tmplStoreDao;
240243
private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
241244
private int _secStorageVmMtuSize;
242245

@@ -568,12 +571,18 @@ protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, Seco
568571
return new HashMap<String, Object>();
569572
}
570573

571-
HypervisorType hypeType = _resourceMgr.getAvailableHypervisor(dataCenterId);
572-
573-
VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId, hypeType);
574-
if (template == null) {
575-
s_logger.debug("Can't find a template to start");
576-
throw new CloudRuntimeException("Insufficient capacity exception");
574+
VMTemplateVO template = null;
575+
HypervisorType defaultHypervisor = _resourceMgr.getDefaultHypervisor(dataCenterId);
576+
if (defaultHypervisor != HypervisorType.None) {
577+
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, defaultHypervisor);
578+
if (template == null) {
579+
throw new CloudRuntimeException("Not able to find the System template or not downloaded in zone " + dataCenterId + " corresponding to default System vm hypervisor " + defaultHypervisor);
580+
}
581+
} else {
582+
template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
583+
if (template == null) {
584+
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
585+
}
577586
}
578587

579588
SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,

0 commit comments

Comments
 (0)