mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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.
This commit is contained in:
parent
56684a52bc
commit
5360ab3d43
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user