nvazquez commented on code in PR #14389:
URL: https://github.com/apache/cloudstack/pull/14389#discussion_r4296748950
##########
server/src/main/java/org/apache/cloudstack/storage/volume/VolumeImportUnmanageManagerImpl.java:
##########
@@ -232,9 +241,11 @@ public VolumeResponse importVolume(ImportVolumeCmd cmd) {
}
}
- protected VolumeOnStorageTO getVolumeOnStorageAndCheck(StoragePoolVO pool,
String volumePath) {
+ protected VolumeOnStorageTO getVolumeOnStorageAndCheck(StoragePoolVO pool,
String volumePath, boolean forUnmanage) {
// send a command to hypervisor to check
- List<VolumeOnStorageTO> volumes = listVolumesForImportInternal(pool,
volumePath, null);
+ List<VolumeOnStorageTO> volumes = forUnmanage
+ ? listVolumesForImportInternal(pool, volumePath, null, true)
+ : listVolumesForImportInternal(pool, volumePath, null);
Review Comment:
In both cases the method `listVolumesForImportInternal` will be invoked but
with different values for `forUnmanage`. Would it make sense to simplify this
to:
```suggestion
List<VolumeOnStorageTO> volumes = listVolumesForImportInternal(pool,
volumePath, null, forUnmanage)
```
##########
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java:
##########
@@ -2976,27 +2997,51 @@ private UserVm importKvmVirtualMachineFromDisk(final
ImportSource importSource,
Map<Volume, StoragePool> storage = dest.getStorageForDisks();
Volume volume = volumeDao.findById(diskProfile.getVolumeId());
StoragePool storagePool = storage.get(volume);
- CheckVolumeCommand checkVolumeCommand = new CheckVolumeCommand();
- checkVolumeCommand.setSrcFile(diskPath);
- StorageFilerTO storageTO = new StorageFilerTO(storagePool);
- checkVolumeCommand.setStorageFilerTO(storageTO);
- Answer answer = agentManager.easySend(dest.getHost().getId(),
checkVolumeCommand);
- if (!(answer instanceof CheckVolumeAnswer)) {
- cleanupFailedImportVM(userVm);
- throw new CloudRuntimeException("Disk not found or is
invalid");
- }
- CheckVolumeAnswer checkVolumeAnswer = (CheckVolumeAnswer) answer;
- try {
- checkVolume(checkVolumeAnswer.getVolumeDetails());
- } catch (CloudRuntimeException e) {
- cleanupFailedImportVM(userVm);
- throw e;
- }
- if (!checkVolumeAnswer.getResult()) {
- cleanupFailedImportVM(userVm);
- throw new CloudRuntimeException("Disk not found or is
invalid");
+
+ Map<VolumeOnStorageTO.Detail, String> volumeDetails;
+ long volumeSize;
+ List<VolumeOnStorageTO> volumesFromDriver =
listVolumesForImportFromDriver(storagePool, diskPath);
+ if (volumesFromDriver != null) {
+ // The storage driver can enumerate its own volumes (e.g.
StorPool, via its
+ // management API), so there is no need to reach the host
agent just to read size.
+ if (CollectionUtils.isEmpty(volumesFromDriver)) {
+ cleanupFailedImportVM(userVm);
+ throw new CloudRuntimeException("Disk not found or is
invalid");
+ }
+ VolumeOnStorageTO volumeOnStorage = volumesFromDriver.get(0);
+ volumeDetails = volumeOnStorage.getDetails();
+ try {
+ checkVolume(volumeDetails);
+ } catch (CloudRuntimeException e) {
+ cleanupFailedImportVM(userVm);
+ throw e;
+ }
+ volumeSize = volumeOnStorage.getVirtualSize();
+ } else {
+ CheckVolumeCommand checkVolumeCommand = new
CheckVolumeCommand();
+ checkVolumeCommand.setSrcFile(diskPath);
+ StorageFilerTO storageTO = new StorageFilerTO(storagePool);
+ checkVolumeCommand.setStorageFilerTO(storageTO);
+ Answer answer = agentManager.easySend(dest.getHost().getId(),
checkVolumeCommand);
+ if (!(answer instanceof CheckVolumeAnswer)) {
+ cleanupFailedImportVM(userVm);
+ throw new CloudRuntimeException("Disk not found or is
invalid");
+ }
+ CheckVolumeAnswer checkVolumeAnswer = (CheckVolumeAnswer)
answer;
+ volumeDetails = checkVolumeAnswer.getVolumeDetails();
+ try {
+ checkVolume(volumeDetails);
+ } catch (CloudRuntimeException e) {
+ cleanupFailedImportVM(userVm);
+ throw e;
+ }
+ if (!checkVolumeAnswer.getResult()) {
+ cleanupFailedImportVM(userVm);
+ throw new CloudRuntimeException("Disk not found or is
invalid");
+ }
+ volumeSize = checkVolumeAnswer.getSize();
Review Comment:
Can this logic be extracted to a method that retrieves a `Pair` of volume
details and volume size?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]