Skip to content

Commit ddf9122

Browse files
committed
CLOUDSTACK-3913
Private templates would now get copied to only one of image storage chosen randamly as was the case earlier. Dont throw an exception for uploading volumes when there are multiple image stores, instead choose one of them randomly Signed off by : nitin mehta<nitin.mehta@citrix.com>
1 parent 465bfba commit ddf9122

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ protected Long getMaxTemplateSizeInBytes() {
106106
}
107107

108108
@Override
109-
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
109+
public void
110+
createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
110111
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
111112
AsyncCallbackDispatcher<BaseImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher
112113
.create(this);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.net.MalformedURLException;
2020
import java.net.URL;
21+
import java.util.Collections;
2122
import java.util.List;
2223
import java.util.concurrent.ExecutionException;
2324

@@ -180,13 +181,18 @@ public VMTemplateVO create(TemplateProfile profile) {
180181
if ( imageStores == null || imageStores.size() == 0 ){
181182
throw new CloudRuntimeException("Unable to find image store to download template "+ profile.getTemplate());
182183
}
184+
185+
Collections.shuffle(imageStores);// For private templates choose a random store. TODO - Have a better algorithm based on size, no. of objects, load etc.
183186
for (DataStore imageStore : imageStores) {
184187
TemplateInfo tmpl = this.imageFactory.getTemplate(template.getId(), imageStore);
185188
CreateTemplateContext<TemplateApiResult> context = new CreateTemplateContext<TemplateApiResult>(null, tmpl);
186189
AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> caller = AsyncCallbackDispatcher.create(this);
187190
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
188191
caller.setContext(context);
189192
this.imageService.createTemplateAsync(tmpl, imageStore, caller);
193+
if( !(profile.getIsPublic() || profile.getFeatured()) ){ // If private template then break
194+
break;
195+
}
190196
}
191197
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
192198

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,10 @@ public DataStore getImageStore(String storeUuid, Long zoneId) {
349349
if (storeUuid != null) {
350350
imageStore = this._dataStoreMgr.getDataStore(storeUuid, DataStoreRole.Image);
351351
} else {
352-
List<DataStore> stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
353-
if (stores.size() > 1) {
354-
throw new CloudRuntimeException("multiple image stores, don't know which one to use");
352+
imageStore = this._dataStoreMgr.getImageStore(zoneId);
353+
if (imageStore == null) {
354+
throw new CloudRuntimeException("cannot find an image store for zone " + zoneId);
355355
}
356-
imageStore = stores.get(0);
357356
}
358357

359358
return imageStore;

0 commit comments

Comments
 (0)