From 92a6bc27ff862be72de7f96a2e836d6bb66a353c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Aur=C3=A8le=20Brothier?= Date: Sun, 7 Jan 2018 11:13:27 +0100 Subject: [PATCH] CLOUDSTACK-9896: listDedicatedXXX should respect pagination (#2073) Fixes listDedicatedxxx APIs to respect pagination options. --- .../DedicatedResourceManagerImpl.java | 22 ++++++++++++++----- .../cloud/dc/dao/DedicatedResourceDao.java | 9 ++++---- .../dc/dao/DedicatedResourceDaoImpl.java | 17 +++++++------- .../deploy/DeploymentPlanningManagerImpl.java | 13 ++++++----- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java b/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java index e7a6f35dce2..7cf193d49be 100644 --- a/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java +++ b/plugins/dedicated-resources/src/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java @@ -73,6 +73,7 @@ import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.Transaction; import com.cloud.utils.db.TransactionCallback; import com.cloud.utils.db.TransactionCallbackNoReturn; @@ -816,6 +817,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService { String accountName = cmd.getAccountName(); Long accountId = null; Long affinityGroupId = cmd.getAffinityGroupId(); + Long startIndex = cmd.getStartIndex(); + Long pageSize = cmd.getPageSizeVal(); if (accountName != 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); } } - Pair, Integer> result = _dedicatedDao.searchDedicatedZones(zoneId, domainId, accountId, affinityGroupId); + Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); + Pair, Integer> result = _dedicatedDao.searchDedicatedZones(zoneId, domainId, accountId, affinityGroupId, searchFilter); return new Pair, Integer>(result.first(), result.second()); } @@ -838,6 +842,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService { String accountName = cmd.getAccountName(); Long accountId = null; Long affinityGroupId = cmd.getAffinityGroupId(); + Long startIndex = cmd.getStartIndex(); + Long pageSize = cmd.getPageSizeVal(); if (accountName != 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); } } - Pair, Integer> result = _dedicatedDao.searchDedicatedPods(podId, domainId, accountId, affinityGroupId); + Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); + Pair, Integer> result = _dedicatedDao.searchDedicatedPods(podId, domainId, accountId, affinityGroupId, searchFilter); return new Pair, Integer>(result.first(), result.second()); } @@ -860,6 +867,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService { String accountName = cmd.getAccountName(); Long accountId = null; Long affinityGroupId = cmd.getAffinityGroupId(); + Long startIndex = cmd.getStartIndex(); + Long pageSize = cmd.getPageSizeVal(); if (accountName != 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); } } - Pair, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId); + Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); + Pair, Integer> result = _dedicatedDao.searchDedicatedClusters(clusterId, domainId, accountId, affinityGroupId, searchFilter); return new Pair, Integer>(result.first(), result.second()); } @@ -881,6 +891,8 @@ public class DedicatedResourceManagerImpl implements DedicatedService { Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); Long affinityGroupId = cmd.getAffinityGroupId(); + Long startIndex = cmd.getStartIndex(); + Long pageSize = cmd.getPageSizeVal(); Long accountId = 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); } } - - Pair, Integer> result = _dedicatedDao.searchDedicatedHosts(hostId, domainId, accountId, affinityGroupId); + Filter searchFilter = new Filter(DedicatedResourceVO.class, "id", true, startIndex, pageSize); + Pair, Integer> result = _dedicatedDao.searchDedicatedHosts(hostId, domainId, accountId, affinityGroupId, searchFilter); return new Pair, Integer>(result.first(), result.second()); } diff --git a/server/src/com/cloud/dc/dao/DedicatedResourceDao.java b/server/src/com/cloud/dc/dao/DedicatedResourceDao.java index 0876d462bb1..7c41439b1ec 100644 --- a/server/src/com/cloud/dc/dao/DedicatedResourceDao.java +++ b/server/src/com/cloud/dc/dao/DedicatedResourceDao.java @@ -20,6 +20,7 @@ import java.util.List; import com.cloud.dc.DedicatedResourceVO; import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDao; public interface DedicatedResourceDao extends GenericDao { @@ -32,13 +33,13 @@ public interface DedicatedResourceDao extends GenericDao, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId); + Pair, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId, Filter filter); - Pair, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId); + Pair, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter); - Pair, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId); + Pair, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId, Filter filter); - Pair, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId); + Pair, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter); List listByAccountId(Long accountId); diff --git a/server/src/com/cloud/dc/dao/DedicatedResourceDaoImpl.java b/server/src/com/cloud/dc/dao/DedicatedResourceDaoImpl.java index 8f51783c8b0..c406755f994 100644 --- a/server/src/com/cloud/dc/dao/DedicatedResourceDaoImpl.java +++ b/server/src/com/cloud/dc/dao/DedicatedResourceDaoImpl.java @@ -19,6 +19,7 @@ package com.cloud.dc.dao; import java.util.List; +import com.cloud.utils.db.Filter; import org.springframework.stereotype.Component; import com.cloud.dc.DedicatedResourceVO; @@ -231,7 +232,7 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId) { + public Pair, Integer> searchDedicatedZones(Long dataCenterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) { SearchCriteria sc = ListAllZonesSearch.create(); if (dataCenterId != null) { sc.setParameters("zoneId", dataCenterId); @@ -247,11 +248,11 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId) { + public Pair, Integer> searchDedicatedPods(Long podId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) { SearchCriteria sc = ListAllPodsSearch.create(); if (podId != null) { sc.setParameters("podId", podId); @@ -267,11 +268,11 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId) { + public Pair, Integer> searchDedicatedClusters(Long clusterId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) { SearchCriteria sc = ListAllClustersSearch.create(); if (clusterId != null) { sc.setParameters("clusterId", clusterId); @@ -288,11 +289,11 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId) { + public Pair, Integer> searchDedicatedHosts(Long hostId, Long domainId, Long accountId, Long affinityGroupId, Filter filter) { SearchCriteria sc = ListAllHostsSearch.create(); if (hostId != null) { sc.setParameters("hostId", hostId); @@ -308,7 +309,7 @@ public class DedicatedResourceDaoImpl extends GenericDaoBase { if (domainGroupMappings == null || domainGroupMappings.isEmpty()) { //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) { allPodsFromDedicatedID.add(vo.getPodId()); } 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) { allClustersFromDedicatedID.add(vo.getClusterId()); } 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) { allHostsFromDedicatedID.add(vo.getHostId()); @@ -667,21 +668,21 @@ StateListener { else { //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) { allPodsFromDedicatedID.add(vo.getPodId()); } 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) { allClustersFromDedicatedID.add(vo.getClusterId()); } 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) { allHostsFromDedicatedID.add(vo.getHostId());