apache / incubator-kie-kogito-runtimes

Kogito Runtimes - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
http://kogito.kie.org
Apache License 2.0
536 stars 206 forks source link

The kogitobusinesskey process attribute is not propagated to subprocess #3286

Open andleosab opened 10 months ago

andleosab commented 10 months ago

Describe the bug

The kogitobusinesskey process attribute does not get propagated to subprocess from the parent process

Expected behavior

the parent process's business key should be set in its subprocess(es)

Actual behavior

the business key is null:

{ "data": { "ProcessInstances": [ { "id": "236945bc-6363-4eb5-86c4-9e6c2e7246dd", "businessKey": null, "parentProcessInstanceId": "c8b3e3e3-7f6d-47ce-847d-a3fcee26793d", "processId": "subProcess", "processName": "subProcess", "state": "COMPLETED",

How to Reproduce?

to reproduce:

  1. have a process with subprocess
  2. start the process with businesskey included
  3. query the subprocess to check the result

{ ProcessInstances (where: {parentProcessInstanceId: {equal: "c8b3e3e3-7f6d-47ce-847d-a3fcee26793d"}} ) { id, businessKey, parentProcessInstanceId, processId, processName, state } }

Output of uname -a or ver

kogito runtime 1.27.0.Final

Output of java -version

11

GraalVM version (if different from Java)

No response

Kogito version or git rev (or at least Quarkus version if you are using Kogito via Quarkus platform BOM)

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

dekaido commented 6 months ago

Any action on this issue?

ricardozanini commented 6 months ago

There are a few issues we are working on related to this topic. This issue missed my sight, sorry. @fjtirado can you include this in the businessKey issue you're currently working on?

fjtirado commented 6 months ago

@elguardian Wdyt? Should the business key of the parent propagated to the subprocess?

fjtirado commented 6 months ago

@dekaido From my point of view, businessKey is intended to optionally provide a human readable identifier to a given workflow. Therefore, it can be argued that businesskey attribute does not really belong to the subprocess and the steps to associate a subprocess to a process given a businnes key are the ones that you are following, first get the process id given the business key, then use the parent process id to get the subprocesses. So, the question here is, besides providing an easier mapping between all the subprocesses opened by the process associated with that business key, what do you need the business key in the subprocess for? @krisv I think this might also interest you.

dekaido commented 6 months ago

@fjtirado I am with you, I was expecting to use the businessKey as a human readable identifier. Maybe the wording is wrong here, or I have another issue. But I can't find anything in the documentation so I expect functionality to work as it's stated in this article.

If you wanted to start an order process correlated to the business key ORDER-0001, for instance, you would issue a request like this one:

POST /orders?businessKey=ORDER-0001 You would then be able to retrieve the new process instance with the new reference ID:

GET /orders/ORD-0001 You could also delete the process instance by sending an HTTP delete request with the same reference ID:

DELETE /orders/ORD-0001

When I am creating instances with the businessKey set, POST returns success and a new process instance is deployed. But the service does not recognize the businessKey (i.e. ORD-0001) as an identifier for any GET/DELETE/etc request. This is where I am assuming the attribute/field is not being saved to the subprocess/instance.

Edit: the documentation only mentions businessKey in the managment console and dev ui.

fjtirado commented 6 months ago

@dekaido But thats a completely different issue ;) I mean, GET and DELETE using business key is not supported by runtimes API (that expects the process instance id). You can use business key in your data index queries and as header of cloud event to resume a paused workflow. I do not think business key being null for a subprocess is necesarily wrong.

dekaido commented 6 months ago

@fjtirado okay... so the "HTTP request" with the "same reference ID" was a lie? 😞

You could also delete the process instance by sending an HTTP delete request with the same reference ID:

fjtirado commented 6 months ago

@dekaido Not necesarily a lie, this is not supported by runtime API, but might be supported in the gateway API (which migh translate businesskey into process instance id) , which one are you calling?

fjtirado commented 6 months ago

In any case, I think GET and DELETE using business key on runtimes should be addressed with a different issue. Lets keep this one focus on businesskey on subprocess.

elguardian commented 6 months ago

business key should be unique among process instances. so propagate the same business keys is a no go from my point of view. In the past we have a way to generate unique keys. I am not sure whay is the use case for sonata flow for business keys but in the case of bpmn2 requires to be unique. @fjtirado ^^

elguardian commented 6 months ago

And option that was in the past was a BusinesskeyFactory to be used and plug anytime a subprocess instances was created (CorrelationKeyFactory) in the past.

fjtirado commented 6 months ago

@elguardian I think the scenario is the same both for bpmn and swf, embedded subprocess should have either a unique business key or not business key at all. To be honest, I do not see a use case for embedded subprocess business key, maybe the author of the issue, @andleosab can provide one. CorrelationKeyFactory is still there in the kie api (what was basically imported as it was when the initial fork was done), but also as part of this fork it seems the implementation was removed (I guess following the rational that there is not use case for embedded subprocess business key)

andleosab commented 3 months ago

Hi all, thank you all for looking into this. The use case I have as follows:

  1. Parent process creates a subprocess.
  2. The subprocess uses intermediate message to wait for an external event.
  3. The external application (non-kogito) sends a message (in cloud event format) to Kafka to resume the workflow using kogitobussneskey.
  4. The subprocess resumes.

Here is an example of the event sent by external process:

{ "id": "51e2b192-b4fe-46ab-8923-e506b65b9649", "source": "", "type": "vendorFileLocationMessage", "time": "2023-11-14T14:04:17.298369-08:00", "data": { "location": "s3://bucket/file-832555" }, "specversion": "1.0", "kogitobusinesskey": "Order-12345" }

An external app may not be aware of kogito internal process IDs (An event could be triggered from UI, etc)

Currently I have a work around where I'd use a parent process Id to lookup a subprocess to send the event to the subprocess to resume it. I need to make an extra call or more for it to work. Instead I could use just one call if a parent shares its business key with its subprocesses.

elguardian commented 2 months ago

@andleosab IMO if you are trying to target a process over its ID you are coupling things. You should use common information shared among process instance to communicate among them. You can use correlated messages instead of process intance id.

For instance you can set a variable in the subprocess called orderId and set the variable. You create a correlation key containing the expresion #{order} (taking for granted that order is a process variable) Now for the message you create a correlation key as well to compute the same order.

You don't need anymore the business key.

andleosab commented 2 months ago

@elguardian That's exactly what I am trying to avoid, using any internal IDs. As I mentioned earlier that's just a work around. And I was thinking that the business key could be naturally that common piece of information shared between the process and its subprocesses. I don't see how using correlation key would be any different. Also, if I can get the main process by it business key and then use its process id to get all of its sub-processes, then why not allow to do the same using just a business key and thus saving on additional logic/component(i.e gateway)/etc? That should allow external apps to control the process flow w/o getting into kogito runtime internals.

elguardian commented 2 months ago

@andleosab business key is a subrogate primary key. you query use CTE queries to get the entire subprocess stuff based on parent process instanace id.

gurrierim commented 3 weeks ago

@elguardian for me it's a little ambiguous on how to do this: For instance you can set a variable in the subprocess called orderId and set the variable. You create a correlation key containing the expresion #{order} (taking for granted that order is a process variable) Now for the message you create a correlation key as well to compute the same order.

Could you give me an example with bpmn file ?