Skip to content

Commit cb0659a

Browse files
committed
CLOUDSTACK-2590: we should only search for active user templates when
deleting an image store.
1 parent 2af36aa commit cb0659a

5 files changed

Lines changed: 314 additions & 434 deletions

File tree

‎server/src/com/cloud/api/query/dao/TemplateJoinDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ public interface TemplateJoinDao extends GenericDao<TemplateJoinVO, Long> {
3939

4040
List<TemplateJoinVO> searchByIds(Long... ids);
4141

42+
List<TemplateJoinVO> listActiveTemplates(long storeId);
43+
4244
}

‎server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
7575

7676
private final SearchBuilder<TemplateJoinVO> tmpltZoneSearch;
7777

78+
private final SearchBuilder<TemplateJoinVO> activeTmpltSearch;
79+
7880

7981
protected TemplateJoinDaoImpl() {
8082

@@ -92,6 +94,11 @@ protected TemplateJoinDaoImpl() {
9294
tmpltZoneSearch.and("downloadState", tmpltZoneSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
9395
tmpltZoneSearch.done();
9496

97+
activeTmpltSearch = createSearchBuilder();
98+
activeTmpltSearch.and("store_id", activeTmpltSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
99+
activeTmpltSearch.and("type", activeTmpltSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
100+
activeTmpltSearch.done();
101+
95102
// select distinct pair (template_id, zone_id)
96103
this._count = "select count(distinct id) from template_view WHERE ";
97104
}
@@ -438,4 +445,15 @@ public List<TemplateJoinVO> searchByIds(Long... tmplIds) {
438445

439446

440447

448+
449+
@Override
450+
public List<TemplateJoinVO> listActiveTemplates(long storeId) {
451+
SearchCriteria<TemplateJoinVO> sc = activeTmpltSearch.create();
452+
sc.setParameters("store_id", storeId);
453+
sc.setParameters("type", TemplateType.USER);
454+
return searchIncludingRemoved(sc, null, null, false);
455+
}
456+
457+
458+
441459
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ public class TemplateJoinVO extends BaseViewVO implements ControlledViewEntity {
179179
@Column(name="data_center_name")
180180
private String dataCenterName;
181181

182+
@Column(name="store_id")
183+
private Long dataStoreId; // this can be null for baremetal templates
184+
182185
@Column (name="download_state")
183186
@Enumerated(EnumType.STRING)
184187
private Status downloadState;
@@ -1003,4 +1006,16 @@ public void setErrorString(String errorString) {
10031006

10041007

10051008

1009+
public Long getDataStoreId() {
1010+
return dataStoreId;
1011+
}
1012+
1013+
1014+
1015+
public void setDataStoreId(Long dataStoreId) {
1016+
this.dataStoreId = dataStoreId;
1017+
}
1018+
1019+
1020+
10061021
}

0 commit comments

Comments
 (0)