|
29 | 29 | import java.util.List; |
30 | 30 | import java.util.Map; |
31 | 31 | import java.util.Map.Entry; |
| 32 | +import java.util.Objects; |
32 | 33 | import java.util.Set; |
33 | 34 | import java.util.UUID; |
34 | 35 | import java.util.concurrent.ConcurrentHashMap; |
@@ -1991,45 +1992,46 @@ public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, Stri |
1991 | 1992 | } |
1992 | 1993 |
|
1993 | 1994 | @Override |
1994 | | - public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, List<String> volumeLocators, int timeout) { |
| 1995 | + public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, int timeout) { |
1995 | 1996 | List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(clusterId, Status.Up); |
1996 | 1997 | StoragePoolVO storagePool = _storagePoolDao.findPoolByUUID(poolUuid); |
1997 | | - for (HostVO neighbor : neighbors) { |
1998 | | - // apply filters: |
1999 | | - // - managed storage |
2000 | | - // - local storage |
2001 | | - if (storagePool.isManaged() || storagePool.isLocal()) { |
2002 | | - |
2003 | | - volumeLocators = getVolumesByHost(neighbor, storagePool); |
| 1998 | + HashMap<String, VolumeStatsEntry> volumeStatsByUuid = new HashMap<>(); |
2004 | 1999 |
|
2005 | | - } |
| 2000 | + for (HostVO neighbor : neighbors) { |
2006 | 2001 |
|
2007 | 2002 | // - zone wide storage for specific hypervisortypes |
2008 | | - if (ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType()) { |
| 2003 | + if ((ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType())) { |
2009 | 2004 | // skip this neighbour if their hypervisor type is not the same as that of the store |
2010 | 2005 | continue; |
2011 | 2006 | } |
2012 | 2007 |
|
2013 | | - GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators); |
| 2008 | + List<String> volumeLocators = getVolumesByHost(neighbor, storagePool); |
| 2009 | + if (!CollectionUtils.isEmpty(volumeLocators)) { |
2014 | 2010 |
|
2015 | | - if (timeout > 0) { |
2016 | | - cmd.setWait(timeout/1000); |
2017 | | - } |
| 2011 | + GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators); |
2018 | 2012 |
|
2019 | | - Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); |
| 2013 | + if (timeout > 0) { |
| 2014 | + cmd.setWait(timeout/1000); |
| 2015 | + } |
| 2016 | + |
| 2017 | + Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); |
2020 | 2018 |
|
2021 | | - if (answer instanceof GetVolumeStatsAnswer){ |
2022 | | - GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer)answer; |
2023 | | - return volstats.getVolumeStats(); |
| 2019 | + if (answer instanceof GetVolumeStatsAnswer){ |
| 2020 | + GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer)answer; |
| 2021 | + if (volstats.getVolumeStats() != null) { |
| 2022 | + volumeStatsByUuid.putAll(volstats.getVolumeStats()); |
| 2023 | + } |
| 2024 | + } |
2024 | 2025 | } |
2025 | 2026 | } |
2026 | | - return null; |
| 2027 | + return volumeStatsByUuid.size() > 0 ? volumeStatsByUuid : null; |
2027 | 2028 | } |
2028 | 2029 |
|
2029 | 2030 | private List<String> getVolumesByHost(HostVO host, StoragePool pool){ |
2030 | | - List<UserVmVO> vmsPerHost = _vmDao.listByHostId(host.getId()); |
| 2031 | + List<VMInstanceVO> vmsPerHost = _vmInstanceDao.listByHostId(host.getId()); |
2031 | 2032 | return vmsPerHost.stream() |
2032 | | - .flatMap(vm -> _volsDao.findByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol -> vol.getPath())) |
| 2033 | + .flatMap(vm -> _volsDao.findByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol -> |
| 2034 | + vol.getState() == Volume.State.Ready ? (vol.getFormat() == ImageFormat.OVA ? vol.getChainInfo() : vol.getPath()) : null).filter(Objects::nonNull)) |
2033 | 2035 | .collect(Collectors.toList()); |
2034 | 2036 | } |
2035 | 2037 |
|
|
0 commit comments