Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1077305

Summary: Knowledge Store REST API POST/DELETE operations are documented as being asynchronous, but are synchronous
Product: [Retired] JBoss BRMS Platform 6 Reporter: Marco Rietveld <mrietvel>
Component: Business CentralAssignee: Shelly McGowan <smcgowan>
Status: CLOSED EOL QA Contact: Ivo Bek <ibek>
Severity: medium Docs Contact:
Priority: high    
Version: 6.0.0CC: kverlaen, mbaluch, smcgowan
Target Milestone: ER2   
Target Release: 6.1.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-27 19:42:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Stacktrace showing problems in errai/uberfire/guvnor none

Description Marco Rietveld 2014-03-17 16:48:15 UTC
Description of problem:

Many of the drools-wb-rest REST operations are documented as being asynchronous although they are
synchronous. 

For the documentation where they are described as being asynchronous, see here:
http://documentation-devel.engineering.redhat.com/site/documentation/en-US/Red_Hat_JBoss_BRMS/6/html-single/User_Guide/index.html#chap-REST_API

For proof that the operations are asynchronous, see this stack trace (associated with BZ 1074989: https://bugzilla.redhat.com/attachment.cgi?id=874325

In it, we see that a (POST) request is done to the ProjectResource class, which fails because of methods called in the JobRequestObserver class (towards the top of the stack). 

The stack trace shows that code executed by the JobRequestObserver class happens in the same thread as the REST request processing in the ProjectResource class. Code executed by the JobRequestObserver should always happen in a separate thread than the REST request code. 


Version-Release number of selected component (if applicable):

6.0.0, 6.0.1

How reproducible:

Always

Steps to Reproduce:
1. Do a POST or DELETE request to the Knowledge Store REST API that should not succeed (See BZ
1074989 for an example)

Actual results:

The REST call will return with an HTTP status above 300. 

Expected results:

The POST and DELETE operations should always return a 202 status, which means that the "request has been accepted for processing, but the processing has not been completed" per RFC 2616. 

When the request fails, that should only be apparent via the results of a GET request to the /job/{jobId} REST call. 


Additional info:

I actually knew about this in November, but dropped the ball.

Comment 2 Marco Rietveld 2014-03-17 16:54:49 UTC
The fix for this is already available since I've implemented asynchronous REST operations for the (BPMS) ../rest/deployment* calls. It's just a question of copy/pasting that code and modifying it to for the Knowledge Store (/repositories, etc) REST API.

Comment 3 Marco Rietveld 2014-04-24 13:58:26 UTC
The problem that I increasingly ran into when trying to make these operations is that the underlying components (guvnor modules, uberfire modules) aren't thread-safe or thread-aware. 

In other words, both uberfire and guvnor modules are created with the assumption that all code will run in the same thread and scope as the (REST) request. 


Just to give an idea of the complexity of issues associated with making uberfire and guvnor components thread-safe and thread-aware, see the attached stacktrace. 

The "npe-on-async-uberfire-use-stacktrace.txt" stack trace shows a "Create Project" request being asynchronously executed. The classes in the org.drools.workbench.common.services.rest.async package were developed to asynchronously execute requests. 

The NPE in the stack trace is caused because the guvnor class (ProjectServiceImpl) needs a instance of a (uberfire) class. A @Provider method is called in the Uberfire code, which ends up calling an Errai class (RpcContext). However, the Errai class uses a ThreadLocal variable which would probably normally be set when the (Request/Application) scope is dealt with. For some reason, it's not set in the RequestScope created when the asynchronous (EJB) business method is called to process the "Create Project" request. 

In short, it's probably possible to make the guvnor and uberfire components used by the drools-wb-rest components both thread-safe and thread-aware, but that work lies outside of the scope of this bugzilla, in my opinion. 

For 6.1, at the very least, I'll change the interface so that it behaves as a synchronous REST interface (status 200 returned instead of 202, job status immediately returned, etc.).

Comment 4 Marco Rietveld 2014-04-24 13:59:27 UTC
Created attachment 889287 [details]
Stacktrace showing problems in errai/uberfire/guvnor

Comment 5 Marco Rietveld 2014-04-24 14:04:06 UTC
Btw, my rough estimate of the time required to fix the problems above (in uberfire/guvnor) is somewhere between 2 weeks and 3 months, depending on which problems there are.

Comment 6 Marco Rietveld 2014-05-29 20:57:08 UTC
This has been fixed on master.

Comment 7 Marco Rietveld 2014-09-30 01:02:33 UTC
This has been fixed in 6.2.x.

Comment 8 Ivo Bek 2015-01-05 15:35:36 UTC
Verified in BPMS 6.1.0.ER3

According to comment 3 that: "For 6.1, at the very least, I'll change the interface so that it behaves as a synchronous REST interface (status 200 returned instead of 202, job status immediately returned, etc.)."

The operations return 202 Accepted but I believe it is the right behaviour of the operations.

After all, the real status is in the returned message, for example:

{"jobId":"1420471761248-1","status":"APPROVED","repository":{"name":"NewRepo","description":null,"userName":null,"password":null,"requestType":"new","gitURL":null}}