Skip to content

Commit

Permalink
change boolean validation parameter to a string parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Dec 22, 2023
1 parent e92977d commit 20893c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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 validation = request.paramAsBoolean(VALIDATION, true);
String[] validation = request.paramAsStringArray(VALIDATION, new String[] { "all" });
boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false);

WorkflowRequest workflowRequest = new WorkflowRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

import java.util.Arrays;
import java.util.List;

import static org.opensearch.flowframework.common.CommonValue.PROVISIONING_PROGRESS_FIELD;
Expand Down Expand Up @@ -95,7 +96,8 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener<Work
user
);

if (request.isValidation()) {
String[] validateAll = { "all" };
if (Arrays.equals(request.getValidation(), validateAll)) {
try {
validateWorkflows(templateWithUser);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class WorkflowRequest extends ActionRequest {
/**
* Validation flag
*/
private boolean validation;
private String[] validation;

/**
* Provision flag
Expand All @@ -59,7 +59,7 @@ public class WorkflowRequest extends ActionRequest {
* @param template the use case template which describes the workflow
*/
public WorkflowRequest(@Nullable String workflowId, @Nullable Template template) {
this(workflowId, template, false, false, null, null);
this(workflowId, template, null, false, null, null);
}

/**
Expand All @@ -75,7 +75,7 @@ public WorkflowRequest(
@Nullable TimeValue requestTimeout,
@Nullable Integer maxWorkflows
) {
this(workflowId, template, false, false, requestTimeout, maxWorkflows);
this(workflowId, template, null, false, requestTimeout, maxWorkflows);
}

/**
Expand All @@ -90,7 +90,7 @@ public WorkflowRequest(
public WorkflowRequest(
@Nullable String workflowId,
@Nullable Template template,
boolean validation,
String[] validation,
boolean provision,
@Nullable TimeValue requestTimeout,
@Nullable Integer maxWorkflows
Expand All @@ -113,7 +113,7 @@ public WorkflowRequest(StreamInput in) throws IOException {
this.workflowId = in.readOptionalString();
String templateJson = in.readOptionalString();
this.template = templateJson == null ? null : Template.parse(templateJson);
this.validation = in.readBoolean();
this.validation = in.readStringArray();
this.provision = in.readBoolean();
this.requestTimeout = in.readOptionalTimeValue();
this.maxWorkflows = in.readOptionalInt();
Expand Down Expand Up @@ -141,7 +141,7 @@ public Template getTemplate() {
* Gets the validation flag
* @return the validation boolean
*/
public boolean isValidation() {
public String[] getValidation() {
return this.validation;
}

Expand Down Expand Up @@ -174,7 +174,7 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(workflowId);
out.writeOptionalString(template == null ? null : template.toJson());
out.writeBoolean(validation);
out.writeStringArray(validation);
out.writeBoolean(provision);
out.writeOptionalTimeValue(requestTimeout);
out.writeOptionalInt(maxWorkflows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void testValidation_withoutProvision_Success() {

@SuppressWarnings("unchecked")
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
WorkflowRequest createNewWorkflow = new WorkflowRequest(null, validTemplate, true, false, null, null);
WorkflowRequest createNewWorkflow = new WorkflowRequest(null, validTemplate, new String[] { "all" }, false, null, null);
createWorkflowTransportAction.doExecute(mock(Task.class), createNewWorkflow, listener);
}

Expand Down Expand Up @@ -203,7 +203,7 @@ public void testValidation_Failed() throws Exception {
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
// Stub validation failure
doThrow(Exception.class).when(workflowProcessSorter).validate(any());
WorkflowRequest createNewWorkflow = new WorkflowRequest(null, cyclicalTemplate, true, false, null, null);
WorkflowRequest createNewWorkflow = new WorkflowRequest(null, cyclicalTemplate, new String[] { "all" }, false, null, null);

createWorkflowTransportAction.doExecute(mock(Task.class), createNewWorkflow, listener);
verify(listener, times(1)).onFailure(any());
Expand All @@ -215,7 +215,7 @@ public void testMaxWorkflow() {
WorkflowRequest workflowRequest = new WorkflowRequest(
null,
template,
false,
new String[] { "off" },
false,
WORKFLOW_REQUEST_TIMEOUT.get(settings),
MAX_WORKFLOWS.get(settings)
Expand Down Expand Up @@ -252,7 +252,7 @@ public void testFailedToCreateNewWorkflow() {
WorkflowRequest workflowRequest = new WorkflowRequest(
null,
template,
false,
new String[] { "off" },
false,
WORKFLOW_REQUEST_TIMEOUT.get(settings),
MAX_WORKFLOWS.get(settings)
Expand Down Expand Up @@ -290,7 +290,7 @@ public void testCreateNewWorkflow() {
WorkflowRequest workflowRequest = new WorkflowRequest(
null,
template,
false,
new String[] { "off" },
false,
WORKFLOW_REQUEST_TIMEOUT.get(settings),
MAX_WORKFLOWS.get(settings)
Expand Down Expand Up @@ -385,7 +385,7 @@ public void testCreateWorkflow_withValidation_withProvision_Success() throws Exc
WorkflowRequest workflowRequest = new WorkflowRequest(
null,
validTemplate,
true,
new String[] { "all" },
true,
WORKFLOW_REQUEST_TIMEOUT.get(settings),
MAX_WORKFLOWS.get(settings)
Expand Down Expand Up @@ -445,7 +445,7 @@ public void testCreateWorkflow_withValidation_withProvision_FailedProvisioning()
WorkflowRequest workflowRequest = new WorkflowRequest(
null,
validTemplate,
true,
new String[] { "all" },
true,
WORKFLOW_REQUEST_TIMEOUT.get(settings),
MAX_WORKFLOWS.get(settings)
Expand Down

0 comments on commit 20893c0

Please sign in to comment.