-
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.
[Backport 2.x] Adds REST APIs for creating and provisioning a workflow (
#63) (#96) Adds REST APIs for creating and provisioning a workflow (#63) * Inital implementation, set up rest/transport actions, registration, pending global context index, state index implementations Signed-off-by: Joshua Palis <[email protected]> * Addressing PR comments, seting params to snake case, removing redundant param default value, setting workflow request to read/write optional string Signed-off-by: Joshua Palis <[email protected]> * Introducing getExecutorBuilders extension point to FlowFramworkPlugin, added FixedExecutorBuilder thread pool for provisioning tasks, set up async workflow execution, added TODOs for state/GC index handling Signed-off-by: Joshua Palis <[email protected]> * updating unit tests for FlowFrameworkPluginTests, adding WorkflowRequestResponse unit tests Signed-off-by: Joshua Palis <[email protected]> * Adding validate/toXContent tests for workflow request/responses Signed-off-by: Joshua Palis <[email protected]> * Adding unit tests for create and provision rest actions Signed-off-by: Joshua Palis <[email protected]> * Addressing PR comments (Part 1). Moving common vlaues to CommonValue class Signed-off-by: Joshua Palis <[email protected]> * Addressing PR comments (Part 2), adding globalcontexthandler to create components, added updateTemplate(), indexExists() methods to handler and createIndex step respecitvely. Implemented CreateWorkflow/ProvisionWorkflow transport actions Signed-off-by: Joshua Palis <[email protected]> * Addressing PR comments (Part 3) Signed-off-by: Joshua Palis <[email protected]> * Removing TODOs for RestAction constructors, adding basic unit tests for added methods in CreateIndexStep, GlobalContextHandler Signed-off-by: Joshua Palis <[email protected]> * Adding CreateWorkflowTransportAction unit tests Signed-off-by: Joshua Palis <[email protected]> * Adding intial failure test case for the ProvisionWorkflowTransportAction. Still need to add tests for success case Signed-off-by: Joshua Palis <[email protected]> * Updating base URI namespace to workflow instead of workflows Signed-off-by: Joshua Palis <[email protected]> * Addressing PR comment, updating invalid template config test, removing field via string replacement Signed-off-by: Joshua Palis <[email protected]> * Add success test case for ProvisionWorkflowTransportAction Signed-off-by: Joshua Palis <[email protected]> * Updating global context index mapping for template version and compatibility version fields from int to text Signed-off-by: Joshua Palis <[email protected]> * Fixing bugs, changed GC index mapping so that template/compatibility versions are of type text, added GC template document readers/writers, modified tests. Still need to add test cases for the new readers/writers Signed-off-by: Joshua Palis <[email protected]> * Updating GlobalContextHandler.updateTemplate() to use toDocumentSource instead of toXContent() Signed-off-by: Joshua Palis <[email protected]> * Replacing exceptions with FlowFrameworException Signed-off-by: Joshua Palis <[email protected]> * Resolving javadoc warnings Signed-off-by: Joshua Palis <[email protected]> * Cleaning up TODOs Signed-off-by: Joshua Palis <[email protected]> * Addressing PR comments Signed-off-by: Joshua Palis <[email protected]> * Addressing PR comments, moving some common template parsing methods to a common TemplateUtil class Signed-off-by: Joshua Palis <[email protected]> --------- Signed-off-by: Joshua Palis <[email protected]> (cherry picked from commit 014475d)
- Loading branch information
Showing
27 changed files
with
1,704 additions
and
48 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
79 changes: 79 additions & 0 deletions
79
src/main/java/org/opensearch/flowframework/common/TemplateUtil.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,79 @@ | ||
/* | ||
* 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.common; | ||
|
||
import org.opensearch.common.xcontent.LoggingDeprecationHandler; | ||
import org.opensearch.common.xcontent.json.JsonXContent; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
/** | ||
* Utility methods for Template parsing | ||
*/ | ||
public class TemplateUtil { | ||
|
||
/** | ||
* Converts a JSON string into an XContentParser | ||
* | ||
* @param json the json string | ||
* @return The XContent parser for the json string | ||
* @throws IOException on failure to create the parser | ||
*/ | ||
public static XContentParser jsonToParser(String json) throws IOException { | ||
XContentParser parser = JsonXContent.jsonXContent.createParser( | ||
NamedXContentRegistry.EMPTY, | ||
LoggingDeprecationHandler.INSTANCE, | ||
json | ||
); | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
return parser; | ||
} | ||
|
||
/** | ||
* Builds an XContent object representing a map of String keys to String values. | ||
* | ||
* @param xContentBuilder An XContent builder whose position is at the start of the map object to build | ||
* @param map A map as key-value String pairs. | ||
* @throws IOException on a build failure | ||
*/ | ||
public static void buildStringToStringMap(XContentBuilder xContentBuilder, Map<?, ?> map) throws IOException { | ||
xContentBuilder.startObject(); | ||
for (Entry<?, ?> e : map.entrySet()) { | ||
xContentBuilder.field((String) e.getKey(), (String) e.getValue()); | ||
} | ||
xContentBuilder.endObject(); | ||
} | ||
|
||
/** | ||
* Parses an XContent object representing a map of String keys to String values. | ||
* | ||
* @param parser An XContent parser whose position is at the start of the map object to parse | ||
* @return A map as identified by the key-value pairs in the XContent | ||
* @throws IOException on a parse failure | ||
*/ | ||
public static Map<String, String> parseStringToStringMap(XContentParser parser) throws IOException { | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); | ||
Map<String, String> map = new HashMap<>(); | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
String fieldName = parser.currentName(); | ||
parser.nextToken(); | ||
map.put(fieldName, parser.text()); | ||
} | ||
return map; | ||
} | ||
|
||
} |
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
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.