Tal Nisan has posted comments on this change.

Change subject: core: Change CommandBase validate method to accept multiple 
results
......................................................................


Patch Set 1: (4 inline comments)

How come we are losing short circuit? In the for loop we use an early return on 
the first failure, exactly the same as short circuit a&&b

....................................................
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java
Line 142: 
Line 143:         if (returnValue && vm != null) {
Line 144:             storage_pool sp = getStoragePool(); // Note this is done 
according to the VM's spId.
Line 145:             returnValue =
Line 146:                     validate(new StoragePoolValidator(sp).isUp()) &&
The two calls are because the flow here do one validate, checks 2 boolean 
values and then do another 3 validates, I didn't want to unify all 4 validates 
in case that the order matters and the tests are dependant on one another
Line 147:                             isStoragePoolMatching(vm) &&
Line 148:                             
performImagesChecks(vm.getStoragePoolId()) &&
Line 149:                             
validate(getSnapshotValidator().vmNotDuringSnapshot(vm.getId()),
Line 150:                                     
getSnapshotValidator().vmNotInPreview(vm.getId()),


Line 147:                             isStoragePoolMatching(vm) &&
Line 148:                             
performImagesChecks(vm.getStoragePoolId()) &&
Line 149:                             
validate(getSnapshotValidator().vmNotDuringSnapshot(vm.getId()),
Line 150:                                     
getSnapshotValidator().vmNotInPreview(vm.getId()),
Line 151:                                     new 
VmValidator(vm).vmNotLocked());
Where do you see that? You have the first validate, if it fails we don't 
continue, then the booleans and the another validate..
Line 152:         }
Line 153: 
Line 154:         return returnValue;
Line 155:     }


....................................................
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
Line 1499:      * @param validationResults
Line 1500:      *            The validation results from the inline call to 
validate, should not be <code>null</code>.
Line 1501:      * @return <code>true</code> if the validations were successful, 
and <code>false</code> if one or more wasn't.
Line 1502:      */
Line 1503:     protected boolean validate(ValidationResult... 
validationResults) {
Matter of style I guess, I rather in that case to not take the overhead of 
creating a Collection
Line 1504:         for (ValidationResult validationResult : validationResults) {
Line 1505:             if (!validationResult.isValid()) {
Line 1506:                 addCanDoActionMessage(validationResult.getMessage());
Line 1507:                 if (validationResult.getVariableReplacements() != 
null) {


Line 1508:                     for (String variableReplacement : 
validationResult.getVariableReplacements()) {
Line 1509:                         addCanDoActionMessage(variableReplacement);
Line 1510:                     }
Line 1511:                 }
Line 1512:                 return false;
How are we getting multiple results? We return false on the first failure thus 
breaking the for loop..
Line 1513:             }
Line 1514:         }
Line 1515:         return true;
Line 1516:     }


--
To view, visit http://gerrit.ovirt.org/11557
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I64a18ec0e6c677192dbd86bf0b38de46e539d138
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tal Nisan <tni...@redhat.com>
Gerrit-Reviewer: Alissa Bonas <abo...@redhat.com>
Gerrit-Reviewer: Allon Mureinik <amure...@redhat.com>
Gerrit-Reviewer: Ayal Baron <aba...@redhat.com>
Gerrit-Reviewer: Liron Aravot <lara...@redhat.com>
Gerrit-Reviewer: Maor Lipchuk <mlipc...@redhat.com>
Gerrit-Reviewer: Tal Nisan <tni...@redhat.com>
Gerrit-Reviewer: Yair Zaslavsky <yzasl...@redhat.com>
Gerrit-Reviewer: liron aravot <liron.ara...@gmail.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to