mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
f73362ae48
commit
ff0cfc9148
|
|
@ -109,6 +109,9 @@ public class ListHostsCmd extends BaseListCmd {
|
|||
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, description = "CPU Arch of the host", since = "4.20.1")
|
||||
private String arch;
|
||||
|
||||
@Parameter(name = ApiConstants.VERSION, type = CommandType.STRING, description = "the host version", since = "4.20.3")
|
||||
private String version;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -197,6 +200,10 @@ public class ListHostsCmd extends BaseListCmd {
|
|||
return StringUtils.isBlank(arch) ? null : CPU.CPUArch.fromType(arch);
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ public class ListMgmtsCmd extends BaseListCmd {
|
|||
since = "4.20.1.0")
|
||||
private Boolean peers;
|
||||
|
||||
@Parameter(name = ApiConstants.VERSION, type = CommandType.STRING,
|
||||
description = "the version of the management server", since = "4.20.3")
|
||||
private String version;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -61,6 +65,10 @@ public class ListMgmtsCmd extends BaseListCmd {
|
|||
return BooleanUtils.toBooleanDefaultIfNull(peers, false);
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -2309,6 +2309,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||
Long pageSize = cmd.getPageSizeVal();
|
||||
Hypervisor.HypervisorType hypervisorType = cmd.getHypervisor();
|
||||
final CPU.CPUArch arch = cmd.getArch();
|
||||
String version = cmd.getVersion();
|
||||
|
||||
Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, startIndex, pageSize);
|
||||
|
||||
|
|
@ -2325,11 +2326,13 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||
hostSearchBuilder.and("resourceState", hostSearchBuilder.entity().getResourceState(), SearchCriteria.Op.EQ);
|
||||
hostSearchBuilder.and("hypervisor_type", hostSearchBuilder.entity().getHypervisorType(), SearchCriteria.Op.EQ);
|
||||
hostSearchBuilder.and("arch", hostSearchBuilder.entity().getArch(), SearchCriteria.Op.EQ);
|
||||
hostSearchBuilder.and("version", hostSearchBuilder.entity().getVersion(), SearchCriteria.Op.EQ);
|
||||
|
||||
if (keyword != null) {
|
||||
hostSearchBuilder.and().op("keywordName", hostSearchBuilder.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
hostSearchBuilder.or("keywordStatus", hostSearchBuilder.entity().getStatus(), SearchCriteria.Op.LIKE);
|
||||
hostSearchBuilder.or("keywordType", hostSearchBuilder.entity().getType(), SearchCriteria.Op.LIKE);
|
||||
hostSearchBuilder.or("keywordVersion", hostSearchBuilder.entity().getVersion(), SearchCriteria.Op.LIKE);
|
||||
hostSearchBuilder.cp();
|
||||
}
|
||||
|
||||
|
|
@ -2360,6 +2363,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||
sc.setParameters("keywordName", "%" + keyword + "%");
|
||||
sc.setParameters("keywordStatus", "%" + keyword + "%");
|
||||
sc.setParameters("keywordType", "%" + keyword + "%");
|
||||
sc.setParameters("keywordVersion", "%" + keyword + "%");
|
||||
}
|
||||
|
||||
if (id != null) {
|
||||
|
|
@ -2409,6 +2413,10 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||
sc.setParameters("arch", arch);
|
||||
}
|
||||
|
||||
if (version != null) {
|
||||
sc.setParameters("version", version);
|
||||
}
|
||||
|
||||
Pair<List<HostVO>, Integer> uniqueHostPair = hostDao.searchAndCount(sc, searchFilter);
|
||||
Integer count = uniqueHostPair.second();
|
||||
List<Long> hostIds = uniqueHostPair.first().stream().map(HostVO::getId).collect(Collectors.toList());
|
||||
|
|
@ -5397,6 +5405,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||
protected Pair<List<ManagementServerJoinVO>, Integer> listManagementServersInternal(ListMgmtsCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
String name = cmd.getHostName();
|
||||
String version = cmd.getVersion();
|
||||
String keyword = cmd.getKeyword();
|
||||
|
||||
SearchBuilder<ManagementServerJoinVO> sb = managementServerJoinDao.createSearchBuilder();
|
||||
SearchCriteria<ManagementServerJoinVO> sc = sb.create();
|
||||
|
|
@ -5406,6 +5416,12 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||
if (name != null) {
|
||||
sc.addAnd("name", SearchCriteria.Op.EQ, name);
|
||||
}
|
||||
if (version != null) {
|
||||
sc.addAnd("version", SearchCriteria.Op.EQ, version);
|
||||
}
|
||||
if (keyword != null) {
|
||||
sc.addAnd("version", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
}
|
||||
return managementServerJoinDao.searchAndCount(sc, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue