Bug 1106464

Summary: if getReturnValue().setSucceeded(true); is called before exception is thrown command is presented as successful.
Product: Red Hat Enterprise Virtualization Manager Reporter: Martin Mucha <mmucha>
Component: ovirt-engineAssignee: Ravi Nori <rnori>
Status: CLOSED CURRENTRELEASE QA Contact: Martin Mucha <mmucha>
Severity: high Docs Contact:
Priority: unspecified    
Version: 3.5.0CC: gklein, iheim, lpeer, michal.skrivanek, oourfali, pstehlik, rbalakri, Rhev-m-bugs, rnori, sherold, yeylon, yzaslavs
Target Milestone: ---Keywords: CodeChange
Target Release: 3.5.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: infra
Fixed In Version: ovirt-engine-3.5.0_beta Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-02-17 17:07:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1142923, 1156165    

Description Martin Mucha 2014-06-09 12:15:16 UTC
Description of problem:

if any Command calls:
getReturnValue().setSucceeded(true);
and after that follows some logic, then if this logic fails, outcome of this command will be presented as successful. Compensation/rollbacks etc. are called, but data sent to user are wrong.

example: 
if commands ends with:

if (1 == 1) throw new RuntimeException();
getReturnValue().setSucceeded(true);

rest will return:

<fault>
    <reason>Operation Failed</reason>
    <detail>[Internal Engine Error]</detail>
</fault>

but if command would be like this:

getReturnValue().setSucceeded(true);
if (1 == 1) throw new RuntimeException();


result will be:

<action>
    <status>
        <state>complete</state>
    </status>
</action>


How reproducible:
100%


Actual results:
see above.

Expected results:
command failed in both scenarios and returned data should reflect that.

Comment 1 Oved Ourfali 2014-06-12 06:27:30 UTC
I think that it should be the responsibility of the command to call setSucceeded(true) only once nothing is left to do... in my opinion, commands that do further logic after that assumes that this logic is insignificant for the successful completion of the command.

Yair/Ravi - thoughts?

Comment 2 Martin Mucha 2014-06-12 07:35:45 UTC
I think, on contrary, that if somewhere there need not to be some convention(setSucceed must be last call of command) or faith in assumptions("insignificant" code will not fail), there should not be such things.

Exception can occur unexpectedly, and so does db rollback. Flagging each command from which exception 'leaks' as unsuccessful will spell more robust architecture — user should not get info "OK" if it's not OK, and we should not rely on each command to behave as expected to provide user right response. It's command 'invoker' responsibility.

Comment 3 Yair Zaslavsky 2014-06-12 08:01:36 UTC
I agree with Martin.
Bare in mind that execute is run from within CommandBase, so I think we should handle it in CommandBase.

Comment 4 Petr Beňas 2014-10-21 15:37:35 UTC
Code change...

Comment 5 Eyal Edri 2015-02-17 17:07:32 UTC
rhev 3.5.0 was released. closing.