Skip to content

Commit 79eae89

Browse files
vishesh92shwstppryadvr
authored
ui: Add filtering by state in account, systemvms, router and storagepool (#7368)
This PR allows admin to filter resources by state for systemvms, router & storagepool. This is part of #7366 . Co-authored-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Co-authored-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent fcbcddb commit 79eae89

13 files changed

Lines changed: 181 additions & 86 deletions

File tree

api/src/main/java/com/cloud/storage/ScopeType.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
*/
1919
package com.cloud.storage;
2020

21+
import com.cloud.exception.InvalidParameterValueException;
22+
import org.apache.commons.lang3.EnumUtils;
23+
2124
public enum ScopeType {
2225
HOST, CLUSTER, ZONE, REGION, GLOBAL;
26+
27+
public static ScopeType validateAndGetScopeType(String value) {
28+
if (value == null) {
29+
return null;
30+
} else {
31+
ScopeType scopeType = EnumUtils.getEnumIgnoreCase(ScopeType.class, value);
32+
if (scopeType == null) {
33+
throw new InvalidParameterValueException("Invalid scope type: " + value);
34+
}
35+
return scopeType;
36+
}
37+
}
2338
}

api/src/main/java/com/cloud/storage/StoragePoolStatus.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19+
import com.cloud.exception.InvalidParameterValueException;
20+
import org.apache.commons.lang3.EnumUtils;
21+
1922
public enum StoragePoolStatus {
2023
Initial, Initialized, Creating, Attaching, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Disabled, Removed;
24+
25+
public static StoragePoolStatus validateAndGetStatus(String value) {
26+
if (value == null) {
27+
return null;
28+
} else {
29+
StoragePoolStatus status = EnumUtils.getEnumIgnoreCase(StoragePoolStatus.class, value);
30+
if (status == null) {
31+
throw new InvalidParameterValueException("Invalid status: " + value);
32+
}
33+
return status;
34+
}
35+
}
2136
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public class ListStoragePoolsCmd extends BaseListCmd {
6666
@Parameter(name = ApiConstants.SCOPE, type = CommandType.STRING, entityType = StoragePoolResponse.class, description = "the ID of the storage pool")
6767
private String scope;
6868

69+
@Parameter(name = ApiConstants.STATUS, type = CommandType.STRING, description = "the status of the storage pool")
70+
private String status;
71+
6972
/////////////////////////////////////////////////////
7073
/////////////////// Accessors ///////////////////////
7174
/////////////////////////////////////////////////////
@@ -94,14 +97,18 @@ public Long getZoneId() {
9497
return zoneId;
9598
}
9699

100+
public String getStatus() {
101+
return status;
102+
}
103+
97104
public Long getId() {
98105
return id;
99106
}
100107

101108
public void setId(Long id) {
102109
this.id = id;
103110
}
104-
/////////////////////////////////////////////////////
111+
/////////////////////////////////////////////////////
105112
/////////////// API Implementation///////////////////
106113
/////////////////////////////////////////////////////
107114

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
import com.cloud.storage.Storage;
230230
import com.cloud.storage.Storage.ImageFormat;
231231
import com.cloud.storage.Storage.TemplateType;
232+
import com.cloud.storage.StoragePoolStatus;
232233
import com.cloud.storage.StoragePoolTagVO;
233234
import com.cloud.storage.VMTemplateVO;
234235
import com.cloud.storage.Volume;
@@ -2603,89 +2604,26 @@ public ListResponse<StoragePoolResponse> searchForStoragePools(ListStoragePoolsC
26032604
}
26042605

26052606
private Pair<List<StoragePoolJoinVO>, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) {
2606-
ScopeType scopeType = null;
2607-
if (cmd.getScope() != null) {
2608-
try {
2609-
scopeType = Enum.valueOf(ScopeType.class, cmd.getScope().toUpperCase());
2610-
} catch (Exception e) {
2611-
throw new InvalidParameterValueException("Invalid scope type: " + cmd.getScope());
2612-
}
2613-
}
2607+
ScopeType scopeType = ScopeType.validateAndGetScopeType(cmd.getScope());
2608+
StoragePoolStatus status = StoragePoolStatus.validateAndGetStatus(cmd.getStatus());
26142609

26152610
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
2616-
Object id = cmd.getId();
2617-
Object name = cmd.getStoragePoolName();
2618-
Object path = cmd.getPath();
2619-
Object pod = cmd.getPodId();
2620-
Object cluster = cmd.getClusterId();
2621-
Object address = cmd.getIpAddress();
2622-
Object keyword = cmd.getKeyword();
2611+
Long id = cmd.getId();
2612+
String name = cmd.getStoragePoolName();
2613+
String path = cmd.getPath();
2614+
Long pod = cmd.getPodId();
2615+
Long cluster = cmd.getClusterId();
2616+
String address = cmd.getIpAddress();
2617+
String keyword = cmd.getKeyword();
26232618
Long startIndex = cmd.getStartIndex();
26242619
Long pageSize = cmd.getPageSizeVal();
26252620

26262621
Filter searchFilter = new Filter(StoragePoolJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
26272622

2628-
SearchBuilder<StoragePoolJoinVO> sb = _poolJoinDao.createSearchBuilder();
2629-
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct
2630-
// ids
2631-
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
2632-
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
2633-
sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ);
2634-
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
2635-
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
2636-
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
2637-
sb.and("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ);
2638-
sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ);
2639-
sb.and("parent", sb.entity().getParent(), Op.EQ);
2640-
2641-
SearchCriteria<StoragePoolJoinVO> sc = sb.create();
2642-
2643-
if (keyword != null) {
2644-
SearchCriteria<StoragePoolJoinVO> ssc = _poolJoinDao.createSearchCriteria();
2645-
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
2646-
ssc.addOr("poolType", SearchCriteria.Op.LIKE, "%" + keyword + "%");
2647-
2648-
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
2649-
}
2650-
2651-
if (id != null) {
2652-
sc.setParameters("id", id);
2653-
}
2654-
2655-
if (name != null) {
2656-
sc.setParameters("name", name);
2657-
}
2658-
2659-
if (path != null) {
2660-
sc.setParameters("path", path);
2661-
}
2662-
if (zoneId != null) {
2663-
sc.setParameters("dataCenterId", zoneId);
2664-
}
2665-
if (pod != null) {
2666-
SearchCriteria<StoragePoolJoinVO> ssc = _poolJoinDao.createSearchCriteria();
2667-
ssc.addOr("podId", Op.EQ, pod);
2668-
ssc.addOr("podId", Op.NULL);
2669-
2670-
sc.addAnd("podId", SearchCriteria.Op.SC, ssc);
2671-
}
2672-
if (address != null) {
2673-
sc.setParameters("hostAddress", address);
2674-
}
2675-
if (cluster != null) {
2676-
SearchCriteria<StoragePoolJoinVO> ssc = _poolJoinDao.createSearchCriteria();
2677-
ssc.addOr("clusterId", Op.EQ, cluster);
2678-
ssc.addOr("clusterId", Op.NULL);
2679-
2680-
sc.addAnd("clusterId", SearchCriteria.Op.SC, ssc);
2681-
}
2682-
if (scopeType != null) {
2683-
sc.setParameters("scope", scopeType.toString());
2684-
}
2685-
sc.setParameters("parent", 0);
2623+
// search & count Pool details by ids
2624+
Pair<List<StoragePoolJoinVO>, Integer> uniquePoolPair = _poolJoinDao.searchAndCount(id, name, zoneId, path, pod,
2625+
cluster, address, scopeType, status, keyword, searchFilter);
26862626

2687-
// search Pool details by ids
2688-
Pair<List<StoragePoolJoinVO>, Integer> uniquePoolPair = _poolJoinDao.searchAndCount(sc, searchFilter);
26892627
Integer count = uniquePoolPair.second();
26902628
if (count.intValue() == 0) {
26912629
// empty result

server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDao.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
import java.util.List;
2020

21+
import com.cloud.storage.ScopeType;
22+
import com.cloud.storage.StoragePoolStatus;
23+
import com.cloud.utils.Pair;
24+
import com.cloud.utils.db.Filter;
2125
import org.apache.cloudstack.api.response.StoragePoolResponse;
2226

2327
import com.cloud.api.query.vo.StoragePoolJoinVO;
@@ -38,4 +42,6 @@ public interface StoragePoolJoinDao extends GenericDao<StoragePoolJoinVO, Long>
3842

3943
List<StoragePoolJoinVO> searchByIds(Long... spIds);
4044

45+
Pair<List<StoragePoolJoinVO>, Integer> searchAndCount(Long storagePoolId, String storagePoolName, Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, String keyword, Filter searchFilter);
46+
4147
}

server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020
import com.cloud.api.query.vo.StoragePoolJoinVO;
2121
import com.cloud.capacity.CapacityManager;
2222
import com.cloud.storage.DataStoreRole;
23+
import com.cloud.storage.ScopeType;
2324
import com.cloud.storage.Storage;
2425
import com.cloud.storage.StoragePool;
26+
import com.cloud.storage.StoragePoolStatus;
2527
import com.cloud.storage.StorageStats;
2628
import com.cloud.user.AccountManager;
29+
import com.cloud.utils.Pair;
2730
import com.cloud.utils.StringUtils;
31+
import com.cloud.utils.db.Filter;
2832
import com.cloud.utils.db.GenericDaoBase;
2933
import com.cloud.utils.db.SearchBuilder;
3034
import com.cloud.utils.db.SearchCriteria;
@@ -291,4 +295,75 @@ public List<StoragePoolJoinVO> searchByIds(Long... spIds) {
291295
return uvList;
292296
}
293297

298+
@Override
299+
public Pair<List<StoragePoolJoinVO>, Integer> searchAndCount(Long storagePoolId, String storagePoolName, Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, String keyword, Filter searchFilter) {
300+
SearchCriteria<StoragePoolJoinVO> sc = createStoragePoolSearchCriteria(storagePoolId, storagePoolName, zoneId, path, podId, clusterId, address, scopeType, status, keyword);
301+
return searchAndCount(sc, searchFilter);
302+
}
303+
304+
private SearchCriteria<StoragePoolJoinVO> createStoragePoolSearchCriteria(Long storagePoolId, String storagePoolName, Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, String keyword) {
305+
SearchBuilder<StoragePoolJoinVO> sb = createSearchBuilder();
306+
sb.select(null, SearchCriteria.Func.DISTINCT, sb.entity().getId()); // select distinct
307+
// ids
308+
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
309+
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
310+
sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ);
311+
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
312+
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
313+
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
314+
sb.and("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ);
315+
sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ);
316+
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
317+
sb.and("parent", sb.entity().getParent(), SearchCriteria.Op.EQ);
318+
319+
SearchCriteria<StoragePoolJoinVO> sc = sb.create();
320+
321+
if (keyword != null) {
322+
SearchCriteria<StoragePoolJoinVO> ssc = createSearchCriteria();
323+
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
324+
ssc.addOr("poolType", SearchCriteria.Op.LIKE, "%" + keyword + "%");
325+
326+
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
327+
}
328+
329+
if (storagePoolId != null) {
330+
sc.setParameters("id", storagePoolId);
331+
}
332+
333+
if (storagePoolName != null) {
334+
sc.setParameters("name", storagePoolName);
335+
}
336+
337+
if (path != null) {
338+
sc.setParameters("path", path);
339+
}
340+
if (zoneId != null) {
341+
sc.setParameters("dataCenterId", zoneId);
342+
}
343+
if (podId != null) {
344+
SearchCriteria<StoragePoolJoinVO> ssc = createSearchCriteria();
345+
ssc.addOr("podId", SearchCriteria.Op.EQ, podId);
346+
ssc.addOr("podId", SearchCriteria.Op.NULL);
347+
348+
sc.addAnd("podId", SearchCriteria.Op.SC, ssc);
349+
}
350+
if (address != null) {
351+
sc.setParameters("hostAddress", address);
352+
}
353+
if (clusterId != null) {
354+
SearchCriteria<StoragePoolJoinVO> ssc = createSearchCriteria();
355+
ssc.addOr("clusterId", SearchCriteria.Op.EQ, clusterId);
356+
ssc.addOr("clusterId", SearchCriteria.Op.NULL);
357+
358+
sc.addAnd("clusterId", SearchCriteria.Op.SC, ssc);
359+
}
360+
if (scopeType != null) {
361+
sc.setParameters("scope", scopeType.toString());
362+
}
363+
if (status != null) {
364+
sc.setParameters("status", status.toString());
365+
}
366+
sc.setParameters("parent", 0);
367+
return sc;
368+
}
294369
}

0 commit comments

Comments
 (0)