cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [2/2] git commit: updated refs/heads/4.3 to e5761cc
Date Tue, 02 Dec 2014 09:53:17 GMT
CLOUDSTACK-5997: Template state changes side affects

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

Conflicts:
	engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
	server/src/com/cloud/template/HypervisorTemplateAdapter.java

This makes setup/db/db/schema-421to430.sql same as in master branch. The
change is table view related and does not affect db at all. Making it same
as the version on master for sanity purposes.


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

Branch: refs/heads/4.3
Commit: e5761cc85fb257867c52e00502d0110be214702e
Parents: 90d6c01
Author: Nitin Mehta <nitin.mehta@citrix.com>
Authored: Thu Jan 30 17:59:55 2014 -0800
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Tue Dec 2 15:16:11 2014 +0530

----------------------------------------------------------------------
 .../cloud/storage/dao/VMTemplateDaoImpl.java    | 31 ++++++++++++--------
 .../template/HypervisorTemplateAdapter.java     | 18 ++++++------
 .../com/cloud/template/TemplateManagerImpl.java |  6 ----
 setup/db/db/schema-421to430.sql                 |  2 +-
 4 files changed, 29 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5761cc8/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
index 73b68ea..d486cb7 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
@@ -49,6 +49,7 @@ import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VMTemplateZoneVO;
 import com.cloud.tags.ResourceTagVO;
 import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GenericDaoBase;
@@ -146,7 +147,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
             sb.and("format", sb.entity().getFormat(), SearchCriteria.Op.EQ);
             sb.and("type", sb.entity().getTemplateType(), SearchCriteria.Op.EQ);
             sb.and("bootable", sb.entity().isBootable(), SearchCriteria.Op.EQ);
-            sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.EQ);
+            sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
 
             SearchBuilder<ResourceTagVO> tagSearch = _tagsDao.createSearchBuilder();
             for (int count = 0; count < tags.size(); count++) {
@@ -170,7 +171,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         }
 
         if (!listRemoved) {
-            sc.setParameters("removed", (Object) null);
+            sc.setParameters("state", VirtualMachineTemplate.State.Active);
         }
 
         if (tags != null && !tags.isEmpty()) {
@@ -197,7 +198,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         sc.setParameters("type", TemplateType.USER.toString());
 
         if (!listRemoved) {
-            sc.setParameters("removed", (Object) null);
+            sc.setParameters("state", VirtualMachineTemplate.State.Active);
         }
 
         return listBy(sc);
@@ -216,7 +217,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     public List<Long> listPrivateTemplatesByHost(Long hostId) {
 
         String sql = "select * from template_host_ref as thr INNER JOIN vm_template as t
ON t.id=thr.template_id "
-                + "where thr.host_id=? and t.public=0 and t.featured=0 and t.type='USER'
and t.removed is NULL";
+                + "where thr.host_id=? and t.public=0 and t.featured=0 and t.type='USER'
and t.state='Active'";
 
         List<Long> l = new ArrayList<Long>();
 
@@ -264,6 +265,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     public List<VMTemplateVO> listByAccountId(long accountId) {
         SearchCriteria<VMTemplateVO> sc = AccountIdSearch.create();
         sc.setParameters("accountId", accountId);
+        sc.setParameters("state", VirtualMachineTemplate.State.Active);
         return listBy(sc);
     }
 
@@ -311,12 +313,12 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         PublicIsoSearch.and("format", PublicIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
         PublicIsoSearch.and("type", PublicIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
         PublicIsoSearch.and("bootable", PublicIsoSearch.entity().isBootable(), SearchCriteria.Op.EQ);
-        PublicIsoSearch.and("removed", PublicIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ);
+        PublicIsoSearch.and("state", PublicIsoSearch.entity().getState(), SearchCriteria.Op.EQ);
 
         UserIsoSearch = createSearchBuilder();
         UserIsoSearch.and("format", UserIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
         UserIsoSearch.and("type", UserIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
-        UserIsoSearch.and("removed", UserIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ);
+        UserIsoSearch.and("state", UserIsoSearch.entity().getState(), SearchCriteria.Op.EQ);
 
         tmpltTypeHyperSearch = createSearchBuilder();
         tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(),
SearchCriteria.Op.EQ);
@@ -331,7 +333,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         tmpltTypeHyperSearch.done();
 
         readySystemTemplateSearch = createSearchBuilder();
-        readySystemTemplateSearch.and("removed", readySystemTemplateSearch.entity().getRemoved(),
SearchCriteria.Op.NULL);
+        readySystemTemplateSearch.and("state", readySystemTemplateSearch.entity().getState(),
SearchCriteria.Op.EQ);
         readySystemTemplateSearch.and("templateType", readySystemTemplateSearch.entity().getTemplateType(),
SearchCriteria.Op.EQ);
         SearchBuilder<TemplateDataStoreVO>  templateDownloadSearch = _templateDataStoreDao.createSearchBuilder();
         templateDownloadSearch.and("downloadState", templateDownloadSearch.entity().getDownloadState(),
SearchCriteria.Op.EQ);
@@ -356,13 +358,13 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         tmpltTypeHyperSearch2.and("templateName", tmpltTypeHyperSearch2.entity().getName(),
SearchCriteria.Op.EQ);
 
         tmpltTypeSearch = createSearchBuilder();
-        tmpltTypeSearch.and("removed", tmpltTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+        tmpltTypeSearch.and("state", tmpltTypeSearch.entity().getState(), SearchCriteria.Op.EQ);
         tmpltTypeSearch.and("templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
 
         AccountIdSearch = createSearchBuilder();
         AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         AccountIdSearch.and("publicTemplate", AccountIdSearch.entity().isPublicTemplate(),
SearchCriteria.Op.EQ);
-        AccountIdSearch.and("removed", AccountIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
// only list not removed templates for this account
+        AccountIdSearch.and("state", AccountIdSearch.entity().getState(), SearchCriteria.Op.EQ);
// only list not removed templates for this account
         AccountIdSearch.done();
 
         SearchBuilder<VMTemplateZoneVO> tmpltZoneSearch = _templateZoneDao.createSearchBuilder();
@@ -370,7 +372,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
 
         TmpltsInZoneSearch = createSearchBuilder();
-        TmpltsInZoneSearch.and("removed", TmpltsInZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+        TmpltsInZoneSearch.and("state", TmpltsInZoneSearch.entity().getState(), SearchCriteria.Op.EQ);
         TmpltsInZoneSearch.and().op("avoidtype", TmpltsInZoneSearch.entity().getTemplateType(),
SearchCriteria.Op.NEQ);
         TmpltsInZoneSearch.or("templateType", TmpltsInZoneSearch.entity().getTemplateType(),
SearchCriteria.Op.NULL);
         TmpltsInZoneSearch.cp();
@@ -380,12 +382,12 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         TmpltsInZoneSearch.done();
 
         ActiveTmpltSearch = createSearchBuilder();
-        ActiveTmpltSearch.and("removed", ActiveTmpltSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+        ActiveTmpltSearch.and("state", ActiveTmpltSearch.entity().getState(), SearchCriteria.Op.EQ);
 
         CountTemplatesByAccount = createSearchBuilder(Long.class);
         CountTemplatesByAccount.select(null, Func.COUNT, null);
         CountTemplatesByAccount.and("account", CountTemplatesByAccount.entity().getAccountId(),
SearchCriteria.Op.EQ);
-        CountTemplatesByAccount.and("removed", CountTemplatesByAccount.entity().getRemoved(),
SearchCriteria.Op.NULL);
+        CountTemplatesByAccount.and("state", CountTemplatesByAccount.entity().getState(),
SearchCriteria.Op.EQ);
         CountTemplatesByAccount.done();
 
         //        updateStateSearch = this.createSearchBuilder();
@@ -778,6 +780,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     public List<VMTemplateVO> listAllInZone(long dataCenterId) {
         SearchCriteria<VMTemplateVO> sc = TmpltsInZoneSearch.create();
         sc.setParameters("avoidtype", TemplateType.PERHOST.toString());
+        sc.setParameters("state", VirtualMachineTemplate.State.Active);
         sc.setJoinParameters("tmpltzone", "zoneId", dataCenterId);
         return listBy(sc);
     }
@@ -785,6 +788,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     @Override
     public List<VMTemplateVO> listAllActive() {
         SearchCriteria<VMTemplateVO> sc = ActiveTmpltSearch.create();
+        sc.setParameters("state", VirtualMachineTemplate.State.Active.toString());
         return listBy(sc);
     }
 
@@ -792,6 +796,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     public List<VMTemplateVO> listDefaultBuiltinTemplates() {
         SearchCriteria<VMTemplateVO> sc = tmpltTypeSearch.create();
         sc.setParameters("templateType", Storage.TemplateType.BUILTIN);
+        sc.setParameters("state", VirtualMachineTemplate.State.Active);
         return listBy(sc);
     }
 
@@ -817,6 +822,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     public VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType)
{
         SearchCriteria<VMTemplateVO> sc = readySystemTemplateSearch.create();
         sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
+        sc.setParameters("state", VirtualMachineTemplate.State.Active);
         sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing);
         sc.setJoinParameters("tmplHyper", "zoneId", zoneId);
         sc.setJoinParameters("vmTemplateJoinTemplateStoreRef", "downloadState", VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
@@ -877,6 +883,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     public Long countTemplatesForAccount(long accountId) {
         SearchCriteria<Long> sc = CountTemplatesByAccount.create();
         sc.setParameters("account", accountId);
+        sc.setParameters("state", VirtualMachineTemplate.State.Active.toString());
         return customSearch(sc, null).get(0);
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5761cc8/server/src/com/cloud/template/HypervisorTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
index 258528a..5e35d78 100755
--- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
@@ -378,15 +378,15 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
             // find all eligible image stores for this template
             List<DataStore> iStores = templateMgr.getImageStoreByTemplate(template.getId(),
null);
             if (iStores == null || iStores.size() == 0) {
-                // remove template from vm_templates table
-                if (_tmpltDao.remove(template.getId())) {
-                    // Decrement the number of templates and total secondary storage
-                    // space used by the account
-                    Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
-                    _resourceLimitMgr.decrementResourceCount(template.getAccountId(), ResourceType.template);
-                    _resourceLimitMgr.recalculateResourceCount(template.getAccountId(), account.getDomainId(),
-                            ResourceType.secondary_storage.getOrdinal());
-                }
+                // Mark template as Inactive.
+                template.setState(VirtualMachineTemplate.State.Inactive);
+                _tmpltDao.update(template.getId(), template);
+
+                // Decrement the number of templates and total secondary storage
+                // space used by the account
+                Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
+                _resourceLimitMgr.decrementResourceCount(template.getAccountId(), ResourceType.template);
+                _resourceLimitMgr.recalculateResourceCount(template.getAccountId(), account.getDomainId(),
ResourceType.secondary_storage.getOrdinal());
             }
         }
         return success;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5761cc8/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 3dd91f4..90ab994 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -1127,9 +1127,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
             throw new InvalidParameterValueException("Please specify a valid template.");
         }
 
-        template.setState(VirtualMachineTemplate.State.Inactive);
-        _tmpltDao.update(template.getId(), template);
-
         TemplateAdapter adapter = getAdapter(template.getHypervisorType());
         TemplateProfile profile = adapter.prepareDelete(cmd);
         return adapter.delete(profile);
@@ -1163,9 +1160,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
             throw new InvalidParameterValueException("Failed to find a secondary storage
store in the specified zone.");
         }
 
-        template.setState(VirtualMachineTemplate.State.Inactive);
-        _tmpltDao.update(template.getId(), template);
-
         TemplateAdapter adapter = getAdapter(template.getHypervisorType());
         TemplateProfile profile = adapter.prepareDelete(cmd);
         boolean result = adapter.delete(profile);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5761cc8/setup/db/db/schema-421to430.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-421to430.sql b/setup/db/db/schema-421to430.sql
index 6a8ec49..174fedc 100644
--- a/setup/db/db/schema-421to430.sql
+++ b/setup/db/db/schema-421to430.sql
@@ -303,7 +303,7 @@ CREATE VIEW `cloud`.`template_view` AS
             left join
         `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id
             left join
-        `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id and
template_store_ref.store_role = 'Image'
+        `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id and
template_store_ref.store_role = 'Image' and template_store_ref.destroyed=0
             left join
         `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id
is not NULL AND image_store.id = template_store_ref.store_id
             left join


Mime
View raw message