Skip to content

Commit ef00f1b

Browse files
author
Jessica Wang
committed
CLOUDSTACK-2120: mixed zone management - API: extend listClusters API to to take in zonetype.
1 parent 271f875 commit ef00f1b

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

api/src/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public class ListClustersCmd extends BaseListCmd {
7070
@Parameter(name=ApiConstants.MANAGED_STATE, type=CommandType.STRING, description="whether this cluster is managed by cloudstack")
7171
private String managedState;
7272

73+
@Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to")
74+
private String zoneType;
75+
7376
@Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the clusters")
7477
private Boolean showCapacities;
7578

@@ -114,7 +117,10 @@ public void setManagedstate(String managedstate) {
114117
this.managedState = managedstate;
115118
}
116119

117-
120+
public String getZoneType() {
121+
return zoneType;
122+
}
123+
118124
public Boolean getShowCapacities() {
119125
return showCapacities;
120126
}

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,48 +616,69 @@ public List<? extends Cluster> searchForClusters(long zoneId, Long startIndex, L
616616

617617
@Override
618618
public Pair<List<? extends Cluster>, Integer> searchForClusters(ListClustersCmd cmd) {
619-
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
620-
SearchCriteria<ClusterVO> sc = _clusterDao.createSearchCriteria();
621-
622-
Object id = cmd.getId();
619+
Object id = cmd.getId();
623620
Object name = cmd.getClusterName();
624621
Object podId = cmd.getPodId();
625622
Long zoneId = cmd.getZoneId();
626623
Object hypervisorType = cmd.getHypervisorType();
627624
Object clusterType = cmd.getClusterType();
628625
Object allocationState = cmd.getAllocationState();
626+
String zoneType = cmd.getZoneType();
629627
String keyword = cmd.getKeyword();
630-
631628
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
632-
629+
630+
631+
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
632+
633+
SearchBuilder<ClusterVO> sb = _clusterDao.createSearchBuilder();
634+
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
635+
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
636+
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
637+
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
638+
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
639+
sb.and("clusterType", sb.entity().getClusterType(), SearchCriteria.Op.EQ);
640+
sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ);
641+
642+
if(zoneType != null) {
643+
SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder();
644+
zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ);
645+
sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER);
646+
}
647+
648+
649+
SearchCriteria<ClusterVO> sc = sb.create();
633650
if (id != null) {
634-
sc.addAnd("id", SearchCriteria.Op.EQ, id);
651+
sc.setParameters("id", id);
635652
}
636653

637654
if (name != null) {
638-
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
655+
sc.setParameters("name", "%" + name + "%");
639656
}
640657

641658
if (podId != null) {
642-
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
659+
sc.setParameters("podId", podId);
643660
}
644661

645662
if (zoneId != null) {
646-
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
663+
sc.setParameters("dataCenterId", zoneId);
647664
}
648665

649666
if (hypervisorType != null) {
650-
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType);
667+
sc.setParameters("hypervisorType", hypervisorType);
651668
}
652669

653670
if (clusterType != null) {
654-
sc.addAnd("clusterType", SearchCriteria.Op.EQ, clusterType);
671+
sc.setParameters("clusterType", clusterType);
655672
}
656673

657674
if (allocationState != null) {
658-
sc.addAnd("allocationState", SearchCriteria.Op.EQ, allocationState);
675+
sc.setParameters("allocationState", allocationState);
659676
}
660677

678+
if(zoneType != null) {
679+
sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType);
680+
}
681+
661682
if (keyword != null) {
662683
SearchCriteria<ClusterVO> ssc = _clusterDao.createSearchCriteria();
663684
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");

0 commit comments

Comments
 (0)