Yair Zaslavsky has uploaded a new change for review. Change subject: core: Use VdsValidator in canDoAction of ActivateVds ......................................................................
core: Use VdsValidator in canDoAction of ActivateVds Introduce usage of VdsValidator to ActivateVds (as exists in other commands) Change-Id: Ie9a887de27757cd8ff89c8d68eb916be68d327fd Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsValidator.java 2 files changed, 18 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/49/16649/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java index 45c7207..4fe451c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java @@ -75,13 +75,8 @@ @Override protected boolean canDoAction() { - if (getVds() == null) { - return failCanDoAction(VdcBllMessages.VDS_DOES_NOT_EXIST); - } - if (getVds().getStatus() == VDSStatus.Up) { - return failCanDoAction(VdcBllMessages.VDS_ALREADY_UP); - } - return true; + VdsValidator validator = new VdsValidator(getVds()); + return validate(validator.exist()) && validate(validator.validStatusForActivation()); } @Override diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsValidator.java index ed9f02e..8ac0687 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsValidator.java @@ -1,6 +1,8 @@ package org.ovirt.engine.core.bll; import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.VDSStatus; +import org.ovirt.engine.core.common.errors.VdcBllMessages; /** * Contains methods used to validate VDS status to execute some operation on it @@ -16,12 +18,8 @@ * * @param vds * specified VDS - * @exception IllegalArgumentException if {@code vds} is {@code null} */ public VdsValidator(VDS vds) { - if (vds == null) { - throw new IllegalArgumentException(); - } this.vds = vds; } @@ -48,4 +46,18 @@ return result; } + + public ValidationResult exist() { + if (vds == null) { + return new ValidationResult(VdcBllMessages.VDS_DOES_NOT_EXIST); + } + return ValidationResult.VALID; + } + + public ValidationResult validStatusForActivation() { + if (vds.getStatus().equals(VDSStatus.Up)) { + return new ValidationResult(VdcBllMessages.VDS_ALREADY_UP); + } + return ValidationResult.VALID; + } } -- To view, visit http://gerrit.ovirt.org/16649 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie9a887de27757cd8ff89c8d68eb916be68d327fd Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches