CLOUDSTACK-9896: listDedicatedXXX should respect pagination (#2073)

Fixes listDedicatedxxx APIs to respect pagination options.
This commit is contained in:
Marc-Aurèle Brothier 2018-01-07 11:13:27 +01:00 committed by Rohit Yadav
parent 1ade09575e
commit 92a6bc27ff
4 changed files with 38 additions and 23 deletions

View File

@ -73,6 +73,7 @@ import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallback; import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionCallbackNoReturn; import com.cloud.utils.db.TransactionCallbackNoReturn;
@ -816,6 +817,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
String accountName = cmd.getAccountName(); String accountName = cmd.getAccountName();
Long accountId = null; Long accountId = null;
Long affinityGroupId = cmd.getAffinityGroupId(); Long affinityGroupId = cmd.getAffinityGroupId();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
if (accountName != null) { if (accountName != null) {
if (domainId != null) { if (domainId != null) {
@ -827,7 +830,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
} }
} }
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedZones(zoneId, domainId, accountId, affinityGroupId); Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize);
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedZones(zoneId, domainId, accountId, affinityGroupId, searchFilter);
return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second());
} }
@ -838,6 +842,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
String accountName = cmd.getAccountName(); String accountName = cmd.getAccountName();
Long accountId = null; Long accountId = null;
Long affinityGroupId = cmd.getAffinityGroupId(); Long affinityGroupId = cmd.getAffinityGroupId();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
if (accountName != null) { if (accountName != null) {
if (domainId != null) { if (domainId != null) {
@ -849,7 +855,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
} }
} }
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedPods(podId, domainId, accountId, affinityGroupId); Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize);
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedPods(podId, domainId, accountId, affinityGroupId, searchFilter);
return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second());
} }
@ -860,6 +867,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
String accountName = cmd.getAccountName(); String accountName = cmd.getAccountName();
Long accountId = null; Long accountId = null;
Long affinityGroupId = cmd.getAffinityGroupId(); Long affinityGroupId = cmd.getAffinityGroupId();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
if (accountName != null) { if (accountName != null) {
if (domainId != null) { if (domainId != null) {
@ -871,7 +880,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
} }
} }
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId); Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize);
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId, searchFilter);
return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second());
} }
@ -881,6 +891,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
Long domainId = cmd.getDomainId(); Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName(); String accountName = cmd.getAccountName();
Long affinityGroupId = cmd.getAffinityGroupId(); Long affinityGroupId = cmd.getAffinityGroupId();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
Long accountId = null; Long accountId = null;
if (accountName != null) { if (accountName != null) {
@ -893,8 +905,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName); throw new InvalidParameterValueException("Please specify the domain id of the account: " + accountName);
} }
} }
Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize);
Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedHosts(hostId, domainId, accountId, affinityGroupId); Pair<List<DedicatedResourceVO>, Integer> result = _dedicatedDao.searchDedicatedHosts(hostId, domainId, accountId, affinityGroupId, searchFilter);
return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second()); return new Pair<List<? extends DedicatedResourceVO>, Integer>(result.first(), result.second());
} }

View File

@ -20,6 +20,7 @@ import java.util.List;
import com.cloud.dc.DedicatedResourceVO; import com.cloud.dc.DedicatedResourceVO;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
public interface DedicatedResourceDao extends GenericDao<DedicatedResourceVO, Long> { public interface DedicatedResourceDao extends GenericDao<DedicatedResourceVO, Long> {
@ -32,13 +33,13 @@ public interface DedicatedResourceDao extends GenericDao<DedicatedResourceVO, Lo
DedicatedResourceVO findByHostId(Long hostId); DedicatedResourceVO findByHostId(Long hostId);
Pair<List<DedicatedResourceVO>, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId); Pair<List<DedicatedResourceVO>, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId, Filter filter);
Pair<List<DedicatedResourceVO>, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId); Pair<List<DedicatedResourceVO>, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter);
Pair<List<DedicatedResourceVO>, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId); Pair<List<DedicatedResourceVO>, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId, Filter filter);
Pair<List<DedicatedResourceVO>, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId); Pair<List<DedicatedResourceVO>, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter);
List<DedicatedResourceVO> listByAccountId(Long accountId); List<DedicatedResourceVO> listByAccountId(Long accountId);

View File

@ -19,6 +19,7 @@ package com.cloud.dc.dao;
import java.util.List; import java.util.List;
import com.cloud.utils.db.Filter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.cloud.dc.DedicatedResourceVO; import com.cloud.dc.DedicatedResourceVO;
@ -231,7 +232,7 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase<DedicatedResourceVO
} }
@Override @Override
public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId) { public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) {
SearchCriteria<DedicatedResourceVO> sc = ListAllZonesSearch.create(); SearchCriteria<DedicatedResourceVO> sc = ListAllZonesSearch.create();
if (dataCenterId != null) { if (dataCenterId != null) {
sc.setParameters("zoneId", dataCenterId); sc.setParameters("zoneId", dataCenterId);
@ -247,11 +248,11 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase<DedicatedResourceVO
sc.setParameters("accountId", (Object)null); sc.setParameters("accountId", (Object)null);
} }
} }
return searchAndCount(sc, null); return searchAndCount(sc, filter);
} }
@Override @Override
public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId) { public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) {
SearchCriteria<DedicatedResourceVO> sc = ListAllPodsSearch.create(); SearchCriteria<DedicatedResourceVO> sc = ListAllPodsSearch.create();
if (podId != null) { if (podId != null) {
sc.setParameters("podId", podId); sc.setParameters("podId", podId);
@ -267,11 +268,11 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase<DedicatedResourceVO
sc.setParameters("accountId", (Object)null); sc.setParameters("accountId", (Object)null);
} }
} }
return searchAndCount(sc, null); return searchAndCount(sc, filter);
} }
@Override @Override
public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId) { public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) {
SearchCriteria<DedicatedResourceVO> sc = ListAllClustersSearch.create(); SearchCriteria<DedicatedResourceVO> sc = ListAllClustersSearch.create();
if (clusterId != null) { if (clusterId != null) {
sc.setParameters("clusterId", clusterId); sc.setParameters("clusterId", clusterId);
@ -288,11 +289,11 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase<DedicatedResourceVO
sc.setParameters("accountId", (Object)null); sc.setParameters("accountId", (Object)null);
} }
} }
return searchAndCount(sc, null); return searchAndCount(sc, filter);
} }
@Override @Override
public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId) { public Pair<List<DedicatedResourceVO>, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) {
SearchCriteria<DedicatedResourceVO> sc = ListAllHostsSearch.create(); SearchCriteria<DedicatedResourceVO> sc = ListAllHostsSearch.create();
if (hostId != null) { if (hostId != null) {
sc.setParameters("hostId", hostId); sc.setParameters("hostId", hostId);
@ -308,7 +309,7 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase<DedicatedResourceVO
sc.setParameters("accountId", (Object)null); sc.setParameters("accountId", (Object)null);
} }
} }
return searchAndCount(sc, null); return searchAndCount(sc, filter);
} }
@Override @Override

View File

@ -30,6 +30,7 @@ import java.util.TreeSet;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import com.cloud.utils.db.Filter;
import com.cloud.utils.fsm.StateMachine2; import com.cloud.utils.fsm.StateMachine2;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -639,21 +640,21 @@ StateListener<State, VirtualMachine.Event, VirtualMachine> {
if (domainGroupMappings == null || domainGroupMappings.isEmpty()) { if (domainGroupMappings == null || domainGroupMappings.isEmpty()) {
//The dedicated resource belongs to VM Account ID. //The dedicated resource belongs to VM Account ID.
tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, vmAccountId, null).first(); tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, vmAccountId, null, new Filter(DedicatedResourceVO.class, "id", true, 0L, 1L)).first();
for(DedicatedResourceVO vo : tempStorage) { for(DedicatedResourceVO vo : tempStorage) {
allPodsFromDedicatedID.add(vo.getPodId()); allPodsFromDedicatedID.add(vo.getPodId());
} }
tempStorage.clear(); tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, vmAccountId, null).first(); tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, vmAccountId, null, new Filter(DedicatedResourceVO.class, "id", true, 0L, 1L)).first();
for(DedicatedResourceVO vo : tempStorage) { for(DedicatedResourceVO vo : tempStorage) {
allClustersFromDedicatedID.add(vo.getClusterId()); allClustersFromDedicatedID.add(vo.getClusterId());
} }
tempStorage.clear(); tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, vmAccountId, null).first(); tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, vmAccountId, null, new Filter(DedicatedResourceVO.class, "id", true, 0L, 1L)).first();
for(DedicatedResourceVO vo : tempStorage) { for(DedicatedResourceVO vo : tempStorage) {
allHostsFromDedicatedID.add(vo.getHostId()); allHostsFromDedicatedID.add(vo.getHostId());
@ -667,21 +668,21 @@ StateListener<State, VirtualMachine.Event, VirtualMachine> {
else { else {
//The dedicated resource belongs to VM Domain ID or No dedication. //The dedicated resource belongs to VM Domain ID or No dedication.
tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, null, null).first(); tempStorage = _dedicatedDao.searchDedicatedPods(null, vmDomainId, null, null, new Filter(DedicatedResourceVO.class, "id", true, 0L, 1L)).first();
for(DedicatedResourceVO vo : tempStorage) { for(DedicatedResourceVO vo : tempStorage) {
allPodsFromDedicatedID.add(vo.getPodId()); allPodsFromDedicatedID.add(vo.getPodId());
} }
tempStorage.clear(); tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, null, null).first(); tempStorage = _dedicatedDao.searchDedicatedClusters(null, vmDomainId, null, null, new Filter(DedicatedResourceVO.class, "id", true, 0L, 1L)).first();
for(DedicatedResourceVO vo : tempStorage) { for(DedicatedResourceVO vo : tempStorage) {
allClustersFromDedicatedID.add(vo.getClusterId()); allClustersFromDedicatedID.add(vo.getClusterId());
} }
tempStorage.clear(); tempStorage.clear();
tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, null, null).first(); tempStorage = _dedicatedDao.searchDedicatedHosts(null, vmDomainId, null, null, new Filter(DedicatedResourceVO.class, "id", true, 0L, 1L)).first();
for(DedicatedResourceVO vo : tempStorage) { for(DedicatedResourceVO vo : tempStorage) {
allHostsFromDedicatedID.add(vo.getHostId()); allHostsFromDedicatedID.add(vo.getHostId());