1616// under the License.
1717package com .cloud .vm ;
1818
19+ import static com .cloud .utils .NumbersUtil .toHumanReadableSize ;
20+
1921import java .io .IOException ;
2022import java .io .StringReader ;
2123import java .io .UnsupportedEncodingException ;
2931import java .util .List ;
3032import java .util .Map ;
3133import java .util .Map .Entry ;
34+ import java .util .Objects ;
3235import java .util .Set ;
3336import java .util .UUID ;
3437import java .util .concurrent .ConcurrentHashMap ;
4750import javax .xml .parsers .DocumentBuilderFactory ;
4851import javax .xml .parsers .ParserConfigurationException ;
4952
50- import com .cloud .exception .UnsupportedServiceException ;
51- import com .cloud .hypervisor .Hypervisor ;
5253import org .apache .cloudstack .acl .ControlledEntity .ACLType ;
5354import org .apache .cloudstack .acl .SecurityChecker .AccessType ;
5455import org .apache .cloudstack .affinity .AffinityGroupService ;
188189import com .cloud .exception .ResourceAllocationException ;
189190import com .cloud .exception .ResourceUnavailableException ;
190191import com .cloud .exception .StorageUnavailableException ;
192+ import com .cloud .exception .UnsupportedServiceException ;
191193import com .cloud .exception .VirtualMachineMigrationException ;
192194import com .cloud .gpu .GPU ;
193195import com .cloud .ha .HighAvailabilityManager ;
194196import com .cloud .host .Host ;
195197import com .cloud .host .HostVO ;
196198import com .cloud .host .Status ;
197199import com .cloud .host .dao .HostDao ;
200+ import com .cloud .hypervisor .Hypervisor ;
198201import com .cloud .hypervisor .Hypervisor .HypervisorType ;
199202import com .cloud .hypervisor .HypervisorCapabilitiesVO ;
200203import com .cloud .hypervisor .dao .HypervisorCapabilitiesDao ;
328331import com .cloud .vm .snapshot .VMSnapshotVO ;
329332import com .cloud .vm .snapshot .dao .VMSnapshotDao ;
330333
331- import static com .cloud .utils .NumbersUtil .toHumanReadableSize ;
332-
333334public class UserVmManagerImpl extends ManagerBase implements UserVmManager , VirtualMachineGuru , UserVmService , Configurable {
334335 private static final Logger s_logger = Logger .getLogger (UserVmManagerImpl .class );
335336
@@ -1930,18 +1931,13 @@ public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, Stri
19301931 public HashMap <String , VolumeStatsEntry > getVolumeStatistics (long clusterId , String poolUuid , StoragePoolType poolType , List <String > volumeLocators , int timeout ) {
19311932 List <HostVO > neighbors = _resourceMgr .listHostsInClusterByStatus (clusterId , Status .Up );
19321933 StoragePoolVO storagePool = _storagePoolDao .findPoolByUUID (poolUuid );
1933- for (HostVO neighbor : neighbors ) {
1934- // apply filters:
1935- // - managed storage
1936- // - local storage
1937- if (storagePool .isManaged () || storagePool .isLocal ()) {
1938-
1939- volumeLocators = getVolumesByHost (neighbor , storagePool );
1934+ HashMap <String , VolumeStatsEntry > volumeStatsByUuid = new HashMap <>();
19401935
1941- }
1936+ for (HostVO neighbor : neighbors ) {
1937+ volumeLocators = getVolumesByHost (neighbor , storagePool );
19421938
19431939 // - zone wide storage for specific hypervisortypes
1944- if (ScopeType .ZONE .equals (storagePool .getScope ()) && storagePool .getHypervisor () != neighbor .getHypervisorType ()) {
1940+ if (( ScopeType .ZONE .equals (storagePool .getScope ()) && storagePool .getHypervisor () != neighbor .getHypervisorType ()) || ( volumeLocators == null || volumeLocators . size () == 0 )) {
19451941 // skip this neighbour if their hypervisor type is not the same as that of the store
19461942 continue ;
19471943 }
@@ -1956,16 +1952,16 @@ public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, Str
19561952
19571953 if (answer instanceof GetVolumeStatsAnswer ){
19581954 GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer )answer ;
1959- return volstats .getVolumeStats ();
1955+ volumeStatsByUuid . putAll ( volstats .getVolumeStats () );
19601956 }
19611957 }
1962- return null ;
1958+ return volumeStatsByUuid . size () > 0 ? volumeStatsByUuid : null ;
19631959 }
19641960
19651961 private List <String > getVolumesByHost (HostVO host , StoragePool pool ){
19661962 List <UserVmVO > vmsPerHost = _vmDao .listByHostId (host .getId ());
19671963 return vmsPerHost .stream ()
1968- .flatMap (vm -> _volsDao .findByInstanceIdAndPoolId (vm .getId (),pool .getId ()).stream ().map (vol -> vol .getPath ()))
1964+ .flatMap (vm -> _volsDao .findByInstanceIdAndPoolId (vm .getId (),pool .getId ()).stream ().map (vol -> vol .getState () == Volume . State . Ready ? vol . getPath () : null ). filter ( Objects :: nonNull ))
19691965 .collect (Collectors .toList ());
19701966 }
19711967
0 commit comments