Skip to content

Commit af607b9

Browse files
committed
Merge branch '4.19'
2 parents 8c301b1 + abaf4b5 commit af607b9

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
@@ -3400,7 +3400,8 @@ public boolean isHostGpuEnabled(final long hostId) {
34003400

34013401
@Override
34023402
public List<HostGpuGroupsVO> listAvailableGPUDevice(final long hostId, final String groupName, final String vgpuType) {
3403-
final Filter searchFilter = new Filter(VGPUTypesVO.class, "remainingCapacity", false, null, null);
3403+
Filter searchFilter = new Filter(null, null);
3404+
searchFilter.addOrderBy(VGPUTypesVO.class, "remainingCapacity", false, "groupId");
34043405
final SearchCriteria<HostGpuGroupsVO> sc = _gpuAvailability.create();
34053406
sc.setParameters("hostId", hostId);
34063407
sc.setParameters("groupName", groupName);

0 commit comments

Comments
 (0)