From 271f8759be06a6a150809f454b469d2301c25d1b Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Sat, 27 Apr 2013 18:29:46 -0700 Subject: [PATCH] CLOUDSTACK-2120: mixed zone management - API: extend listPods API to to take in zonetype. --- .../api/command/admin/pod/ListPodsByCmd.java | 7 ++++ .../cloud/server/ManagementServerImpl.java | 42 +++++++++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java b/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java index 3dace4244ae..db233ae441e 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java @@ -55,6 +55,9 @@ public class ListPodsByCmd extends BaseListCmd { @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="list pods by allocation state") private String allocationState; + @Parameter(name=ApiConstants.ZONE_TYPE, type=CommandType.STRING, description="the network type of the zone that the virtual machine belongs to") + private String zoneType; + @Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the pods") private Boolean showCapacities; @@ -78,6 +81,10 @@ public class ListPodsByCmd extends BaseListCmd { return allocationState; } + public String getZoneType() { + return zoneType; + } + public Boolean getShowCapacities() { return showCapacities; } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 050f57bca98..5db8329928a 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1068,17 +1068,29 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public Pair, Integer> searchForPods(ListPodsByCmd cmd) { - Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchCriteria sc = _hostPodDao.createSearchCriteria(); - String podName = cmd.getPodName(); Long id = cmd.getId(); - Long zoneId = cmd.getZoneId(); + Long zoneId = cmd.getZoneId(); Object keyword = cmd.getKeyword(); Object allocationState = cmd.getAllocationState(); - + String zoneType = cmd.getZoneType(); zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); + + Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchBuilder sb = _hostPodDao.createSearchBuilder(); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); + sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); + sb.and("allocationState", sb.entity().getAllocationState(), SearchCriteria.Op.EQ); + + if(zoneType != null) { + SearchBuilder zoneSb = _dcDao.createSearchBuilder(); + zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); + sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); + } + + SearchCriteria sc = sb.create(); if (keyword != null) { SearchCriteria ssc = _hostPodDao.createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -1088,21 +1100,25 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } if (id != null) { - sc.addAnd("id", SearchCriteria.Op.EQ, id); + sc.setParameters("id", id); } - + if (podName != null) { - sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + podName + "%"); + sc.setParameters("name", "%" + podName + "%"); } - + if (zoneId != null) { - sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); + sc.setParameters("dataCenterId", zoneId); } - + if (allocationState != null) { - sc.addAnd("allocationState", SearchCriteria.Op.EQ, allocationState); + sc.setParameters("allocationState", allocationState); + } + + if(zoneType != null) { + sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); } - + Pair, Integer> result = _hostPodDao.searchAndCount(sc, searchFilter); return new Pair, Integer>(result.first(), result.second()); }