Skip to content

Commit abaf4b5

Browse files
authored
Fix VGPU available devices listing (#9573)
* Fix VGPU available devices listing * Missing space * Refactor
1 parent 0204cb7 commit abaf4b5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

framework/db/src/main/java/com/cloud/utils/db/Filter.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.cloud.utils.Pair;
2424
import com.cloud.utils.ReflectUtil;
25+
import org.apache.commons.lang3.StringUtils;
2526

2627
/**
2728
* Try to use static initialization to help you in finding incorrect
@@ -59,6 +60,11 @@ public Filter(long limit) {
5960
_orderBy = " ORDER BY RAND() LIMIT " + limit;
6061
}
6162

63+
public Filter(Long offset, Long limit) {
64+
_offset = offset;
65+
_limit = limit;
66+
}
67+
6268
/**
6369
* Note that this copy constructor does not copy offset and limit.
6470
* @param that filter
@@ -70,6 +76,10 @@ public Filter(Filter that) {
7076
}
7177

7278
public void addOrderBy(Class<?> clazz, String field, boolean ascending) {
79+
addOrderBy(clazz, field, ascending, null);
80+
}
81+
82+
public void addOrderBy(Class<?> clazz, String field, boolean ascending, String tableAlias) {
7383
if (field == null) {
7484
return;
7585
}
@@ -83,7 +93,9 @@ public void addOrderBy(Class<?> clazz, String field, boolean ascending) {
8393
String name = column != null ? column.name() : field;
8494

8595
StringBuilder order = new StringBuilder();
86-
if (column == null || column.table() == null || column.table().length() == 0) {
96+
if (StringUtils.isNotBlank(tableAlias)) {
97+
order.append(tableAlias);
98+
} else if (column == null || column.table() == null || column.table().length() == 0) {
8799
order.append(DbUtil.getTableName(clazz));
88100
} else {
89101
order.append(column.table());

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3417,7 +3417,8 @@ public boolean isHostGpuEnabled(final long hostId) {
34173417

34183418
@Override
34193419
public List<HostGpuGroupsVO> listAvailableGPUDevice(final long hostId, final String groupName, final String vgpuType) {
3420-
final Filter searchFilter = new Filter(VGPUTypesVO.class, "remainingCapacity", false, null, null);
3420+
Filter searchFilter = new Filter(null, null);
3421+
searchFilter.addOrderBy(VGPUTypesVO.class, "remainingCapacity", false, "groupId");
34213422
final SearchCriteria<HostGpuGroupsVO> sc = _gpuAvailability.create();
34223423
sc.setParameters("hostId", hostId);
34233424
sc.setParameters("groupName", groupName);

0 commit comments

Comments
 (0)