|
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; |
@@ -1954,45 +1955,46 @@ public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, Stri |
1954 | 1955 | } |
1955 | 1956 |
|
1956 | 1957 | @Override |
1957 | | - public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, List<String> volumeLocators, int timeout) { |
| 1958 | + public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, int timeout) { |
1958 | 1959 | List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(clusterId, Status.Up); |
1959 | 1960 | StoragePoolVO storagePool = _storagePoolDao.findPoolByUUID(poolUuid); |
1960 | | - for (HostVO neighbor : neighbors) { |
1961 | | - // apply filters: |
1962 | | - // - managed storage |
1963 | | - // - local storage |
1964 | | - if (storagePool.isManaged() || storagePool.isLocal()) { |
1965 | | - |
1966 | | - volumeLocators = getVolumesByHost(neighbor, storagePool); |
| 1961 | + HashMap<String, VolumeStatsEntry> volumeStatsByUuid = new HashMap<>(); |
1967 | 1962 |
|
1968 | | - } |
| 1963 | + for (HostVO neighbor : neighbors) { |
1969 | 1964 |
|
1970 | 1965 | // - zone wide storage for specific hypervisortypes |
1971 | | - if (ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType()) { |
| 1966 | + if ((ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType())) { |
1972 | 1967 | // skip this neighbour if their hypervisor type is not the same as that of the store |
1973 | 1968 | continue; |
1974 | 1969 | } |
1975 | 1970 |
|
1976 | | - GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators); |
| 1971 | + List<String> volumeLocators = getVolumesByHost(neighbor, storagePool); |
| 1972 | + if (!CollectionUtils.isEmpty(volumeLocators)) { |
1977 | 1973 |
|
1978 | | - if (timeout > 0) { |
1979 | | - cmd.setWait(timeout/1000); |
1980 | | - } |
| 1974 | + GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators); |
1981 | 1975 |
|
1982 | | - Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); |
| 1976 | + if (timeout > 0) { |
| 1977 | + cmd.setWait(timeout/1000); |
| 1978 | + } |
| 1979 | + |
| 1980 | + Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); |
1983 | 1981 |
|
1984 | | - if (answer instanceof GetVolumeStatsAnswer){ |
1985 | | - GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer)answer; |
1986 | | - return volstats.getVolumeStats(); |
| 1982 | + if (answer instanceof GetVolumeStatsAnswer){ |
| 1983 | + GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer)answer; |
| 1984 | + if (volstats.getVolumeStats() != null) { |
| 1985 | + volumeStatsByUuid.putAll(volstats.getVolumeStats()); |
| 1986 | + } |
| 1987 | + } |
1987 | 1988 | } |
1988 | 1989 | } |
1989 | | - return null; |
| 1990 | + return volumeStatsByUuid.size() > 0 ? volumeStatsByUuid : null; |
1990 | 1991 | } |
1991 | 1992 |
|
1992 | 1993 | private List<String> getVolumesByHost(HostVO host, StoragePool pool){ |
1993 | | - List<UserVmVO> vmsPerHost = _vmDao.listByHostId(host.getId()); |
| 1994 | + List<VMInstanceVO> vmsPerHost = _vmInstanceDao.listByHostId(host.getId()); |
1994 | 1995 | return vmsPerHost.stream() |
1995 | | - .flatMap(vm -> _volsDao.findByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol -> vol.getPath())) |
| 1996 | + .flatMap(vm -> _volsDao.findByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol -> |
| 1997 | + vol.getState() == Volume.State.Ready ? (vol.getFormat() == ImageFormat.OVA ? vol.getChainInfo() : vol.getPath()) : null).filter(Objects::nonNull)) |
1996 | 1998 | .collect(Collectors.toList()); |
1997 | 1999 | } |
1998 | 2000 |
|
|
0 commit comments