Skip to content

Commit ab1f6b0

Browse files
committed
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>
1 parent c19630f commit ab1f6b0

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,6 @@ List<VMInstanceVO> searchRemovedByRemoveDate(final Date startDate, final Date en
190190
int getVmCountByOfferingId(Long serviceOfferingId);
191191

192192
int getVmCountByOfferingNotInDomain(Long serviceOfferingId, List<Long> domainIds);
193+
194+
List<Long> listIdsByHostIdForVolumeStats(long hostIds);
193195
}

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,4 +1261,20 @@ public int getVmCountByOfferingNotInDomain(Long serviceOfferingId, List<Long> do
12611261
List<Integer> count = customSearch(sc, null);
12621262
return count.get(0);
12631263
}
1264+
1265+
@Override
1266+
public List<Long> listIdsByHostIdForVolumeStats(long hostId) {
1267+
GenericSearchBuilder<VMInstanceVO, Long> sb = createSearchBuilder(Long.class);
1268+
sb.selectFields(sb.entity().getId());
1269+
sb.and().op("host", sb.entity().getHostId(), SearchCriteria.Op.EQ);
1270+
sb.or().op("hostNull", sb.entity().getHostId(), Op.NULL);
1271+
sb.and("lastHost", sb.entity().getLastHostId(), SearchCriteria.Op.EQ);
1272+
sb.cp();
1273+
sb.cp();
1274+
sb.done();
1275+
SearchCriteria<Long> sc = sb.create();
1276+
sc.setParameters("host", hostId);
1277+
sc.setParameters("lastHost", hostId);
1278+
return customSearch(sc, null);
1279+
}
12641280
}

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,9 +2273,9 @@ public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, Str
22732273
}
22742274

22752275
private List<String> getVolumesByHost(HostVO host, StoragePool pool){
2276-
List<VMInstanceVO> vmsPerHost = _vmInstanceDao.listByHostId(host.getId());
2276+
List<Long> vmsPerHost = _vmInstanceDao.listIdsByHostIdForVolumeStats(host.getId());
22772277
return vmsPerHost.stream()
2278-
.flatMap(vm -> _volsDao.findNonDestroyedVolumesByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol ->
2278+
.flatMap(vmId -> _volsDao.findNonDestroyedVolumesByInstanceIdAndPoolId(vmId,pool.getId()).stream().map(vol ->
22792279
vol.getState() == Volume.State.Ready ? (vol.getFormat() == ImageFormat.OVA ? vol.getChainInfo() : vol.getPath()) : null).filter(Objects::nonNull))
22802280
.collect(Collectors.toList());
22812281
}

0 commit comments

Comments
 (0)