Skip to content

Commit 870833b

Browse files
committed
wip
1 parent 1f53b82 commit 870833b

File tree

5 files changed

+266
-158
lines changed

5 files changed

+266
-158
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
11
package io.javaoperatorsdk.operator.processing.dependent.workflow;
22

3-
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
4-
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.CleanupCondition;
5-
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.ReconcileCondition;
6-
73
import java.util.ArrayList;
84
import java.util.List;
95
import java.util.Optional;
106

11-
public class DependentResourceNode {
12-
13-
private final DependentResource<?,?> dependentResource;
14-
private final ReconcileCondition reconcileCondition;
15-
private final CleanupCondition cleanupCondition;
16-
private List<DependsOnRelation> dependsOnRelations = new ArrayList<>(1);
17-
18-
public DependentResourceNode(DependentResource<?, ?> dependentResource) {
19-
this(dependentResource,null,null);
20-
}
21-
22-
public DependentResourceNode(DependentResource<?, ?> dependentResource, ReconcileCondition reconcileCondition) {
23-
this(dependentResource, reconcileCondition,null);
24-
}
25-
26-
public DependentResourceNode(DependentResource<?, ?> dependentResource, ReconcileCondition reconcileCondition, CleanupCondition cleanupCondition) {
27-
this.dependentResource = dependentResource;
28-
this.reconcileCondition = reconcileCondition;
29-
this.cleanupCondition = cleanupCondition;
30-
}
31-
32-
public DependentResource<?, ?> getDependentResource() {
33-
return dependentResource;
34-
}
35-
36-
public Optional<ReconcileCondition> getReconcileCondition() {
37-
return Optional.ofNullable(reconcileCondition);
38-
}
39-
40-
public Optional<CleanupCondition> getCleanupCondition() {
41-
return Optional.ofNullable(cleanupCondition);
42-
}
7+
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
8+
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.CleanupCondition;
9+
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.ReconcileCondition;
4310

44-
public void setDependsOnRelations(List<DependsOnRelation> dependsOnRelations) {
45-
this.dependsOnRelations = dependsOnRelations;
46-
}
11+
public class DependentResourceNode {
4712

48-
public List<DependsOnRelation> getDependsOnRelations() {
49-
return dependsOnRelations;
50-
}
13+
private final DependentResource<?, ?> dependentResource;
14+
private final ReconcileCondition reconcileCondition;
15+
private final CleanupCondition cleanupCondition;
16+
private List<DependsOnRelation> dependsOnRelations = new ArrayList<>(1);
17+
18+
public DependentResourceNode(DependentResource<?, ?> dependentResource) {
19+
this(dependentResource, null, null);
20+
}
21+
22+
public DependentResourceNode(DependentResource<?, ?> dependentResource,
23+
ReconcileCondition reconcileCondition) {
24+
this(dependentResource, reconcileCondition, null);
25+
}
26+
27+
public DependentResourceNode(DependentResource<?, ?> dependentResource,
28+
ReconcileCondition reconcileCondition, CleanupCondition cleanupCondition) {
29+
this.dependentResource = dependentResource;
30+
this.reconcileCondition = reconcileCondition;
31+
this.cleanupCondition = cleanupCondition;
32+
}
33+
34+
public DependentResource getDependentResource() {
35+
return dependentResource;
36+
}
37+
38+
public Optional<ReconcileCondition> getReconcileCondition() {
39+
return Optional.ofNullable(reconcileCondition);
40+
}
41+
42+
public Optional<CleanupCondition> getCleanupCondition() {
43+
return Optional.ofNullable(cleanupCondition);
44+
}
45+
46+
public void setDependsOnRelations(List<DependsOnRelation> dependsOnRelations) {
47+
this.dependsOnRelations = dependsOnRelations;
48+
}
49+
50+
public List<DependsOnRelation> getDependsOnRelations() {
51+
return dependsOnRelations;
52+
}
53+
54+
@Override
55+
public String toString() {
56+
return "DependentResourceNode{" +
57+
"dependentResource=" + dependentResource +
58+
'}';
59+
}
5160
}

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

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

55
public class DependsOnRelation {
66

7-
private DependentResourceNode owner;
8-
private DependentResourceNode dependsOn;
9-
private WaitCondition waitCondition;
7+
private DependentResourceNode owner;
8+
private DependentResourceNode dependsOn;
9+
private WaitCondition waitCondition;
1010

11-
public DependsOnRelation() {
12-
}
11+
public DependsOnRelation() {}
1312

14-
public DependsOnRelation(DependentResourceNode owner, DependentResourceNode dependsOn, WaitCondition waitCondition) {
15-
this.owner = owner;
16-
this.dependsOn = dependsOn;
17-
this.waitCondition = waitCondition;
18-
}
13+
public DependsOnRelation(DependentResourceNode owner, DependentResourceNode dependsOn,
14+
WaitCondition waitCondition) {
15+
this.owner = owner;
16+
this.dependsOn = dependsOn;
17+
this.waitCondition = waitCondition;
18+
}
1919

2020

21-
public void setOwner(DependentResourceNode owner) {
22-
this.owner = owner;
23-
}
21+
public void setOwner(DependentResourceNode owner) {
22+
this.owner = owner;
23+
}
2424

25-
public void setDependsOn(DependentResourceNode dependsOn) {
26-
this.dependsOn = dependsOn;
27-
}
25+
public void setDependsOn(DependentResourceNode dependsOn) {
26+
this.dependsOn = dependsOn;
27+
}
2828

29-
public void setWaitCondition(WaitCondition waitCondition) {
30-
this.waitCondition = waitCondition;
31-
}
29+
public void setWaitCondition(WaitCondition waitCondition) {
30+
this.waitCondition = waitCondition;
31+
}
3232

33-
public DependentResourceNode getOwner() {
34-
return owner;
35-
}
33+
public DependentResourceNode getOwner() {
34+
return owner;
35+
}
3636

37-
public DependentResourceNode getDependsOn() {
38-
return dependsOn;
39-
}
37+
public DependentResourceNode getDependsOn() {
38+
return dependsOn;
39+
}
4040

41-
public WaitCondition getWaitCondition() {
42-
return waitCondition;
43-
}
41+
public WaitCondition getWaitCondition() {
42+
return waitCondition;
43+
}
4444
}
Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
11
package io.javaoperatorsdk.operator.processing.dependent.workflow;
22

3-
import io.fabric8.kubernetes.api.model.HasMetadata;
4-
import io.javaoperatorsdk.operator.api.reconciler.Context;
5-
63
import java.util.ArrayList;
74
import java.util.List;
85
import java.util.Map;
9-
import java.util.Set;
106
import java.util.concurrent.ConcurrentHashMap;
117
import java.util.concurrent.ExecutorService;
128
import java.util.concurrent.Executors;
139

10+
import io.fabric8.kubernetes.api.model.HasMetadata;
11+
import io.javaoperatorsdk.operator.api.reconciler.Context;
12+
1413
public class Workflow<P extends HasMetadata> {
1514

16-
private final List<DependentResourceNode> dependentResourceNodes;
15+
private final List<DependentResourceNode> dependentResourceNodes;
1716

18-
private List<DependentResourceNode> topLevelResources = new ArrayList<>();
19-
private Map<DependentResourceNode, List<DependentResourceNode>> reverseDependsOn;
17+
private List<DependentResourceNode> topLevelResources = new ArrayList<>();
18+
private Map<DependentResourceNode, List<DependentResourceNode>> reverseDependsOn;
2019

21-
// it's "global" executor service shared between multiple reconciliations running parallel
22-
private ExecutorService executorService;
20+
// it's "global" executor service shared between multiple reconciliations running parallel
21+
private ExecutorService executorService;
2322

24-
public Workflow(List<DependentResourceNode> dependentResourceNodes, ExecutorService executorService) {
25-
this.executorService = executorService;
26-
this.dependentResourceNodes = dependentResourceNodes;
27-
preprocessForReconcile();
28-
}
23+
public Workflow(List<DependentResourceNode> dependentResourceNodes,
24+
ExecutorService executorService) {
25+
this.executorService = executorService;
26+
this.dependentResourceNodes = dependentResourceNodes;
27+
preprocessForReconcile();
28+
}
2929

30-
public Workflow(List<DependentResourceNode> dependentResourceNodes, int globalParallelism) {
31-
this(dependentResourceNodes,Executors.newFixedThreadPool(globalParallelism));
32-
}
30+
public Workflow(List<DependentResourceNode> dependentResourceNodes, int globalParallelism) {
31+
this(dependentResourceNodes, Executors.newFixedThreadPool(globalParallelism));
32+
}
3333

34-
public void reconcile(P primary, Context<P> context) {
34+
public void reconcile(P primary, Context<P> context) {
3535

36-
}
36+
}
3737

38-
public void cleanup(P resource, Context<P> context) {
38+
public void cleanup(P resource, Context<P> context) {
3939

40-
}
40+
}
4141

42-
private void preprocessForReconcile() {
43-
reverseDependsOn = new ConcurrentHashMap<>(dependentResourceNodes.size());
44-
45-
for (DependentResourceNode node : dependentResourceNodes) {
46-
if (node.getDependsOnRelations().isEmpty()) {
47-
topLevelResources.add(node);
48-
} else {
49-
for (DependsOnRelation relation : node.getDependsOnRelations()) {
50-
reverseDependsOn.computeIfAbsent(relation.getDependsOn(), dr -> new ArrayList<>());
51-
reverseDependsOn.get(relation.getDependsOn()).add(relation.getOwner());
52-
}
53-
}
42+
private void preprocessForReconcile() {
43+
reverseDependsOn = new ConcurrentHashMap<>(dependentResourceNodes.size());
44+
45+
for (DependentResourceNode node : dependentResourceNodes) {
46+
if (node.getDependsOnRelations().isEmpty()) {
47+
topLevelResources.add(node);
48+
} else {
49+
for (DependsOnRelation relation : node.getDependsOnRelations()) {
50+
reverseDependsOn.computeIfAbsent(relation.getDependsOn(), dr -> new ArrayList<>());
51+
reverseDependsOn.get(relation.getDependsOn()).add(relation.getOwner());
5452
}
53+
}
5554
}
55+
}
5656

57-
public void setExecutorService(ExecutorService executorService) {
58-
this.executorService = executorService;
59-
}
57+
public void setExecutorService(ExecutorService executorService) {
58+
this.executorService = executorService;
59+
}
6060

61-
List<DependentResourceNode> getTopLevelResources() {
62-
return topLevelResources;
63-
}
61+
List<DependentResourceNode> getTopLevelDependentResources() {
62+
return topLevelResources;
63+
}
6464

65-
Map<DependentResourceNode, List<DependentResourceNode>> getReverseDependsOn() {
66-
return reverseDependsOn;
67-
}
65+
Map<DependentResourceNode, List<DependentResourceNode>> getReverseDependsOn() {
66+
return reverseDependsOn;
67+
}
6868

69-
ExecutorService getExecutorService() {
70-
return executorService;
71-
}
69+
ExecutorService getExecutorService() {
70+
return executorService;
71+
}
7272
}

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)