|
| 1 | +package io.javaoperatorsdk.operator.processing.dependent.workflow; |
| 2 | + |
| 3 | +import io.fabric8.kubernetes.api.model.HasMetadata; |
| 4 | +import io.javaoperatorsdk.operator.api.reconciler.Context; |
| 5 | + |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.Collections; |
| 8 | +import java.util.List; |
| 9 | +import java.util.Set; |
| 10 | +import java.util.concurrent.*; |
| 11 | + |
| 12 | +public class WorkflowReconcileExecutor<P extends HasMetadata> { |
| 13 | + |
| 14 | + private Set<DependentResourceNode> alreadyReconciled = ConcurrentHashMap.newKeySet(); |
| 15 | + |
| 16 | + private Workflow<P> workflow; |
| 17 | + private List<Exception> exceptionsDuringExecution = Collections.synchronizedList(new ArrayList<>()); |
| 18 | + private List<Future<?>> actualExecutions = Collections.synchronizedList(new ArrayList<>()); |
| 19 | + |
| 20 | + public WorkflowReconcileExecutor(Workflow<P> workflow) { |
| 21 | + this.workflow = workflow; |
| 22 | + } |
| 23 | + |
| 24 | + public synchronized void reconcile(P primary, Context<P> context) { |
| 25 | + try { |
| 26 | + for (DependentResourceNode dependentResourceNode : workflow.getTopLevelResources()) { |
| 27 | + var nodeFuture = workflow.getExecutorService().submit(new NodeExecutor(dependentResourceNode)); |
| 28 | + actualExecutions.add(nodeFuture); |
| 29 | + } |
| 30 | + this.wait(); |
| 31 | + } catch (InterruptedException e) { |
| 32 | + // todo check this better |
| 33 | + throw new IllegalStateException(e); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + private boolean terminateExecution() { |
| 38 | + return !exceptionsDuringExecution.isEmpty(); |
| 39 | + } |
| 40 | + private class NodeExecutor implements Runnable { |
| 41 | + |
| 42 | + private final DependentResourceNode dependentResourceNode; |
| 43 | + |
| 44 | + private NodeExecutor(DependentResourceNode dependentResourceNode) { |
| 45 | + this.dependentResourceNode = dependentResourceNode; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void run() { |
| 50 | + |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments