Skip to content

Commit b2fd1f6

Browse files
authored
server: Allow public templates with no url to be migrated (apache#5404)
This PR allows migration of public templates that are created from snapshots / volumes. Data migration across secondary stores initially excluded all public templates on the pretext that public templates are automatically synced when a new image store is added; however, this assumption isn't true for templates marked as "public" when created from snapshots / volumes. Such templates can be identified if their url is null
1 parent 0bc6e05 commit b2fd1f6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ protected List<DataObject> getAllReadyTemplates(DataStore srcDataStore) {
179179
List<TemplateDataStoreVO> templates = templateDataStoreDao.listByStoreId(srcDataStore.getId());
180180
for (TemplateDataStoreVO template : templates) {
181181
VMTemplateVO templateVO = templateDao.findById(template.getTemplateId());
182-
if (template.getState() == ObjectInDataStoreStateMachine.State.Ready && templateVO != null && !templateVO.isPublicTemplate() &&
182+
if (template.getState() == ObjectInDataStoreStateMachine.State.Ready && templateVO != null &&
183+
(!templateVO.isPublicTemplate() || (templateVO.isPublicTemplate() && templateVO.getUrl() == null)) &&
183184
templateVO.getHypervisorType() != Hypervisor.HypervisorType.Simulator) {
184185
files.add(templateFactory.getTemplate(template.getTemplateId(), srcDataStore));
185186
}

server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ protected TemplateJoinDaoImpl() {
122122
activeTmpltSearch.and("store_id", activeTmpltSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
123123
activeTmpltSearch.and("type", activeTmpltSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
124124
activeTmpltSearch.and("templateState", activeTmpltSearch.entity().getTemplateState(), SearchCriteria.Op.EQ);
125-
activeTmpltSearch.and("public", activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
125+
activeTmpltSearch.and().op("public", activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
126+
activeTmpltSearch.or().op("publicNoUrl", activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
127+
activeTmpltSearch.and("url", activeTmpltSearch.entity().getUrl(), SearchCriteria.Op.NULL);
128+
activeTmpltSearch.cp();
129+
activeTmpltSearch.cp();
126130
activeTmpltSearch.done();
127131

128132
// select distinct pair (template_id, zone_id)
@@ -528,6 +532,7 @@ public List<TemplateJoinVO> listActiveTemplates(long storeId) {
528532
sc.setParameters("type", TemplateType.USER);
529533
sc.setParameters("templateState", VirtualMachineTemplate.State.Active);
530534
sc.setParameters("public", Boolean.FALSE);
535+
sc.setParameters("publicNoUrl",Boolean.TRUE);
531536
return searchIncludingRemoved(sc, null, null, false);
532537
}
533538

0 commit comments

Comments
 (0)