Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds REST APIs for creating and provisioning a workflow #63

Merged
merged 30 commits into from
Oct 12, 2023

Conversation

joshpalis
Copy link
Member

@joshpalis joshpalis commented Sep 29, 2023

Description

Initial implementation, set up rest/transport actions, registration, pending state index implementations

This PR exposes two new APIs to CreateWorkflow (save) and to ProvisionWorkflow (execute). More details on the URI, payloads can be found on issue #49 .

Additionally, this PR integrates PR #65,

In this current state, the rest and transport actions to facilitate these requests have been set up. The CreateWorkflow API will be the main entry point in which the plugin's system indices are created (Global Context and State). Once created. the CreateWorkflow API will parse a use case template from the request content and either save to or update an existing entry within the Global Context index, returning the document ID as the workflow_id. Any insert into the Global Context entry will create a corresponding State index entry mapped with the workflow_id, defaulted to a NOT_STARTED state. Additionally, any update to a use case template will default its state back to NOT_STARTED.

The Provision API is responsible for executing the provisioning workflow for a use case template stored in the Global Context. The workflow_id is returned back to the user for use in querying provisioning status and the provision workflow is executed asynchronously on a separate thread, updating the state entry on success or failure.

Using test template (invalid due to self-connecting edge):

{
  "name": "semantic-search",
  "description": "My semantic search use case",
  "use_case": "SEMANTIC_SEARCH",
  "operations": [
    "PROVISION"
  ],
  "version": {
    "template": "1.0.0",
    "compatibility": [
      "2.9.0",
      "3.0.0"
    ]
  },
  "user_inputs": {
    "index_name": "my-knn-index",
    "index_settings": {}
  },
  "workflows": {
    "provision": {
      "nodes": [
        {
          "id": "create_index",
          "type": "create_index",
          "inputs": {
            "name": "user_inputs.index_name",
            "settings": "user_inputs.index_settings",
            "node_timeout": "10s"
          }
        }
      ],
      "edges": [
        {
          "source": "create_index",
          "dest": "create_index"
        }
      ]
    }
  }
}

Create API :

curl -XPOST "localhost:9200/_plugins/_flow_framework/workflow" -H "Content-Type:application/json" --data '{"name":"semantic-search","description":"My semantic search use case","use_case":"SEMANTIC_SEARCH","operations":["PROVISION"],"version":{"template":"1.0.0","compatibility":["2.9.0","3.0.0"]},"user_inputs":{"index_name":"my-knn-index","index_settings":{}},"workflows":{"provision":{"nodes":[{"id":"create_index","type":"create_index","inputs":{"name":"user_inputs.index_name","settings":"user_inputs.index_settings","node_timeout":"10s"}}],"edges":[{"source":"create_index","dest":"create_index"}]}}}'
{"workflow_id":"0IDAJIsBzSbcoaec4g95"}% 

OpenSearch logs successful Global Context Creation :

[2023-10-12T16:38:18,615][INFO ][o.o.n.Node               ] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] started
[2023-10-12T16:38:18,627][INFO ][o.o.g.GatewayService     ] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] recovered [0] indices into cluster_state
[2023-10-12T16:38:22,272][INFO ][o.o.p.PluginsService     ] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] PluginService:onIndexModule index:[.plugins-ai-global-context/EQigAvM-QsKlhEMMTfs0gw]
[2023-10-12T16:38:22,373][INFO ][o.o.c.m.MetadataCreateIndexService] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] [.plugins-ai-global-context] creating index, cause [api], templates [], shards [1]/[1]
[2023-10-12T16:38:22,379][INFO ][o.o.c.r.a.AllocationService] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] updating number_of_replicas to [0] for indices [.plugins-ai-global-context]
[2023-10-12T16:38:22,421][INFO ][o.o.p.PluginsService     ] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] PluginService:onIndexModule index:[.plugins-ai-global-context/EQigAvM-QsKlhEMMTfs0gw]
[2023-10-12T16:38:22,555][INFO ][o.o.c.r.a.AllocationService] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[.plugins-ai-global-context][0]]]).
[2023-10-12T16:38:22,578][INFO ][o.o.f.w.CreateIndexStep  ] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] create index:.plugins-ai-global-context

Provision API :

curl -XPOST "localhost:9200/_plugins/_flow_framework/workflow/0IDAJIsBzSbcoaec4g95/_provision"
{"workflow_id":"0IDAJIsBzSbcoaec4g95"}

OpenSearch logs process sorting error due to self connecting edge :

[2023-10-12T16:38:37,617][ERROR][o.o.b.OpenSearchUncaughtExceptionHandler] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] uncaught exception in thread [opensearch[dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com][opensearch_workflow_provision][T#1]]
java.lang.IllegalArgumentException: Edge connects node create_index to itself.
        at org.opensearch.flowframework.workflow.WorkflowProcessSorter.topologicalSort(WorkflowProcessSorter.java:110) ~[?:?]
        at org.opensearch.flowframework.workflow.WorkflowProcessSorter.sortProcessNodes(WorkflowProcessSorter.java:62) ~[?:?]
        at org.opensearch.flowframework.transport.ProvisionWorkflowTransportAction.executeWorkflow(ProvisionWorkflowTransportAction.java:135) ~[?:?]
        at org.opensearch.flowframework.transport.ProvisionWorkflowTransportAction.lambda$executeWorkflowAsync$4(ProvisionWorkflowTransportAction.java:122) ~[?:?]
        at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:849) ~[opensearch-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) [?:?]

Once the workflow steps are polished, we can proceed with full end to end testing of a valid use case template

Issues Resolved

#49
#61

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…ending global context index, state index implementations

Signed-off-by: Joshua Palis <[email protected]>
@github-actions github-actions bot added the backport 2.x backport PRs to 2.x branch label Sep 29, 2023
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Merging #63 (8200441) into main (9b10b23) will decrease coverage by 0.07%.
The diff coverage is 81.51%.

@@             Coverage Diff              @@
##               main      #63      +/-   ##
============================================
- Coverage     81.74%   81.68%   -0.07%     
- Complexity      211      285      +74     
============================================
  Files            21       30       +9     
  Lines           838     1119     +281     
  Branches         96      125      +29     
============================================
+ Hits            685      914     +229     
- Misses          119      160      +41     
- Partials         34       45      +11     
Files Coverage Δ
.../opensearch/flowframework/FlowFrameworkPlugin.java 100.00% <100.00%> (ø)
...g/opensearch/flowframework/common/CommonValue.java 66.66% <ø> (ø)
...lowframework/exception/FlowFrameworkException.java 40.00% <ø> (+40.00%) ⬆️
...arch/flowframework/indices/FlowFrameworkIndex.java 100.00% <ø> (ø)
...nsearch/flowframework/model/PipelineProcessor.java 100.00% <100.00%> (ø)
...g/opensearch/flowframework/model/WorkflowNode.java 90.54% <100.00%> (ø)
.../flowframework/transport/CreateWorkflowAction.java 100.00% <100.00%> (ø)
...ework/transport/CreateWorkflowTransportAction.java 100.00% <100.00%> (ø)
...owframework/transport/ProvisionWorkflowAction.java 100.00% <100.00%> (ø)
...earch/flowframework/transport/WorkflowRequest.java 100.00% <100.00%> (ø)
... and 8 more

…nt param default value, setting workflow request to read/write optional string

Signed-off-by: Joshua Palis <[email protected]>
…, 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]>
@joshpalis joshpalis marked this pull request as ready for review October 6, 2023 16:14
Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, would approve except with the TODOs not sure this is done.

Copy link
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to discuss more on the APIs. This would also require integ tests, let's create an issue for the same

…e components, added updateTemplate(), indexExists() methods to handler and createIndex step respecitvely. Implemented CreateWorkflow/ProvisionWorkflow transport actions

Signed-off-by: Joshua Palis <[email protected]>
…or added methods in CreateIndexStep, GlobalContextHandler

Signed-off-by: Joshua Palis <[email protected]>
…ion. Still need to add tests for success case

Signed-off-by: Joshua Palis <[email protected]>
…ibility version fields from int to text

Signed-off-by: Joshua Palis <[email protected]>
…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]>
…e instead of toXContent()

Signed-off-by: Joshua Palis <[email protected]>
Signed-off-by: Joshua Palis <[email protected]>
Signed-off-by: Joshua Palis <[email protected]>
Copy link
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there. Looks good overall.

Signed-off-by: Joshua Palis <[email protected]>
…o a common TemplateUtil class

Signed-off-by: Joshua Palis <[email protected]>
Copy link
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for addressing the comments patiently

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please create an issue for the TODO if there isn't one.

@joshpalis joshpalis merged commit 014475d into opensearch-project:main Oct 12, 2023
10 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/opensearch-ai-flow-framework/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/opensearch-ai-flow-framework/backport-2.x
# Create a new branch
git switch --create backport/backport-63-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 014475d7e2968b723c916fb5c134d257f0b11578
# Push it to GitHub
git push --set-upstream origin backport/backport-63-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/opensearch-ai-flow-framework/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-63-to-2.x.

@joshpalis
Copy link
Member Author

Seems the backport PR failed to get raised, @owaiskazi19 ill create a manual PR

joshpalis added a commit to joshpalis/opensearch-ai-flow-framework that referenced this pull request Oct 16, 2023
…roject#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)
owaiskazi19 pushed a commit that referenced this pull request Oct 16, 2023
#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport PRs to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants