-
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.
Add WorkflowStep Factory and implement XContent-based Template Parsing (
#47) * Add WorkflowStepFactory class Signed-off-by: Daniel Widdis <[email protected]> * Add XContent classes representing Template JSON Signed-off-by: Daniel Widdis <[email protected]> * Add parse methods for the Template XContent Signed-off-by: Daniel Widdis <[email protected]> * Cleanup parsing, javadocs, and demo output Signed-off-by: Daniel Widdis <[email protected]> * Refactor to use field name constants, get tests working again Signed-off-by: Daniel Widdis <[email protected]> * Separate WorkflowNode and ProcessNode functionality Signed-off-by: Daniel Widdis <[email protected]> * Fix demos to align with template field names Signed-off-by: Daniel Widdis <[email protected]> * Add workflow, node, and edge tests Signed-off-by: Daniel Widdis <[email protected]> * Add Template tests Signed-off-by: Daniel Widdis <[email protected]> * Refactor TemplateParser to WorkflowProcessSorter Signed-off-by: Daniel Widdis <[email protected]> * Test exceptional cases Signed-off-by: Daniel Widdis <[email protected]> * Finish up exceptional cases Signed-off-by: Daniel Widdis <[email protected]> * Fix a template field name bug in demo Signed-off-by: Daniel Widdis <[email protected]> * Rebase with #34 Signed-off-by: Daniel Widdis <[email protected]> * Rebase changes from #54 Signed-off-by: Daniel Widdis <[email protected]> * Integrate thread pool executor service Signed-off-by: Daniel Widdis <[email protected]> * Fix flaky ProcessNodeTests by removing orTimeout Signed-off-by: Daniel Widdis <[email protected]> * Rebase and refactor with #44 Signed-off-by: Daniel Widdis <[email protected]> * Fix demos and remove DataDemo Signed-off-by: Daniel Widdis <[email protected]> * Use non-deprecated mapping method for CreateIndexStep Signed-off-by: Daniel Widdis <[email protected]> * Eliminate casting and deprecation warnings on test classes Signed-off-by: Daniel Widdis <[email protected]> * Remove unused/leftover demo class Signed-off-by: Daniel Widdis <[email protected]> * Typo Signed-off-by: Daniel Widdis <[email protected]> * Don't offer steps as an alternative to nodes Signed-off-by: Daniel Widdis <[email protected]> * Move Workflow into package with all the other parsing classes Signed-off-by: Daniel Widdis <[email protected]> * Move process sequencing classes into workflow package Signed-off-by: Daniel Widdis <[email protected]> * Add PipelineProcessor class and XContent parsing, rename package Signed-off-by: Daniel Widdis <[email protected]> --------- Signed-off-by: Daniel Widdis <[email protected]>
- Loading branch information
Showing
33 changed files
with
2,099 additions
and
748 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 demo; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.common.SuppressForbidden; | ||
import org.opensearch.common.io.PathUtils; | ||
import org.opensearch.flowframework.model.Template; | ||
import org.opensearch.flowframework.model.Workflow; | ||
import org.opensearch.flowframework.workflow.WorkflowProcessSorter; | ||
import org.opensearch.flowframework.workflow.WorkflowStepFactory; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.Map.Entry; | ||
import java.util.concurrent.Executors; | ||
|
||
/** | ||
* Demo class exercising {@link WorkflowProcessSorter}. This will be moved to a unit test. | ||
*/ | ||
public class TemplateParseDemo { | ||
|
||
private static final Logger logger = LogManager.getLogger(TemplateParseDemo.class); | ||
|
||
/** | ||
* Demonstrate parsing a JSON graph. | ||
* | ||
* @param args unused | ||
* @throws IOException on error. | ||
*/ | ||
@SuppressForbidden(reason = "just a demo class that will be deleted") | ||
public static void main(String[] args) throws IOException { | ||
String path = "src/test/resources/template/finaltemplate.json"; | ||
String json; | ||
try { | ||
json = new String(Files.readAllBytes(PathUtils.get(path)), StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
logger.error("Failed to read JSON at path {}", path); | ||
return; | ||
} | ||
Client client = new NodeClient(null, null); | ||
WorkflowStepFactory factory = WorkflowStepFactory.create(client); | ||
WorkflowProcessSorter.create(factory, Executors.newFixedThreadPool(10)); | ||
|
||
Template t = Template.parse(json); | ||
|
||
System.out.println(t.toJson()); | ||
System.out.println(t.toYaml()); | ||
|
||
for (Entry<String, Workflow> e : t.workflows().entrySet()) { | ||
logger.info("Parsing {} workflow.", e.getKey()); | ||
WorkflowProcessSorter.get().sortProcessNodes(e.getValue()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.