cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject git commit: updated refs/heads/4.3 to 4907a8f
Date Wed, 11 Dec 2013 18:33:13 GMT
Updated Branches:
  refs/heads/4.3 9435d2e93 -> 4907a8f6f


CLOUDSTACK-4904: Unable to see a derieved template if the
 parent template is deleted
Signed off by : nitin mehta<nitin.mehta@citrix.com>


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

Branch: refs/heads/4.3
Commit: 4907a8f6faf17294f4ca58e05cee9faaf77a385b
Parents: 9435d2e
Author: Harikrishna Patnala <harikrishna.patnala@citrix.com>
Authored: Wed Dec 11 10:30:39 2013 -0800
Committer: Nitin Mehta <nitin.mehta@citrix.com>
Committed: Wed Dec 11 10:32:27 2013 -0800

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |  1 +
 .../api/command/user/iso/ListIsosCmd.java       |  7 +++++
 .../command/user/template/ListTemplatesCmd.java |  7 +++++
 .../com/cloud/api/query/QueryManagerImpl.java   | 27 ++++++++++++++++----
 .../cloud/api/query/dao/TemplateJoinDao.java    |  5 ++++
 .../api/query/dao/TemplateJoinDaoImpl.java      |  8 ++++++
 6 files changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4907a8f6/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index e08923c..1f99481 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -209,6 +209,7 @@ public class ApiConstants {
     public static final String SENT_BYTES = "sentbytes";
     public static final String SERVICE_OFFERING_ID = "serviceofferingid";
     public static final String SHOW_CAPACITIES = "showcapacities";
+    public static final String SHOW_REMOVED = "showremoved";
     public static final String SIZE = "size";
     public static final String SNAPSHOT_ID = "snapshotid";
     public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4907a8f6/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
index c3f558b..9b4b414 100644
--- a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
@@ -79,6 +79,9 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd {
             description="the ID of the zone")
     private Long zoneId;
 
+    @Parameter(name=ApiConstants.SHOW_REMOVED, type=CommandType.BOOLEAN, description="show
removed ISOs as well")
+    private Boolean showRemoved;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -116,6 +119,10 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd {
         return zoneId;
     }
 
+    public Boolean getShowRemoved() {
+        return (showRemoved != null ? showRemoved : false);
+    }
+
     public boolean listInReadyState() {
         Account account = CallContext.current().getCallingAccount();
         // It is account specific if account is admin type and domainId and accountName are
not null

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4907a8f6/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
index 4b34909..b055bf2 100644
--- a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
@@ -70,6 +70,9 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
     @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
             description="list templates by zoneId")
     private Long zoneId;
+
+    @Parameter(name=ApiConstants.SHOW_REMOVED, type=CommandType.BOOLEAN, description="show
removed templates as well")
+    private Boolean showRemoved;
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -94,6 +97,10 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
         return zoneId;
     }
 
+    public Boolean getShowRemoved() {
+        return (showRemoved != null ? showRemoved : false);
+    }
+
     public boolean listInReadyState() {
 
         Account account = CallContext.current().getCallingAccount();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4907a8f6/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index 58df38c..3830b2d 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -2793,6 +2793,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
         TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
         Long id = cmd.getId();
         Map<String, String> tags = cmd.getTags();
+        boolean showRemovedTmpl = cmd.getShowRemoved();
         Account caller = CallContext.current().getCallingAccount();
 
         boolean listAll = false;
@@ -2820,14 +2821,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
 
         return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter,
false, null,
                 cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType,
showDomr,
-                cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria,
tags);
+                cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria,
tags, showRemovedTmpl);
     }
 
     private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long
templateId, String name,
             String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable,
Long pageSize,
             Long startIndex, Long zoneId, HypervisorType hyperType, boolean showDomr, boolean
onlyReady,
             List<Account> permittedAccounts, Account caller, ListProjectResourcesCriteria
listProjectResourcesCriteria,
-            Map<String, String> tags) {
+            Map<String, String> tags, boolean showRemovedTmpl) {
 
         // check if zone is configured, if not, just return empty list
         List<HypervisorType> hypers = null;
@@ -2850,7 +2851,11 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
 
         // verify templateId parameter and specially handle it
         if (templateId != null) {
-            template = _templateDao.findByIdIncludingRemoved(templateId); // Done for backward
compatibility - Bug-5221
+            if(showRemovedTmpl){
+                template = _templateDao.findByIdIncludingRemoved(templateId);
+            } else {
+                template = _templateDao.findById(templateId);
+            }
             if (template == null) {
                 throw new InvalidParameterValueException("Please specify a valid template
ID.");
             }// If ISO requested then it should be ISO.
@@ -2868,6 +2873,11 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
                 ex.addProxyObject(template.getUuid(), "templateId");
                 throw ex;
             }
+            // If template is removed and showRemoved flag not turned -> throw exception.
findbyId returns removed template as well above.
+            if ((template == null) || ((template.getRemoved() != null) && !showRemovedTmpl)){
+                s_logger.error("Please specify a valid template ID, template " + template.getUuid()
+ " is removed");
+                throw new InvalidParameterValueException("Please specify a valid template
ID " + template.getUuid());
+            }
 
             // if template is not public, perform permission check here
             if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN)
{
@@ -3051,7 +3061,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
         // sc.addAnd("removed", SearchCriteria.Op.NULL);
 
         // search unique templates and find details by Ids
-        Pair<List<TemplateJoinVO>, Integer> uniqueTmplPair = _templateJoinDao.searchAndCount(sc,
searchFilter);
+        Pair<List<TemplateJoinVO>, Integer> uniqueTmplPair = null;
+        if(showRemovedTmpl){
+            uniqueTmplPair = _templateJoinDao.searchIncludingRemovedAndCount(sc, searchFilter);
+        } else {
+            uniqueTmplPair = _templateJoinDao.searchAndCount(sc, searchFilter);
+        }
+
         Integer count = uniqueTmplPair.second();
         if (count.intValue() == 0) {
             // empty result
@@ -3088,6 +3104,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
         TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter());
         Long id = cmd.getId();
         Map<String, String> tags = cmd.getTags();
+        boolean showRemovedISO = cmd.getShowRemoved();
         Account caller = CallContext.current().getCallingAccount();
 
         boolean listAll = false;
@@ -3114,7 +3131,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
 
         return searchForTemplatesInternal(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(),
isoFilter, true,
                 cmd.isBootable(), cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(),
hypervisorType, true,
-                cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria,
tags);
+                cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria,
tags, showRemovedISO);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4907a8f6/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/TemplateJoinDao.java b/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
index f73f5bd..e0c3fc0 100644
--- a/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
+++ b/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
@@ -18,6 +18,9 @@ package com.cloud.api.query.dao;
 
 import java.util.List;
 
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.SearchCriteria;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
 import com.cloud.api.query.vo.TemplateJoinVO;
@@ -42,4 +45,6 @@ public interface TemplateJoinDao extends GenericDao<TemplateJoinVO, Long>
{
 
     List<TemplateJoinVO> listActiveTemplates(long storeId);
 
+    public Pair<List<TemplateJoinVO>, Integer> searchIncludingRemovedAndCount(final
SearchCriteria<TemplateJoinVO> sc, final Filter filter);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4907a8f6/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
index 468fb83..a35b334 100644
--- a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
@@ -24,6 +24,8 @@ import java.util.Map;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.Filter;
 import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -445,6 +447,12 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO,
Long> im
         return searchIncludingRemoved(sc, null, null, false);
     }
 
+    public Pair<List<TemplateJoinVO>, Integer> searchIncludingRemovedAndCount(final
SearchCriteria<TemplateJoinVO> sc, final Filter filter) {
+        List<TemplateJoinVO> objects = searchIncludingRemoved(sc, filter, null, false);
+        Integer count = getCount(sc);
+        return new Pair<List<TemplateJoinVO>, Integer>(objects, count);
+    }
+
 
 
 }


Mime
View raw message