You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ni...@apache.org on 2014/02/28 23:40:37 UTC

git commit: updated refs/heads/4.3-forward to 258d8e2

Repository: cloudstack
Updated Branches:
  refs/heads/4.3-forward 37ce4e52c -> 258d8e2a0


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. Reviewed-by: Min


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

Branch: refs/heads/4.3-forward
Commit: 258d8e2a0494ec8772d9238511fe5f8c6bf0ea01
Parents: 37ce4e5
Author: Nitin Mehta <ni...@citrix.com>
Authored: Fri Feb 28 10:42:24 2014 -0800
Committer: Nitin Mehta <ni...@citrix.com>
Committed: Fri Feb 28 14:39:59 2014 -0800

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


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/258d8e2a/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 c6bb617..258528a 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;
@@ -187,7 +189,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();
@@ -203,6 +206,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);
@@ -211,15 +222,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;
         public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateInfo template) {