Repository: cloudstack
Updated Branches:
  refs/heads/master 56684a52b -> 5360ab3d4


CLOUDSTACK-6186:
Unable to register private template across all Zones - crosszones flag no 
longer works.
This was because the code skipped the loop after the first download initiation. 
Introduced a set so that if it is already downloaded to the same zone then skip 
it for private template.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5360ab3d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5360ab3d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5360ab3d

Branch: refs/heads/master
Commit: 5360ab3d43c55e36a8c5437be363dc759d8e28d3
Parents: 56684a5
Author: Nitin Mehta <nitin.me...@citrix.com>
Authored: Thu Feb 27 18:29:58 2014 -0800
Committer: Nitin Mehta <nitin.me...@citrix.com>
Committed: Thu Feb 27 18:29:58 2014 -0800

----------------------------------------------------------------------
 .../template/HypervisorTemplateAdapter.java     | 25 ++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5360ab3d/server/src/com/cloud/template/HypervisorTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java 
b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
index 96bf9a3..71eac66 100755
--- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
@@ -19,7 +19,9 @@ package com.cloud.template;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ExecutionException;
 
 import javax.ejb.Local;
@@ -219,7 +221,8 @@ public class HypervisorTemplateAdapter extends 
TemplateAdapterBase {
             throw new CloudRuntimeException("Unable to find image store to 
download template " + profile.getTemplate());
         }
 
-        Collections.shuffle(imageStores);// For private templates choose a 
random store. TODO - Have a better algorithm based on size, no. of objects, 
load etc.
+        Set<Long> zoneSet = new HashSet<Long>();
+        Collections.shuffle(imageStores); // For private templates choose a 
random store. TODO - Have a better algorithm based on size, no. of objects, 
load etc.
         for (DataStore imageStore : imageStores) {
             // skip data stores for a disabled zone
             Long zoneId = imageStore.getScope().getScopeId();
@@ -235,6 +238,14 @@ public class HypervisorTemplateAdapter extends 
TemplateAdapterBase {
                     s_logger.info("Zone " + zoneId + " is disabled, so skip 
downloading template to its image store " + imageStore.getId());
                     continue;
                 }
+
+                // We want to download private template to one of the image 
store in a zone
+                if(isPrivateTemplate(template) && zoneSet.contains(zoneId)){
+                    continue;
+                }else {
+                    zoneSet.add(zoneId);
+                }
+
             }
 
             TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), 
imageStore);
@@ -243,15 +254,21 @@ public class HypervisorTemplateAdapter extends 
TemplateAdapterBase {
             
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
             caller.setContext(context);
             imageService.createTemplateAsync(tmpl, imageStore, caller);
-            if (!(profile.getIsPublic() || profile.getFeatured())) {  // If 
private template then break
-                break;
-            }
         }
         _resourceLimitMgr.incrementResourceCount(profile.getAccountId(), 
ResourceType.template);
 
         return template;
     }
 
+    private boolean isPrivateTemplate(VMTemplateVO template){
+
+        // if public OR featured OR system template
+        if(template.isPublicTemplate() || template.isFeatured() || 
template.getTemplateType() == TemplateType.SYSTEM)
+            return false;
+        else
+            return true;
+    }
+
     private class CreateTemplateContext<T> extends AsyncRpcContext<T> {
         final TemplateInfo template;
 

Reply via email to