Skip to content

Commit

Permalink
Renaming GetTemplate API to GetWorkflow API
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <[email protected]>
  • Loading branch information
joshpalis committed Dec 11, 2023
1 parent 59c7f2a commit 4b113ba
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
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.GetWorkflowStateAction;
import org.opensearch.flowframework.transport.GetWorkflowStateTransportAction;
import org.opensearch.flowframework.transport.GetWorkflowTransportAction;
import org.opensearch.flowframework.transport.ProvisionWorkflowAction;
import org.opensearch.flowframework.transport.ProvisionWorkflowTransportAction;
import org.opensearch.flowframework.transport.SearchWorkflowAction;
Expand Down Expand Up @@ -129,7 +129,7 @@ public List<RestHandler> getRestHandlers(
new RestProvisionWorkflowAction(flowFrameworkFeatureEnabledSetting),
new RestSearchWorkflowAction(flowFrameworkFeatureEnabledSetting),
new RestGetWorkflowStateAction(flowFrameworkFeatureEnabledSetting),
new RestGetTemplateAction(flowFrameworkFeatureEnabledSetting)
new RestGetWorkflowAction(flowFrameworkFeatureEnabledSetting)
);
}

Expand All @@ -140,7 +140,7 @@ public List<RestHandler> getRestHandlers(
new ActionHandler<>(ProvisionWorkflowAction.INSTANCE, ProvisionWorkflowTransportAction.class),
new ActionHandler<>(SearchWorkflowAction.INSTANCE, SearchWorkflowTransportAction.class),
new ActionHandler<>(GetWorkflowStateAction.INSTANCE, GetWorkflowStateTransportAction.class),
new ActionHandler<>(GetTemplateAction.INSTANCE, GetTemplateTransportAction.class)
new ActionHandler<>(GetWorkflowAction.INSTANCE, GetWorkflowTransportAction.class)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.transport.GetTemplateAction;
import org.opensearch.flowframework.transport.GetWorkflowAction;
import org.opensearch.flowframework.transport.WorkflowRequest;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.BytesRestResponse;
Expand All @@ -36,23 +36,23 @@
/**
* Rest Action to facilitate requests to get a stored template
*/
public class RestGetTemplateAction extends BaseRestHandler {
public class RestGetWorkflowAction extends BaseRestHandler {

private static final String GET_TEMPLATE_ACTION = "get_template";
private static final Logger logger = LogManager.getLogger(RestGetTemplateAction.class);
private static final String GET_WORKFLOW_ACTION = "get_workflow";
private static final Logger logger = LogManager.getLogger(RestGetWorkflowAction.class);
private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new RestGetWorkflowAction
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestGetTemplateAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestGetWorkflowAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
this.flowFrameworkFeatureEnabledSetting = flowFrameworkFeatureEnabledSetting;
}

@Override
public String getName() {
return GET_TEMPLATE_ACTION;
return GET_WORKFLOW_ACTION;
}

@Override
Expand Down Expand Up @@ -82,7 +82,7 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request
}

WorkflowRequest workflowRequest = new WorkflowRequest(workflowId, null);
return channel -> client.execute(GetTemplateAction.INSTANCE, workflowRequest, ActionListener.wrap(response -> {
return channel -> client.execute(GetWorkflowAction.INSTANCE, workflowRequest, ActionListener.wrap(response -> {
XContentBuilder builder = response.toXContent(channel.newBuilder(), ToXContent.EMPTY_PARAMS);
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
}, exception -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
import static org.opensearch.flowframework.common.CommonValue.TRANSPORT_ACTION_NAME_PREFIX;

/**
* External Action for public facing RestGetTemplateAction
* External Action for public facing RestGetWorkflowAction
*/
public class GetTemplateAction extends ActionType<GetTemplateResponse> {
public class GetWorkflowAction extends ActionType<GetWorkflowResponse> {
/** The name of this action */
public static final String NAME = TRANSPORT_ACTION_NAME_PREFIX + "template/get";
public static final String NAME = TRANSPORT_ACTION_NAME_PREFIX + "workflow/get";
/** An instance of this action */
public static final GetTemplateAction INSTANCE = new GetTemplateAction();
public static final GetWorkflowAction INSTANCE = new GetWorkflowAction();

private GetTemplateAction() {
super(NAME, GetTemplateResponse::new);
private GetWorkflowAction() {
super(NAME, GetWorkflowResponse::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@
/**
* Transport Response from getting a template
*/
public class GetTemplateResponse extends ActionResponse implements ToXContentObject {
public class GetWorkflowResponse extends ActionResponse implements ToXContentObject {

/** The template */
private Template template;

/**
* Instantiates a new GetTemplateResponse from an input stream
* Instantiates a new GetWorkflowResponse from an input stream
* @param in the input stream to read from
* @throws IOException if the template json cannot be read from the input stream
*/
public GetTemplateResponse(StreamInput in) throws IOException {
public GetWorkflowResponse(StreamInput in) throws IOException {
super(in);
this.template = Template.parse(in.readString());
}

/**
* Instantiates a new GetTemplateResponse
* Instantiates a new GetWorkflowResponse
* @param template the template
*/
public GetTemplateResponse(Template template) {
public GetWorkflowResponse(Template template) {
this.template = template;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@
/**
* Transport action to retrieve a use case template within the Global Context
*/
public class GetTemplateTransportAction extends HandledTransportAction<WorkflowRequest, GetTemplateResponse> {
public class GetWorkflowTransportAction extends HandledTransportAction<WorkflowRequest, GetWorkflowResponse> {

private final Logger logger = LogManager.getLogger(GetTemplateTransportAction.class);
private final Logger logger = LogManager.getLogger(GetWorkflowTransportAction.class);
private final FlowFrameworkIndicesHandler flowFrameworkIndicesHandler;
private final Client client;

/**
* Instantiates a new GetTempltateTransportAction instance
* Instantiates a new GetWorkflowTransportAction instance
* @param transportService the transport service
* @param actionFilters action filters
* @param flowFrameworkIndicesHandler The Flow Framework indices handler
* @param client the Opensearch Client
*/
@Inject
public GetTemplateTransportAction(
public GetWorkflowTransportAction(
TransportService transportService,
ActionFilters actionFilters,
FlowFrameworkIndicesHandler flowFrameworkIndicesHandler,
Client client
) {
super(GetTemplateAction.NAME, transportService, actionFilters, WorkflowRequest::new);
super(GetWorkflowAction.NAME, transportService, actionFilters, WorkflowRequest::new);
this.flowFrameworkIndicesHandler = flowFrameworkIndicesHandler;
this.client = client;
}

@Override
protected void doExecute(Task task, WorkflowRequest request, ActionListener<GetTemplateResponse> listener) {
protected void doExecute(Task task, WorkflowRequest request, ActionListener<GetWorkflowResponse> listener) {
if (flowFrameworkIndicesHandler.doesIndexExist(GLOBAL_CONTEXT_INDEX)) {

String workflowId = request.getWorkflowId();
Expand All @@ -75,7 +75,7 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener<GetT
)
);
} else {
listener.onResponse(new GetTemplateResponse(Template.parse(response.getSourceAsString())));
listener.onResponse(new GetWorkflowResponse(Template.parse(response.getSourceAsString())));
}
}, exception -> {
logger.error("Failed to retrieve template from global context.", exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RestGetTemplateActionTests extends OpenSearchTestCase {
private RestGetTemplateAction restGetTemplateAction;
public class RestGetWorkflowActionTests extends OpenSearchTestCase {
private RestGetWorkflowAction restGetWorkflowAction;
private String getPath;
private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private NodeClient nodeClient;
Expand All @@ -39,17 +39,17 @@ public void setUp() throws Exception {
this.getPath = String.format(Locale.ROOT, "%s/{%s}", WORKFLOW_URI, "workflow_id");
flowFrameworkFeatureEnabledSetting = mock(FlowFrameworkFeatureEnabledSetting.class);
when(flowFrameworkFeatureEnabledSetting.isFlowFrameworkEnabled()).thenReturn(true);
this.restGetTemplateAction = new RestGetTemplateAction(flowFrameworkFeatureEnabledSetting);
this.restGetWorkflowAction = new RestGetWorkflowAction(flowFrameworkFeatureEnabledSetting);
this.nodeClient = mock(NodeClient.class);
}

public void testRestGetWorkflowActionName() {
String name = restGetTemplateAction.getName();
assertEquals("get_template", name);
String name = restGetWorkflowAction.getName();
assertEquals("get_workflow", name);
}

public void testRestGetWorkflowActionRoutes() {
List<RestHandler.Route> routes = restGetTemplateAction.routes();
List<RestHandler.Route> routes = restGetWorkflowAction.routes();
assertEquals(1, routes.size());
assertEquals(RestRequest.Method.GET, routes.get(0).getMethod());
assertEquals(this.getPath, routes.get(0).getPath());
Expand All @@ -63,7 +63,7 @@ public void testInvalidRequestWithContent() {

FakeRestChannel channel = new FakeRestChannel(request, false, 1);
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> {
restGetTemplateAction.handleRequest(request, channel, nodeClient);
restGetWorkflowAction.handleRequest(request, channel, nodeClient);
});
assertEquals("request [POST /_plugins/_flow_framework/workflow/{workflow_id}] does not support having a body", ex.getMessage());
}
Expand All @@ -76,7 +76,7 @@ public void testNullWorkflowId() throws Exception {
.build();

FakeRestChannel channel = new FakeRestChannel(request, true, 1);
restGetTemplateAction.handleRequest(request, channel, nodeClient);
restGetWorkflowAction.handleRequest(request, channel, nodeClient);

assertEquals(1, channel.errors().get());
assertEquals(RestStatus.BAD_REQUEST, channel.capturedResponse().status());
Expand All @@ -89,7 +89,7 @@ public void testFeatureFlagNotEnabled() throws Exception {
.withPath(this.getPath)
.build();
FakeRestChannel channel = new FakeRestChannel(request, false, 1);
restGetTemplateAction.handleRequest(request, channel, nodeClient);
restGetWorkflowAction.handleRequest(request, channel, nodeClient);
assertEquals(RestStatus.FORBIDDEN, channel.capturedResponse().status());
assertTrue(channel.capturedResponse().content().utf8ToString().contains("This API is disabled."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static org.mockito.Mockito.when;

public class RestGetWorkflowStateActionTests extends OpenSearchTestCase {
private RestGetWorkflowStateAction restGetWorkflowAction;
private RestGetWorkflowStateAction restGetWorkflowStateAction;
private String getPath;
private NodeClient nodeClient;
private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
Expand All @@ -39,7 +39,7 @@ public void setUp() throws Exception {
this.getPath = String.format(Locale.ROOT, "%s/{%s}/%s", WORKFLOW_URI, "workflow_id", "_status");
flowFrameworkFeatureEnabledSetting = mock(FlowFrameworkFeatureEnabledSetting.class);
when(flowFrameworkFeatureEnabledSetting.isFlowFrameworkEnabled()).thenReturn(true);
this.restGetWorkflowAction = new RestGetWorkflowStateAction(flowFrameworkFeatureEnabledSetting);
this.restGetWorkflowStateAction = new RestGetWorkflowStateAction(flowFrameworkFeatureEnabledSetting);
this.nodeClient = mock(NodeClient.class);
}

Expand All @@ -48,13 +48,13 @@ public void testConstructor() {
assertNotNull(getWorkflowAction);
}

public void testRestGetWorkflowActionName() {
String name = restGetWorkflowAction.getName();
public void testRestGetWorkflowStateActionName() {
String name = restGetWorkflowStateAction.getName();
assertEquals("get_workflow_state", name);
}

public void testRestGetWorkflowActionRoutes() {
List<RestHandler.Route> routes = restGetWorkflowAction.routes();
public void testRestGetWorkflowStateActionRoutes() {
List<RestHandler.Route> routes = restGetWorkflowStateAction.routes();
assertEquals(1, routes.size());
assertEquals(RestRequest.Method.GET, routes.get(0).getMethod());
assertEquals(this.getPath, routes.get(0).getPath());
Expand All @@ -68,7 +68,7 @@ public void testNullWorkflowId() throws Exception {
.build();

FakeRestChannel channel = new FakeRestChannel(request, true, 1);
restGetWorkflowAction.handleRequest(request, channel, nodeClient);
restGetWorkflowStateAction.handleRequest(request, channel, nodeClient);

assertEquals(1, channel.errors().get());
assertEquals(RestStatus.BAD_REQUEST, channel.capturedResponse().status());
Expand All @@ -83,7 +83,7 @@ public void testInvalidRequestWithContent() {

FakeRestChannel channel = new FakeRestChannel(request, false, 1);
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> {
restGetWorkflowAction.handleRequest(request, channel, nodeClient);
restGetWorkflowStateAction.handleRequest(request, channel, nodeClient);
});
assertEquals(
"request [POST /_plugins/_flow_framework/workflow/{workflow_id}/_status] does not support having a body",
Expand All @@ -97,7 +97,7 @@ public void testFeatureFlagNotEnabled() throws Exception {
.withPath(this.getPath)
.build();
FakeRestChannel channel = new FakeRestChannel(request, false, 1);
restGetWorkflowAction.handleRequest(request, channel, nodeClient);
restGetWorkflowStateAction.handleRequest(request, channel, nodeClient);
assertEquals(RestStatus.FORBIDDEN, channel.capturedResponse().status());
assertTrue(channel.capturedResponse().content().utf8ToString().contains("This API is disabled."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testGetAction() {
Assert.assertEquals(GetWorkflowStateAction.INSTANCE.name(), GetWorkflowStateAction.NAME);
}

public void testGetAnomalyDetectorRequest() throws IOException {
public void testGetWorkflowStateRequest() throws IOException {
GetWorkflowStateRequest request = new GetWorkflowStateRequest("1234", false);
BytesStreamOutput out = new BytesStreamOutput();
request.writeTo(out);
Expand All @@ -98,7 +98,7 @@ public void testGetAnomalyDetectorRequest() throws IOException {
Assert.assertNull(newRequest.validate());
}

public void testGetAnomalyDetectorResponse() throws IOException {
public void testGetWorkflowStateResponse() throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
String workflowId = randomAlphaOfLength(5);
WorkflowState workFlowState = new WorkflowState(
Expand Down
Loading

0 comments on commit 4b113ba

Please sign in to comment.