cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [8/8] git commit: updated refs/heads/4.5 to 31a6517
Date Tue, 20 Jan 2015 06:41:53 GMT
CLOUDSTACK-7754: Templates source_template_id is null when it is created from Snapshot with
its corresponding volume removed. Fix it by searching for volumes including removed. Also
bring the logic of setting source template id to create() method than execute which was wrongly
put in.

(cherry picked from commit e1a993d37b1bf9be24edd46f6d3566826692f853)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/31a65174
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/31a65174
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/31a65174

Branch: refs/heads/4.5
Commit: 31a6517402d2007a4857d3ae9be2da8a697892b1
Parents: a6f9411
Author: Nitin Mehta <nitin.mehta@citrix.com>
Authored: Tue Oct 21 09:57:02 2014 -0700
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Tue Jan 20 12:07:42 2015 +0530

----------------------------------------------------------------------
 .../com/cloud/template/TemplateManagerImpl.java | 40 +++-----------------
 1 file changed, 6 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/31a65174/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 5641f57..a498dc7 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -1412,29 +1412,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
                 }
 
                 privateTemplate = _tmpltDao.findById(templateId);
-                if (snapshotId != null) {
-                    //getting the parent volume
-                    long parentVolumeId = _snapshotDao.findById(snapshotId).getVolumeId();
-                    //Volume can be removed
-                    VolumeVO parentVolume = _volumeDao.findByIdIncludingRemoved(parentVolumeId);
-
-                    if (parentVolume != null && parentVolume.getIsoId() != null &&
parentVolume.getIsoId() != 0) {
-                        privateTemplate.setSourceTemplateId(parentVolume.getIsoId());
-                        _tmpltDao.update(privateTemplate.getId(), privateTemplate);
-                    } else if (parentVolume != null && parentVolume.getTemplateId()
!= null) {
-                        privateTemplate.setSourceTemplateId(parentVolume.getTemplateId());
-                        _tmpltDao.update(privateTemplate.getId(), privateTemplate);
-                    }
-                } else if (volumeId != null) {
-                    VolumeVO parentVolume = _volumeDao.findById(volumeId);
-                    if (parentVolume.getIsoId() != null && parentVolume.getIsoId()
!= 0) {
-                        privateTemplate.setSourceTemplateId(parentVolume.getIsoId());
-                        _tmpltDao.update(privateTemplate.getId(), privateTemplate);
-                    } else if (parentVolume.getTemplateId() != null) {
-                        privateTemplate.setSourceTemplateId(parentVolume.getTemplateId());
-                        _tmpltDao.update(privateTemplate.getId(), privateTemplate);
-                    }
-                }
                 TemplateDataStoreVO srcTmpltStore = _tmplStoreDao.findByStoreTemplate(store.getId(),
templateId);
                 UsageEventVO usageEvent =
                         new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, privateTemplate.getAccountId(),
zoneId, privateTemplate.getId(), privateTemplate.getName(), null,
@@ -1570,8 +1547,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
             if (snapshot == null) {
                 throw new InvalidParameterValueException("Failed to create private template
record, unable to find snapshot " + snapshotId);
             }
-
-            volume = _volumeDao.findById(snapshot.getVolumeId());
+            // Volume could be removed so find including removed to record source template
id.
+            volume = _volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId());
 
             // check permissions
             _accountMgr.checkAccess(caller, null, true, snapshot);
@@ -1612,15 +1589,10 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         if (volume != null) {
             VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
             isExtractable = template != null && template.isExtractable() &&
template.getTemplateType() != Storage.TemplateType.SYSTEM;
-            if (template != null) {
-                sourceTemplateId = template.getId();
-            } else if (volume.getVolumeType() == Volume.Type.ROOT) { // vm
-                // created
-                // out
-                // of blank
-                // template
-                UserVm userVm = ApiDBUtils.findUserVmById(volume.getInstanceId());
-                sourceTemplateId = userVm.getIsoId();
+            if (volume.getIsoId() != null && volume.getIsoId() != 0) {
+                sourceTemplateId = volume.getIsoId();
+            } else if (volume.getTemplateId() != null) {
+                sourceTemplateId = volume.getTemplateId();
             }
         }
         String templateTag = cmd.getTemplateTag();


Mime
View raw message