-
Notifications
You must be signed in to change notification settings - Fork 221
Add Saga pattern support in java-sdk #956
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
90e6ba0
first versoin of saga pattern support based on workflow
skyao 221438b
add unit test for SagaConfiguration to improve code coverage
skyao 18c61ac
Merge branch 'master' into saga
artursouza f0ab98d
save draft version before refactory to not hide saga.registerCompensa…
skyao 551ce5a
remove auto register compensation activity on callActivity()
skyao ff1b569
update branch
skyao a9a0712
Merge branch 'master' into saga-in-workflow
skyao fb9470a
rollback COVEREDRATIO to 80%
skyao 5d5ad6a
improve code implementation accordings to proposal
skyao f6231ba
Merge branch 'master' into saga-in-workflow
skyao d5980e5
Merge branch 'dapr:master' into saga-in-workflow
skyao 490e9ff
use ctx.allOf() to do compensation in parallel
skyao 34f9ab3
Merge branch 'saga-in-workflow' of github.com:skyao/java-sdk into sag…
skyao 3db12a4
Merge branch 'master' into saga-in-workflow
mukundansundar e63996b
Merge branch 'master' into saga-in-workflow
artursouza c4ade6e
Merge branch 'master' into saga-in-workflow
skyao f8ca83a
add code to handle ContinueAsNewInterruption exception for saga compe…
skyao 5dbe494
Merge remote-tracking branch 'upstream/master' into saga-in-workflow
skyao 1872ba4
add saga context for saga related method
skyao 59e76f1
fix for checkstyle
skyao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
sdk-workflows/src/main/java/io/dapr/workflows/saga/CompensatationInformation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2023 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.workflows.saga; | ||
|
||
import com.microsoft.durabletask.TaskOptions; | ||
|
||
/** | ||
* Information for a compensation activity. | ||
*/ | ||
class CompensatationInformation { | ||
private final String compensatationActivityClassName; | ||
private final Object compensatationActivityInput; | ||
private final TaskOptions taskOptions; | ||
|
||
/** | ||
* Constructor for a compensation information. | ||
* | ||
* @param compensatationActivityClassName Class name of the activity to do | ||
* compensatation. | ||
* @param compensatationActivityInput Input of the activity to do | ||
* compensatation. | ||
* @param taskOptions task options to set retry strategy | ||
*/ | ||
public CompensatationInformation(String compensatationActivityClassName, | ||
Object compensatationActivityInput, TaskOptions taskOptions) { | ||
this.compensatationActivityClassName = compensatationActivityClassName; | ||
this.compensatationActivityInput = compensatationActivityInput; | ||
this.taskOptions = taskOptions; | ||
} | ||
|
||
/** | ||
* Gets the class name of the activity. | ||
* | ||
* @return the class name of the activity. | ||
*/ | ||
public String getCompensatationActivityClassName() { | ||
return compensatationActivityClassName; | ||
} | ||
|
||
/** | ||
* Gets the input of the activity. | ||
* | ||
* @return the input of the activity. | ||
*/ | ||
public Object getCompensatationActivityInput() { | ||
return compensatationActivityInput; | ||
} | ||
|
||
/** | ||
* get task options. | ||
* | ||
* @return task options, null if not set | ||
*/ | ||
public TaskOptions getTaskOptions() { | ||
return taskOptions; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
sdk-workflows/src/main/java/io/dapr/workflows/saga/DaprSagaContextImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2023 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.workflows.saga; | ||
|
||
import io.dapr.workflows.WorkflowContext; | ||
|
||
/** | ||
* Dapr Saga Context implementation. | ||
*/ | ||
public class DaprSagaContextImpl implements SagaContext { | ||
|
||
private final Saga saga; | ||
private final WorkflowContext workflowContext; | ||
|
||
/** | ||
* Constructor to build up instance. | ||
* | ||
* @param saga Saga instance. | ||
* @param workflowContext Workflow context. | ||
* @throws IllegalArgumentException if saga or workflowContext is null. | ||
*/ | ||
public DaprSagaContextImpl(Saga saga, WorkflowContext workflowContext) { | ||
if (saga == null) { | ||
throw new IllegalArgumentException("Saga should not be null"); | ||
} | ||
if (workflowContext == null) { | ||
throw new IllegalArgumentException("workflowContext should not be null"); | ||
} | ||
|
||
this.saga = saga; | ||
this.workflowContext = workflowContext; | ||
} | ||
|
||
@Override | ||
public void registerCompensation(String activityClassName, Object activityInput) { | ||
this.saga.registerCompensation(activityClassName, activityInput); | ||
} | ||
|
||
@Override | ||
public void compensate() { | ||
this.saga.compensate(workflowContext); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.