Skip to content

Commit

Permalink
Added javadoc
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Nov 3, 2023
1 parent 0013282 commit 57869ff
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
import org.opensearch.flowframework.rest.RestCreateWorkflowAction;
import org.opensearch.flowframework.rest.RestProvisionWorkflowAction;
import org.opensearch.flowframework.rest.RestSearchWorkflowAction;
import org.opensearch.flowframework.transport.*;
import org.opensearch.flowframework.transport.CreateWorkflowAction;
import org.opensearch.flowframework.transport.CreateWorkflowTransportAction;
import org.opensearch.flowframework.transport.ProvisionWorkflowAction;
import org.opensearch.flowframework.transport.ProvisionWorkflowTransportAction;
import org.opensearch.flowframework.transport.SearchWorkflowAction;
import org.opensearch.flowframework.transport.SearchWorkflowTransportAction;
import org.opensearch.flowframework.workflow.WorkflowProcessSorter;
import org.opensearch.flowframework.workflow.WorkflowStepFactory;
import org.opensearch.ml.client.MachineLearningNodeClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@
import static org.opensearch.core.xcontent.ToXContent.EMPTY_PARAMS;
import static org.opensearch.flowframework.util.RestHandlerUtils.getSourceContext;

/**
* Abstract class to handle search request.
*/
public class AbstractSearchWorkflowAction<T extends ToXContentObject> extends BaseRestHandler {

protected final List<String> urlPaths;
protected final String index;
protected final Class<T> clazz;
protected final ActionType<SearchResponse> actionType;

/**
* Instantiates a new AbstractSearchWorkflowAction
* @param urlPaths urlPaths to create routes
* @param index index the search should be done on
* @param clazz model class
* @param actionType from which action abstract class is called
*/
public AbstractSearchWorkflowAction(List<String> urlPaths, String index, Class<T> clazz, ActionType<SearchResponse> actionType) {
this.urlPaths = urlPaths;
this.index = index;
Expand All @@ -58,6 +68,12 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
return channel -> client.execute(actionType, searchRequest, search(channel));

Check warning on line 68 in src/main/java/org/opensearch/flowframework/rest/AbstractSearchWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/AbstractSearchWorkflowAction.java#L64-L68

Added lines #L64 - L68 were not covered by tests
}

/**
* Builds the action response for the Search Request
*
* @param channel the REST channel
* @return the action response
*/
protected RestResponseListener<SearchResponse> search(RestChannel channel) {
return new RestResponseListener<SearchResponse>(channel) {

Check warning on line 78 in src/main/java/org/opensearch/flowframework/rest/AbstractSearchWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/AbstractSearchWorkflowAction.java#L78

Added line #L78 was not covered by tests
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class RestCreateWorkflowAction extends BaseRestHandler {
private static final String CREATE_WORKFLOW_ACTION = "create_workflow_action";

/**
* Intantiates a new RestCreateWorkflowAction
* Instantiates a new RestCreateWorkflowAction
*/
public RestCreateWorkflowAction() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX;
import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_URI;

/**
* Rest Action to facilitate requests to search workflows
*/
public class RestSearchWorkflowAction extends AbstractSearchWorkflowAction<Template> {

private static final String SEARCH_WORKFLOW_ACTION = "search_workflow_action";
private static final String SEARCH_WORKFLOW_PATH = WORKFLOW_URI + "/_search";

/**
* Instantiates a new RestCreateWorkflowAction
*/
public RestSearchWorkflowAction() {
super(ImmutableList.of(SEARCH_WORKFLOW_PATH), GLOBAL_CONTEXT_INDEX, Template.class, SearchWorkflowAction.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.opensearch.flowframework.common.CommonValue.TRANSPORT_ACION_NAME_PREFIX;

/**
* External Action for public facing RestCreateWorkflowActiom
* External Action for public facing RestCreateWorkflowAction
*/
public class CreateWorkflowAction extends ActionType<WorkflowResponse> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import static org.opensearch.flowframework.common.CommonValue.TRANSPORT_ACION_NAME_PREFIX;

/**
* External Action for public facing RestSearchWorkflowAction
*/
public class SearchWorkflowAction extends ActionType<SearchResponse> {

/** The name of this action */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

/**
* Transport Action to search workflows created
*/
public class SearchWorkflowTransportAction extends HandledTransportAction<SearchRequest, SearchResponse> {
private Client client;

/**
* Intantiates a new CreateWorkflowTransportAction
* @param transportService the TransportService
* @param actionFilters action filters
* @param client The client used to make the request to OS
*/
@Inject
public SearchWorkflowTransportAction(TransportService transportService, ActionFilters actionFilters, Client client) {
super(SearchWorkflowAction.NAME, transportService, actionFilters, SearchRequest::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.search.fetch.subphase.FetchSourceContext;

/**
* Utility methods for Rest Handlers
*/
public class RestHandlerUtils {

public static final String[] USER_EXCLUDE = new String[] { CommonValue.USER_FIELD };

Check warning on line 22 in src/main/java/org/opensearch/flowframework/util/RestHandlerUtils.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/util/RestHandlerUtils.java#L22

Added line #L22 was not covered by tests

private RestHandlerUtils() {}

/**
* Creates a source context and include/exclude information to be shared based on the user
*
* @param request the REST request
* @param searchSourceBuilder the search request source builder
* @return modified sources
*/
public static FetchSourceContext getSourceContext(RestRequest request, SearchSourceBuilder searchSourceBuilder) {
// TODO
// 1. Move UI_METADATA to GC Index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void tearDown() throws Exception {
public void testPlugin() throws IOException {
try (FlowFrameworkPlugin ffp = new FlowFrameworkPlugin()) {
assertEquals(3, ffp.createComponents(client, null, threadPool, null, null, null, null, null, null, null, null).size());
assertEquals(2, ffp.getRestHandlers(null, null, null, null, null, null, null).size());
assertEquals(2, ffp.getActions().size());
assertEquals(3, ffp.getRestHandlers(null, null, null, null, null, null, null).size());
assertEquals(3, ffp.getActions().size());
assertEquals(1, ffp.getExecutorBuilders(settings).size());
}
}
Expand Down

0 comments on commit 57869ff

Please sign in to comment.