|
1 | 1 | package io.javaoperatorsdk.operator.processing.dependent.workflow;
|
2 | 2 |
|
| 3 | +import java.util.LinkedList; |
3 | 4 | import java.util.List;
|
4 | 5 | import java.util.Optional;
|
5 | 6 |
|
6 | 7 | import io.fabric8.kubernetes.api.model.HasMetadata;
|
7 | 8 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
|
8 | 9 |
|
9 | 10 | @SuppressWarnings("rawtypes")
|
10 |
| -public interface DependentResourceNode<R, P extends HasMetadata> { |
| 11 | +public class DependentResourceNode<R, P extends HasMetadata> { |
11 | 12 |
|
12 |
| - Optional<Condition<R, P>> getReconcilePrecondition(); |
| 13 | + private final List<DependentResourceNode> dependsOn = new LinkedList<>(); |
| 14 | + private final List<DependentResourceNode> parents = new LinkedList<>(); |
| 15 | + private final String name; |
| 16 | + private Condition<R, P> reconcilePrecondition; |
| 17 | + private Condition<R, P> deletePostcondition; |
| 18 | + private Condition<R, P> readyPostcondition; |
| 19 | + private DependentResource<R, P> dependentResource; |
13 | 20 |
|
14 |
| - Optional<Condition<R, P>> getDeletePostcondition(); |
| 21 | + public List<? extends DependentResourceNode> getDependsOn() { |
| 22 | + return dependsOn; |
| 23 | + } |
15 | 24 |
|
16 |
| - List<? extends DependentResourceNode> getDependsOn(); |
| 25 | + void addParent(DependentResourceNode parent) { |
| 26 | + parents.add(parent); |
| 27 | + } |
17 | 28 |
|
18 |
| - Optional<Condition<R, P>> getReadyPostcondition(); |
19 | 29 |
|
20 |
| - List<? extends DependentResourceNode> getParents(); |
| 30 | + void addDependsOnRelation(DependentResourceNode node) { |
| 31 | + node.addParent(this); |
| 32 | + dependsOn.add(node); |
| 33 | + } |
21 | 34 |
|
22 |
| - String getName(); |
| 35 | + public List<DependentResourceNode> getParents() { |
| 36 | + return parents; |
| 37 | + } |
23 | 38 |
|
24 |
| - DependentResource<R, P> getDependentResource(); |
| 39 | + public String getName() { |
| 40 | + return name; |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + public Optional<Condition<R, P>> getReconcilePrecondition() { |
| 45 | + return Optional.ofNullable(reconcilePrecondition); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + public Optional<Condition<R, P>> getDeletePostcondition() { |
| 50 | + return Optional.ofNullable(deletePostcondition); |
| 51 | + } |
| 52 | + |
| 53 | + void setReconcilePrecondition(Condition<R, P> reconcilePrecondition) { |
| 54 | + this.reconcilePrecondition = reconcilePrecondition; |
| 55 | + } |
| 56 | + |
| 57 | + void setDeletePostcondition(Condition<R, P> cleanupCondition) { |
| 58 | + this.deletePostcondition = cleanupCondition; |
| 59 | + } |
| 60 | + |
| 61 | + public Optional<Condition<R, P>> getReadyPostcondition() { |
| 62 | + return Optional.ofNullable(readyPostcondition); |
| 63 | + } |
| 64 | + |
| 65 | + void setReadyPostcondition(Condition<R, P> readyPostcondition) { |
| 66 | + this.readyPostcondition = readyPostcondition; |
| 67 | + } |
| 68 | + |
| 69 | + public DependentResource<R, P> getDependentResource() { |
| 70 | + return dependentResource; |
| 71 | + } |
| 72 | + |
| 73 | + public void setDependentResource(DependentResource<R, P> dependentResource) { |
| 74 | + this.dependentResource = dependentResource; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public boolean equals(Object o) { |
| 79 | + if (this == o) { |
| 80 | + return true; |
| 81 | + } |
| 82 | + if (o == null || getClass() != o.getClass()) { |
| 83 | + return false; |
| 84 | + } |
| 85 | + DependentResourceNode<?, ?> that = (DependentResourceNode<?, ?>) o; |
| 86 | + return name.equals(that.name); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public int hashCode() { |
| 91 | + return name.hashCode(); |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + public DependentResourceNode(DependentResource<R, P> dependentResource) { |
| 96 | + this(dependentResource, null, null); |
| 97 | + } |
| 98 | + |
| 99 | + public DependentResourceNode(DependentResource<R, P> dependentResource, |
| 100 | + Condition<R, P> reconcilePrecondition, Condition<R, P> deletePostcondition) { |
| 101 | + this.name = getNameFor(dependentResource); |
| 102 | + setDependentResource(dependentResource); |
| 103 | + setReconcilePrecondition(reconcilePrecondition); |
| 104 | + setDeletePostcondition(deletePostcondition); |
| 105 | + } |
| 106 | + |
| 107 | + @SuppressWarnings("rawtypes") |
| 108 | + static String getNameFor(DependentResource dependentResource) { |
| 109 | + return DependentResource.defaultNameFor(dependentResource.getClass()) + "#" |
| 110 | + + dependentResource.hashCode(); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public String toString() { |
| 115 | + return "DependentResourceNode{" + getDependentResource() + '}'; |
| 116 | + } |
25 | 117 | }
|
0 commit comments