mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1010: Fix count issue for listHosts command
This commit is contained in:
parent
0306d2f52d
commit
0d3eaa63d6
|
|
@ -161,11 +161,11 @@ public class ListHostsCmd extends BaseListCmd {
|
|||
|
||||
@Override
|
||||
public void execute(){
|
||||
List<? extends Host> result = new ArrayList<Host>();
|
||||
List<? extends Host> hostsWithCapacity = new ArrayList<Host>();
|
||||
|
||||
if(getVirtualMachineId() != null){
|
||||
Pair<List<? extends Host>, List<? extends Host>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal());
|
||||
Pair<List<? extends Host>,Integer> result;
|
||||
List<? extends Host> hostsWithCapacity = new ArrayList<Host>();
|
||||
|
||||
if(getVirtualMachineId() != null){
|
||||
Pair<Pair<List<? extends Host>,Integer>, List<? extends Host>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal());
|
||||
result = hostsForMigration.first();
|
||||
hostsWithCapacity = hostsForMigration.second();
|
||||
}else{
|
||||
|
|
@ -174,7 +174,7 @@ public class ListHostsCmd extends BaseListCmd {
|
|||
|
||||
ListResponse<HostResponse> 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)){
|
||||
|
|
@ -185,7 +185,7 @@ public class ListHostsCmd extends BaseListCmd {
|
|||
hostResponses.add(hostResponse);
|
||||
}
|
||||
|
||||
response.setResponses(hostResponses);
|
||||
response.setResponses(hostResponses, result.second());
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ import com.cloud.storage.GuestOsCategory;
|
|||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.SSHKeyPair;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
|
@ -154,7 +155,7 @@ public interface ManagementService {
|
|||
* @param cmd
|
||||
* @return List of Hosts
|
||||
*/
|
||||
List<? extends Host> searchForServers(ListHostsCmd cmd);
|
||||
Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd);
|
||||
|
||||
/**
|
||||
* Creates a new template
|
||||
|
|
@ -435,7 +436,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();
|
||||
|
||||
|
|
|
|||
|
|
@ -223,6 +223,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;
|
||||
|
|
@ -897,7 +898,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<HostVO> searchForServers(ListHostsCmd cmd) {
|
||||
public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
|
||||
|
||||
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
|
||||
Object name = cmd.getHostName();
|
||||
|
|
@ -910,11 +911,12 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
Object resourceState = cmd.getResourceState();
|
||||
Object haHosts = cmd.getHaHost();
|
||||
|
||||
return searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), name, type, state, zoneId, pod, cluster, id, keyword, resourceState, haHosts);
|
||||
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) {
|
||||
|
|
@ -972,9 +974,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);
|
||||
|
|
@ -1008,10 +1013,10 @@ 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,
|
||||
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);
|
||||
|
||||
|
|
@ -1082,7 +1087,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