This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.15
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.15 by this push:
     new b2fd1f6  server: Allow public templates with no url to be migrated 
(#5404)
b2fd1f6 is described below

commit b2fd1f6d32f418942bbe88d9e924646af1a4272d
Author: Pearl Dsilva <[email protected]>
AuthorDate: Fri Sep 3 16:25:11 2021 +0530

    server: Allow public templates with no url to be migrated (#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
---
 .../cloudstack/engine/orchestration/DataMigrationUtility.java      | 3 ++-
 .../src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git 
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java
 
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java
index 7fad871..9d044f3 100644
--- 
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java
+++ 
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java
@@ -179,7 +179,8 @@ public class DataMigrationUtility {
         List<TemplateDataStoreVO> templates = 
templateDataStoreDao.listByStoreId(srcDataStore.getId());
         for (TemplateDataStoreVO template : templates) {
             VMTemplateVO templateVO = 
templateDao.findById(template.getTemplateId());
-            if (template.getState() == 
ObjectInDataStoreStateMachine.State.Ready && templateVO != null && 
!templateVO.isPublicTemplate() &&
+            if (template.getState() == 
ObjectInDataStoreStateMachine.State.Ready && templateVO != null &&
+                    (!templateVO.isPublicTemplate() || 
(templateVO.isPublicTemplate() && templateVO.getUrl() == null)) &&
                     templateVO.getHypervisorType() != 
Hypervisor.HypervisorType.Simulator) {
                 
files.add(templateFactory.getTemplate(template.getTemplateId(), srcDataStore));
             }
diff --git 
a/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java 
b/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
index d807863..3739b06 100644
--- a/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
@@ -122,7 +122,11 @@ public class TemplateJoinDaoImpl extends 
GenericDaoBaseWithTagInformation<Templa
         activeTmpltSearch.and("store_id", 
activeTmpltSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
         activeTmpltSearch.and("type", 
activeTmpltSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
         activeTmpltSearch.and("templateState", 
activeTmpltSearch.entity().getTemplateState(), SearchCriteria.Op.EQ);
-        activeTmpltSearch.and("public", 
activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
+        activeTmpltSearch.and().op("public", 
activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
+        activeTmpltSearch.or().op("publicNoUrl", 
activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
+        activeTmpltSearch.and("url", activeTmpltSearch.entity().getUrl(), 
SearchCriteria.Op.NULL);
+        activeTmpltSearch.cp();
+        activeTmpltSearch.cp();
         activeTmpltSearch.done();
 
         // select distinct pair (template_id, zone_id)
@@ -528,6 +532,7 @@ public class TemplateJoinDaoImpl extends 
GenericDaoBaseWithTagInformation<Templa
         sc.setParameters("type", TemplateType.USER);
         sc.setParameters("templateState", VirtualMachineTemplate.State.Active);
         sc.setParameters("public", Boolean.FALSE);
+        sc.setParameters("publicNoUrl",Boolean.TRUE);
         return searchIncludingRemoved(sc, null, null, false);
     }
 

Reply via email to