From eeb88a02dee6e42d5fa709761649037568a173a5 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 20 Dec 2023 14:07:08 -0800 Subject: [PATCH] Change dryrun param in create workflow to validation Signed-off-by: Jackie Han --- .../flowframework/common/CommonValue.java | 4 ++-- .../rest/RestCreateWorkflowAction.java | 6 ++--- .../CreateWorkflowTransportAction.java | 2 +- .../transport/WorkflowRequest.java | 24 +++++++++---------- .../FlowFrameworkRestTestCase.java | 6 ++--- .../rest/FlowFrameworkRestApiIT.java | 2 +- .../CreateWorkflowTransportActionTests.java | 8 +++---- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/common/CommonValue.java b/src/main/java/org/opensearch/flowframework/common/CommonValue.java index bb9eaf108..ffe45c87e 100644 --- a/src/main/java/org/opensearch/flowframework/common/CommonValue.java +++ b/src/main/java/org/opensearch/flowframework/common/CommonValue.java @@ -63,8 +63,8 @@ private CommonValue() {} public static final String WORKFLOW_URI = FLOW_FRAMEWORK_BASE_URI + "/workflow"; /** Field name for workflow Id, the document Id of the indexed use case template */ public static final String WORKFLOW_ID = "workflow_id"; - /** Field name for dry run, the flag to indicate if validation is necessary */ - public static final String DRY_RUN = "dryrun"; + /** Field name for template validation, the flag to indicate if validation is necessary */ + public static final String VALIDATION = "validation"; /** The field name for provision workflow within a use case template*/ public static final String PROVISION_WORKFLOW = "provision"; diff --git a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java index e254b66f7..a70b0104b 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java @@ -32,8 +32,8 @@ import java.util.Locale; import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; -import static org.opensearch.flowframework.common.CommonValue.DRY_RUN; import static org.opensearch.flowframework.common.CommonValue.PROVISION_WORKFLOW; +import static org.opensearch.flowframework.common.CommonValue.VALIDATION; import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_ID; import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_URI; import static org.opensearch.flowframework.common.FlowFrameworkSettings.FLOW_FRAMEWORK_ENABLED; @@ -94,10 +94,10 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentParser parser = request.contentParser(); ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); Template template = Template.parse(parser); - boolean dryRun = request.paramAsBoolean(DRY_RUN, false); + boolean validation = request.paramAsBoolean(VALIDATION, true); boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false); - WorkflowRequest workflowRequest = new WorkflowRequest(workflowId, template, dryRun, provision, requestTimeout, maxWorkflows); + WorkflowRequest workflowRequest = new WorkflowRequest(workflowId, template, validation, provision, requestTimeout, maxWorkflows); return channel -> client.execute(CreateWorkflowAction.INSTANCE, workflowRequest, ActionListener.wrap(response -> { XContentBuilder builder = response.toXContent(channel.newBuilder(), ToXContent.EMPTY_PARAMS); diff --git a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java index 92f89c082..83bd586bf 100644 --- a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java @@ -95,7 +95,7 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener createWorkflowDryRun(cyclicalTemplate)); + ResponseException exception = expectThrows(ResponseException.class, () -> createWorkflowValidation(cyclicalTemplate)); assertTrue(exception.getMessage().contains("Cycle detected: [workflow_step_2->workflow_step_1, workflow_step_1->workflow_step_2]")); // Hit Create Workflow API with original template diff --git a/src/test/java/org/opensearch/flowframework/transport/CreateWorkflowTransportActionTests.java b/src/test/java/org/opensearch/flowframework/transport/CreateWorkflowTransportActionTests.java index 0addb7f1f..9e3f1c409 100644 --- a/src/test/java/org/opensearch/flowframework/transport/CreateWorkflowTransportActionTests.java +++ b/src/test/java/org/opensearch/flowframework/transport/CreateWorkflowTransportActionTests.java @@ -138,7 +138,7 @@ public void setUp() throws Exception { ); } - public void testDryRunValidation_withoutProvision_Success() { + public void testValidation_withoutProvision_Success() { Template validTemplate = generateValidTemplate(); @SuppressWarnings("unchecked") @@ -147,7 +147,7 @@ public void testDryRunValidation_withoutProvision_Success() { createWorkflowTransportAction.doExecute(mock(Task.class), createNewWorkflow, listener); } - public void testDryRunValidation_Failed() throws Exception { + public void testValidation_Failed() throws Exception { WorkflowNode createConnector = new WorkflowNode( "workflow_step_1", @@ -374,7 +374,7 @@ public void testUpdateWorkflow() { assertEquals("1", responseCaptor.getValue().getWorkflowId()); } - public void testCreateWorkflow_withDryRun_withProvision_Success() throws Exception { + public void testCreateWorkflow_withValidation_withProvision_Success() throws Exception { Template validTemplate = generateValidTemplate(); @@ -435,7 +435,7 @@ public void testCreateWorkflow_withDryRun_withProvision_Success() throws Excepti assertEquals("1", workflowResponseCaptor.getValue().getWorkflowId()); } - public void testCreateWorkflow_withDryRun_withProvision_FailedProvisioning() throws Exception { + public void testCreateWorkflow_withValidation_withProvision_FailedProvisioning() throws Exception { Template validTemplate = generateValidTemplate();