-
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.
[Feature/agent_framework] Adds a Search Workflow State API (#284)
* Modifying workflow state index mapping and resources created Signed-off-by: Joshua Palis <jpalis@amazon.com> * Adding Search workflow state API Signed-off-by: Joshua Palis <jpalis@amazon.com> * Adding rest unit tests Signed-off-by: Joshua Palis <jpalis@amazon.com> * Transport unit tests Signed-off-by: Joshua Palis <jpalis@amazon.com> * Moving resourceType determination outside of the resources created class Signed-off-by: Joshua Palis <jpalis@amazon.com> --------- Signed-off-by: Joshua Palis <jpalis@amazon.com>
- Loading branch information
Showing
13 changed files
with
403 additions
and
41 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
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
47 changes: 47 additions & 0 deletions
47
src/main/java/org/opensearch/flowframework/rest/RestSearchWorkflowStateAction.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,47 @@ | ||
/* | ||
* 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.rest; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting; | ||
import org.opensearch.flowframework.model.WorkflowState; | ||
import org.opensearch.flowframework.transport.SearchWorkflowStateAction; | ||
|
||
import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_STATE_INDEX; | ||
import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_URI; | ||
|
||
/** | ||
* Rest Action to facilitate requests to search workflow states | ||
*/ | ||
public class RestSearchWorkflowStateAction extends AbstractSearchWorkflowAction<WorkflowState> { | ||
|
||
private static final String SEARCH_WORKFLOW_STATE_ACTION = "search_workflow_state_action"; | ||
private static final String SEARCH_WORKFLOW_STATE_PATH = WORKFLOW_URI + "/state/_search"; | ||
|
||
/** | ||
* Instantiates a new RestSearchWorkflowStateAction | ||
* | ||
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled | ||
*/ | ||
public RestSearchWorkflowStateAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) { | ||
super( | ||
ImmutableList.of(SEARCH_WORKFLOW_STATE_PATH), | ||
WORKFLOW_STATE_INDEX, | ||
WorkflowState.class, | ||
SearchWorkflowStateAction.INSTANCE, | ||
flowFrameworkFeatureEnabledSetting | ||
); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return SEARCH_WORKFLOW_STATE_ACTION; | ||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/opensearch/flowframework/transport/SearchWorkflowStateAction.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,29 @@ | ||
/* | ||
* 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.transport; | ||
|
||
import org.opensearch.action.ActionType; | ||
import org.opensearch.action.search.SearchResponse; | ||
|
||
import static org.opensearch.flowframework.common.CommonValue.TRANSPORT_ACTION_NAME_PREFIX; | ||
|
||
/** | ||
* External Action for public facing RestSearchWorkflowStateAction | ||
*/ | ||
public class SearchWorkflowStateAction extends ActionType<SearchResponse> { | ||
|
||
/** The name of this action */ | ||
public static final String NAME = TRANSPORT_ACTION_NAME_PREFIX + "workflow_state/search"; | ||
/** An instance of this action */ | ||
public static final SearchWorkflowStateAction INSTANCE = new SearchWorkflowStateAction(); | ||
|
||
private SearchWorkflowStateAction() { | ||
super(NAME, SearchResponse::new); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/org/opensearch/flowframework/transport/SearchWorkflowStateTransportAction.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,50 @@ | ||
/* | ||
* 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.transport; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.HandledTransportAction; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.common.util.concurrent.ThreadContext; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.tasks.Task; | ||
import org.opensearch.transport.TransportService; | ||
|
||
/** | ||
* Transport Action to search workflow states | ||
*/ | ||
public class SearchWorkflowStateTransportAction extends HandledTransportAction<SearchRequest, SearchResponse> { | ||
|
||
private Client client; | ||
|
||
/** | ||
* Intantiates a new SearchWorkflowStateTransportAction | ||
* @param transportService the TransportService | ||
* @param actionFilters action filters | ||
* @param client The client used to make the request to OS | ||
*/ | ||
@Inject | ||
public SearchWorkflowStateTransportAction(TransportService transportService, ActionFilters actionFilters, Client client) { | ||
super(SearchWorkflowStateAction.NAME, transportService, actionFilters, SearchRequest::new); | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
protected void doExecute(Task task, SearchRequest request, ActionListener<SearchResponse> actionListener) { | ||
// TODO: AccessController should take care of letting the user with right permission to view the workflow | ||
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) { | ||
client.search(request, ActionListener.runBefore(actionListener, () -> context.restore())); | ||
} catch (Exception e) { | ||
actionListener.onFailure(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.