Skip to content

Commit 84bc1c0

Browse files
committed
some smell fixes
1 parent 6653d03 commit 84bc1c0

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,35 @@
44
import java.util.List;
55
import java.util.Optional;
66

7+
import io.fabric8.kubernetes.api.model.HasMetadata;
78
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
89
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.CleanupCondition;
910
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.ReconcileCondition;
1011

11-
public class DependentResourceNode {
12+
public class DependentResourceNode<R, P extends HasMetadata> {
1213

13-
private final DependentResource<?, ?> dependentResource;
14+
private final DependentResource<R, P> dependentResource;
1415
private ReconcileCondition reconcileCondition;
1516
private CleanupCondition cleanupCondition;
1617
private List<DependsOnRelation> dependsOnRelations = new ArrayList<>(1);
1718

18-
public DependentResourceNode(DependentResource<?, ?> dependentResource) {
19+
public DependentResourceNode(DependentResource<R, P> dependentResource) {
1920
this(dependentResource, null, null);
2021
}
2122

22-
public DependentResourceNode(DependentResource<?, ?> dependentResource,
23+
public DependentResourceNode(DependentResource<R, P> dependentResource,
2324
ReconcileCondition reconcileCondition) {
2425
this(dependentResource, reconcileCondition, null);
2526
}
2627

27-
public DependentResourceNode(DependentResource<?, ?> dependentResource,
28+
public DependentResourceNode(DependentResource<R, P> dependentResource,
2829
ReconcileCondition reconcileCondition, CleanupCondition cleanupCondition) {
2930
this.dependentResource = dependentResource;
3031
this.reconcileCondition = reconcileCondition;
3132
this.cleanupCondition = cleanupCondition;
3233
}
3334

34-
public DependentResource getDependentResource() {
35+
public DependentResource<R, P> getDependentResource() {
3536
return dependentResource;
3637
}
3738

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependsOnRelation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
public class DependsOnRelation {
66

7-
private DependentResourceNode owner;
8-
private DependentResourceNode dependsOn;
7+
private DependentResourceNode<?, ?> owner;
8+
private DependentResourceNode<?, ?> dependsOn;
99
private WaitCondition waitCondition;
1010

1111
public DependsOnRelation() {}
@@ -34,7 +34,7 @@ public void setWaitCondition(WaitCondition waitCondition) {
3434
this.waitCondition = waitCondition;
3535
}
3636

37-
public DependentResourceNode getOwner() {
37+
public DependentResourceNode<?, ?> getOwner() {
3838
return owner;
3939
}
4040

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,29 @@
1616
*
1717
* @param <P> primary resource
1818
*/
19-
// todo build time graph creation for quarkus
2019
public class Workflow<P extends HasMetadata> {
2120

22-
private final List<DependentResourceNode> dependentResourceNodes;
23-
24-
private List<DependentResourceNode> topLevelResources = new ArrayList<>();
25-
private Map<DependentResourceNode, List<DependentResourceNode>> dependents;
21+
private final List<DependentResourceNode<?, ?>> dependentResourceNodes;
22+
private final List<DependentResourceNode<?, ?>> topLevelResources = new ArrayList<>();
23+
private Map<DependentResourceNode<?, ?>, List<DependentResourceNode<?, ?>>> dependents;
2624

2725
// it's "global" executor service shared between multiple reconciliations running parallel
2826
private ExecutorService executorService;
2927

30-
public Workflow(List<DependentResourceNode> dependentResourceNodes) {
28+
public Workflow(List<DependentResourceNode<?, ?>> dependentResourceNodes) {
3129
this.executorService = ConfigurationServiceProvider.instance().getExecutorService();
3230
this.dependentResourceNodes = dependentResourceNodes;
3331
preprocessForReconcile();
3432
}
3533

36-
public Workflow(List<DependentResourceNode> dependentResourceNodes,
34+
public Workflow(List<DependentResourceNode<?, ?>> dependentResourceNodes,
3735
ExecutorService executorService) {
3836
this.executorService = executorService;
3937
this.dependentResourceNodes = dependentResourceNodes;
4038
preprocessForReconcile();
4139
}
4240

43-
public Workflow(List<DependentResourceNode> dependentResourceNodes, int globalParallelism) {
41+
public Workflow(List<DependentResourceNode<?, ?>> dependentResourceNodes, int globalParallelism) {
4442
this(dependentResourceNodes, Executors.newFixedThreadPool(globalParallelism));
4543
}
4644

@@ -57,7 +55,7 @@ public void cleanup(P resource, Context<P> context) {
5755
// add cycle detection?
5856
private void preprocessForReconcile() {
5957
dependents = new ConcurrentHashMap<>(dependentResourceNodes.size());
60-
for (DependentResourceNode node : dependentResourceNodes) {
58+
for (DependentResourceNode<?, ?> node : dependentResourceNodes) {
6159
if (node.getDependsOnRelations().isEmpty()) {
6260
topLevelResources.add(node);
6361
} else {
@@ -73,11 +71,11 @@ public void setExecutorService(ExecutorService executorService) {
7371
this.executorService = executorService;
7472
}
7573

76-
List<DependentResourceNode> getTopLevelDependentResources() {
74+
List<DependentResourceNode<?, ?>> getTopLevelDependentResources() {
7775
return topLevelResources;
7876
}
7977

80-
Map<DependentResourceNode, List<DependentResourceNode>> getDependents() {
78+
Map<DependentResourceNode<?, ?>, List<DependentResourceNode<?, ?>>> getDependents() {
8179
return dependents;
8280
}
8381

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ public class WorkflowReconcileExecutor<P extends HasMetadata> {
1515
// todo add log messages
1616
private static final Logger log = LoggerFactory.getLogger(WorkflowReconcileExecutor.class);
1717

18-
private Workflow<P> workflow;
18+
private final Workflow<P> workflow;
1919

20-
private Set<DependentResourceNode> alreadyReconciled = ConcurrentHashMap.newKeySet();
21-
private Set<Future<?>> actualExecutions = ConcurrentHashMap.newKeySet();
22-
private Map<DependentResourceNode, Future<?>> nodeToFuture = new ConcurrentHashMap<>();
23-
private List<Exception> exceptionsDuringExecution =
20+
private final Set<DependentResourceNode<?, ?>> alreadyReconciled = ConcurrentHashMap.newKeySet();
21+
private final Set<Future<?>> actualExecutions = ConcurrentHashMap.newKeySet();
22+
private final Map<DependentResourceNode<?, ?>, Future<?>> nodeToFuture =
23+
new ConcurrentHashMap<>();
24+
private final List<Exception> exceptionsDuringExecution =
2425
Collections.synchronizedList(new ArrayList<>());
25-
private Set<DependentResourceNode> markedToReconcileAgain = ConcurrentHashMap.newKeySet();
26+
private final Set<DependentResourceNode<?, ?>> markedToReconcileAgain =
27+
ConcurrentHashMap.newKeySet();
2628

2729
private final P primary;
2830
private final Context<P> context;
@@ -34,13 +36,15 @@ public WorkflowReconcileExecutor(Workflow<P> workflow, P primary, Context<P> con
3436
}
3537

3638
public synchronized void reconcile() {
37-
for (DependentResourceNode dependentResourceNode : workflow.getTopLevelDependentResources()) {
39+
for (DependentResourceNode<?, ?> dependentResourceNode : workflow
40+
.getTopLevelDependentResources()) {
3841
submitForReconcile(dependentResourceNode);
3942
}
4043
while (true) {
4144
try {
4245
this.wait();
4346
if (exceptionsPresent()) {
47+
log.debug("Exception during re");
4448
throw createFinalException();
4549
}
4650
if (noMoreExecutionsScheduled()) {
@@ -59,11 +63,13 @@ private AggregatedOperatorException createFinalException() {
5963
return new AggregatedOperatorException("Exception during workflow.", exceptionsDuringExecution);
6064
}
6165

62-
private synchronized boolean alreadyReconciled(DependentResourceNode dependentResourceNode) {
66+
private synchronized boolean alreadyReconciled(
67+
DependentResourceNode<?, ?> dependentResourceNode) {
6368
return alreadyReconciled.contains(dependentResourceNode);
6469
}
6570

66-
private synchronized boolean allDependOnsReconciled(DependentResourceNode dependentResourceNode) {
71+
private synchronized boolean allDependOnsReconciled(
72+
DependentResourceNode<?, ?> dependentResourceNode) {
6773
return dependentResourceNode.getDependsOnRelations().isEmpty()
6874
|| dependentResourceNode.getDependsOnRelations().stream()
6975
.allMatch(relation -> alreadyReconciled(relation.getDependsOn()));
@@ -96,7 +102,7 @@ && alreadyReconciled(dependentResourceNode)) {
96102
}
97103
}
98104

99-
private synchronized void submitForReconcile(DependentResourceNode dependentResourceNode) {
105+
private synchronized void submitForReconcile(DependentResourceNode<?, ?> dependentResourceNode) {
100106
log.debug("Submitting for reconcile: {}", dependentResourceNode);
101107

102108
if (alreadyReconciled(dependentResourceNode)
@@ -113,15 +119,14 @@ private synchronized void submitForReconcile(DependentResourceNode dependentReso
113119
return;
114120
}
115121

116-
117122
Future<?> nodeFuture =
118123
workflow.getExecutorService().submit(new NodeExecutor(dependentResourceNode));
119124
actualExecutions.add(nodeFuture);
120125
nodeToFuture.put(dependentResourceNode, nodeFuture);
121126
log.debug("Submitted to reconcile: {}", dependentResourceNode);
122127
}
123128

124-
private synchronized void submitDependents(DependentResourceNode dependentResourceNode) {
129+
private synchronized void submitDependents(DependentResourceNode<?, ?> dependentResourceNode) {
125130
if (!exceptionsPresent()) {
126131
var dependents = workflow.getDependents().get(dependentResourceNode);
127132
if (dependents != null) {
@@ -151,7 +156,7 @@ private class NodeExecutor implements Runnable {
151156

152157
private final DependentResourceNode dependentResourceNode;
153158

154-
private NodeExecutor(DependentResourceNode dependentResourceNode) {
159+
private NodeExecutor(DependentResourceNode<?, ?> dependentResourceNode) {
155160
this.dependentResourceNode = dependentResourceNode;
156161
}
157162

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/builder/WorkflowBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class WorkflowBuilder<P extends HasMetadata> {
1414

15-
private List<DependentResourceNode> dependentResourceNodes = new ArrayList<>();
15+
private List<DependentResourceNode<?, ?>> dependentResourceNodes = new ArrayList<>();
1616

1717
public DependentBuilder<P> addDependent(DependentResource dependentResource) {
1818
DependentResourceNode node = new DependentResourceNode(dependentResource);

0 commit comments

Comments
 (0)