Allon Mureinik has uploaded a new change for review. Change subject: core: Cleanup AbstractDisk.isDiskCanBeAddedToVm ......................................................................
core: Cleanup AbstractDisk.isDiskCanBeAddedToVm Extracted the updateDisksFromDb() method form isDiskCanBeAddedToVm() method for better encapsulation, and employed the early-return idiom for better readability. Relates-To: https://bugzilla.redhat.com/854964 Change-Id: If7e5aafada5012ae06c7105bafa5538026e42b1b Signed-off-by: Allon Mureinik <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java 3 files changed, 13 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/96/12896/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java index 0e48e19..bada7dd 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AbstractDiskVmCommand.java @@ -10,16 +10,16 @@ import org.ovirt.engine.core.common.action.VmDiskOperationParameterBase; import org.ovirt.engine.core.common.businessentities.Disk; import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType; -import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.businessentities.DiskInterface; import org.ovirt.engine.core.common.businessentities.LUNs; import org.ovirt.engine.core.common.businessentities.LunDisk; +import org.ovirt.engine.core.common.businessentities.StorageServerConnections; import org.ovirt.engine.core.common.businessentities.StorageType; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VMStatus; import org.ovirt.engine.core.common.businessentities.VmDevice; import org.ovirt.engine.core.common.businessentities.VolumeFormat; -import org.ovirt.engine.core.common.businessentities.StorageServerConnections; +import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VdcBLLException; @@ -111,20 +111,17 @@ } protected boolean isDiskCanBeAddedToVm(Disk diskInfo) { - boolean returnValue = true; - updateDisksFromDb(); - if (returnValue && diskInfo.isBoot()) { + if (diskInfo.isBoot()) { for (Disk disk : getVm().getDiskMap().values()) { if (disk.isBoot()) { - returnValue = false; addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_DISK_BOOT_IN_USE); getReturnValue().getCanDoActionMessages().add( String.format("$DiskName %1$s", disk.getDiskAlias())); - break; + return false; } } } - return returnValue; + return true; } /** Updates the VM's disks from the database */ @@ -189,6 +186,7 @@ return getDbFacade().getImageDao(); } + @Override protected DiskDao getDiskDao() { return getDbFacade().getDiskDao(); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java index 12a9072..634139c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java @@ -93,6 +93,7 @@ VM vm = getVm(); if (vm != null) { + updateDisksFromDb(); // if user sent drive check that its not in use if (!isDiskCanBeAddedToVm(getParameters().getDiskInfo()) || !isDiskPassPciAndIdeLimit(getParameters().getDiskInfo())) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java index 39dbb96..5e04f0a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java @@ -68,8 +68,12 @@ return false; } - if (!isVmExist() || !isVmUpOrDown() || !isDiskCanBeAddedToVm(disk) - || !isDiskPassPciAndIdeLimit(disk)) { + if (!isVmExist() || !isVmUpOrDown()) { + return false; + } + + updateDisksFromDb(); + if (!isDiskCanBeAddedToVm(disk) || !isDiskPassPciAndIdeLimit(disk)) { return false; } -- To view, visit http://gerrit.ovirt.org/12896 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If7e5aafada5012ae06c7105bafa5538026e42b1b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Allon Mureinik <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
