Skip to content

improve: workflow builder naming #2559

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 3 commits into from
Oct 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -94,17 +94,17 @@ public WorkflowBuilder<P> withThrowExceptionFurther(boolean throwExceptionFurthe
return WorkflowBuilder.this.withThrowExceptionFurther(throwExceptionFurther);
}

public WorkflowNodeConfigurationBuilder toDependOn(Set<DependentResource> dependentResources) {
public WorkflowNodeConfigurationBuilder dependsOn(Set<DependentResource> dependentResources) {
for (var dependentResource : dependentResources) {
var dependsOn = getNodeByDependentResource(dependentResource);
currentNode.addDependsOnRelation(dependsOn);
}
return this;
}

public WorkflowNodeConfigurationBuilder toDependOn(DependentResource... dependentResources) {
public WorkflowNodeConfigurationBuilder dependsOn(DependentResource... dependentResources) {
if (dependentResources != null) {
return toDependOn(new HashSet<>(Arrays.asList(dependentResources)));
return dependsOn(new HashSet<>(Arrays.asList(dependentResources)));
}
return this;
}
Original file line number Diff line number Diff line change
@@ -54,9 +54,9 @@ void setup() {
void cleanUpDiamondWorkflow() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dr1).toDependOn(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd3).toDependOn(dr1, dd2)
.addDependentResourceAndConfigure(dr1).dependsOn(dd1)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.addDependentResourceAndConfigure(dd3).dependsOn(dr1, dd2)
.build();

var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -73,9 +73,9 @@ void cleanUpDiamondWorkflow() {
void dontDeleteIfDependentErrored() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd3).toDependOn(dd2)
.addDependentResourceAndConfigure(errorDD).toDependOn(dd2)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.addDependentResourceAndConfigure(dd3).dependsOn(dd2)
.addDependentResourceAndConfigure(errorDD).dependsOn(dd2)
.withThrowExceptionFurther(false)
.build();

@@ -95,7 +95,7 @@ void dontDeleteIfDependentErrored() {
void cleanupConditionTrivialCase() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.withDeletePostcondition(notMetCondition)
.build();

@@ -111,7 +111,7 @@ void cleanupConditionTrivialCase() {
void cleanupConditionMet() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1).withDeletePostcondition(metCondition)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1).withDeletePostcondition(metCondition)
.build();

var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -127,10 +127,10 @@ void cleanupConditionMet() {
void cleanupConditionDiamondWorkflow() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.addDependentResourceAndConfigure(dd3).dependsOn(dd1)
.withDeletePostcondition(notMetCondition)
.addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3)
.build();

var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -164,10 +164,10 @@ void dontDeleteIfGarbageCollected() {
void ifDependentActiveDependentNormallyDeleted() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.addDependentResourceAndConfigure(dd3).dependsOn(dd1)
.withActivationCondition(metCondition)
.addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3)
.build();

var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -184,11 +184,11 @@ void ifDependentActiveDependentNormallyDeleted() {
void ifDependentActiveDeletePostConditionIsChecked() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.addDependentResourceAndConfigure(dd3).dependsOn(dd1)
.withDeletePostcondition(notMetCondition)
.withActivationCondition(metCondition)
.addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3)
.build();

var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -208,10 +208,10 @@ void ifDependentActiveDeletePostConditionIsChecked() {
void ifDependentInactiveDeleteIsNotCalled() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.addDependentResourceAndConfigure(dd3).dependsOn(dd1)
.withActivationCondition(notMetCondition)
.addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3)
.build();

var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -227,11 +227,11 @@ void ifDependentInactiveDeleteIsNotCalled() {
void ifDependentInactiveDeletePostConditionNotChecked() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dd1)
.addDependentResourceAndConfigure(dd2).toDependOn(dd1)
.addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.addDependentResourceAndConfigure(dd2).dependsOn(dd1)
.addDependentResourceAndConfigure(dd3).dependsOn(dd1)
.withDeletePostcondition(notMetCondition)
.withActivationCondition(notMetCondition)
.addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.addDependentResourceAndConfigure(dd4).dependsOn(dd2, dd3)
.build();

var res = workflow.cleanup(new TestCustomResource(), mockContext);
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ void reconcileTopLevelResources() {
void reconciliationWithSimpleDependsOn() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -75,8 +75,8 @@ void reconciliationWithTwoTheDependsOns() {

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.addDependentResourceAndConfigure(dr3).dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -93,9 +93,9 @@ void reconciliationWithTwoTheDependsOns() {
void diamondShareWorkflowReconcile() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.addDependentResourceAndConfigure(dr4).toDependOn(dr3).toDependOn(dr2)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.addDependentResourceAndConfigure(dr3).dependsOn(dr1)
.addDependentResourceAndConfigure(dr4).dependsOn(dr3).dependsOn(dr2)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -133,8 +133,8 @@ void exceptionHandlingSimpleCases() {
void dependentsOnErroredResourceNotReconciled() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(drError).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(drError)
.addDependentResourceAndConfigure(drError).dependsOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(drError)
.withThrowExceptionFurther(false)
.build();

@@ -153,9 +153,9 @@ void oneBranchErrorsOtherCompletes() {

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(drError).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr3).toDependOn(dr2)
.addDependentResourceAndConfigure(drError).dependsOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.addDependentResourceAndConfigure(dr3).dependsOn(dr2)
.withThrowExceptionFurther(false)
.build();

@@ -174,7 +174,7 @@ void onlyOneDependsOnErroredResourceNotReconciled() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResource(drError)
.addDependentResourceAndConfigure(dr2).toDependOn(drError, dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(drError, dr1)
.withThrowExceptionFurther(false)
.build();

@@ -221,9 +221,9 @@ public Result<String> detailedIsMet(
void triangleOnceConditionNotMet() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
.toDependOn(dr1)
.dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -240,11 +240,11 @@ void reconcileConditionTransitiveDelete() {

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.withReconcilePrecondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter).toDependOn(dr2)
.addDependentResourceAndConfigure(drDeleter).dependsOn(dr2)
.withReconcilePrecondition(metCondition)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter)
.withReconcilePrecondition(metCondition)
.build();

@@ -267,7 +267,7 @@ void reconcileConditionAlsoErrorDependsOn() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(drError)
.addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(drError, drDeleter)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(drError, drDeleter)
.withReconcilePrecondition(metCondition)
.withThrowExceptionFurther(false)
.build();
@@ -290,7 +290,7 @@ void oneDependsOnConditionNotMet() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).withReconcilePrecondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter).toDependOn(dr1, dr2)
.addDependentResourceAndConfigure(drDeleter).dependsOn(dr1, dr2)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -308,9 +308,9 @@ void deletedIfReconcileConditionNotMet() {
TestDeleterDependent drDeleter2 = new TestDeleterDependent("DR_DELETER_2");
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(drDeleter).toDependOn(dr1)
.addDependentResourceAndConfigure(drDeleter).dependsOn(dr1)
.withReconcilePrecondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(dr1, drDeleter)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(dr1, drDeleter)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -333,10 +333,10 @@ void deleteDoneInReverseOrder() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
.toDependOn(dr1)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3)
.dependsOn(dr1)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter3).dependsOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter4).dependsOn(drDeleter3)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -359,10 +359,10 @@ void diamondDeleteWithPostConditionInMiddle() {

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter3).dependsOn(drDeleter)
.withDeletePostcondition(this.notMetCondition)
.addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3, drDeleter2)
.addDependentResourceAndConfigure(drDeleter4).dependsOn(drDeleter3, drDeleter2)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -383,9 +383,9 @@ void diamondDeleteErrorInMiddle() {

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.addDependentResourceAndConfigure(errorDD).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter3).toDependOn(errorDD, drDeleter2)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter)
.addDependentResourceAndConfigure(errorDD).dependsOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter3).dependsOn(errorDD, drDeleter2)
.withThrowExceptionFurther(false)
.build();

@@ -404,7 +404,7 @@ void diamondDeleteErrorInMiddle() {
void readyConditionTrivialCase() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(dr1).withReadyPostcondition(metCondition)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -420,7 +420,7 @@ void readyConditionTrivialCase() {
void readyConditionNotMetTrivialCase() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -439,7 +439,7 @@ void readyConditionNotMetInOneParent() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition)
.addDependentResource(dr2)
.addDependentResourceAndConfigure(dr3).toDependOn(dr1, dr2)
.addDependentResourceAndConfigure(dr3).dependsOn(dr1, dr2)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -455,10 +455,10 @@ void diamondShareWithReadyCondition() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2)
.toDependOn(dr1)
.dependsOn(dr1)
.withReadyPostcondition(notMetCondition)
.addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.addDependentResourceAndConfigure(dr4).toDependOn(dr2, dr3)
.addDependentResourceAndConfigure(dr3).dependsOn(dr1)
.addDependentResourceAndConfigure(dr4).dependsOn(dr2, dr3)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -489,7 +489,7 @@ void garbageCollectedResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
void garbageCollectedDeepResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(dr1).withReconcilePrecondition(notMetCondition)
.addDependentResourceAndConfigure(gcDeleter).toDependOn(dr1)
.addDependentResourceAndConfigure(gcDeleter).dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -518,7 +518,7 @@ void dependentsOnANonActiveDependentNotReconciled() {
.addDependentResourceAndConfigure(dr1)
.withActivationCondition(notMetCondition)
.addDependentResource(dr2)
.addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.addDependentResourceAndConfigure(dr3).dependsOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);

@@ -534,7 +534,7 @@ void readyConditionNotCheckedOnNonActiveDependent() {
.withActivationCondition(notMetCondition)
.withReadyPostcondition(notMetCondition)
.addDependentResource(dr2)
.addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.addDependentResourceAndConfigure(dr3).dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -565,10 +565,10 @@ void deletesDependentsOfNonActiveDependentButNotTheNonActive() {

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(dr1).withActivationCondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter).toDependOn(dr1)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter).dependsOn(dr1)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter)
.withActivationCondition(notMetCondition)
.addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter2)
.addDependentResourceAndConfigure(drDeleter3).dependsOn(drDeleter2)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -588,7 +588,7 @@ void activationConditionOnlyCalledOnceOnDeleteDependents() {

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(drDeleter).withActivationCondition(condition)
.addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.addDependentResourceAndConfigure(drDeleter2).dependsOn(drDeleter)
.build();

workflow.reconcile(new TestCustomResource(), mockContext);
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@ void zeroTopLevelDRShouldThrowException() {
var dr3 = mockDependent("dr3");

var cyclicWorkflowBuilderSetup = new WorkflowBuilder<TestCustomResource>()
.addDependentResourceAndConfigure(dr1).toDependOn()
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr3).toDependOn(dr2)
.addDependentResourceAndConfigure(dr1).toDependOn(dr2);
.addDependentResourceAndConfigure(dr1).dependsOn()
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.addDependentResourceAndConfigure(dr3).dependsOn(dr2)
.addDependentResourceAndConfigure(dr1).dependsOn(dr2);

assertThrows(IllegalStateException.class,
cyclicWorkflowBuilderSetup::build);
@@ -45,7 +45,7 @@ void calculatesTopLevelResources() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(independentDR)
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.buildAsDefaultWorkflow();

Set<DependentResource> topResources =
@@ -65,7 +65,7 @@ void calculatesBottomLevelResources() {
final var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(independentDR)
.addDependentResource(dr1)
.addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.addDependentResourceAndConfigure(dr2).dependsOn(dr1)
.buildAsDefaultWorkflow();

Set<DependentResource> bottomResources =