Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make WorkflowSpec an interface #2300

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -168,8 +167,18 @@ protected <P extends HasMetadata> ControllerConfiguration<P> configFor(Reconcile
final var workflowAnnotation = reconciler.getClass().getAnnotation(
io.javaoperatorsdk.operator.api.reconciler.Workflow.class);
if (workflowAnnotation != null) {
List<DependentResourceSpec> specs = dependentResources(workflowAnnotation, config);
WorkflowSpec workflowSpec = new WorkflowSpec(specs, workflowAnnotation.explicitInvocation());
final var specs = dependentResources(workflowAnnotation, config);
WorkflowSpec workflowSpec = new WorkflowSpec() {
@Override
public List<DependentResourceSpec> getDependentResourceSpecs() {
return specs;
}

@Override
public boolean isExplicitInvocation() {
return workflowAnnotation.explicitInvocation();
}
};
config.setWorkflowSpec(workflowSpec);
}

Expand Down Expand Up @@ -212,7 +221,7 @@ private static List<DependentResourceSpec> dependentResources(
eventSourceName);
specsMap.put(dependentName, spec);
}
return specsMap.values().stream().collect(Collectors.toUnmodifiableList());
return specsMap.values().stream().toList();
}

protected boolean createIfNeeded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@

import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;

public class WorkflowSpec {
public interface WorkflowSpec {

@SuppressWarnings("rawtypes")
private final List<DependentResourceSpec> dependentResourceSpecs;
private final boolean explicitInvocation;
List<DependentResourceSpec> getDependentResourceSpecs();

public WorkflowSpec(List<DependentResourceSpec> dependentResourceSpecs,
boolean explicitInvocation) {
this.dependentResourceSpecs = dependentResourceSpecs;
this.explicitInvocation = explicitInvocation;
}

public List<DependentResourceSpec> getDependentResourceSpecs() {
return dependentResourceSpecs;
}

public boolean isExplicitInvocation() {
return explicitInvocation;
}
boolean isExplicitInvocation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public void checkForNameDuplication(List<DependentResourceSpec> dependentResourc
}
}

public <P extends HasMetadata> ManagedWorkflow<P> createWorkflow(
WorkflowSpec workflowSpec) {

public <P extends HasMetadata> ManagedWorkflow<P> createWorkflow(WorkflowSpec workflowSpec) {
return createAsDefault(workflowSpec.getDependentResourceSpecs());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,18 @@ void isCleanerIfHasDeleter() {
@SuppressWarnings("unchecked")
ManagedWorkflow managedWorkflow(DependentResourceSpec... specs) {
final var configuration = mock(ControllerConfiguration.class);
final var specList = List.of(specs);

var ws = new WorkflowSpec(specList, false);
var ws = new WorkflowSpec() {
@Override
public List<DependentResourceSpec> getDependentResourceSpecs() {
return List.of(specs);
}

@Override
public boolean isExplicitInvocation() {
return false;
}
};
when(configuration.getWorkflowSpec()).thenReturn(Optional.of(ws));

return new BaseConfigurationService().getWorkflowFactory()
Expand Down
Loading