Skip to content

Commit

Permalink
[Feature/agent_framework] Actually make the WorkflowStepFactory a Fac…
Browse files Browse the repository at this point in the history
…tory (#243)

Actually make the WorkflowStepFactory a Factory

Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Dec 18, 2023
1 parent 830cff2 commit 5d69e5b
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

/**
* Generates instances implementing {@link WorkflowStep}.
*/
public class WorkflowStepFactory {

private final Map<String, WorkflowStep> stepMap = new HashMap<>();
private final Map<String, Supplier<WorkflowStep>> stepMap = new HashMap<>();

/**
* Instantiate this class.
Expand All @@ -42,21 +43,21 @@ public WorkflowStepFactory(
MachineLearningNodeClient mlClient,
FlowFrameworkIndicesHandler flowFrameworkIndicesHandler
) {
stepMap.put(NoOpStep.NAME, new NoOpStep());
stepMap.put(CreateIndexStep.NAME, new CreateIndexStep(clusterService, client, flowFrameworkIndicesHandler));
stepMap.put(CreateIngestPipelineStep.NAME, new CreateIngestPipelineStep(client, flowFrameworkIndicesHandler));
stepMap.put(NoOpStep.NAME, NoOpStep::new);
stepMap.put(CreateIndexStep.NAME, () -> new CreateIndexStep(clusterService, client, flowFrameworkIndicesHandler));
stepMap.put(CreateIngestPipelineStep.NAME, () -> new CreateIngestPipelineStep(client, flowFrameworkIndicesHandler));
stepMap.put(
RegisterLocalModelStep.NAME,
new RegisterLocalModelStep(settings, clusterService, mlClient, flowFrameworkIndicesHandler)
() -> new RegisterLocalModelStep(settings, clusterService, mlClient, flowFrameworkIndicesHandler)
);
stepMap.put(RegisterRemoteModelStep.NAME, new RegisterRemoteModelStep(mlClient, flowFrameworkIndicesHandler));
stepMap.put(DeployModelStep.NAME, new DeployModelStep(mlClient));
stepMap.put(UndeployModelStep.NAME, new UndeployModelStep(mlClient));
stepMap.put(CreateConnectorStep.NAME, new CreateConnectorStep(mlClient, flowFrameworkIndicesHandler));
stepMap.put(DeleteConnectorStep.NAME, new DeleteConnectorStep(mlClient));
stepMap.put(ModelGroupStep.NAME, new ModelGroupStep(mlClient, flowFrameworkIndicesHandler));
stepMap.put(ToolStep.NAME, new ToolStep());
stepMap.put(RegisterAgentStep.NAME, new RegisterAgentStep(mlClient));
stepMap.put(RegisterRemoteModelStep.NAME, () -> new RegisterRemoteModelStep(mlClient, flowFrameworkIndicesHandler));
stepMap.put(DeployModelStep.NAME, () -> new DeployModelStep(mlClient));
stepMap.put(UndeployModelStep.NAME, () -> new UndeployModelStep(mlClient));
stepMap.put(CreateConnectorStep.NAME, () -> new CreateConnectorStep(mlClient, flowFrameworkIndicesHandler));
stepMap.put(DeleteConnectorStep.NAME, () -> new DeleteConnectorStep(mlClient));
stepMap.put(ModelGroupStep.NAME, () -> new ModelGroupStep(mlClient, flowFrameworkIndicesHandler));
stepMap.put(ToolStep.NAME, ToolStep::new);
stepMap.put(RegisterAgentStep.NAME, () -> new RegisterAgentStep(mlClient));
}

/**
Expand All @@ -66,7 +67,7 @@ public WorkflowStepFactory(
*/
public WorkflowStep createStep(String type) {
if (stepMap.containsKey(type)) {
return stepMap.get(type);
return stepMap.get(type).get();
}
throw new FlowFrameworkException("Workflow step type [" + type + "] is not implemented.", RestStatus.NOT_IMPLEMENTED);
}
Expand All @@ -75,7 +76,7 @@ public WorkflowStep createStep(String type) {
* Gets the step map
* @return a read-only copy of the step map
*/
public Map<String, WorkflowStep> getStepMap() {
public Map<String, Supplier<WorkflowStep>> getStepMap() {
return Map.copyOf(this.stepMap);
}
}

0 comments on commit 5d69e5b

Please sign in to comment.