diff --git a/src/main/java/org/opensearch/flowframework/FlowFrameworkPlugin.java b/src/main/java/org/opensearch/flowframework/FlowFrameworkPlugin.java index 2119c134b..8614a0be7 100644 --- a/src/main/java/org/opensearch/flowframework/FlowFrameworkPlugin.java +++ b/src/main/java/org/opensearch/flowframework/FlowFrameworkPlugin.java @@ -29,15 +29,15 @@ import org.opensearch.flowframework.indices.FlowFrameworkIndicesHandler; import org.opensearch.flowframework.rest.RestCreateWorkflowAction; import org.opensearch.flowframework.rest.RestGetTemplateAction; -import org.opensearch.flowframework.rest.RestGetWorkflowAction; +import org.opensearch.flowframework.rest.RestGetWorkflowStateAction; import org.opensearch.flowframework.rest.RestProvisionWorkflowAction; import org.opensearch.flowframework.rest.RestSearchWorkflowAction; import org.opensearch.flowframework.transport.CreateWorkflowAction; import org.opensearch.flowframework.transport.CreateWorkflowTransportAction; import org.opensearch.flowframework.transport.GetTemplateAction; import org.opensearch.flowframework.transport.GetTemplateTransportAction; -import org.opensearch.flowframework.transport.GetWorkflowAction; -import org.opensearch.flowframework.transport.GetWorkflowTransportAction; +import org.opensearch.flowframework.transport.GetWorkflowStateAction; +import org.opensearch.flowframework.transport.GetWorkflowStateTransportAction; import org.opensearch.flowframework.transport.ProvisionWorkflowAction; import org.opensearch.flowframework.transport.ProvisionWorkflowTransportAction; import org.opensearch.flowframework.transport.SearchWorkflowAction; @@ -128,7 +128,7 @@ public List getRestHandlers( new RestCreateWorkflowAction(flowFrameworkFeatureEnabledSetting, settings, clusterService), new RestProvisionWorkflowAction(flowFrameworkFeatureEnabledSetting), new RestSearchWorkflowAction(flowFrameworkFeatureEnabledSetting), - new RestGetWorkflowAction(flowFrameworkFeatureEnabledSetting), + new RestGetWorkflowStateAction(flowFrameworkFeatureEnabledSetting), new RestGetTemplateAction(flowFrameworkFeatureEnabledSetting) ); } @@ -139,7 +139,7 @@ public List getRestHandlers( new ActionHandler<>(CreateWorkflowAction.INSTANCE, CreateWorkflowTransportAction.class), new ActionHandler<>(ProvisionWorkflowAction.INSTANCE, ProvisionWorkflowTransportAction.class), new ActionHandler<>(SearchWorkflowAction.INSTANCE, SearchWorkflowTransportAction.class), - new ActionHandler<>(GetWorkflowAction.INSTANCE, GetWorkflowTransportAction.class), + new ActionHandler<>(GetWorkflowStateAction.INSTANCE, GetWorkflowStateTransportAction.class), new ActionHandler<>(GetTemplateAction.INSTANCE, GetTemplateTransportAction.class) ); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java similarity index 84% rename from src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java rename to src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java index 6d9d5e3b5..ab7335b2d 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java @@ -19,8 +19,8 @@ import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting; import org.opensearch.flowframework.exception.FlowFrameworkException; -import org.opensearch.flowframework.transport.GetWorkflowAction; -import org.opensearch.flowframework.transport.GetWorkflowRequest; +import org.opensearch.flowframework.transport.GetWorkflowStateAction; +import org.opensearch.flowframework.transport.GetWorkflowStateRequest; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestRequest; @@ -36,23 +36,23 @@ /** * Rest Action to facilitate requests to get a workflow status */ -public class RestGetWorkflowAction extends BaseRestHandler { +public class RestGetWorkflowStateAction extends BaseRestHandler { - private static final String GET_WORKFLOW_ACTION = "get_workflow"; - private static final Logger logger = LogManager.getLogger(RestGetWorkflowAction.class); + private static final String GET_WORKFLOW_STATE_ACTION = "get_workflow_state"; + private static final Logger logger = LogManager.getLogger(RestGetWorkflowStateAction.class); private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting; /** - * Instantiates a new RestGetWorkflowAction + * Instantiates a new RestGetWorkflowStateAction * @param flowFrameworkFeatureEnabledSetting Whether this API is enabled */ - public RestGetWorkflowAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) { + public RestGetWorkflowStateAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) { this.flowFrameworkFeatureEnabledSetting = flowFrameworkFeatureEnabledSetting; } @Override public String getName() { - return GET_WORKFLOW_ACTION; + return GET_WORKFLOW_STATE_ACTION; } @Override @@ -77,8 +77,8 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request } boolean all = request.paramAsBoolean("all", false); - GetWorkflowRequest getWorkflowRequest = new GetWorkflowRequest(workflowId, all); - return channel -> client.execute(GetWorkflowAction.INSTANCE, getWorkflowRequest, ActionListener.wrap(response -> { + GetWorkflowStateRequest getWorkflowRequest = new GetWorkflowStateRequest(workflowId, all); + return channel -> client.execute(GetWorkflowStateAction.INSTANCE, getWorkflowRequest, ActionListener.wrap(response -> { XContentBuilder builder = response.toXContent(channel.newBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); }, exception -> { @@ -103,7 +103,6 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request @Override public List routes() { return ImmutableList.of( - // Provision workflow from indexed use case template new Route(RestRequest.Method.GET, String.format(Locale.ROOT, "%s/{%s}/%s", WORKFLOW_URI, WORKFLOW_ID, "_status")) ); } diff --git a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowAction.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateAction.java similarity index 62% rename from src/main/java/org/opensearch/flowframework/transport/GetWorkflowAction.java rename to src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateAction.java index 6abee3867..99c521362 100644 --- a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateAction.java @@ -13,15 +13,15 @@ import static org.opensearch.flowframework.common.CommonValue.TRANSPORT_ACTION_NAME_PREFIX; /** - * External Action for public facing RestGetWorkflowAction + * External Action for public facing RestGetWorkflowStateAction */ -public class GetWorkflowAction extends ActionType { +public class GetWorkflowStateAction extends ActionType { /** The name of this action */ - public static final String NAME = TRANSPORT_ACTION_NAME_PREFIX + "workflow/get"; + public static final String NAME = TRANSPORT_ACTION_NAME_PREFIX + "workflowstate/get"; /** An instance of this action */ - public static final GetWorkflowAction INSTANCE = new GetWorkflowAction(); + public static final GetWorkflowStateAction INSTANCE = new GetWorkflowStateAction(); - private GetWorkflowAction() { - super(NAME, GetWorkflowResponse::new); + private GetWorkflowStateAction() { + super(NAME, GetWorkflowStateResponse::new); } } diff --git a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowRequest.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateRequest.java similarity index 88% rename from src/main/java/org/opensearch/flowframework/transport/GetWorkflowRequest.java rename to src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateRequest.java index c7594eb77..36a9ccf6c 100644 --- a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowRequest.java +++ b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateRequest.java @@ -17,9 +17,9 @@ import java.io.IOException; /** - * Transport Request to get a workflow or workflow status + * Transport Request to get a workflow state */ -public class GetWorkflowRequest extends ActionRequest { +public class GetWorkflowStateRequest extends ActionRequest { /** * The documentId of the workflow entry within the Global Context index @@ -37,7 +37,7 @@ public class GetWorkflowRequest extends ActionRequest { * @param workflowId the documentId of the workflow * @param all whether the get request is looking for all fields in status */ - public GetWorkflowRequest(@Nullable String workflowId, boolean all) { + public GetWorkflowStateRequest(@Nullable String workflowId, boolean all) { this.workflowId = workflowId; this.all = all; } @@ -47,7 +47,7 @@ public GetWorkflowRequest(@Nullable String workflowId, boolean all) { * @param in The input stream to read from * @throws IOException If the stream cannot be read properly */ - public GetWorkflowRequest(StreamInput in) throws IOException { + public GetWorkflowStateRequest(StreamInput in) throws IOException { super(in); this.workflowId = in.readString(); this.all = in.readBoolean(); diff --git a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowResponse.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateResponse.java similarity index 89% rename from src/main/java/org/opensearch/flowframework/transport/GetWorkflowResponse.java rename to src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateResponse.java index 922a8a3f5..ec24aa2cd 100644 --- a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowResponse.java +++ b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateResponse.java @@ -20,7 +20,7 @@ /** * Transport Response from getting a workflow status */ -public class GetWorkflowResponse extends ActionResponse implements ToXContentObject { +public class GetWorkflowStateResponse extends ActionResponse implements ToXContentObject { /** The workflow state */ public WorkflowState workflowState; @@ -32,7 +32,7 @@ public class GetWorkflowResponse extends ActionResponse implements ToXContentObj * @param in the input stream to read from * @throws IOException if the workflowId cannot be read from the input stream */ - public GetWorkflowResponse(StreamInput in) throws IOException { + public GetWorkflowStateResponse(StreamInput in) throws IOException { super(in); workflowState = new WorkflowState(in); allStatus = in.readBoolean(); @@ -43,7 +43,7 @@ public GetWorkflowResponse(StreamInput in) throws IOException { * @param workflowState the workflow state object * @param allStatus whether to return all fields in state index */ - public GetWorkflowResponse(WorkflowState workflowState, boolean allStatus) { + public GetWorkflowStateResponse(WorkflowState workflowState, boolean allStatus) { if (allStatus) { this.workflowState = workflowState; } else { diff --git a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateTransportAction.java similarity index 87% rename from src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java rename to src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateTransportAction.java index f3bc1dd9e..57fcc2b89 100644 --- a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateTransportAction.java @@ -38,34 +38,34 @@ * Transport Action to get a specific workflow. Currently, we only support the action with _status * in the API path but will add the ability to get the workflow and not just the status in the future */ -public class GetWorkflowTransportAction extends HandledTransportAction { +public class GetWorkflowStateTransportAction extends HandledTransportAction { - private final Logger logger = LogManager.getLogger(GetWorkflowTransportAction.class); + private final Logger logger = LogManager.getLogger(GetWorkflowStateTransportAction.class); private final Client client; private final NamedXContentRegistry xContentRegistry; /** - * Intantiates a new CreateWorkflowTransportAction + * Intantiates a new GetWorkflowStateTransportAction * @param transportService The TransportService * @param actionFilters action filters * @param client The client used to make the request to OS * @param xContentRegistry contentRegister to parse get response */ @Inject - public GetWorkflowTransportAction( + public GetWorkflowStateTransportAction( TransportService transportService, ActionFilters actionFilters, Client client, NamedXContentRegistry xContentRegistry ) { - super(GetWorkflowAction.NAME, transportService, actionFilters, GetWorkflowRequest::new); + super(GetWorkflowStateAction.NAME, transportService, actionFilters, GetWorkflowStateRequest::new); this.client = client; this.xContentRegistry = xContentRegistry; } @Override - protected void doExecute(Task task, GetWorkflowRequest request, ActionListener listener) { + protected void doExecute(Task task, GetWorkflowStateRequest request, ActionListener listener) { String workflowId = request.getWorkflowId(); User user = ParseUtils.getUserContext(client); GetRequest getRequest = new GetRequest(WORKFLOW_STATE_INDEX).id(workflowId); @@ -75,7 +75,7 @@ protected void doExecute(Task task, GetWorkflowRequest request, ActionListener response; + private ActionListener response; private Task task; @Override @@ -52,7 +52,7 @@ public void setUp() throws Exception { super.setUp(); this.client = mock(Client.class); this.threadPool = mock(ThreadPool.class); - this.getWorkflowTransportAction = new GetWorkflowTransportAction( + this.getWorkflowTransportAction = new GetWorkflowStateTransportAction( mock(TransportService.class), mock(ActionFilters.class), client, @@ -65,9 +65,9 @@ public void setUp() throws Exception { when(client.threadPool()).thenReturn(clientThreadPool); when(clientThreadPool.getThreadContext()).thenReturn(threadContext); - response = new ActionListener() { + response = new ActionListener() { @Override - public void onResponse(GetWorkflowResponse getResponse) { + public void onResponse(GetWorkflowStateResponse getResponse) { assertTrue(true); } @@ -78,21 +78,21 @@ public void onFailure(Exception e) {} } public void testGetTransportAction() throws IOException { - GetWorkflowRequest getWorkflowRequest = new GetWorkflowRequest("1234", false); + GetWorkflowStateRequest getWorkflowRequest = new GetWorkflowStateRequest("1234", false); getWorkflowTransportAction.doExecute(task, getWorkflowRequest, response); } public void testGetAction() { - Assert.assertNotNull(GetWorkflowAction.INSTANCE.name()); - Assert.assertEquals(GetWorkflowAction.INSTANCE.name(), GetWorkflowAction.NAME); + Assert.assertNotNull(GetWorkflowStateAction.INSTANCE.name()); + Assert.assertEquals(GetWorkflowStateAction.INSTANCE.name(), GetWorkflowStateAction.NAME); } public void testGetAnomalyDetectorRequest() throws IOException { - GetWorkflowRequest request = new GetWorkflowRequest("1234", false); + GetWorkflowStateRequest request = new GetWorkflowStateRequest("1234", false); BytesStreamOutput out = new BytesStreamOutput(); request.writeTo(out); StreamInput input = out.bytes().streamInput(); - GetWorkflowRequest newRequest = new GetWorkflowRequest(input); + GetWorkflowStateRequest newRequest = new GetWorkflowStateRequest(input); Assert.assertEquals(request.getWorkflowId(), newRequest.getWorkflowId()); Assert.assertEquals(request.getAll(), newRequest.getAll()); Assert.assertNull(newRequest.validate()); @@ -113,10 +113,10 @@ public void testGetAnomalyDetectorResponse() throws IOException { Collections.emptyList() ); - GetWorkflowResponse response = new GetWorkflowResponse(workFlowState, false); + GetWorkflowStateResponse response = new GetWorkflowStateResponse(workFlowState, false); response.writeTo(out); NamedWriteableAwareStreamInput input = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), writableRegistry()); - GetWorkflowResponse newResponse = new GetWorkflowResponse(input); + GetWorkflowStateResponse newResponse = new GetWorkflowStateResponse(input); XContentBuilder builder = TestHelpers.builder(); Assert.assertNotNull(newResponse.toXContent(builder, ToXContent.EMPTY_PARAMS));