mirror of https://github.com/apache/cloudstack.git
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>
This commit is contained in:
parent
465bfbadb3
commit
ddf91226ea
|
|
@ -106,7 +106,8 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
public void
|
||||
createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
|
||||
AsyncCallbackDispatcher<BaseImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher
|
||||
.create(this);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package com.cloud.template;
|
|||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
|
@ -180,6 +181,8 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||
if ( imageStores == null || imageStores.size() == 0 ){
|
||||
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.
|
||||
for (DataStore imageStore : imageStores) {
|
||||
TemplateInfo tmpl = this.imageFactory.getTemplate(template.getId(), imageStore);
|
||||
CreateTemplateContext<TemplateApiResult> context = new CreateTemplateContext<TemplateApiResult>(null, tmpl);
|
||||
|
|
@ -187,6 +190,9 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
|
||||
caller.setContext(context);
|
||||
this.imageService.createTemplateAsync(tmpl, imageStore, caller);
|
||||
if( !(profile.getIsPublic() || profile.getFeatured()) ){ // If private template then break
|
||||
break;
|
||||
}
|
||||
}
|
||||
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
||||
|
||||
|
|
|
|||
|
|
@ -349,11 +349,10 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
if (storeUuid != null) {
|
||||
imageStore = this._dataStoreMgr.getDataStore(storeUuid, DataStoreRole.Image);
|
||||
} else {
|
||||
List<DataStore> stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
||||
if (stores.size() > 1) {
|
||||
throw new CloudRuntimeException("multiple image stores, don't know which one to use");
|
||||
imageStore = this._dataStoreMgr.getImageStore(zoneId);
|
||||
if (imageStore == null) {
|
||||
throw new CloudRuntimeException("cannot find an image store for zone " + zoneId);
|
||||
}
|
||||
imageStore = stores.get(0);
|
||||
}
|
||||
|
||||
return imageStore;
|
||||
|
|
|
|||
Loading…
Reference in New Issue