-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(engine): support completion condition for multi-instance #8321
Conversation
each parent execution of the created executions for each instance will have following variables:
|
Hi @saig0 , I've implemented the first version. Can you review it and give me some suggestions? :) |
7babee6
to
2e2745f
Compare
@saig0 Sure! I'll have a look. Do you have anything that you think I should be especially aware of regarding this topic? |
2e2745f
to
7853013
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lzgabel Thanks for this contribution. I really like it! 🚀
There is quite a lot to unwrap here because this is a big topic. So as a first step in this review, I'd like to ask you to break the changes down into separate pull requests. We can then discuss each of the topics individually, which will help make the reviews easier and allows you to get the important functionality merged faster.
Specifically, it seems you're adding 2 features at once:
- transformation and evaluation of the
completionCondition
expression to terminate other instances of the multi instance and complete the multi instance when the condition is met (AKA completion condition for multi-instance) - introduction of
nrOfCompletedElementInstances
andnrOfElementInstances
as new local variables of a multi instance body, so these can be used in expressions (i.e. mainly for the completion condition expression, but they are also available to others)
In my opinion, these features should be developed independently. Therefore, let's focus this review on the main feature. Please open a new issue for the introduction of nrOfCompletedElementInstances
and nrOfElementInstances
as new local variables of a multi instance body. We should discuss whether that is the best solution, since it might break existing processes of other Zeebe users.
First, please remove the changes related to the nrOfCompletedElementInstances
and nrOfElementInstances
variables from this pull request.
Second, please add some test cases to MultiInstanceActivityTest.java to show that the logic works. If you struggle with this, please reach out so I can help.
Third, please make sure that an incident is created when the completion condition fails to evaluate to a boolean.
If you have any questions, please reach out. I'm happy to help. There's great potential in the changes you've provided here. Thanks again for working on this 🙇
7853013
to
7430c0d
Compare
Hi @korthout, I've removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! Thanks for the fast changes @lzgabel 🚀
When I run mvn test -pl :zeebe-workflow-engine
, I see some failing tests. I think this is mainly because of the changes to the unrelated processors:
- SubProcessProcessor
- CallActivityProcessor
- ProcessMessageSubscriptionCorrelateProcessor
- JobCompleteProcessor
I think that these don't require any changes. Instead, I would move the logic to terminate the child instances entirely to the responsibility of the MultiInstanceBodyProcessor.
Currently, in the MultiInstanceBodyProcessor you check that the completion condition is met (in the afterExecutionPathCompleted
method which is executed for each completed child instance). I agree with that, but when that happens, we should not immediately complete the multi-instance. Instead, it should start terminating all the active child instances (by writing the TERMINATE_ELEMENT
commands for them), which will asynchronously start terminating those tasks (and as a consequence cancel their respective jobs). Note, this also means you don't have to introduce a new JobIntent.TERMINATED, we already use CANCELLED for this same concept.
For each child instance that has completed its termination, the onChildTerminated
method of the MultiInstanceBodyProcessor will be called. There we should check, whether there are still any child instances active, or that this was the last one to terminate.
As soon as all have terminated we can either:
- terminate the multi-instance, if the intent of the multi-instance body is TERMINATING (this is the case if we were currently trying to terminate the multi-instance, and so all of its children were actively trying to terminate, this is simply what the current implementation does)
- complete the multi-instance, because the only other reason why the children could terminate is in response to the completion condition having met
Please give this strategy a try and let me know if you have any questions.
...st/java/io/camunda/zeebe/engine/processing/bpmn/multiinstance/MultiInstanceActivityTest.java
Outdated
Show resolved
Hide resolved
7430c0d
to
4e77ea0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 I'm so impressed with how fast you managed to tackle my comments. This is a difficult topic to implement and you're doing amazing. Your code has also improved massively and it was a joy to read and review.
For this review round, please add new commits for the changes instead of rebasing/squashing/amending, so I can review the changes independently.
I have a couple remarks, but we're already nearing the end.
🔧 Please also add a validation to ZeebeRuntimeValidators
for the completion condition expression. This also requires a test case in ZeebeRuntimeValidationTest
EDIT: Also, it's my weekend. I'll stop for now and have another look on Monday 👍
.../main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
...st/java/io/camunda/zeebe/engine/processing/bpmn/multiinstance/MultiInstanceActivityTest.java
Outdated
Show resolved
Hide resolved
...st/java/io/camunda/zeebe/engine/processing/bpmn/multiinstance/MultiInstanceActivityTest.java
Outdated
Show resolved
Hide resolved
Hi @korthout , I've fixed all review comments, please check this out. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @lzgabel! I think you're almost there 🏁
I only have a few remarks and changes to request. Please have another look.
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
engine/src/test/java/io/camunda/zeebe/engine/processing/incident/MultiInstanceIncidentTest.java
Outdated
Show resolved
Hide resolved
Hi @korthout , thank you very much for your patience in correcting my problems, i've fixed all comments, please check this out, thanks. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @lzgabel. It looks great! Just one last thing 🤞
🔧 In addition to my last comment, please squash your changes. Feel free to turn it into 1 commit or to split it up in to several if you feel that makes more sense. Goal should be that future readers of the code can find why specific changes were made, so please provide a clear commit message.
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
4146448
to
c1bd0eb
Compare
Hi @korthout , I've squashed this changes, please check it. :) |
c1bd0eb
to
4465982
Compare
Hi @korthout , I'm very sorry. I lost a commit during squash this changes. I'll deal with it later. 🙇 |
4465982
to
c1bd0eb
Compare
Hi @lzgabel Sorry for the long wait. 🙇 I'm currently running some manual tests and checking whether all my assumptions were correct. For example, Operate should be able to show the terminated children and completed multi-instance element. However, during testing I ran into the following issue: I created a process with a multi-instance element: <bpmn:multiInstanceLoopCharacteristics isSequential="true">
<bpmn:extensionElements>
<zeebe:loopCharacteristics inputCollection="= [1,2,3,4,5]" inputElement="index" />
</bpmn:extensionElements>
<bpmn:completionCondition>= index = value</bpmn:completionCondition>
</bpmn:multiInstanceLoopCharacteristics> It expects that the
❓ The reason for this is that we evaluate the expression at the scope of the multi-instance body, while the inputElement 🔧 In the meantime, I have another question for you: would you be willing to write the documentation for this topic? This topic should be described in some detail in the reference documentation (probably on this page). I've already opened an issue for it here. If you're willing, please have a look. |
I will follow up and take a look at this problem.
Yes, my pleasure! |
Hi @korthout, I'm currently running some manual tests through the for As required by the specification:
This brings another question: The variables were also removed when the child instance completed( in the
|
Thanks @lzgabel for looking into this. 👍 And sorry for the late reply. I've also dug into it and for now the topic is still under discussion by the team. We don't yet know what is the best solution. However, at this time we think that evaluating at the child instance is likely better, as it provides access to many more variables. If you're open to continue working on this, please have a go at it. If not, please let me know so I can have a look. It's fine by me either way, I'm already so thankful for your contribution.🎖️ If you do want to try this, please create new commits so we can always return to the current implementation. The way to approach this change is to only evaluate the completion condition expression in the If that works, then you'll also have to do this for As always, please let me know if there's anything I can help with. 🙇 |
@oleschoenburg Pointed me to a paragraph in the spec that seems to indicate that the completion condition expression has access to the inputDataItem and thus evaluates at the child instance scope. 💯
|
Hi @korthout , I've fixed the completion condition expression be evaluated at the scope of the child instance problem, please check this out. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! 👏
Please have a look at my comments
...io/camunda/zeebe/engine/processing/deployment/model/element/ExecutableMultiInstanceBody.java
Outdated
Show resolved
Hide resolved
...st/java/io/camunda/zeebe/engine/processing/bpmn/multiinstance/MultiInstanceActivityTest.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java
Outdated
Show resolved
Hide resolved
Hi @korthout , I've fixed all review comments, please check this out. 🙇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @lzgabel.
There's just some final clean up left I think.
.../main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java
Outdated
Show resolved
Hide resolved
.../main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java
Outdated
Show resolved
Hide resolved
Thanks @lzgabel. I'm going to run the CI on this code and manually test it out a bit again. This may again take some time. Sorry about that. I do think this is it though🤞 |
@lzgabel Can you please rebase/squash the commits again? |
7fee938
to
09e6ecd
Compare
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lzgabel Seems there's a small problem leading to failing tests. Please have a look
.../main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java
Outdated
Show resolved
Hide resolved
09e6ecd
to
a58d20c
Compare
@lzgabel Please rebase your changes on top of |
a58d20c
to
00d9cb3
Compare
Hi @korthout, Sorry for the long wait. I just resolved a code conflict.🙇 |
I've just finished manually testing the operability with Operate on Camunda Cloud SaaS and it looks okay with some minor mistakes:
Sequential multi-instanceCollection of 5 elements, completed after the second iteration
Here's the same page after refresh: Parallel multi-instanceCollection of 5 elements, completed after the first and second instances were completed.
Here's the same page after refresh:
@lzgabel There's not really much for you to about this. I'll discuss with the team to decide whether we can afford these minor bugs when this feature is used in combination with Operate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a go from the team on this feature. So: LGTM 🎖️
Thanks again for this great contribution @lzgabel. This is a really cool feature and it was a pleasure to review this. 🙇
🏆 I recommend that you have a look at our Camunda Champions program and apply for it. I'd be happy to set up a personal call for you with our Community Manager to answer any questions you may have about it. Would you be interested in that?
Lastly, let's get this merged 🎉
bors merge
Build succeeded: |
Hi @korthout , I'm honored to be able to contribute to the construction of the community.💪 Thank you for patiently reviewing my code and giving me many suggestions to deal with problems better.
Yes, I'm very interested. I'll apply to join later. ❤️ |
I'll DM you on Slack to follow up on this. |
Description
Support completion condition expression for multi-instance.
Multi-instance loop-characteristics with a
<completionCondition>
are now used by Zeebe.Zeebe expects the completion condition to be a FEEL-expression that evaluates to a
boolean
.Processes that contain an unparsable completion condition are rejected.
The completion condition expression is evaluated each time an instance of a multi-instance element completes.
The expression is expected to evaluate to a boolean, if it doesn't an incident is raised.
The expression is evaluated at the scope of the instance element, not at the scope of the multi-instance element.
If it evaluates to
false
, the normal completion behavior of the multi-instance body is used.If it evaluates to
true
, any still active child instances of the multi-instance are terminated and the multi-instance element is completed.Related issues
closes #5439
Definition of Done
Not all items need to be done depending on the issue and the pull request.
Code changes:
backport stable/0.25
) to the PR, in case that fails you need to create backports manually.Testing:
Documentation: