Skip to content
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

feature: add saga state machine Java stream builder support #5849

Merged
merged 10 commits into from
Oct 26, 2023

Conversation

ptyin
Copy link
Member

@ptyin ptyin commented Sep 15, 2023

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

Add APIs for saga state machine orchestration at the Java language level.

Why

The current solution for Seata Saga statemachine orchestration employs a scheme in which state machine definitions are declared in JSON DSL and parsed by the StateMachineParser to obtain a StateMachine.

While the JSON-based orchestration solution has high portability and decoupling from business code, it also has the following disadvantages:

  1. High learning curve: Declarative orchestration requires a long time to learn or refer to documentation due to the large number of configurable properties.
  2. Limited flexibility: Declarative orchestration is still less flexible than code when defining structures and cannot meet specific requirements.
  3. Slightly slower performance: Since declarative languages are interpretation-executed, there is a certain performance loss when processing large definition files. If developers use the JSON file generated by the assistive design tool, the framework needs to convert the Designer JSON to standard JSON before interpretation.

To address the above issues, a streaming programming approach can be considered for Saga orchestration as a complementary solution to JSON DSL.

Example

StateMachine builtStateMachine = stateMachineBuilder
        .withName("simpleTestStateMachine")
        .withComment("测试状态机定义")
        .withStartState("FirstState")
        .withVersion("0.0.1")
        .withStates()
            .build(ServiceTaskStateBuilder.class)
                .withName("FirstState")
                .withServiceName("is.seata.saga.DemoService")
                .withServiceMethod("foo")
                .withPersist(false)
                .withNext("ScriptState")
                .and()
            .build(ChoiceStateBuilder.class)
                .withName("ChoiceState")
                .withChoice("foo == 1", "FirstMatchState")
                .withChoice("foo == 2", "SecondMatchState")
                .withDefault("FailState")
                .and()
            // ..., A full example can be referred to StateBuilderTests#testBuildStateMachine
            .configure()
        .build();

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

This pr is based on #5847 considering Fork and Join states . Plz merge it before this pr merged. The commits focus on this branch starts from the commit 76b2a51.

@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

❗ No coverage uploaded for pull request base (summer-code_sagas@cc89241). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 348a944 differs from pull request most recent head d369ddd. Consider uploading reports for the commit d369ddd to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                  @@
##             summer-code_sagas    #5849   +/-   ##
====================================================
  Coverage                     ?   49.19%           
  Complexity                   ?     4566           
====================================================
  Files                        ?      845           
  Lines                        ?    28999           
  Branches                     ?     3597           
====================================================
  Hits                         ?    14267           
  Misses                       ?    13258           
  Partials                     ?     1474           

@ptyin ptyin force-pushed the feature/saga-builder branch from f41995d to 348a944 Compare September 20, 2023 08:23
@slievrly slievrly added this to the Summer Code 2023 milestone Oct 19, 2023
@ptyin ptyin changed the base branch from 2.x to summer-code_sagas October 21, 2023 00:34
@wt-better
Copy link
Contributor

LGTM

@ptyin ptyin force-pushed the feature/saga-builder branch from 32ed087 to d369ddd Compare October 26, 2023 08:22
@wt-better wt-better merged commit ba2e54d into apache:summer-code_sagas Oct 26, 2023
@wt-better wt-better added the type: feature Category issues or prs related to feature request. label Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
summer2023 type: feature Category issues or prs related to feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants