Skip to content

Commit ab07a12

Browse files
committed
fixes
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent c1750c8 commit ab07a12

File tree

9 files changed

+152
-119
lines changed

9 files changed

+152
-119
lines changed

engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
3434

3535
List<HypervisorType> getAvailableHypervisorInZone(Long zoneId);
3636

37-
List<Pair<HypervisorType, String>> listDistinctHypervisorsArchAcrossClusters(Long zoneId);
37+
List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorsArchAcrossClusters(Long zoneId);
3838

3939
List<ClusterVO> listByDcHyType(long dcId, String hyType);
4040

engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,18 @@ public List<HypervisorType> getAvailableHypervisorInZone(Long zoneId) {
169169
}
170170

171171
@Override
172-
public List<Pair<HypervisorType, String>> listDistinctHypervisorsArchAcrossClusters(Long zoneId) {
172+
public List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorsArchAcrossClusters(Long zoneId) {
173173
SearchBuilder<ClusterVO> sb = createSearchBuilder();
174174
sb.select(null, Func.DISTINCT_PAIR, sb.entity().getHypervisorType(), sb.entity().getArch());
175175
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
176176
sb.done();
177177
SearchCriteria<ClusterVO> sc = sb.create();
178-
sc.setParameters("zoneId", zoneId);
178+
if (zoneId != null) {
179+
sc.setParameters("zoneId", zoneId);
180+
}
179181
final List<ClusterVO> clusters = search(sc, null);
180182
return clusters.stream()
181-
.map(c -> new Pair<>(c.getHypervisorType(), c.getArch().getType()))
183+
.map(c -> new Pair<>(c.getHypervisorType(), c.getArch()))
182184
.collect(Collectors.toList());
183185
}
184186

engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,9 @@ public List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorArchTypes(f
17661766
sb.done();
17671767
SearchCriteria<HostVO> sc = sb.create();
17681768
sc.setParameters("type", Type.Routing);
1769-
sc.setParameters("zoneId", zoneId);
1769+
if (zoneId != null) {
1770+
sc.setParameters("zoneId", zoneId);
1771+
}
17701772
final List<HostVO> hosts = search(sc, null);
17711773
return hosts.stream()
17721774
.map(h -> new Pair<>(h.getHypervisorType(), h.getArch()))

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

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

9393
List<VMTemplateVO> listByParentTemplatetId(long parentTemplatetId);
9494

95-
VMTemplateVO findLatestTemplateByName(String name);
95+
VMTemplateVO findLatestTemplateByName(String name, CPU.CPUArch arch);
9696

9797
List<VMTemplateVO> findTemplatesLinkedToUserdata(long userdataId);
9898

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,16 @@ public List<VMTemplateVO> listReadyTemplates() {
244244

245245

246246
@Override
247-
public VMTemplateVO findLatestTemplateByName(String name) {
248-
SearchCriteria<VMTemplateVO> sc = createSearchCriteria();
249-
sc.addAnd("name", SearchCriteria.Op.EQ, name);
250-
sc.addAnd("removed", SearchCriteria.Op.NULL);
247+
public VMTemplateVO findLatestTemplateByName(String name, CPU.CPUArch arch) {
248+
SearchBuilder<VMTemplateVO> sb = createSearchBuilder();
249+
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
250+
sb.and("arch", sb.entity().getArch(), SearchCriteria.Op.EQ);
251+
sb.done();
252+
SearchCriteria<VMTemplateVO> sc = sb.create();
253+
sc.setParameters("name", name);
254+
if (arch != null) {
255+
sc.setParameters("arch", arch);
256+
}
251257
Filter filter = new Filter(VMTemplateVO.class, "id", false, null, 1L);
252258
List<VMTemplateVO> templates = listBy(sc, filter);
253259
if ((templates != null) && !templates.isEmpty()) {

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 85 additions & 75 deletions
Large diffs are not rendered by default.

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42000to42010.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void updateSystemVmTemplates(Connection conn) {
7878
try {
7979
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
8080
} catch (Exception e) {
81-
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
81+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)", e);
8282
}
8383
}
8484

engine/schema/templateConfig.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ function createMetadataFile() {
5858
for template in "${templates[@]}"
5959
do
6060
section="${template%%:*}"
61-
hvName=$(getGenericName $section)
61+
sectionHv="${section%%-*}"
62+
hvName=$(getGenericName $sectionHv)
6263

6364
downloadurl="${template#*:}"
6465
arch=$(echo ${downloadurl#*"/systemvmtemplate-$VERSION-"} | cut -d'-' -f 1)
65-
templatename="systemvm-${section%.*}-${VERSION}-${arch}"
66+
templatename="systemvm-${sectionHv%.*}-${VERSION}-${arch}"
6667
checksum=$(getChecksum "$fileData" "$VERSION-${arch}-$hvName")
6768
filename=$(echo ${downloadurl##*'/'})
6869
echo -e "["$section"]\ntemplatename = $templatename\nchecksum = $checksum\ndownloadurl = $downloadurl\nfilename = $filename\narch = $arch\n" >> $METADATAFILE

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
import com.cloud.configuration.ConfigurationManager;
179179
import com.cloud.configuration.ConfigurationManagerImpl;
180180
import com.cloud.configuration.Resource.ResourceType;
181+
import com.cloud.cpu.CPU;
181182
import com.cloud.dc.ClusterVO;
182183
import com.cloud.dc.DataCenterVO;
183184
import com.cloud.dc.VsphereStoragePolicyVO;
@@ -3585,6 +3586,40 @@ public ImageStore discoverImageStore(String name, String url, String providerNam
35853586
return (ImageStore)_dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
35863587
}
35873588

3589+
protected void registerSystemVmTemplateForHypervisorArch(final HypervisorType hypervisorType,
3590+
final CPU.CPUArch arch, final Long zoneId, final String url, final DataStore store,
3591+
final SystemVmTemplateRegistration systemVmTemplateRegistration, final String filePath,
3592+
final Pair<String, Long> storeUrlAndId, final String nfsVersion) {
3593+
if (HypervisorType.Simulator.equals(hypervisorType)) {
3594+
return;
3595+
}
3596+
String templateName = getValidTemplateName(zoneId, hypervisorType);
3597+
Long templateId = systemVmTemplateRegistration.getRegisteredTemplateId(templateName, arch);
3598+
VMTemplateVO vmTemplateVO = null;
3599+
TemplateDataStoreVO templateDataStoreVO = null;
3600+
if (templateId != null) {
3601+
vmTemplateVO = _templateDao.findById(templateId);
3602+
templateDataStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
3603+
if (templateDataStoreVO != null) {
3604+
try {
3605+
if (systemVmTemplateRegistration.validateIfSeeded(templateDataStoreVO, url,
3606+
templateDataStoreVO.getInstallPath(), nfsVersion)) {
3607+
return;
3608+
}
3609+
} catch (Exception e) {
3610+
logger.error("Failed to validated if template is seeded", e);
3611+
}
3612+
}
3613+
}
3614+
SystemVmTemplateRegistration.mountStore(storeUrlAndId.first(), filePath, nfsVersion);
3615+
if (templateDataStoreVO != null && vmTemplateVO != null) {
3616+
systemVmTemplateRegistration.registerTemplate(hypervisorType, templateName, storeUrlAndId, vmTemplateVO,
3617+
templateDataStoreVO, filePath);
3618+
} else {
3619+
systemVmTemplateRegistration.registerTemplate(hypervisorType, arch, templateName, storeUrlAndId, filePath);
3620+
}
3621+
}
3622+
35883623
private void registerSystemVmTemplateOnFirstNfsStore(Long zoneId, String providerName, String url, DataStore store) {
35893624
if (DataStoreProvider.NFS_IMAGE.equals(providerName) && zoneId != null) {
35903625
Transaction.execute(new TransactionCallbackNoReturn() {
@@ -3593,8 +3628,8 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
35933628
List<ImageStoreVO> stores = _imageStoreDao.listAllStoresInZoneExceptId(zoneId, providerName,
35943629
DataStoreRole.Image, store.getId());
35953630
if (CollectionUtils.isEmpty(stores)) {
3596-
List<HypervisorType> hypervisorTypes = _clusterDao.getAvailableHypervisorInZone(zoneId);
3597-
Set<HypervisorType> hypervisorTypeSet = new HashSet<>(hypervisorTypes);
3631+
List<Pair<HypervisorType, CPU.CPUArch>> hypervisorTypes =
3632+
_clusterDao.listDistinctHypervisorsArchAcrossClusters(zoneId);
35983633
TransactionLegacy txn = TransactionLegacy.open("AutomaticTemplateRegister");
35993634
SystemVmTemplateRegistration systemVmTemplateRegistration = new SystemVmTemplateRegistration();
36003635
String filePath = null;
@@ -3605,38 +3640,15 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
36053640
}
36063641
Pair<String, Long> storeUrlAndId = new Pair<>(url, store.getId());
36073642
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(store.getId());
3608-
for (HypervisorType hypervisorType : hypervisorTypeSet) {
3643+
for (Pair<HypervisorType, CPU.CPUArch> hypervisorArchType : hypervisorTypes) {
36093644
try {
3610-
if (HypervisorType.Simulator == hypervisorType) {
3611-
continue;
3612-
}
3613-
String templateName = getValidTemplateName(zoneId, hypervisorType);
3614-
Long templateId = systemVmTemplateRegistration.getRegisteredTemplateId(templateName);
3615-
VMTemplateVO vmTemplateVO = null;
3616-
TemplateDataStoreVO templateDataStoreVO = null;
3617-
if (templateId != null) {
3618-
vmTemplateVO = _templateDao.findById(templateId);
3619-
templateDataStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
3620-
if (templateDataStoreVO != null) {
3621-
try {
3622-
if (systemVmTemplateRegistration.validateIfSeeded(templateDataStoreVO,
3623-
url, templateDataStoreVO.getInstallPath(), nfsVersion)) {
3624-
continue;
3625-
}
3626-
} catch (Exception e) {
3627-
logger.error("Failed to validated if template is seeded", e);
3628-
}
3629-
}
3630-
}
3631-
SystemVmTemplateRegistration.mountStore(storeUrlAndId.first(), filePath, nfsVersion);
3632-
if (templateDataStoreVO != null && vmTemplateVO != null) {
3633-
systemVmTemplateRegistration.registerTemplate(hypervisorType, templateName, storeUrlAndId, vmTemplateVO, templateDataStoreVO, filePath);
3634-
} else {
3635-
systemVmTemplateRegistration.registerTemplate(hypervisorType, templateName, storeUrlAndId, filePath);
3636-
}
3645+
registerSystemVmTemplateForHypervisorArch(hypervisorArchType.first(),
3646+
hypervisorArchType.second(), zoneId, url, store,
3647+
systemVmTemplateRegistration, filePath, storeUrlAndId, nfsVersion);
36373648
} catch (CloudRuntimeException e) {
36383649
SystemVmTemplateRegistration.unmountStore(filePath);
3639-
logger.error(String.format("Failed to register systemVM template for hypervisor: %s", hypervisorType.name()), e);
3650+
logger.error("Failed to register system VM template for hypervisor: {} {}",
3651+
hypervisorArchType.first().name(), hypervisorArchType.second().name(), e);
36403652
}
36413653
}
36423654
} catch (Exception e) {

0 commit comments

Comments
 (0)