-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Widdis <[email protected]>
- Loading branch information
Showing
7 changed files
with
106 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/org/opensearch/flowframework/workflow/WorkflowStepFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.workflow; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import demo.CreateIndexWorkflowStep; | ||
import demo.DemoWorkflowStep; | ||
|
||
/** | ||
* Generates instances implementing {@link WorkflowStep}. | ||
*/ | ||
public class WorkflowStepFactory { | ||
|
||
private static final WorkflowStepFactory INSTANCE = new WorkflowStepFactory(); | ||
|
||
private final Map<String, WorkflowStep> stepMap = new HashMap<>(); | ||
|
||
private WorkflowStepFactory() { | ||
populateMap(); | ||
} | ||
|
||
/** | ||
* Gets the singleton instance of this class | ||
* @return The instance of this class | ||
*/ | ||
public static WorkflowStepFactory get() { | ||
return INSTANCE; | ||
} | ||
|
||
private void populateMap() { | ||
// TODO: These are from the demo class as placeholders | ||
// Replace with actual implementations such as | ||
// https://github.com/opensearch-project/opensearch-ai-flow-framework/pull/38 | ||
// https://github.com/opensearch-project/opensearch-ai-flow-framework/pull/44 | ||
stepMap.put("create_index", new CreateIndexWorkflowStep()); | ||
stepMap.put("fetch_model", new DemoWorkflowStep(3000)); | ||
stepMap.put("create_ingest_pipeline", new DemoWorkflowStep(3000)); | ||
stepMap.put("create_search_pipeline", new DemoWorkflowStep(5000)); | ||
stepMap.put("create_neural_search_index", new DemoWorkflowStep(2000)); | ||
|
||
// Use until all the actual implementations are ready | ||
stepMap.put("placeholder", new WorkflowStep() { | ||
@Override | ||
public CompletableFuture<WorkflowData> execute(List<WorkflowData> data) { | ||
CompletableFuture<WorkflowData> future = new CompletableFuture<>(); | ||
future.complete(WorkflowData.EMPTY); | ||
return future; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "placeholder"; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Create a new instance of a {@link WorkflowStep}. | ||
* @param type The type of instance to create | ||
* @return an instance of the specified type | ||
*/ | ||
public WorkflowStep createStep(String type) { | ||
if (stepMap.containsKey(type)) { | ||
return stepMap.get(type); | ||
} | ||
// TODO: replace this with a FlowFrameworkException | ||
// https://github.com/opensearch-project/opensearch-ai-flow-framework/pull/43 | ||
throw new UnsupportedOperationException("No workflow steps of type [" + type + "] are implemented."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters