Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ public String call(L3NetworkInventory arg) {
} else {
msg.setAllocatorStrategy(spec.getVmInventory().getAllocatorStrategy());
}

if (msg.getAllocatorStrategy() == null &&
(spec.getRequiredClusterUuid() != null
|| spec.getRequiredHostUuid() != null
|| CollectionUtils.isEmpty(spec.getRequiredClusterUuids())
|| CollectionUtils.isEmpty(spec.getVmInventory().getVmNics()))) {
msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE);
}
Comment on lines +112 to +118
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

条件逻辑块的目的是在特定条件下设置allocatorStrategy。但是,条件判断(spec.getRequiredClusterUuid() != null || spec.getRequiredHostUuid() != null || CollectionUtils.isEmpty(spec.getRequiredClusterUuids()) || CollectionUtils.isEmpty(spec.getVmInventory().getVmNics()))可能存在逻辑错误。特别是,CollectionUtils.isEmpty(spec.getRequiredClusterUuids())CollectionUtils.isEmpty(spec.getVmInventory().getVmNics())的判断逻辑与其他条件相反,这可能导致在不应该设置allocatorStrategy的情况下被错误设置。

- if (msg.getAllocatorStrategy() == null &&
-         (spec.getRequiredClusterUuid() != null
-                 || spec.getRequiredHostUuid() != null
-                 || CollectionUtils.isEmpty(spec.getRequiredClusterUuids())
-                 || CollectionUtils.isEmpty(spec.getVmInventory().getVmNics()))) {
+ if (msg.getAllocatorStrategy() == null &&
+         (spec.getRequiredClusterUuid() != null
+                 || spec.getRequiredHostUuid() != null
+                 && !CollectionUtils.isEmpty(spec.getRequiredClusterUuids())
+                 && !CollectionUtils.isEmpty(spec.getVmInventory().getVmNics()))) {
    msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE);
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (msg.getAllocatorStrategy() == null &&
(spec.getRequiredClusterUuid() != null
|| spec.getRequiredHostUuid() != null
|| CollectionUtils.isEmpty(spec.getRequiredClusterUuids())
|| CollectionUtils.isEmpty(spec.getVmInventory().getVmNics()))) {
msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE);
}
if (msg.getAllocatorStrategy() == null &&
(spec.getRequiredClusterUuid() != null
|| spec.getRequiredHostUuid() != null
&& !CollectionUtils.isEmpty(spec.getRequiredClusterUuids())
&& !CollectionUtils.isEmpty(spec.getVmInventory().getVmNics()))) {
msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE);
}


if (spec.getCandidatePrimaryStorageUuidsForRootVolume().size() == 1) {
msg.addRequiredPrimaryStorageUuid(spec.getCandidatePrimaryStorageUuidsForRootVolume().get(0));
} else if (spec.getCandidatePrimaryStorageUuidsForRootVolume().size() > 1) {
Expand Down