From 17b0739964cf30a32a2499d2a91b79595274c5b7 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 13 Dec 2023 16:27:13 -0800 Subject: [PATCH] keep both dryRun and provision parameter Signed-off-by: Jackie Han --- .../rest/RestCreateWorkflowAction.java | 4 +++- .../CreateWorkflowTransportAction.java | 2 +- .../transport/WorkflowRequest.java | 17 +++++++++++++++-- .../CreateWorkflowTransportActionTests.java | 15 ++++++++++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java index 8fb354fa1..deeabdd76 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Locale; +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.WORKFLOW_ID; import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_URI; @@ -90,9 +91,10 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli String workflowId = request.param(WORKFLOW_ID); Template template = Template.parse(request.content().utf8ToString()); + boolean dryRun = request.paramAsBoolean(DRY_RUN, false); boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false); - WorkflowRequest workflowRequest = new WorkflowRequest(workflowId, template, provision, requestTimeout, maxWorkflows); + WorkflowRequest workflowRequest = new WorkflowRequest(workflowId, template, dryRun, 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 de3c6fc13..765c9cae5 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 listener = mock(ActionListener.class); - WorkflowRequest createNewWorkflow = new WorkflowRequest(null, validTemplate, true, null, null); + WorkflowRequest createNewWorkflow = new WorkflowRequest(null, validTemplate, true, false, null, null); createWorkflowTransportAction.doExecute(mock(Task.class), createNewWorkflow, listener); } @@ -207,7 +207,7 @@ public void testDryRunValidation_Failed() { @SuppressWarnings("unchecked") ActionListener listener = mock(ActionListener.class); - WorkflowRequest createNewWorkflow = new WorkflowRequest(null, cyclicalTemplate, true, null, null); + WorkflowRequest createNewWorkflow = new WorkflowRequest(null, cyclicalTemplate, true, false, null, null); createWorkflowTransportAction.doExecute(mock(Task.class), createNewWorkflow, listener); ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(Exception.class); @@ -222,6 +222,7 @@ public void testMaxWorkflow() { null, template, false, + false, WORKFLOW_REQUEST_TIMEOUT.get(settings), MAX_WORKFLOWS.get(settings) ); @@ -259,6 +260,7 @@ public void testFailedToCreateNewWorkflow() { null, template, false, + false, WORKFLOW_REQUEST_TIMEOUT.get(settings), MAX_WORKFLOWS.get(settings) ); @@ -296,6 +298,7 @@ public void testCreateNewWorkflow() { null, template, false, + false, WORKFLOW_REQUEST_TIMEOUT.get(settings), MAX_WORKFLOWS.get(settings) ); @@ -378,7 +381,7 @@ public void testUpdateWorkflow() { assertEquals("1", responseCaptor.getValue().getWorkflowId()); } - public void testCreateWorkflow_withProvisionParam() { + public void testCreateWorkflow_withDryRun_withProvision_Success() { Template validTemplate = generateValidTemplate(); @@ -388,6 +391,7 @@ public void testCreateWorkflow_withProvisionParam() { null, validTemplate, true, + true, WORKFLOW_REQUEST_TIMEOUT.get(settings), MAX_WORKFLOWS.get(settings) ); @@ -436,7 +440,7 @@ public void testCreateWorkflow_withProvisionParam() { assertEquals("1", workflowResponseCaptor.getValue().getWorkflowId()); } - public void testCreateWorkflow_withFailedProvision() { + public void testCreateWorkflow_withDryRun_withProvision_FailedProvisioning() { Template validTemplate = generateValidTemplate(); @SuppressWarnings("unchecked") @@ -445,6 +449,7 @@ public void testCreateWorkflow_withFailedProvision() { null, validTemplate, true, + true, WORKFLOW_REQUEST_TIMEOUT.get(settings), MAX_WORKFLOWS.get(settings) );