mirror of https://github.com/apache/cloudstack.git
server,engine-schema: allow retrieving volume stats for stopped vms
Earlier, we were finding only those instance which have host_id equal to the given host. Changed code now also returns those VMs which have host_id as NULL and last_host_id as the given host. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
cb2d736032
commit
38c8b70cf3
|
|
@ -192,4 +192,6 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
|
|||
int getVmCountByOfferingNotInDomain(Long serviceOfferingId, List<Long> domainIds);
|
||||
|
||||
List<VMInstanceVO> listByIdsIncludingRemoved(List<Long> ids);
|
||||
|
||||
List<Long> listIdsByHostIdForVolumeStats(long hostIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1296,4 +1296,20 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
sc.setParameters("ids", ids.toArray());
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listIdsByHostIdForVolumeStats(long hostId) {
|
||||
GenericSearchBuilder<VMInstanceVO, Long> sb = createSearchBuilder(Long.class);
|
||||
sb.selectFields(sb.entity().getId());
|
||||
sb.and().op("host", sb.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
sb.or().op("hostNull", sb.entity().getHostId(), Op.NULL);
|
||||
sb.and("lastHost", sb.entity().getLastHostId(), SearchCriteria.Op.EQ);
|
||||
sb.cp();
|
||||
sb.cp();
|
||||
sb.done();
|
||||
SearchCriteria<Long> sc = sb.create();
|
||||
sc.setParameters("host", hostId);
|
||||
sc.setParameters("lastHost", hostId);
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2343,9 +2343,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
|
||||
private List<String> getVolumesByHost(HostVO host, StoragePool pool) {
|
||||
List<VMInstanceVO> vmsPerHost = _vmInstanceDao.listByHostId(host.getId());
|
||||
List<Long> vmsPerHost = _vmInstanceDao.listIdsByHostIdForVolumeStats(host.getId());
|
||||
return vmsPerHost.stream()
|
||||
.flatMap(vm -> _volsDao.findNonDestroyedVolumesByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol ->
|
||||
.flatMap(vmId -> _volsDao.findNonDestroyedVolumesByInstanceIdAndPoolId(vmId,pool.getId()).stream().map(vol ->
|
||||
vol.getState() == Volume.State.Ready ? (vol.getFormat() == ImageFormat.OVA ? vol.getChainInfo() : vol.getPath()) : null).filter(Objects::nonNull))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue