Skip to content

Commit 45dbd9c

Browse files
author
Jessica Wang
committed
CLOUDSTACK-2120: mixed zone management - API: extend listTemplates, listIsos API to to take in zonetype.
1 parent 1f0863f commit 45dbd9c

5 files changed

Lines changed: 29 additions & 11 deletions

File tree

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.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to")
82+
private String zoneType;
83+
8184
/////////////////////////////////////////////////////
8285
/////////////////// Accessors ///////////////////////
8386
/////////////////////////////////////////////////////
@@ -115,6 +118,10 @@ public Long getZoneId() {
115118
return zoneId;
116119
}
117120

121+
public String getZoneType() {
122+
return zoneType;
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
6868
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
6969
description="list templates by zoneId")
7070
private Long zoneId;
71+
72+
@Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to")
73+
private String zoneType;
74+
7175
/////////////////////////////////////////////////////
7276
/////////////////// Accessors ///////////////////////
7377
/////////////////////////////////////////////////////
@@ -92,6 +96,10 @@ public Long getZoneId() {
9296
return zoneId;
9397
}
9498

99+
public String getZoneType() {
100+
return zoneType;
101+
}
102+
95103
public boolean listInReadyState() {
96104

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

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ public Set<Pair<Long, Long>> listIsos(ListIsosCmd cmd) throws IllegalArgumentExc
13091309
HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
13101310
return listTemplates(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true, cmd.isBootable(), cmd.getPageSizeVal(),
13111311
cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, true, cmd.listInReadyState(), permittedAccounts, caller,
1312-
listProjectResourcesCriteria, tags);
1312+
listProjectResourcesCriteria, tags, cmd.getZoneType());
13131313
}
13141314

13151315
@Override
@@ -1342,12 +1342,12 @@ public Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd) throws IllegalA
13421342
HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
13431343

13441344
return listTemplates(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, cmd.getPageSizeVal(), cmd.getStartIndex(),
1345-
cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags);
1345+
cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags, cmd.getZoneType());
13461346
}
13471347

13481348
private Set<Pair<Long, Long>> listTemplates(Long templateId, String name, String keyword, TemplateFilter templateFilter, boolean isIso,
13491349
Boolean bootable, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean showDomr, boolean onlyReady,
1350-
List<Account> permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
1350+
List<Account> permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags, String zoneType) {
13511351

13521352
VMTemplateVO template = null;
13531353
if (templateId != null) {
@@ -1388,7 +1388,7 @@ private Set<Pair<Long, Long>> listTemplates(Long templateId, String name, String
13881388
startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, tags);
13891389
Set<Pair<Long, Long>> templateZonePairSet2 = new HashSet<Pair<Long, Long>>();
13901390
templateZonePairSet2 = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize,
1391-
startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags);
1391+
startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags, zoneType);
13921392

13931393
for (Pair<Long, Long> tmpltPair : templateZonePairSet2) {
13941394
if (!templateZonePairSet.contains(new Pair<Long, Long>(tmpltPair.first(), -1L))) {
@@ -1412,7 +1412,7 @@ private Set<Pair<Long, Long>> listTemplates(Long templateId, String name, String
14121412
Set<Pair<Long, Long>> templateZonePairSet2 = new HashSet<Pair<Long, Long>>();
14131413
templateZonePairSet2 = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers,
14141414
bootable, domain, pageSize, startIndex, zoneId, hyperType, onlyReady, showDomr,
1415-
permittedAccounts, caller, listProjectResourcesCriteria, tags);
1415+
permittedAccounts, caller, listProjectResourcesCriteria, tags, zoneType);
14161416

14171417
for (Pair<Long, Long> tmpltPair : templateZonePairSet2) {
14181418
if (!templateZonePairSet.contains(new Pair<Long, Long>(tmpltPair.first(), -1L))) {
@@ -1430,7 +1430,7 @@ private Set<Pair<Long, Long>> listTemplates(Long templateId, String name, String
14301430
} else {
14311431
if (template == null) {
14321432
templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers, bootable, domain, pageSize,
1433-
startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags);
1433+
startIndex, zoneId, hyperType, onlyReady, showDomr, permittedAccounts, caller, listProjectResourcesCriteria, tags, zoneType);
14341434
} else {
14351435
// if template is not public, perform permission check here
14361436
if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {

server/src/com/cloud/storage/dao/VMTemplateDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
5656
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso,
5757
List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId,
5858
HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
59-
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags);
59+
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags, String zoneType);
6060

6161
public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter,
6262
boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,

server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, T
520520
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter,
521521
boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
522522
Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr,List<Account> permittedAccounts,
523-
Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
523+
Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags, String zoneType) {
524524
StringBuilder builder = new StringBuilder();
525525
if (!permittedAccounts.isEmpty()) {
526526
for (Account permittedAccount : permittedAccounts) {
@@ -561,7 +561,7 @@ public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, Templa
561561
sql = SELECT_TEMPLATE_HOST_REF;
562562
groupByClause = " GROUP BY t.id, h.data_center_id ";
563563
}
564-
if ((templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.community)) {
564+
if (((templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.community)) ||(zoneType != null && zoneId != null)) {
565565
dataCenterJoin = " INNER JOIN data_center dc on (h.data_center_id = dc.id)";
566566
}
567567

@@ -691,7 +691,7 @@ public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, Templa
691691
}
692692

693693
sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId,
694-
onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex);
694+
onlyReady, showDomr, zoneType) + groupByClause + getOrderByLimit(pageSize, startIndex);
695695

696696
pstmt = txn.prepareStatement(sql);
697697
rs = pstmt.executeQuery();
@@ -752,7 +752,7 @@ public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, Templa
752752
return templateZonePairList;
753753
}
754754

755-
private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr) {
755+
private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr, String zoneType) {
756756
String sql = "";
757757
if (keyword != null) {
758758
sql += " t.name LIKE \"%" + keyword + "%\" AND";
@@ -783,6 +783,9 @@ private String getExtrasWhere(TemplateFilter templateFilter, String name, String
783783
}
784784
}else if (zoneId != null){
785785
sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ;
786+
if (zoneType != null){
787+
sql += " AND dc.networktype = " + zoneType;
788+
}
786789
}else{
787790
sql += " AND tzr.removed is null ";
788791
}

0 commit comments

Comments
 (0)