Tal Nisan has uploaded a new change for review. Change subject: core: Consolidated similar validations in add/update storage connection CDA ......................................................................
core: Consolidated similar validations in add/update storage connection CDA AddStorageServerConnection & UpdateStorageServerConnection command both contained a lot of similar validations in the CDA part, all those validations were extracted to the parent class for better readability and easier maintenance Change-Id: Id90cea934e0a9c10c5df435f564530b8658a64bb Bug-Url: https://bugzilla.redhat.com/1129597 Signed-off-by: Tal Nisan <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommand.java 3 files changed, 31 insertions(+), 45 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/32487/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommand.java index fa130b7..77097c5 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommand.java @@ -13,14 +13,12 @@ import org.ovirt.engine.core.common.action.LockProperties.Scope; import org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase; import org.ovirt.engine.core.common.businessentities.StorageServerConnections; -import org.ovirt.engine.core.common.businessentities.StorageType; import org.ovirt.engine.core.common.businessentities.VDSStatus; import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.common.utils.Pair; -import org.ovirt.engine.core.common.validation.NfsMountPointConstraint; import org.ovirt.engine.core.common.validation.group.CreateEntity; import org.ovirt.engine.core.compat.Guid; @@ -79,26 +77,7 @@ return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_CONNECTION_ID_NOT_EMPTY); } - if (paramConnection.getstorage_type() == StorageType.NFS - && !new NfsMountPointConstraint().isValid(paramConnection.getconnection(), null)) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID); - } - if (paramConnection.getstorage_type() == StorageType.POSIXFS - && (StringUtils.isEmpty(paramConnection.getVfsType()))) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE); - } - - if (paramConnection.getstorage_type() == StorageType.ISCSI - && StringUtils.isEmpty(paramConnection.getiqn())) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_IQN); - } - - if (paramConnection.getstorage_type() == StorageType.ISCSI - && !isValidStorageConnectionPort(paramConnection.getport())) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT); - } - - if (checkIsConnectionFieldEmpty(paramConnection)) { + if (!isValidConnection(paramConnection)) { return false; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java index b7fc733..e8203b1 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java @@ -13,8 +13,10 @@ import org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase; import org.ovirt.engine.core.common.businessentities.StorageServerConnections; import org.ovirt.engine.core.common.businessentities.StorageType; +import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.errors.VdcFault; import org.ovirt.engine.core.common.utils.Pair; +import org.ovirt.engine.core.common.validation.NfsMountPointConstraint; import org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.compat.Guid; @@ -72,4 +74,31 @@ protected boolean isValidStorageConnectionPort(String port) { return !StringUtils.isEmpty(port) && StringUtils.isNumeric(port) && Integer.parseInt(port) > 0; } + + protected boolean isValidConnection(StorageServerConnections conn) { + StorageType storageType = conn.getstorage_type(); + + if (storageType == StorageType.NFS && !new NfsMountPointConstraint().isValid(conn.getconnection(), null)) { + return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID); + } + + if (storageType == StorageType.POSIXFS && (StringUtils.isEmpty(conn.getVfsType()))) { + return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE); + } + + if (storageType == StorageType.ISCSI) { + if (StringUtils.isEmpty(conn.getiqn())) { + return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_IQN); + } + if (!isValidStorageConnectionPort(conn.getport())) { + return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT); + } + } + + if (checkIsConnectionFieldEmpty(conn)) { + return false; + } + + return true; + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommand.java index 38a8783..9975f38 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommand.java @@ -26,7 +26,6 @@ import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.common.utils.Pair; -import org.ovirt.engine.core.common.validation.NfsMountPointConstraint; import org.ovirt.engine.core.common.vdscommands.GetStorageDomainStatsVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; @@ -60,28 +59,7 @@ return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_CONNECTION_UNSUPPORTED_ACTION_FOR_STORAGE_TYPE); } - // Check if the NFS path has a valid format - if (newConnectionDetails.getstorage_type() == StorageType.NFS - && !new NfsMountPointConstraint().isValid(newConnectionDetails.getconnection(), null)) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID); - } - - if (newConnectionDetails.getstorage_type() == StorageType.POSIXFS - && (StringUtils.isEmpty(newConnectionDetails.getVfsType()))) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE); - } - - if (newConnectionDetails.getstorage_type() == StorageType.ISCSI - && StringUtils.isEmpty(newConnectionDetails.getiqn())) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_IQN); - } - - if (newConnectionDetails.getstorage_type() == StorageType.ISCSI - && !isValidStorageConnectionPort(newConnectionDetails.getport())) { - return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT); - } - - if (checkIsConnectionFieldEmpty(newConnectionDetails)) { + if (!isValidConnection(newConnectionDetails)) { return false; } -- To view, visit http://gerrit.ovirt.org/32487 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id90cea934e0a9c10c5df435f564530b8658a64bb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Tal Nisan <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
