You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2013/01/18 11:45:55 UTC

git commit: CLOUDSTACK-1010: Fix count issue for listHosts command

Updated Branches:
  refs/heads/master 55e8965bd -> 51c1ca7cb


CLOUDSTACK-1010: Fix count issue for listHosts command


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/51c1ca7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/51c1ca7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/51c1ca7c

Branch: refs/heads/master
Commit: 51c1ca7cbe0ed5206ea5844acb71a3f6f53d1959
Parents: 55e8965
Author: Kishan Kavala <ki...@cloud.com>
Authored: Fri Jan 18 16:13:25 2013 +0530
Committer: Kishan Kavala <ki...@cloud.com>
Committed: Fri Jan 18 16:13:25 2013 +0530

----------------------------------------------------------------------
 api/src/com/cloud/server/ManagementService.java    |   11 ++++-
 .../api/command/admin/host/ListHostsCmd.java       |    9 ++--
 .../src/com/cloud/server/ManagementServerImpl.java |   37 +++++++++++---
 3 files changed, 43 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/51c1ca7c/api/src/com/cloud/server/ManagementService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java
index fb8af1a..5302daa 100755
--- a/api/src/com/cloud/server/ManagementService.java
+++ b/api/src/com/cloud/server/ManagementService.java
@@ -25,6 +25,7 @@ import java.util.Set;
 import com.cloud.alert.Alert;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
+import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
 import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
 import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
 import org.apache.cloudstack.api.command.admin.resource.ListAlertsCmd;
@@ -140,6 +141,14 @@ public interface ManagementService {
      */
     Pair<List<? extends Pod>, Integer> searchForPods(ListPodsByCmd cmd);
 
+    /**
+     * Searches for servers by the specified search criteria Can search by: "name", "type", "state", "dataCenterId",
+     * "podId"
+     * 
+     * @param cmd
+     * @return List of Hosts
+     */
+    Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd);
 
     /**
      * Creates a new template
@@ -384,7 +393,7 @@ public interface ManagementService {
      * @return Pair<List<? extends Host>, List<? extends Host>> List of all Hosts in VM's cluster and list of Hosts with
      *         enough capacity
      */
-    Pair<List<? extends Host>, List<? extends Host>> listHostsForMigrationOfVM(Long vmId, Long startIndex, Long pageSize);
+    Pair<Pair<List<? extends Host>, Integer>, List<? extends Host>> listHostsForMigrationOfVM(Long vmId, Long startIndex, Long pageSize);
 
     String[] listEventTypes();
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/51c1ca7c/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
index 82f329f..876da9a 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java
@@ -168,17 +168,16 @@ public class ListHostsCmd extends BaseListCmd {
         if (getVirtualMachineId() == null) {
             response = _queryService.searchForServers(this);
         } else {
-            List<? extends Host> result = new ArrayList<Host>();
+            Pair<List<? extends Host>,Integer> result;
             List<? extends Host> hostsWithCapacity = new ArrayList<Host>();
 
-            Pair<List<? extends Host>, List<? extends Host>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(),
-                    this.getStartIndex(), this.getPageSizeVal());
+            Pair<Pair<List<? extends Host>,Integer>, List<? extends Host>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal());
             result = hostsForMigration.first();
             hostsWithCapacity = hostsForMigration.second();
 
             response = new ListResponse<HostResponse>();
             List<HostResponse> hostResponses = new ArrayList<HostResponse>();
-            for (Host host : result) {
+            for (Host host : result.first()) {
                 HostResponse hostResponse = _responseGenerator.createHostResponse(host, getDetails());
                 Boolean suitableForMigration = false;
                 if (hostsWithCapacity.contains(host)) {
@@ -189,7 +188,7 @@ public class ListHostsCmd extends BaseListCmd {
                 hostResponses.add(hostResponse);
             }
 
-            response.setResponses(hostResponses);
+            response.setResponses(hostResponses, result.second());
         }
         response.setResponseName(getCommandName());
         this.setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/51c1ca7c/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 4efae63..bad834d 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -89,6 +89,7 @@ import org.apache.cloudstack.api.command.admin.vlan.ListVlanIpRangesCmd;
 import org.apache.cloudstack.api.command.admin.systemvm.RebootSystemVmCmd;
 import org.apache.cloudstack.api.command.admin.systemvm.StopSystemVmCmd;
 import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
+import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
 import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
 import com.cloud.api.query.dao.DomainRouterJoinDao;
 import com.cloud.api.query.dao.InstanceGroupJoinDao;
@@ -219,6 +220,7 @@ import com.cloud.user.UserVO;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.SSHKeyPairDao;
 import com.cloud.user.dao.UserDao;
+import com.cloud.uservm.UserVm;
 import com.cloud.utils.EnumUtils;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
@@ -915,9 +917,26 @@ public class ManagementServerImpl implements ManagementServer {
         return new Pair<List<? extends Cluster>, Integer>(result.first(), result.second());
     }
 
+    @Override
+    public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
+
+        Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
+        Object name = cmd.getHostName();
+        Object type = cmd.getType();
+        Object state = cmd.getState();
+        Object pod = cmd.getPodId();
+        Object cluster = cmd.getClusterId();
+        Object id = cmd.getId();
+        Object keyword = cmd.getKeyword();
+        Object resourceState = cmd.getResourceState();
+        Object haHosts = cmd.getHaHost();
+
+        Pair<List<HostVO>, Integer> result = searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), name, type, state, zoneId, pod, cluster, id, keyword, resourceState, haHosts);
+        return new Pair<List<? extends Host>, Integer>(result.first(), result.second());
+    }
 
     @Override
-    public Pair<List<? extends Host>, List<? extends Host>> listHostsForMigrationOfVM(Long vmId, Long startIndex, Long pageSize) {
+    public Pair<Pair<List<? extends Host>, Integer>, List<? extends Host>> listHostsForMigrationOfVM(Long vmId, Long startIndex, Long pageSize) {
         // access check - only root admin can migrate VM
         Account caller = UserContext.current().getCaller();
         if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
@@ -976,10 +995,12 @@ public class ManagementServerImpl implements ManagementServer {
             s_logger.debug("Searching for all hosts in cluster: " + cluster + " for migrating VM " + vm);
         }
 
-        List<? extends Host> allHostsInCluster = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, null, null,
-                null);
-        // filter out the current host
+        Pair<List<HostVO>, Integer> allHostsInClusterPair = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, null, null, null);
+
+        // filter out the current host        
+        List<HostVO> allHostsInCluster = allHostsInClusterPair.first();
         allHostsInCluster.remove(srcHost);
+        Pair<List<? extends Host>, Integer> otherHostsInCluster = new Pair<List <? extends Host>, Integer>(allHostsInCluster, new Integer(allHostsInClusterPair.second().intValue()-1));
 
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Other Hosts in this cluster: " + allHostsInCluster);
@@ -1013,11 +1034,11 @@ public class ManagementServerImpl implements ManagementServer {
             }
         }
 
-        return new Pair<List<? extends Host>, List<? extends Host>>(allHostsInCluster, suitableHosts);
+        return new Pair<Pair<List<? extends Host>, Integer>, List<? extends Host>>(otherHostsInCluster, suitableHosts);
     }
 
-    private List<HostVO> searchForServers(Long startIndex, Long pageSize, Object name, Object type, Object state, Object zone, Object pod,
-            Object cluster, Object id, Object keyword, Object resourceState, Object haHosts) {
+    private Pair<List<HostVO>, Integer> searchForServers(Long startIndex, Long pageSize, Object name, Object type, Object state, Object zone, Object pod, Object cluster, Object id, Object keyword,
+            Object resourceState, Object haHosts) {
         Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, startIndex, pageSize);
 
         SearchBuilder<HostVO> sb = _hostDao.createSearchBuilder();
@@ -1087,7 +1108,7 @@ public class ManagementServerImpl implements ManagementServer {
             sc.setJoinParameters("hostTagSearch", "tag", haTag);
         }
 
-        return _hostDao.search(sc, searchFilter);
+        return _hostDao.searchAndCount(sc, searchFilter);
     }
 
     @Override