mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1010: Fix count issue for listHosts command
This commit is contained in:
parent
55e8965bd0
commit
51c1ca7cbe
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue