Skip to content

Commit 5360ab3

Browse files
committed
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.
1 parent 56684a5 commit 5360ab3

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

‎server/src/com/cloud/template/HypervisorTemplateAdapter.java‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.net.MalformedURLException;
2020
import java.net.URL;
2121
import java.util.Collections;
22+
import java.util.HashSet;
2223
import java.util.List;
24+
import java.util.Set;
2325
import java.util.concurrent.ExecutionException;
2426

2527
import javax.ejb.Local;
@@ -219,7 +221,8 @@ public VMTemplateVO create(TemplateProfile profile) {
219221
throw new CloudRuntimeException("Unable to find image store to download template " + profile.getTemplate());
220222
}
221223

222-
Collections.shuffle(imageStores);// For private templates choose a random store. TODO - Have a better algorithm based on size, no. of objects, load etc.
224+
Set<Long> zoneSet = new HashSet<Long>();
225+
Collections.shuffle(imageStores); // For private templates choose a random store. TODO - Have a better algorithm based on size, no. of objects, load etc.
223226
for (DataStore imageStore : imageStores) {
224227
// skip data stores for a disabled zone
225228
Long zoneId = imageStore.getScope().getScopeId();
@@ -235,6 +238,14 @@ public VMTemplateVO create(TemplateProfile profile) {
235238
s_logger.info("Zone " + zoneId + " is disabled, so skip downloading template to its image store " + imageStore.getId());
236239
continue;
237240
}
241+
242+
// We want to download private template to one of the image store in a zone
243+
if(isPrivateTemplate(template) && zoneSet.contains(zoneId)){
244+
continue;
245+
}else {
246+
zoneSet.add(zoneId);
247+
}
248+
238249
}
239250

240251
TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), imageStore);
@@ -243,15 +254,21 @@ public VMTemplateVO create(TemplateProfile profile) {
243254
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
244255
caller.setContext(context);
245256
imageService.createTemplateAsync(tmpl, imageStore, caller);
246-
if (!(profile.getIsPublic() || profile.getFeatured())) { // If private template then break
247-
break;
248-
}
249257
}
250258
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
251259

252260
return template;
253261
}
254262

263+
private boolean isPrivateTemplate(VMTemplateVO template){
264+
265+
// if public OR featured OR system template
266+
if(template.isPublicTemplate() || template.isFeatured() || template.getTemplateType() == TemplateType.SYSTEM)
267+
return false;
268+
else
269+
return true;
270+
}
271+
255272
private class CreateTemplateContext<T> extends AsyncRpcContext<T> {
256273
final TemplateInfo template;
257274

0 commit comments

Comments
 (0)