Skip to content

Commit 271f875

Browse files
author
Jessica Wang
committed
CLOUDSTACK-2120: mixed zone management - API: extend listPods API to to take in zonetype.
1 parent 2ec28ce commit 271f875

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class ListPodsByCmd extends BaseListCmd {
5555
@Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="list pods by allocation state")
5656
private String allocationState;
5757

58+
@Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to")
59+
private String zoneType;
60+
5861
@Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the pods")
5962
private Boolean showCapacities;
6063

@@ -78,6 +81,10 @@ public String getAllocationState() {
7881
return allocationState;
7982
}
8083

84+
public String getZoneType() {
85+
return zoneType;
86+
}
87+
8188
public Boolean getShowCapacities() {
8289
return showCapacities;
8390
}

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,17 +1068,29 @@ private Pair<List<HostVO>, Integer> searchForServers(Long startIndex, Long pageS
10681068

10691069
@Override
10701070
public Pair<List<? extends Pod>, Integer> searchForPods(ListPodsByCmd cmd) {
1071-
Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal());
1072-
SearchCriteria<HostPodVO> sc = _hostPodDao.createSearchCriteria();
1073-
10741071
String podName = cmd.getPodName();
10751072
Long id = cmd.getId();
1076-
Long zoneId = cmd.getZoneId();
1073+
Long zoneId = cmd.getZoneId();
10771074
Object keyword = cmd.getKeyword();
10781075
Object allocationState = cmd.getAllocationState();
1079-
1076+
String zoneType = cmd.getZoneType();
10801077
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
10811078

1079+
1080+
Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal());
1081+
SearchBuilder<HostPodVO> sb = _hostPodDao.createSearchBuilder();
1082+
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
1083+
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
1084+
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
1085+
sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
1086+
1087+
if(zoneType != null) {
1088+
SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
1089+
zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
1090+
sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
1091+
}
1092+
1093+
SearchCriteria<HostPodVO> sc = sb.create();
10821094
if (keyword != null) {
10831095
SearchCriteria<HostPodVO> ssc = _hostPodDao.createSearchCriteria();
10841096
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@@ -1088,21 +1100,25 @@ public Pair<List<? extends Pod>, Integer> searchForPods(ListPodsByCmd cmd) {
10881100
}
10891101

10901102
if (id != null) {
1091-
sc.addAnd("id", SearchCriteria.Op.EQ, id);
1103+
sc.setParameters("id", id);
10921104
}
1093-
1105+
10941106
if (podName != null) {
1095-
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + podName + "%");
1107+
sc.setParameters("name", "%" + podName + "%");
10961108
}
1097-
1109+
10981110
if (zoneId != null) {
1099-
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
1111+
sc.setParameters("dataCenterId", zoneId);
11001112
}
1101-
1113+
11021114
if (allocationState != null) {
1103-
sc.addAnd("allocationState", SearchCriteria.Op.EQ, allocationState);
1115+
sc.setParameters("allocationState", allocationState);
1116+
}
1117+
1118+
if(zoneType != null) {
1119+
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
11041120
}
1105-
1121+
11061122
Pair<List<HostPodVO>, Integer> result = _hostPodDao.searchAndCount(sc, searchFilter);
11071123
return new Pair<List<? extends Pod>, Integer>(result.first(), result.second());
11081124
}

0 commit comments

Comments
 (0)