Skip to content

Commit adce7af

Browse files
committed
Address Copilot reviews
1 parent bb64294 commit adce7af

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

engine/schema/src/main/java/org/apache/cloudstack/storage/DiskControllerMappingVO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ public boolean equals(Object obj) {
197197
return controllerReference.equals(that.getControllerReference());
198198
}
199199

200+
@Override
201+
public int hashCode() {
202+
return controllerReference.hashCode();
203+
}
204+
200205
@Override
201206
public String toString() {
202207
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "name", "controllerReference",

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ protected void validateRequiredVirtualHardwareVersionForNewDiskControllers(Virtu
20412041
if (!unsupportedDiskControllers.isEmpty()) {
20422042
String names = unsupportedDiskControllers.stream().map(DiskControllerMappingVO::getName).collect(Collectors.joining(", "));
20432043
String requiredVersions = unsupportedDiskControllers.stream().map(DiskControllerMappingVO::getMinHardwareVersion).collect(Collectors.joining(", "));
2044-
logger.debug("Virtual machine [{}] does not support disk controllers [{}], as its virtual hardware version is [{}] but the controllers require, respectfully, versions [{}].",
2044+
logger.debug("Virtual machine [{}] does not support disk controllers [{}], as its virtual hardware version is [{}] but the controllers require, respectively, versions [{}].",
20452045
vmMo, names, hardwareVersion, requiredVersions);
20462046
throw new CloudRuntimeException(String.format("Disk controllers [%s] are not supported.", names));
20472047
}

plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean
21042104
if (isAttach) {
21052105
// Let's first find which disk controller should be used for the volume being attached.
21062106
//
2107-
// `controllerInfo` can not be null here. It is always defined when creating the `AttachComand` in
2107+
// `controllerInfo` can not be null here. It is always defined when creating the `AttachCommand` in
21082108
// `com.cloud.storage.VolumeApiServiceImpl#sendAttachVolumeCommand`.
21092109
//
21102110
// If `VmDetailConstants.ROOT_DISK_CONTROLLER` or `VmDetailConstants.DATA_DISK_CONTROLLER` are not present

vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import com.vmware.vim25.VirtualSCSISharing;
7878
import com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec;
7979
import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec;
80+
import org.apache.cloudstack.api.response.StoragePoolResponse;
8081
import org.apache.cloudstack.storage.DiskControllerMappingVO;
8182
import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo;
8283
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
@@ -146,6 +147,7 @@ public class VmwareHelper {
146147
private static List<DiskControllerMappingVO> supportedDiskControllers;
147148

148149
public static void setSupportedDiskControllers(List<DiskControllerMappingVO> controllers) {
150+
controllers.sort(Comparator.comparing(DiskControllerMappingVO::getControllerReference));
149151
supportedDiskControllers = controllers;
150152
}
151153

@@ -1172,7 +1174,7 @@ public static void addDiskControllersToVmConfigSpec(VirtualMachineConfigSpec vmC
11721174
continue;
11731175
}
11741176
for (int bus = 0; bus < diskController.getMaxControllerCount(); bus++) {
1175-
VirtualController controller = (VirtualController) controllerClass.newInstance();
1177+
VirtualController controller = (VirtualController) controllerClass.getDeclaredConstructor().newInstance();
11761178
controller.setBusNumber(bus);
11771179
controller.setKey(currentKey);
11781180
currentKey--;
@@ -1269,6 +1271,12 @@ public static void configureDiskControllerMappingsInVmwareBaseModule(List<DiskCo
12691271
try {
12701272
if (!DiskControllerType.osdefault.toString().equals(mapping.getName())) {
12711273
Class.forName(mapping.getControllerReference());
1274+
if (ObjectUtils.anyNull(mapping.getMaxDeviceCount(), mapping.getMaxControllerCount(), mapping.getVmdkAdapterType())) {
1275+
LOGGER.debug("Disk controller mapping with name [{}] and controller reference [{}] is invalid " +
1276+
"because it has null required values (max_device_count, max_controller_count, and/or vmdk_adapter_type); ignoring it.",
1277+
mapping.getName(), mapping.getControllerReference());
1278+
continue;
1279+
}
12721280
}
12731281
LOGGER.debug("Adding disk controller mapping with name [{}] and controller reference [{}] to the list of available disk controllers.",
12741282
mapping.getName(), mapping.getControllerReference());

vmware-base/src/test/java/com/cloud/hypervisor/vmware/util/VmwareHelperTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ public void addDiskControllersToVmConfigSpecTestMaximumAmmountOfControllersIsAdd
338338

339339
VmwareHelper.addDiskControllersToVmConfigSpec(virtualMachineConfigSpecMock, requiredControllers, false);
340340

341-
int expectedControllerAmmount = nvmeMapping.getMaxControllerCount() + sataMapping.getMaxControllerCount();
342-
Assert.assertEquals(expectedControllerAmmount, virtualMachineConfigSpecMock.getDeviceChange().size());
341+
int expectedControllerAmount = nvmeMapping.getMaxControllerCount() + sataMapping.getMaxControllerCount();
342+
Assert.assertEquals(expectedControllerAmount, virtualMachineConfigSpecMock.getDeviceChange().size());
343343

344344
Set<Integer> usedKeys = new HashSet<>();
345345
Map<String, Set<Integer>> usedBusNumbers = new HashMap<>();
@@ -351,7 +351,7 @@ public void addDiskControllersToVmConfigSpecTestMaximumAmmountOfControllersIsAdd
351351
usedKeys.add(controller.getKey());
352352
usedBusNumbers.get(controller.getClass().getName()).add(controller.getBusNumber());
353353
}
354-
Assert.assertEquals(expectedControllerAmmount, usedKeys.size());
354+
Assert.assertEquals(expectedControllerAmount, usedKeys.size());
355355
Assert.assertEquals((int) nvmeMapping.getMaxControllerCount(), usedBusNumbers.get(nvmeMapping.getControllerReference()).size());
356356
Assert.assertEquals((int) sataMapping.getMaxControllerCount(), usedBusNumbers.get(sataMapping.getControllerReference()).size());
357357
}

0 commit comments

Comments
 (0)