CLOUDSTACK-4783: Added supported for listing all templates/ISOs with showremoved = true

This commit is contained in:
Harikrishna Patnala 2013-10-18 16:13:04 +05:30 committed by Kishan Kavala
parent 8f5965c793
commit 5eb5594e8e
5 changed files with 33 additions and 5 deletions

View File

@ -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";

View File

@ -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

View File

@ -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();

View File

@ -2683,6 +2683,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 = 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<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;
@ -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<List<TemplateJoinVO>, 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<String, String> 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

View File

@ -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;