-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 2.x] Add WorkflowStep Factory and implement XContent-based …
…Template Parsing (#60) Add WorkflowStep Factory and implement XContent-based Template Parsing (#47) * Add WorkflowStepFactory class * Add XContent classes representing Template JSON * Add parse methods for the Template XContent * Cleanup parsing, javadocs, and demo output * Refactor to use field name constants, get tests working again * Separate WorkflowNode and ProcessNode functionality * Fix demos to align with template field names * Add workflow, node, and edge tests * Add Template tests * Refactor TemplateParser to WorkflowProcessSorter * Test exceptional cases * Finish up exceptional cases * Fix a template field name bug in demo * Rebase with #34 * Rebase changes from #54 * Integrate thread pool executor service * Fix flaky ProcessNodeTests by removing orTimeout * Rebase and refactor with #44 * Fix demos and remove DataDemo * Use non-deprecated mapping method for CreateIndexStep * Eliminate casting and deprecation warnings on test classes * Remove unused/leftover demo class * Typo * Don't offer steps as an alternative to nodes * Move Workflow into package with all the other parsing classes * Move process sequencing classes into workflow package * Add PipelineProcessor class and XContent parsing, rename package --------- (cherry picked from commit 734f9c2) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6f3b720
commit 5161294
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.