|
4 | 4 | import io.javaoperatorsdk.operator.api.reconciler.Context;
|
5 | 5 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
|
6 | 6 |
|
| 7 | +/** |
| 8 | + * A condition that can return extra information in addition of whether it is met or not. |
| 9 | + * |
| 10 | + * @param <R> the resource type this condition applies to |
| 11 | + * @param <P> the primary resource type associated with the dependent workflow this condition is |
| 12 | + * part of |
| 13 | + * @param <T> the type of the extra information returned by the condition |
| 14 | + */ |
7 | 15 | public interface ResultCondition<R, P extends HasMetadata, T> extends Condition<R, P> {
|
| 16 | + |
| 17 | + /** |
| 18 | + * Checks whether a condition holds true for the specified {@link DependentResource}, returning |
| 19 | + * additional information as needed. |
| 20 | + * |
| 21 | + * @param dependentResource the {@link DependentResource} for which we want to check the condition |
| 22 | + * @param primary the primary resource being considered |
| 23 | + * @param context the current reconciliation {@link Context} |
| 24 | + * @return a {@link Result} instance containing the result of the evaluation of the condition as |
| 25 | + * well as additional detail |
| 26 | + * @see Condition#isMet(DependentResource, HasMetadata, Context) |
| 27 | + */ |
8 | 28 | Result<T> detailedIsMet(DependentResource<R, P> dependentResource, P primary, Context<P> context);
|
9 | 29 |
|
10 | 30 | @Override
|
11 | 31 | default boolean isMet(DependentResource<R, P> dependentResource, P primary, Context<P> context) {
|
12 | 32 | return detailedIsMet(dependentResource, primary, context).isSuccess();
|
13 | 33 | }
|
14 | 34 |
|
| 35 | + /** |
| 36 | + * Holds a more detailed {@link Condition} result. |
| 37 | + * |
| 38 | + * @param <T> the type of the extra information provided in condition evaluation |
| 39 | + */ |
15 | 40 | @SuppressWarnings({"rawtypes", "unchecked"})
|
16 | 41 | interface Result<T> {
|
| 42 | + /** |
| 43 | + * A result expressing a condition has been met without extra information |
| 44 | + */ |
17 | 45 | ResultCondition.Result metWithoutResult = new DefaultResult(true, null);
|
18 | 46 |
|
| 47 | + /** |
| 48 | + * A result expressing a condition has not been met without extra information |
| 49 | + */ |
19 | 50 | ResultCondition.Result unmetWithoutResult = new DefaultResult(false, null);
|
20 | 51 |
|
| 52 | + /** |
| 53 | + * Creates a {@link Result} without extra information |
| 54 | + * |
| 55 | + * @param success whether or not the condition has been met |
| 56 | + * @return a {@link Result} without extra information |
| 57 | + */ |
21 | 58 | static Result withoutResult(boolean success) {
|
22 | 59 | return success ? metWithoutResult : unmetWithoutResult;
|
23 | 60 | }
|
24 | 61 |
|
25 |
| - static <T> Result<T> withResult(boolean success, T result) { |
26 |
| - return new DefaultResult<>(success, result); |
| 62 | + /** |
| 63 | + * Creates a {@link Result} with the specified condition evaluation result and extra information |
| 64 | + * |
| 65 | + * @param success whether or not the condition has been met |
| 66 | + * @param detail the extra information that the condition provided during its evaluation |
| 67 | + * @return a {@link Result} with the specified condition evaluation result and extra information |
| 68 | + * @param <T> the type of the extra information provided by the condition |
| 69 | + */ |
| 70 | + static <T> Result<T> withResult(boolean success, T detail) { |
| 71 | + return new DefaultResult<>(success, detail); |
27 | 72 | }
|
28 | 73 |
|
29 | 74 | default String asString() {
|
30 |
| - return "Result: " + getResult() + " met: " + isSuccess(); |
| 75 | + return "Detail: " + getDetail() + " met: " + isSuccess(); |
31 | 76 | }
|
32 | 77 |
|
33 |
| - T getResult(); |
| 78 | + /** |
| 79 | + * The extra information provided by the associated {@link ResultCondition} during its evaluation |
| 80 | + * @return extra information provided by the associated {@link ResultCondition} during its evaluation or {@code null} if none was provided |
| 81 | + */ |
| 82 | + T getDetail(); |
34 | 83 |
|
| 84 | + /** |
| 85 | + * Whether the associated condition held true |
| 86 | + * @return {@code true} if the associated condition was met, {@code false} otherwise |
| 87 | + */ |
35 | 88 | boolean isSuccess();
|
36 | 89 | }
|
37 | 90 | }
|
0 commit comments