Fix VGPU available devices listing (#9573)

* Fix VGPU available devices listing

* Missing space

* Refactor
This commit is contained in:
Nicolas Vazquez 2024-09-02 21:04:06 -03:00 committed by GitHub
parent 0204cb75e3
commit abaf4b52ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import javax.persistence.Column;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.ReflectUtil; import com.cloud.utils.ReflectUtil;
import org.apache.commons.lang3.StringUtils;
/** /**
* Try to use static initialization to help you in finding incorrect * Try to use static initialization to help you in finding incorrect
@ -59,6 +60,11 @@ public class Filter {
_orderBy = " ORDER BY RAND() LIMIT " + limit; _orderBy = " ORDER BY RAND() LIMIT " + limit;
} }
public Filter(Long offset, Long limit) {
_offset = offset;
_limit = limit;
}
/** /**
* Note that this copy constructor does not copy offset and limit. * Note that this copy constructor does not copy offset and limit.
* @param that filter * @param that filter
@ -70,6 +76,10 @@ public class Filter {
} }
public void addOrderBy(Class<?> clazz, String field, boolean ascending) { public void addOrderBy(Class<?> clazz, String field, boolean ascending) {
addOrderBy(clazz, field, ascending, null);
}
public void addOrderBy(Class<?> clazz, String field, boolean ascending, String tableAlias) {
if (field == null) { if (field == null) {
return; return;
} }
@ -83,7 +93,9 @@ public class Filter {
String name = column != null ? column.name() : field; String name = column != null ? column.name() : field;
StringBuilder order = new StringBuilder(); StringBuilder order = new StringBuilder();
if (column == null || column.table() == null || column.table().length() == 0) { if (StringUtils.isNotBlank(tableAlias)) {
order.append(tableAlias);
} else if (column == null || column.table() == null || column.table().length() == 0) {
order.append(DbUtil.getTableName(clazz)); order.append(DbUtil.getTableName(clazz));
} else { } else {
order.append(column.table()); order.append(column.table());

View File

@ -3417,7 +3417,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@Override @Override
public List<HostGpuGroupsVO> listAvailableGPUDevice(final long hostId, final String groupName, final String vgpuType) { public List<HostGpuGroupsVO> listAvailableGPUDevice(final long hostId, final String groupName, final String vgpuType) {
final Filter searchFilter = new Filter(VGPUTypesVO.class, "remainingCapacity", false, null, null); Filter searchFilter = new Filter(null, null);
searchFilter.addOrderBy(VGPUTypesVO.class, "remainingCapacity", false, "groupId");
final SearchCriteria<HostGpuGroupsVO> sc = _gpuAvailability.create(); final SearchCriteria<HostGpuGroupsVO> sc = _gpuAvailability.create();
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
sc.setParameters("groupName", groupName); sc.setParameters("groupName", groupName);