Skip to content

Commit

Permalink
core: fix NPE when picking host for transfer-image
Browse files Browse the repository at this point in the history
When picking a host for transfer-image job, we filter hosts that
are UP and then process the data they reported on storage domains
without checking whether the host actually reported this data.
It can happen that hosts are UP and still have not reported data
on storage domains, in which case the data is null, resulting in
an NPE in the transfer-image flow.

This patch changes the predicate that is used to filter hosts for
transfer-image, adding a null-check to avoid that NPE.

Bug-Url: https://bugzilla.redhat.com/2203132
Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed May 21, 2023
1 parent d37b4f7 commit 0f82182
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.ovirt.engine.core.common.businessentities.ActionGroup;
import org.ovirt.engine.core.common.businessentities.StorageDomain;
import org.ovirt.engine.core.common.businessentities.VDS;
import org.ovirt.engine.core.common.businessentities.VDSDomainsData;
import org.ovirt.engine.core.common.businessentities.VM;
import org.ovirt.engine.core.common.businessentities.VmBackup;
import org.ovirt.engine.core.common.businessentities.VmBackupPhase;
Expand Down Expand Up @@ -1136,12 +1135,17 @@ private static boolean proxyEnabled() {

@Override
protected VDS checkForActiveVds() {
Guid hostForExecution = vdsCommandsHelper.getHostForExecution(getStoragePoolId(), host ->
resourceManager.getVdsManager(host.getId()).getDomains()
.stream()
Guid hostForExecution = vdsCommandsHelper.getHostForExecution(getStoragePoolId(), host -> {
var domainsData = resourceManager.getVdsManager(host.getId()).getDomains();
if (domainsData == null) {
return false;
}
var domainData = domainsData.stream()
.filter(vdsDomainsData -> vdsDomainsData.getDomainId().equals(getStorageDomainId()))
.allMatch(VDSDomainsData::isValid)
);
.findFirst()
.orElse(null);
return domainData != null ? domainData.isValid() : false;
});

if (hostForExecution == null) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_NO_VDS_IN_POOL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public Guid getHostForExecution(Guid poolId, Predicate<VDS> predicate) {
List<Guid> hostsForExecution = vdsDao
.getAllForStoragePoolAndStatus(poolId, VDSStatus.Up).stream()
.filter(predicate)
.map(x -> x.getId()).collect(Collectors.toList());
.map(VDS::getId)
.collect(Collectors.toList());
if (hostsForExecution.isEmpty()) {
return null;
}
Expand Down

0 comments on commit 0f82182

Please sign in to comment.