Skip to content

Commit de702eb

Browse files
committed
fix_filter_and_pagination
1 parent f0b757e commit de702eb

13 files changed

Lines changed: 66 additions & 28 deletions

File tree

api/src/main/java/com/cloud/server/ManagementService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,11 @@ public interface ManagementService {
449449
* this method removes the child storage pools and adds the corresponding parent datastore cluster for API response listing
450450
*
451451
* @param Long volumeId
452+
* @param String keyword if passed, will only return storage pools that contain this keyword in the name
452453
* @return Pair<List<? extends StoragePool>, List<? extends StoragePool>> List of storage pools in cluster and list
453454
* of pools with enough capacity.
454455
*/
455-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId);
456+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId, String keyword);
456457

457458
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForSystemMigrationOfVolume(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck);
458459

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ApiCommandResourceType getApiResourceType() {
6767

6868
@Override
6969
public void execute() {
70-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> pools = _mgr.listStoragePoolsForMigrationOfVolume(getId());
70+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> pools = _mgr.listStoragePoolsForMigrationOfVolume(getId(), getKeyword());
7171
ListResponse<StoragePoolResponse> response = new ListResponse<StoragePoolResponse>();
7272
List<StoragePoolResponse> poolResponses = new ArrayList<StoragePoolResponse>();
7373

@@ -87,7 +87,8 @@ public void execute() {
8787
poolResponses.add(poolResponse);
8888
}
8989
sortPoolsBySuitabilityAndName(poolResponses);
90-
response.setResponses(poolResponses);
90+
List<StoragePoolResponse> pagingList = com.cloud.utils.StringUtils.applyPagination(poolResponses, this.getStartIndex(), this.getPageSizeVal());
91+
response.setResponses(pagingList, poolResponses.size());
9192
response.setResponseName(getCommandName());
9293
this.setResponseObject(response);
9394
}

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ public interface StoragePoolAllocator extends Adapter {
5252
* avoid
5353
* @param int returnUpTo (use -1 to return all possible pools)
5454
* @param boolean bypassStorageTypeCheck allows bypassing useLocalStorage check for provided DiskProfile when true
55+
* @param String keyword if passed, will only return storage pools that contain this keyword in the name
5556
* @return List<StoragePool> List of storage pools that are suitable for the
5657
* VM
5758
**/
59+
List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword);
60+
5861
List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck);
5962

6063

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
3939
*/
4040
List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope);
4141

42+
List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope, String keyword);
43+
4244
/**
4345
* Set capacity of storage pool in bytes
4446
* @param id pool id.
@@ -114,15 +116,19 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
114116

115117
List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags);
116118

119+
List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags, String keyword);
120+
117121
List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags);
118122

119123
List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType);
120124

125+
List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType, String keyword);
126+
121127
List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags);
122128

123129
List<StoragePoolVO> listLocalStoragePoolByPath(long datacenterId, String path);
124130

125-
List<StoragePoolVO> findPoolsInClusters(List<Long> clusterIds);
131+
List<StoragePoolVO> findPoolsInClusters(List<Long> clusterIds, String keyword);
126132

127133
void deletePoolTags(long poolId);
128134

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ public List<StoragePoolVO> listLocalStoragePoolByPath(long datacenterId, String
243243

244244
@Override
245245
public List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope) {
246+
return listBy(datacenterId, podId, clusterId, scope, null);
247+
}
248+
249+
@Override
250+
public List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope, String keyword) {
246251
SearchCriteria<StoragePoolVO> sc = null;
247252
if (clusterId != null) {
248253
sc = DcPodSearch.create();
@@ -254,6 +259,9 @@ public List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId,
254259
sc.setParameters("datacenterId", datacenterId);
255260
sc.setParameters("podId", podId);
256261
sc.setParameters("status", Status.Up);
262+
if (keyword != null) {
263+
sc.addAnd("name", Op.LIKE, "%" + keyword + "%");
264+
}
257265
if (scope != null) {
258266
sc.setParameters("scope", scope);
259267
}
@@ -435,12 +443,16 @@ public List<StoragePoolVO> findDisabledPoolsByScope(long dcId, Long podId, Long
435443

436444
return storagePools;
437445
}
438-
439446
@Override
440447
public List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags) {
448+
return findLocalStoragePoolsByTags(dcId, podId, clusterId, tags, null);
449+
}
450+
451+
@Override
452+
public List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags, String keyword) {
441453
List<StoragePoolVO> storagePools = null;
442454
if (tags == null || tags.length == 0) {
443-
storagePools = listBy(dcId, podId, clusterId, ScopeType.HOST);
455+
storagePools = listBy(dcId, podId, clusterId, ScopeType.HOST, keyword);
444456
} else {
445457
String sqlValues = getSqlValuesFromStorageTags(tags);
446458
storagePools = findPoolsByDetailsOrTagsInternal(dcId, podId, clusterId, ScopeType.HOST, sqlValues, ValueType.TAGS, tags.length);
@@ -552,11 +564,19 @@ public List<StoragePoolVO> listPoolsByCluster(long clusterId) {
552564

553565
@Override
554566
public List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType) {
567+
return findZoneWideStoragePoolsByHypervisor(dataCenterId, hypervisorType, null);
568+
}
569+
570+
@Override
571+
public List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType, String keyword) {
555572
QueryBuilder<StoragePoolVO> sc = QueryBuilder.create(StoragePoolVO.class);
556573
sc.and(sc.entity().getDataCenterId(), Op.EQ, dataCenterId);
557574
sc.and(sc.entity().getStatus(), Op.EQ, Status.Up);
558575
sc.and(sc.entity().getScope(), Op.EQ, ScopeType.ZONE);
559576
sc.and(sc.entity().getHypervisor(), Op.EQ, hypervisorType);
577+
if (keyword != null) {
578+
sc.and(sc.entity().getName(), Op.LIKE, "%" + keyword + "%");
579+
}
560580
return sc.list();
561581
}
562582

@@ -581,10 +601,13 @@ public Integer countAll() {
581601
}
582602

583603
@Override
584-
public List<StoragePoolVO> findPoolsInClusters(List<Long> clusterIds) {
604+
public List<StoragePoolVO> findPoolsInClusters(List<Long> clusterIds, String keyword) {
585605
SearchCriteria<StoragePoolVO> sc = ClustersSearch.create();
586606
sc.setParameters("clusterIds", clusterIds.toArray());
587607
sc.setParameters("status", StoragePoolStatus.Up);
608+
if (keyword != null) {
609+
sc.addAnd("name", Op.LIKE, "%" + keyword + "%");
610+
}
588611
return listBy(sc);
589612
}
590613

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,20 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
102102
return false;
103103
}
104104

105-
protected abstract List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck);
105+
protected abstract List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword);
106106

107107
@Override
108108
public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
109-
return allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo, false);
109+
return allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo, false, null);
110110
}
111111

112112
@Override
113113
public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
114-
List<StoragePool> pools = select(dskCh, vmProfile, plan, avoid, returnUpTo, bypassStorageTypeCheck);
114+
return allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo, bypassStorageTypeCheck, null);
115+
}
116+
117+
public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) {
118+
List<StoragePool> pools = select(dskCh, vmProfile, plan, avoid, returnUpTo, bypassStorageTypeCheck, keyword);
115119
return reorderPools(pools, vmProfile, plan, dskCh);
116120
}
117121

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat
4545
DiskOfferingDao _diskOfferingDao;
4646

4747
@Override
48-
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
48+
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) {
4949
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
5050

5151
if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) {

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl
4747
boolean _storagePoolCleanupEnabled;
4848

4949
@Override
50-
public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
50+
public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) {
5151
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
5252
if (!_storagePoolCleanupEnabled) {
5353
s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped.");

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator {
6060
ConfigurationDao _configDao;
6161

6262
@Override
63-
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
63+
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) {
6464
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
6565

6666
if (!bypassStorageTypeCheck && !dskCh.useLocalStorage()) {
@@ -101,7 +101,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
101101
return null;
102102
}
103103
List<StoragePoolVO> availablePools =
104-
storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags());
104+
storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags(), keyword);
105105
for (StoragePoolVO pool : availablePools) {
106106
if (suitablePools.size() == returnUpTo) {
107107
break;

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator {
5050
private CapacityDao capacityDao;
5151

5252
@Override
53-
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
53+
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) {
5454
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
5555

5656
if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) {

0 commit comments

Comments
 (0)