mirror of https://github.com/apache/cloudstack.git
orchestartion: optimise vm list fetching excluding that reported
This optimises the sql query and iterator to simply return the VMs list excluding those in the received report. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
de82aa8e91
commit
5484d3c7e6
|
|
@ -17,6 +17,7 @@
|
|||
package com.cloud.vm;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -94,14 +95,8 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat
|
|||
// any state outdates should be checked against the time before this list was retrieved
|
||||
Date startTime = DateUtil.currentGMTTime();
|
||||
// for all running/stopping VMs, we provide monitoring of missing report
|
||||
List<VMInstanceVO> vmsThatAreMissingReport = _instanceDao.findByHostInStates(hostId, VirtualMachine.State.Running,
|
||||
VirtualMachine.State.Stopping, VirtualMachine.State.Starting);
|
||||
java.util.Iterator<VMInstanceVO> it = vmsThatAreMissingReport.iterator();
|
||||
while (it.hasNext()) {
|
||||
VMInstanceVO instance = it.next();
|
||||
if (translatedInfo.get(instance.getId()) != null)
|
||||
it.remove();
|
||||
}
|
||||
List<VMInstanceVO> vmsThatAreMissingReport = _instanceDao.findByHostInStatesExcluding(hostId, new ArrayList<>(translatedInfo.keySet()),
|
||||
VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Starting);
|
||||
|
||||
// here we need to be wary of out of band migration as opposed to other, more unexpected state changes
|
||||
if (vmsThatAreMissingReport.size() > 0) {
|
||||
|
|
|
|||
|
|
@ -144,6 +144,8 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
|
|||
*/
|
||||
List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types);
|
||||
|
||||
List<VMInstanceVO> findByHostInStatesExcluding(Long hostId, List<Long> excludingIds, State... states);
|
||||
|
||||
List<VMInstanceVO> findByHostInStates(Long hostId, State... states);
|
||||
|
||||
List<VMInstanceVO> listStartingWithNoHostId();
|
||||
|
|
|
|||
|
|
@ -268,6 +268,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
HostAndStateSearch = createSearchBuilder();
|
||||
HostAndStateSearch.and("host", HostAndStateSearch.entity().getHostId(), Op.EQ);
|
||||
HostAndStateSearch.and("states", HostAndStateSearch.entity().getState(), Op.IN);
|
||||
HostAndStateSearch.and("idsNotIn", HostAndStateSearch.entity().getId(), Op.NIN);
|
||||
HostAndStateSearch.done();
|
||||
|
||||
StartingWithNoHostSearch = createSearchBuilder();
|
||||
|
|
@ -880,6 +881,17 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> findByHostInStatesExcluding(Long hostId, List<Long> excludingIds, State... states) {
|
||||
SearchCriteria<VMInstanceVO> sc = HostAndStateSearch.create();
|
||||
sc.setParameters("host", hostId);
|
||||
if (excludingIds != null && !excludingIds.isEmpty()) {
|
||||
sc.setParameters("idsNotIn", excludingIds.toArray());
|
||||
}
|
||||
sc.setParameters("states", (Object[])states);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> findByHostInStates(Long hostId, State... states) {
|
||||
SearchCriteria<VMInstanceVO> sc = HostAndStateSearch.create();
|
||||
|
|
|
|||
Loading…
Reference in New Issue