CLOUDSTACK-3639:Unable to create template from snapshot when there are

multiple secondary storages in the zone.
This commit is contained in:
Min Chen 2013-07-23 16:55:26 -07:00
parent 040292d606
commit ae248afc57
1 changed files with 19 additions and 20 deletions

View File

@ -611,7 +611,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
@DB
public boolean copy(long userId, VMTemplateVO template, DataStore srcSecStore, DataCenterVO dstZone) throws StorageUnavailableException,
ResourceAllocationException {
ResourceAllocationException {
long tmpltId = template.getId();
long dstZoneId = dstZone.getId();
// find all eligible image stores for the destination zone
@ -913,7 +913,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
}
boolean result = attachISOToVM(vmId, userId, isoId, false); // attach=false
// => detach
// => detach
if (result) {
return result;
} else {
@ -1256,14 +1256,14 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
}
if (isExtractable != null && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {// Only
// ROOT
// admins
// allowed
// to
// change
// this
// powerful
// attribute
// ROOT
// admins
// allowed
// to
// change
// this
// powerful
// attribute
updatedTemplate.setExtractable(isExtractable.booleanValue());
} else if (isExtractable != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new InvalidParameterValueException("Only ROOT admins are allowed to modify this attribute.");
@ -1279,7 +1279,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
if (permittedAccount != null) {
if (permittedAccount.getId() == caller.getId()) {
continue; // don't grant permission to the template
// owner, they implicitly have permission
// owner, they implicitly have permission
}
LaunchPermissionVO existingPermission = _launchPermissionDao.findByTemplateAndAccount(id, permittedAccount.getId());
if (existingPermission == null) {
@ -1336,7 +1336,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
try {
TemplateInfo tmplInfo = this._tmplFactory.getTemplate(templateId, DataStoreRole.Image);
Long zoneId = null;
long zoneId = 0;
if (snapshotId != null) {
snapshot = _snapshotDao.findById(snapshotId);
zoneId = snapshot.getDataCenterId();
@ -1344,18 +1344,17 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
volume = _volumeDao.findById(volumeId);
zoneId = volume.getDataCenterId();
}
ZoneScope scope = new ZoneScope(zoneId);
List<DataStore> store = this._dataStoreMgr.getImageStoresByScope(scope);
if (store.size() > 1) {
throw new CloudRuntimeException("muliple image data store, don't know which one to use");
DataStore store = this._dataStoreMgr.getImageStore(zoneId);
if (store == null) {
throw new CloudRuntimeException("cannot find an image store for zone " + zoneId);
}
AsyncCallFuture<TemplateApiResult> future = null;
if (snapshotId != null) {
SnapshotInfo snapInfo = this._snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Image);
future = this._tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, tmplInfo, store.get(0));
future = this._tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, tmplInfo, store);
} else if (volumeId != null) {
VolumeInfo volInfo = this._volFactory.getVolume(volumeId);
future = this._tmpltSvr.createTemplateFromVolumeAsync(volInfo, tmplInfo, store.get(0));
future = this._tmpltSvr.createTemplateFromVolumeAsync(volInfo, tmplInfo, store);
} else {
throw new CloudRuntimeException("Creating private Template need to specify snapshotId or volumeId");
}
@ -1556,8 +1555,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
if (template != null) {
sourceTemplateId = template.getId();
} else if (volume.getVolumeType() == Volume.Type.ROOT) { // vm
// created
// out
// created
// out
// of blank
// template
UserVm userVm = ApiDBUtils.findUserVmById(volume.getInstanceId());