-
Notifications
You must be signed in to change notification settings - Fork 31
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
4 changed files
with
160 additions
and
72 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/main/java/org/opensearch/flowframework/template/Demo.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,89 @@ | ||
/* | ||
* 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.template; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Demo class exercising {@link TemplateParser}. This will be moved to a unit test. | ||
*/ | ||
public class Demo { | ||
|
||
/** | ||
* Demonstrate parsing a JSON graph. | ||
* | ||
* @param args unused | ||
*/ | ||
public static void main(String[] args) { | ||
String json = "{\n" | ||
+ " \"sequence\": {\n" | ||
+ " \"nodes\": [\n" | ||
+ " {\n" | ||
+ " \"id\": \"fetch_model\"\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"id\": \"create_ingest_pipeline\"\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"id\": \"create_search_pipeline\"\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"id\": \"create_neural_search_index\"\n" | ||
+ " }\n" | ||
+ " ],\n" | ||
+ " \"edges\": [\n" | ||
+ " {\n" | ||
+ " \"source\": \"fetch_model\",\n" | ||
+ " \"dest\": \"create_ingest_pipeline\"\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"source\": \"fetch_model\",\n" | ||
+ " \"dest\": \"create_search_pipeline\"\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"source\": \"create_ingest_pipeline\",\n" | ||
+ " \"dest\": \"create_neural_search_index\"\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"source\": \"create_search_pipeline\",\n" | ||
+ " \"dest\": \"create_neural_search_index\"\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ " }\n" | ||
+ "}"; | ||
|
||
System.out.println(json); | ||
|
||
System.out.println("Parsing graph to sequence..."); | ||
List<ProcessNode> processSequence = TemplateParser.parseJsonGraphToSequence(json); | ||
List<CompletableFuture<String>> futureList = new ArrayList<>(); | ||
|
||
for (ProcessNode n : processSequence) { | ||
Set<ProcessNode> predecessors = n.getPredecessors(); | ||
System.out.format( | ||
"Queueing process [%s]. %s.%n", | ||
n.getId(), | ||
predecessors.isEmpty() | ||
? "Can start immediately!" | ||
: String.format( | ||
"Must wait for [%s] to complete first.", | ||
predecessors.stream().map(p -> p.getId()).collect(Collectors.joining(", ")) | ||
) | ||
); | ||
futureList.add(n.execute()); | ||
} | ||
futureList.forEach(CompletableFuture::join); | ||
System.out.println("All done!"); | ||
} | ||
|
||
} |
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