Skip to content

Commit 5eb5594

Browse files
Harikrishna PatnalaKishan Kavala
authored andcommitted
CLOUDSTACK-4783: Added supported for listing all templates/ISOs with showremoved = true
1 parent 8f5965c commit 5eb5594

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎api/src/org/apache/cloudstack/api/ApiConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public class ApiConstants {
201201
public static final String SENT_BYTES = "sentbytes";
202202
public static final String SERVICE_OFFERING_ID = "serviceofferingid";
203203
public static final String SHOW_CAPACITIES = "showcapacities";
204+
public static final String SHOW_REMOVED = "showremoved";
204205
public static final String SIZE = "size";
205206
public static final String SNAPSHOT_ID = "snapshotid";
206207
public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid";

‎api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd {
7878
description="the ID of the zone")
7979
private Long zoneId;
8080

81+
@Parameter(name=ApiConstants.SHOW_REMOVED, type=CommandType.BOOLEAN, description="show removed ISOs as well")
82+
private Boolean showRemoved;
83+
8184
/////////////////////////////////////////////////////
8285
/////////////////// Accessors ///////////////////////
8386
/////////////////////////////////////////////////////
@@ -115,6 +118,10 @@ public Long getZoneId() {
115118
return zoneId;
116119
}
117120

121+
public Boolean getShowRemoved() {
122+
return (showRemoved != null ? showRemoved : false);
123+
}
124+
118125
public boolean listInReadyState() {
119126
Account account = UserContext.current().getCaller();
120127
// It is account specific if account is admin type and domainId and accountName are not null

‎api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
6969
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
7070
description="list templates by zoneId")
7171
private Long zoneId;
72+
73+
@Parameter(name=ApiConstants.SHOW_REMOVED, type=CommandType.BOOLEAN, description="show removed templates as well")
74+
private Boolean showRemoved;
7275
/////////////////////////////////////////////////////
7376
/////////////////// Accessors ///////////////////////
7477
/////////////////////////////////////////////////////
@@ -93,6 +96,10 @@ public Long getZoneId() {
9396
return zoneId;
9497
}
9598

99+
public Boolean getShowRemoved() {
100+
return (showRemoved != null ? showRemoved : false);
101+
}
102+
96103
public boolean listInReadyState() {
97104

98105
Account account = UserContext.current().getCaller();

‎server/src/com/cloud/api/query/QueryManagerImpl.java‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
26832683
TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
26842684
Long id = cmd.getId();
26852685
Map<String, String> tags = cmd.getTags();
2686+
boolean showRemovedTmpl = cmd.getShowRemoved();
26862687
Account caller = UserContext.current().getCaller();
26872688

26882689
boolean listAll = false;
@@ -2710,14 +2711,14 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
27102711

27112712
return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null,
27122713
cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, showDomr,
2713-
cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags);
2714+
cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags, showRemovedTmpl);
27142715
}
27152716

27162717
private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long templateId, String name,
27172718
String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Long pageSize,
27182719
Long startIndex, Long zoneId, HypervisorType hyperType, boolean showDomr, boolean onlyReady,
27192720
List<Account> permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria,
2720-
Map<String, String> tags) {
2721+
Map<String, String> tags, boolean showRemovedTmpl) {
27212722

27222723
// check if zone is configured, if not, just return empty list
27232724
List<HypervisorType> hypers = null;
@@ -2740,7 +2741,11 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
27402741

27412742
// verify templateId parameter and specially handle it
27422743
if (templateId != null) {
2743-
template = _templateDao.findById(templateId);
2744+
if(showRemovedTmpl){
2745+
template = _templateDao.findByIdIncludingRemoved(templateId);
2746+
}else{
2747+
template = _templateDao.findById(templateId);
2748+
}
27442749
if (template == null) {
27452750
throw new InvalidParameterValueException("Please specify a valid template ID.");
27462751
}// If ISO requested then it should be ISO.
@@ -2758,6 +2763,10 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
27582763
ex.addProxyObject(template.getUuid(), "templateId");
27592764
throw ex;
27602765
}
2766+
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.
2767+
s_logger.error("Please specify a valid template ID, template " + template.getUuid() + " is removed");
2768+
throw new InvalidParameterValueException("Please specify a valid template ID " + template.getUuid());
2769+
}
27612770

27622771
// if template is not public, perform permission check here
27632772
if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
@@ -2940,6 +2949,9 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
29402949
// don't return removed template, this should not be needed since we
29412950
// changed annotation for removed field in TemplateJoinVO.
29422951
// sc.addAnd("removed", SearchCriteria.Op.NULL);
2952+
if(!showRemovedTmpl){
2953+
sc.addAnd("removed", SearchCriteria.Op.NULL);
2954+
}
29432955

29442956
// search unique templates and find details by Ids
29452957
Pair<List<TemplateJoinVO>, Integer> uniqueTmplPair = _templateJoinDao.searchAndCount(sc, searchFilter);
@@ -2979,6 +2991,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
29792991
TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter());
29802992
Long id = cmd.getId();
29812993
Map<String, String> tags = cmd.getTags();
2994+
boolean showRemovedIso = cmd.getShowRemoved();
29822995
Account caller = UserContext.current().getCaller();
29832996

29842997
boolean listAll = false;
@@ -3005,7 +3018,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
30053018

30063019
return searchForTemplatesInternal(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true,
30073020
cmd.isBootable(), cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, true,
3008-
cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags);
3021+
cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags, showRemovedIso);
30093022
}
30103023

30113024
@Override

‎server/src/com/cloud/api/query/vo/TemplateJoinVO.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class TemplateJoinVO extends BaseViewVO implements ControlledViewEntity {
8282
@Column(name="created_on_store")
8383
private Date createdOnStore = null;
8484

85-
@Column(name=GenericDao.REMOVED_COLUMN)
85+
@Column(name=GenericDao.REMOVED)
8686
@Temporal(TemporalType.TIMESTAMP)
8787
private Date removed;
8888

0 commit comments

Comments
 (0)