diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index d71db40df69..761ff45196b 100755 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -201,6 +201,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"; 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 b490ca9966a..4bee476a58b 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 @@ -78,6 +78,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 /////////////////////// ///////////////////////////////////////////////////// @@ -115,6 +118,10 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd { return zoneId; } + public Boolean getShowRemoved() { + return (showRemoved != null ? showRemoved : false); + } + public boolean listInReadyState() { Account account = UserContext.current().getCaller(); // It is account specific if account is admin type and domainId and accountName are not null 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 0b937be6d59..a25723c9b33 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 @@ -69,6 +69,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 /////////////////////// ///////////////////////////////////////////////////// @@ -93,6 +96,10 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd { return zoneId; } + public Boolean getShowRemoved() { + return (showRemoved != null ? showRemoved : false); + } + public boolean listInReadyState() { Account account = UserContext.current().getCaller(); diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 6104ec0c863..9963d42e35d 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -2683,6 +2683,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter()); Long id = cmd.getId(); Map tags = cmd.getTags(); + boolean showRemovedTmpl = cmd.getShowRemoved(); Account caller = UserContext.current().getCaller(); boolean listAll = false; @@ -2710,14 +2711,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, 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 permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, - Map tags) { + Map tags, boolean showRemovedTmpl) { // check if zone is configured, if not, just return empty list List hypers = null; @@ -2740,7 +2741,11 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // verify templateId parameter and specially handle it if (templateId != null) { - template = _templateDao.findById(templateId); + 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. @@ -2758,6 +2763,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { ex.addProxyObject(template.getUuid(), "templateId"); throw ex; } + if ((template == null) || ((template.getRemoved() != null) && !showRemovedTmpl)){ // If template is removed and showRemoved flag not turned -> throw exception. findbyId returns removed template as well above. + 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) { @@ -2940,6 +2949,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { // don't return removed template, this should not be needed since we // changed annotation for removed field in TemplateJoinVO. // sc.addAnd("removed", SearchCriteria.Op.NULL); + if(!showRemovedTmpl){ + sc.addAnd("removed", SearchCriteria.Op.NULL); + } // search unique templates and find details by Ids Pair, Integer> uniqueTmplPair = _templateJoinDao.searchAndCount(sc, searchFilter); @@ -2979,6 +2991,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter()); Long id = cmd.getId(); Map tags = cmd.getTags(); + boolean showRemovedIso = cmd.getShowRemoved(); Account caller = UserContext.current().getCaller(); boolean listAll = false; @@ -3005,7 +3018,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 diff --git a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java index bb1cfedd781..618b813e733 100644 --- a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java +++ b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java @@ -82,7 +82,7 @@ public class TemplateJoinVO extends BaseViewVO implements ControlledViewEntity { @Column(name="created_on_store") private Date createdOnStore = null; - @Column(name=GenericDao.REMOVED_COLUMN) + @Column(name=GenericDao.REMOVED) @Temporal(TemporalType.TIMESTAMP) private Date removed;