|
27 | 27 | import java.util.List; |
28 | 28 | import java.util.Map; |
29 | 29 | import java.util.Map.Entry; |
| 30 | +import java.util.Objects; |
30 | 31 | import java.util.Set; |
31 | 32 | import java.util.UUID; |
32 | 33 | import java.util.concurrent.ConcurrentHashMap; |
|
96 | 97 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
97 | 98 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
98 | 99 | import org.apache.commons.codec.binary.Base64; |
| 100 | +import org.apache.commons.collections.CollectionUtils; |
99 | 101 | import org.apache.commons.collections.MapUtils; |
100 | 102 | import org.apache.commons.lang3.StringUtils; |
101 | 103 | import org.apache.log4j.Logger; |
@@ -1882,45 +1884,46 @@ public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, Stri |
1882 | 1884 | } |
1883 | 1885 |
|
1884 | 1886 | @Override |
1885 | | - public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, List<String> volumeLocators, int timeout) { |
| 1887 | + public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, int timeout) { |
1886 | 1888 | List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(clusterId, Status.Up); |
1887 | 1889 | StoragePoolVO storagePool = _storagePoolDao.findPoolByUUID(poolUuid); |
1888 | | - for (HostVO neighbor : neighbors) { |
1889 | | - // apply filters: |
1890 | | - // - managed storage |
1891 | | - // - local storage |
1892 | | - if (storagePool.isManaged() || storagePool.isLocal()) { |
1893 | | - |
1894 | | - volumeLocators = getVolumesByHost(neighbor, storagePool); |
| 1890 | + HashMap<String, VolumeStatsEntry> volumeStatsByUuid = new HashMap<>(); |
1895 | 1891 |
|
1896 | | - } |
| 1892 | + for (HostVO neighbor : neighbors) { |
1897 | 1893 |
|
1898 | 1894 | // - zone wide storage for specific hypervisortypes |
1899 | | - if (ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType()) { |
| 1895 | + if ((ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType())) { |
1900 | 1896 | // skip this neighbour if their hypervisor type is not the same as that of the store |
1901 | 1897 | continue; |
1902 | 1898 | } |
1903 | 1899 |
|
1904 | | - GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators); |
| 1900 | + List<String> volumeLocators = getVolumesByHost(neighbor, storagePool); |
| 1901 | + if (!CollectionUtils.isEmpty(volumeLocators)) { |
1905 | 1902 |
|
1906 | | - if (timeout > 0) { |
1907 | | - cmd.setWait(timeout/1000); |
1908 | | - } |
| 1903 | + GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators); |
1909 | 1904 |
|
1910 | | - Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); |
| 1905 | + if (timeout > 0) { |
| 1906 | + cmd.setWait(timeout/1000); |
| 1907 | + } |
| 1908 | + |
| 1909 | + Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); |
1911 | 1910 |
|
1912 | | - if (answer instanceof GetVolumeStatsAnswer){ |
1913 | | - GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer)answer; |
1914 | | - return volstats.getVolumeStats(); |
| 1911 | + if (answer instanceof GetVolumeStatsAnswer){ |
| 1912 | + GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer)answer; |
| 1913 | + if (volstats.getVolumeStats() != null) { |
| 1914 | + volumeStatsByUuid.putAll(volstats.getVolumeStats()); |
| 1915 | + } |
| 1916 | + } |
1915 | 1917 | } |
1916 | 1918 | } |
1917 | | - return null; |
| 1919 | + return volumeStatsByUuid.size() > 0 ? volumeStatsByUuid : null; |
1918 | 1920 | } |
1919 | 1921 |
|
1920 | 1922 | private List<String> getVolumesByHost(HostVO host, StoragePool pool){ |
1921 | | - List<UserVmVO> vmsPerHost = _vmDao.listByHostId(host.getId()); |
| 1923 | + List<VMInstanceVO> vmsPerHost = _vmInstanceDao.listByHostId(host.getId()); |
1922 | 1924 | return vmsPerHost.stream() |
1923 | | - .flatMap(vm -> _volsDao.findByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol -> vol.getPath())) |
| 1925 | + .flatMap(vm -> _volsDao.findByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol -> |
| 1926 | + vol.getState() == Volume.State.Ready ? (vol.getFormat() == ImageFormat.OVA ? vol.getChainInfo() : vol.getPath()) : null).filter(Objects::nonNull)) |
1924 | 1927 | .collect(Collectors.toList()); |
1925 | 1928 | } |
1926 | 1929 |
|
|
0 commit comments