Skip to content

Commit

Permalink
Change dryrun param in create workflow to validation
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Dec 20, 2023
1 parent 7986cbf commit eeb88a0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener<Work
user
);

if (request.isDryRun()) {
if (request.isValidation()) {
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 dryRun;
private boolean validation;

/**
* Provision flag
Expand All @@ -54,7 +54,7 @@ public class WorkflowRequest extends ActionRequest {
private Integer maxWorkflows;

/**
* Instantiates a new WorkflowRequest, defaults dry run to false and set requestTimeout and maxWorkflows to null
* Instantiates a new WorkflowRequest, defaults validation to false and set requestTimeout and maxWorkflows to null
* @param workflowId the documentId of the workflow
* @param template the use case template which describes the workflow
*/
Expand All @@ -63,7 +63,7 @@ public WorkflowRequest(@Nullable String workflowId, @Nullable Template template)
}

/**
* Instantiates a new WorkflowRequest and defaults dry run to false
* Instantiates a new WorkflowRequest and defaults validation to false
* @param workflowId the documentId of the workflow
* @param template the use case template which describes the workflow
* @param requestTimeout timeout of the request
Expand All @@ -82,22 +82,22 @@ public WorkflowRequest(
* Instantiates a new WorkflowRequest
* @param workflowId the documentId of the workflow
* @param template the use case template which describes the workflow
* @param dryRun flag to indicate if validation is necessary
* @param validation flag to indicate if validation is necessary
* @param provision flag to indicate if provision is necessary
* @param requestTimeout timeout of the request
* @param maxWorkflows max number of workflows
*/
public WorkflowRequest(
@Nullable String workflowId,
@Nullable Template template,
boolean dryRun,
boolean validation,
boolean provision,
@Nullable TimeValue requestTimeout,
@Nullable Integer maxWorkflows
) {
this.workflowId = workflowId;
this.template = template;
this.dryRun = dryRun;
this.validation = validation;
this.provision = provision;
this.requestTimeout = requestTimeout;
this.maxWorkflows = 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.dryRun = in.readBoolean();
this.validation = in.readBoolean();
this.provision = in.readBoolean();
this.requestTimeout = in.readOptionalTimeValue();
this.maxWorkflows = in.readOptionalInt();
Expand All @@ -138,11 +138,11 @@ public Template getTemplate() {
}

/**
* Gets the dry run validation flag
* @return the dry run boolean
* Gets the validation flag
* @return the validation boolean
*/
public boolean isDryRun() {
return this.dryRun;
public boolean isValidation() {
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(dryRun);
out.writeBoolean(validation);
out.writeBoolean(provision);
out.writeOptionalTimeValue(requestTimeout);
out.writeOptionalInt(maxWorkflows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ protected Response createWorkflow(Template template) throws Exception {
}

/**
* Helper method to invoke the Create Workflow Rest Action with dry run validation
* Helper method to invoke the Create Workflow Rest Action with validation
* @param template the template to create
* @throws Exception if the request fails
* @return a rest response
*/
protected Response createWorkflowDryRun(Template template) throws Exception {
return TestHelpers.makeRequest(client(), "POST", WORKFLOW_URI + "?dryrun=true", ImmutableMap.of(), template.toJson(), null);
protected Response createWorkflowValidation(Template template) throws Exception {
return TestHelpers.makeRequest(client(), "POST", WORKFLOW_URI, ImmutableMap.of(), template.toJson(), null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testCreateAndProvisionRemoteModelWorkflow() throws Exception {
.build();

// Hit dry run
ResponseException exception = expectThrows(ResponseException.class, () -> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void setUp() throws Exception {
);
}

public void testDryRunValidation_withoutProvision_Success() {
public void testValidation_withoutProvision_Success() {
Template validTemplate = generateValidTemplate();

@SuppressWarnings("unchecked")
Expand All @@ -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",
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit eeb88a0

Please sign in to comment.