Skip to content

Commit ce8d989

Browse files
committed
test refactor, bottom resources
1 parent 91215b4 commit ce8d989

File tree

7 files changed

+500
-399
lines changed

7 files changed

+500
-399
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.javaoperatorsdk.operator.processing.dependent.workflow;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
import java.util.Map;
3+
import java.util.*;
64
import java.util.concurrent.ConcurrentHashMap;
75
import java.util.concurrent.ExecutorService;
86
import java.util.concurrent.Executors;
@@ -18,42 +16,46 @@
1816
*/
1917
public class Workflow<P extends HasMetadata> {
2018

21-
private final List<DependentResourceNode<?, P>> dependentResourceNodes;
22-
private final List<DependentResourceNode<?, P>> topLevelResources = new ArrayList<>();
19+
private final Set<DependentResourceNode<?, P>> dependentResourceNodes;
20+
private final Set<DependentResourceNode<?, P>> topLevelResources = new HashSet<>();
21+
private final Set<DependentResourceNode<?, P>> bottomLevelResource = new HashSet<>();
2322
private Map<DependentResourceNode<?, P>, List<DependentResourceNode<?, P>>> dependents;
2423

2524
// it's "global" executor service shared between multiple reconciliations running parallel
2625
private ExecutorService executorService;
2726

28-
public Workflow(List<DependentResourceNode<?, P>> dependentResourceNodes) {
27+
public Workflow(Set<DependentResourceNode<?, P>> dependentResourceNodes) {
2928
this.executorService = ConfigurationServiceProvider.instance().getExecutorService();
3029
this.dependentResourceNodes = dependentResourceNodes;
3130
preprocessForReconcile();
3231
}
3332

34-
public Workflow(List<DependentResourceNode<?, P>> dependentResourceNodes,
33+
public Workflow(Set<DependentResourceNode<?, P>> dependentResourceNodes,
3534
ExecutorService executorService) {
3635
this.executorService = executorService;
3736
this.dependentResourceNodes = dependentResourceNodes;
3837
preprocessForReconcile();
3938
}
4039

41-
public Workflow(List<DependentResourceNode<?, P>> dependentResourceNodes, int globalParallelism) {
40+
public Workflow(Set<DependentResourceNode<?, P>> dependentResourceNodes, int globalParallelism) {
4241
this(dependentResourceNodes, Executors.newFixedThreadPool(globalParallelism));
4342
}
4443

4544
public WorkflowExecutionResult reconcile(P primary, Context<P> context) {
46-
WorkflowReconcileExecutor workflowReconcileExecutor =
45+
WorkflowReconcileExecutor<P> workflowReconcileExecutor =
4746
new WorkflowReconcileExecutor<>(this, primary, context);
4847
return workflowReconcileExecutor.reconcile();
4948
}
5049

51-
public void cleanup(P resource, Context<P> context) {
52-
50+
public WorkflowCleanupResult cleanup(P primary, Context<P> context) {
51+
WorkflowCleanupExecutor<P> workflowCleanupExecutor =
52+
new WorkflowCleanupExecutor<>(this, primary, context);
53+
return workflowCleanupExecutor.cleanup();
5354
}
5455

5556
// add cycle detection?
5657
private void preprocessForReconcile() {
58+
bottomLevelResource.addAll(dependentResourceNodes);
5759
dependents = new ConcurrentHashMap<>(dependentResourceNodes.size());
5860
for (DependentResourceNode<?, P> node : dependentResourceNodes) {
5961
if (node.getDependsOn().isEmpty()) {
@@ -62,6 +64,7 @@ private void preprocessForReconcile() {
6264
for (DependentResourceNode<?, P> dependsOn : node.getDependsOn()) {
6365
dependents.computeIfAbsent(dependsOn, dr -> new ArrayList<>());
6466
dependents.get(dependsOn).add(node);
67+
bottomLevelResource.remove(dependsOn);
6568
}
6669
}
6770
}
@@ -71,10 +74,14 @@ public void setExecutorService(ExecutorService executorService) {
7174
this.executorService = executorService;
7275
}
7376

74-
List<DependentResourceNode<?, P>> getTopLevelDependentResources() {
77+
Set<DependentResourceNode<?, P>> getTopLevelDependentResources() {
7578
return topLevelResources;
7679
}
7780

81+
Set<DependentResourceNode<?, P>> getBottomLevelResource() {
82+
return bottomLevelResource;
83+
}
84+
7885
Map<DependentResourceNode<?, P>, List<DependentResourceNode<?, P>>> getDependents() {
7986
return dependents;
8087
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.javaoperatorsdk.operator.processing.dependent.workflow;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import io.fabric8.kubernetes.api.model.HasMetadata;
7+
import io.javaoperatorsdk.operator.api.reconciler.Context;
8+
9+
public class WorkflowCleanupExecutor<P extends HasMetadata> {
10+
11+
private static final Logger log = LoggerFactory.getLogger(WorkflowReconcileExecutor.class);
12+
13+
private final Workflow<P> workflow;
14+
private final P primary;
15+
private final Context<P> context;
16+
17+
public WorkflowCleanupExecutor(Workflow<P> workflow, P primary, Context<P> context) {
18+
this.workflow = workflow;
19+
this.primary = primary;
20+
this.context = context;
21+
}
22+
23+
24+
public WorkflowCleanupResult cleanup() {
25+
26+
return null;
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.javaoperatorsdk.operator.processing.dependent.workflow;
2+
3+
public class WorkflowCleanupResult {
4+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private synchronized void handleNodeExecutionFinish(DependentResourceNode depend
106106

107107
// needs to be synced
108108
private synchronized void updateStatusForNotReady(ReadyCondition<?, P> readyCondition) {
109+
// todo think through this, since more can't be not ready
109110
readyCondition.addNotReadyStatusInfo(primary);
110111
}
111112

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.javaoperatorsdk.operator.processing.dependent.workflow.builder;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
3+
import java.util.HashSet;
4+
import java.util.Set;
55
import java.util.concurrent.ExecutorService;
66

77
import io.fabric8.kubernetes.api.model.HasMetadata;
@@ -12,7 +12,7 @@
1212

1313
public class WorkflowBuilder<P extends HasMetadata> {
1414

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

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

0 commit comments

Comments
 (0)