Skip to content

Commit ff0cfc9

Browse files
authored
Add ability to filter by version for listHosts and listMgmtServers APIs (#12472)
* Add ability to filter by version for listHosts and listMgmtServers APIs * Address review comment * Fix listMgmtServers API
1 parent f73362a commit ff0cfc9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public class ListHostsCmd extends BaseListCmd {
109109
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, description = "CPU Arch of the host", since = "4.20.1")
110110
private String arch;
111111

112+
@Parameter(name = ApiConstants.VERSION, type = CommandType.STRING, description = "the host version", since = "4.20.3")
113+
private String version;
114+
112115
/////////////////////////////////////////////////////
113116
/////////////////// Accessors ///////////////////////
114117
/////////////////////////////////////////////////////
@@ -197,6 +200,10 @@ public CPU.CPUArch getArch() {
197200
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
198201
}
199202

203+
public String getVersion() {
204+
return version;
205+
}
206+
200207
/////////////////////////////////////////////////////
201208
/////////////// API Implementation///////////////////
202209
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public class ListMgmtsCmd extends BaseListCmd {
4545
since = "4.20.1.0")
4646
private Boolean peers;
4747

48+
@Parameter(name = ApiConstants.VERSION, type = CommandType.STRING,
49+
description = "the version of the management server", since = "4.20.3")
50+
private String version;
51+
4852
/////////////////////////////////////////////////////
4953
/////////////////// Accessors ///////////////////////
5054
/////////////////////////////////////////////////////
@@ -61,6 +65,10 @@ public Boolean getPeers() {
6165
return BooleanUtils.toBooleanDefaultIfNull(peers, false);
6266
}
6367

68+
public String getVersion() {
69+
return version;
70+
}
71+
6472
/////////////////////////////////////////////////////
6573
/////////////// API Implementation///////////////////
6674
/////////////////////////////////////////////////////

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,7 @@ public Pair<List<Long>, Integer> searchForServerIdsAndCount(ListHostsCmd cmd) {
23092309
Long pageSize = cmd.getPageSizeVal();
23102310
Hypervisor.HypervisorType hypervisorType = cmd.getHypervisor();
23112311
final CPU.CPUArch arch = cmd.getArch();
2312+
String version = cmd.getVersion();
23122313

23132314
Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, startIndex, pageSize);
23142315

@@ -2325,11 +2326,13 @@ public Pair<List<Long>, Integer> searchForServerIdsAndCount(ListHostsCmd cmd) {
23252326
hostSearchBuilder.and("resourceState", hostSearchBuilder.entity().getResourceState(), SearchCriteria.Op.EQ);
23262327
hostSearchBuilder.and("hypervisor_type", hostSearchBuilder.entity().getHypervisorType(), SearchCriteria.Op.EQ);
23272328
hostSearchBuilder.and("arch", hostSearchBuilder.entity().getArch(), SearchCriteria.Op.EQ);
2329+
hostSearchBuilder.and("version", hostSearchBuilder.entity().getVersion(), SearchCriteria.Op.EQ);
23282330

23292331
if (keyword != null) {
23302332
hostSearchBuilder.and().op("keywordName", hostSearchBuilder.entity().getName(), SearchCriteria.Op.LIKE);
23312333
hostSearchBuilder.or("keywordStatus", hostSearchBuilder.entity().getStatus(), SearchCriteria.Op.LIKE);
23322334
hostSearchBuilder.or("keywordType", hostSearchBuilder.entity().getType(), SearchCriteria.Op.LIKE);
2335+
hostSearchBuilder.or("keywordVersion", hostSearchBuilder.entity().getVersion(), SearchCriteria.Op.LIKE);
23332336
hostSearchBuilder.cp();
23342337
}
23352338

@@ -2360,6 +2363,7 @@ public Pair<List<Long>, Integer> searchForServerIdsAndCount(ListHostsCmd cmd) {
23602363
sc.setParameters("keywordName", "%" + keyword + "%");
23612364
sc.setParameters("keywordStatus", "%" + keyword + "%");
23622365
sc.setParameters("keywordType", "%" + keyword + "%");
2366+
sc.setParameters("keywordVersion", "%" + keyword + "%");
23632367
}
23642368

23652369
if (id != null) {
@@ -2409,6 +2413,10 @@ public Pair<List<Long>, Integer> searchForServerIdsAndCount(ListHostsCmd cmd) {
24092413
sc.setParameters("arch", arch);
24102414
}
24112415

2416+
if (version != null) {
2417+
sc.setParameters("version", version);
2418+
}
2419+
24122420
Pair<List<HostVO>, Integer> uniqueHostPair = hostDao.searchAndCount(sc, searchFilter);
24132421
Integer count = uniqueHostPair.second();
24142422
List<Long> hostIds = uniqueHostPair.first().stream().map(HostVO::getId).collect(Collectors.toList());
@@ -5397,6 +5405,8 @@ public ListResponse<ManagementServerResponse> listManagementServers(ListMgmtsCmd
53975405
protected Pair<List<ManagementServerJoinVO>, Integer> listManagementServersInternal(ListMgmtsCmd cmd) {
53985406
Long id = cmd.getId();
53995407
String name = cmd.getHostName();
5408+
String version = cmd.getVersion();
5409+
String keyword = cmd.getKeyword();
54005410

54015411
SearchBuilder<ManagementServerJoinVO> sb = managementServerJoinDao.createSearchBuilder();
54025412
SearchCriteria<ManagementServerJoinVO> sc = sb.create();
@@ -5406,6 +5416,12 @@ protected Pair<List<ManagementServerJoinVO>, Integer> listManagementServersInter
54065416
if (name != null) {
54075417
sc.addAnd("name", SearchCriteria.Op.EQ, name);
54085418
}
5419+
if (version != null) {
5420+
sc.addAnd("version", SearchCriteria.Op.EQ, version);
5421+
}
5422+
if (keyword != null) {
5423+
sc.addAnd("version", SearchCriteria.Op.LIKE, "%" + keyword + "%");
5424+
}
54095425
return managementServerJoinDao.searchAndCount(sc, null);
54105426
}
54115427

0 commit comments

Comments
 (0)