From ae248afc5791f0af8b915f15ef5d368ac69a0256 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 23 Jul 2013 16:55:26 -0700 Subject: [PATCH] CLOUDSTACK-3639:Unable to create template from snapshot when there are multiple secondary storages in the zone. --- .../cloud/template/TemplateManagerImpl.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 5005ee04627..c87f8ebac6e 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -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 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 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());