-
Notifications
You must be signed in to change notification settings - Fork 220
feat: improve workflow error reporting #1613
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
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
29 changes: 13 additions & 16 deletions
29
...framework-core/src/main/java/io/javaoperatorsdk/operator/AggregatedOperatorException.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 |
---|---|---|
@@ -1,31 +1,28 @@ | ||
package io.javaoperatorsdk.operator; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class AggregatedOperatorException extends OperatorException { | ||
|
||
private final List<Exception> causes; | ||
private final Map<String, Exception> causes; | ||
|
||
public AggregatedOperatorException(String message, Exception... exceptions) { | ||
super(message, exceptions != null && exceptions.length > 0 ? exceptions[0] : null); | ||
this.causes = exceptions != null ? Arrays.asList(exceptions) : Collections.emptyList(); | ||
public AggregatedOperatorException(String message, Map<String, Exception> exceptions) { | ||
super(message); | ||
this.causes = | ||
exceptions != null ? Collections.unmodifiableMap(exceptions) : Collections.emptyMap(); | ||
} | ||
|
||
public AggregatedOperatorException(String message, List<Exception> exceptions) { | ||
super(message, exceptions != null && !exceptions.isEmpty() ? exceptions.get(0) : null); | ||
this.causes = exceptions != null ? exceptions : Collections.emptyList(); | ||
} | ||
|
||
public List<Exception> getAggregatedExceptions() { | ||
@SuppressWarnings("unused") | ||
public Map<String, Exception> getAggregatedExceptions() { | ||
return causes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AggregatedOperatorException{" + | ||
"causes=" + causes + | ||
'}'; | ||
public String getMessage() { | ||
return super.getMessage() + " " + causes.entrySet().stream() | ||
.map(entry -> entry.getKey() + " -> " + entry.getValue()) | ||
.collect(Collectors.joining("\n - ", "Details:\n", "")); | ||
} | ||
} |
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
52 changes: 10 additions & 42 deletions
52
...java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupResult.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 |
---|---|---|
@@ -1,64 +1,32 @@ | ||
package io.javaoperatorsdk.operator.processing.dependent.workflow; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.javaoperatorsdk.operator.AggregatedOperatorException; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public class WorkflowCleanupResult { | ||
public class WorkflowCleanupResult extends WorkflowResult { | ||
|
||
private List<DependentResource> deleteCalledOnDependents = new ArrayList<>(); | ||
private List<DependentResource> postConditionNotMetDependents = new ArrayList<>(); | ||
private Map<DependentResource, Exception> erroredDependents = new HashMap<>(); | ||
private final List<DependentResource> deleteCalledOnDependents; | ||
private final List<DependentResource> postConditionNotMetDependents; | ||
|
||
public List<DependentResource> getDeleteCalledOnDependents() { | ||
return deleteCalledOnDependents; | ||
WorkflowCleanupResult(Map<DependentResource, Exception> erroredDependents, | ||
List<DependentResource> postConditionNotMet, List<DependentResource> deleteCalled) { | ||
super(erroredDependents); | ||
this.deleteCalledOnDependents = deleteCalled; | ||
this.postConditionNotMetDependents = postConditionNotMet; | ||
} | ||
|
||
public WorkflowCleanupResult setDeleteCalledOnDependents( | ||
List<DependentResource> deletedDependents) { | ||
this.deleteCalledOnDependents = deletedDependents; | ||
return this; | ||
public List<DependentResource> getDeleteCalledOnDependents() { | ||
return deleteCalledOnDependents; | ||
} | ||
|
||
public List<DependentResource> getPostConditionNotMetDependents() { | ||
return postConditionNotMetDependents; | ||
} | ||
|
||
public WorkflowCleanupResult setPostConditionNotMetDependents( | ||
List<DependentResource> postConditionNotMetDependents) { | ||
this.postConditionNotMetDependents = postConditionNotMetDependents; | ||
return this; | ||
} | ||
|
||
public Map<DependentResource, Exception> getErroredDependents() { | ||
return erroredDependents; | ||
} | ||
|
||
public WorkflowCleanupResult setErroredDependents( | ||
Map<DependentResource, Exception> erroredDependents) { | ||
this.erroredDependents = erroredDependents; | ||
return this; | ||
} | ||
|
||
public boolean allPostConditionsMet() { | ||
return postConditionNotMetDependents.isEmpty(); | ||
} | ||
|
||
public boolean erroredDependentsExists() { | ||
return !erroredDependents.isEmpty(); | ||
} | ||
|
||
public void throwAggregateExceptionIfErrorsPresent() { | ||
if (erroredDependentsExists()) { | ||
throw new AggregatedOperatorException("Exception(s) during workflow execution.", | ||
new ArrayList<>(erroredDependents.values())); | ||
} | ||
} | ||
|
||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
...c/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.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,43 @@ | ||
package io.javaoperatorsdk.operator.processing.dependent.workflow; | ||
|
||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.stream.Collectors; | ||
|
||
import io.javaoperatorsdk.operator.AggregatedOperatorException; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
|
||
@SuppressWarnings("rawtypes") | ||
class WorkflowResult { | ||
|
||
private final Map<DependentResource, Exception> erroredDependents; | ||
|
||
WorkflowResult(Map<DependentResource, Exception> erroredDependents) { | ||
this.erroredDependents = erroredDependents; | ||
} | ||
|
||
public Map<DependentResource, Exception> getErroredDependents() { | ||
return erroredDependents; | ||
} | ||
|
||
/** | ||
* @deprecated Use {@link #erroredDependentsExist()} instead | ||
*/ | ||
@Deprecated(forRemoval = true) | ||
public boolean erroredDependentsExists() { | ||
return !erroredDependents.isEmpty(); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public boolean erroredDependentsExist() { | ||
return !erroredDependents.isEmpty(); | ||
} | ||
|
||
public void throwAggregateExceptionIfErrorsPresent() { | ||
if (erroredDependentsExist()) { | ||
throw new AggregatedOperatorException("Exception(s) during workflow execution.", | ||
erroredDependents.entrySet().stream() | ||
.collect(Collectors.toMap(e -> e.getKey().getClass().getName(), Entry::getValue))); | ||
} | ||
} | ||
} |
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.
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.
Why is the key String here? It could be
DependentResource
I guess.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.
The exception is not necessarily meant only for workflow errors so the key could be anything identifying "what" caused that specific error so that user has some idea of what's going on.