Skip to content

Commit 7bdc199

Browse files
authored
[Backport 2.x] Remove useCase and defaultParams field in WorkflowRequest (#952) (#954)
* Remove useCase and defaultParams field in WorkflowRequest (#952) * Remove useCase and defaultParams field in WorkflowRequest Signed-off-by: Junwei Dai <[email protected]> * Remove useCase and defaultParams field in WorkflowRequest Signed-off-by: Junwei Dai <[email protected]> * Removed the constructor that has never been used and tested. Signed-off-by: Junwei Dai <[email protected]> --------- Signed-off-by: Junwei Dai <[email protected]> Co-authored-by: Junwei Dai <[email protected]> (cherry picked from commit 219aec5) * Remove useCase and defaultParams field in WorkflowRequest (#952) * Remove useCase and defaultParams field in WorkflowRequest Signed-off-by: Junwei Dai <[email protected]> * Remove useCase and defaultParams field in WorkflowRequest Signed-off-by: Junwei Dai <[email protected]> * Removed the constructor that has never been used and tested. Signed-off-by: Junwei Dai <[email protected]> --------- Signed-off-by: Junwei Dai <[email protected]> Co-authored-by: Junwei Dai <[email protected]> (cherry picked from commit 219aec5) --------- Signed-off-by: Junwei Dai <[email protected]>
1 parent ccb4e85 commit 7bdc199

File tree

5 files changed

+12
-194
lines changed

5 files changed

+12
-194
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
2727
- Incrementally remove resources from workflow state during deprovisioning ([#898](https://github.com/opensearch-project/flow-framework/pull/898))
2828

2929
### Bug Fixes
30+
- Remove useCase and defaultParams field in WorkflowRequest ([#758](https://github.com/opensearch-project/flow-framework/pull/758))
3031
- Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction ([#918](https://github.com/opensearch-project/flow-framework/pull/918))
3132

3233
### Infrastructure

src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java

-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
226226
validation,
227227
provision || updateFields,
228228
params,
229-
useCase,
230-
useCaseDefaultsMap,
231229
reprovision
232230
);
233231

src/main/java/org/opensearch/flowframework/transport/WorkflowRequest.java

+2-55
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,13 @@ public class WorkflowRequest extends ActionRequest {
6262
*/
6363
private Map<String, String> params;
6464

65-
/**
66-
* use case flag
67-
*/
68-
private String useCase;
69-
70-
/**
71-
* Deafult params map from use case
72-
*/
73-
private Map<String, String> defaultParams;
74-
7565
/**
7666
* Instantiates a new WorkflowRequest, set validation to all, no provisioning
7767
* @param workflowId the documentId of the workflow
7868
* @param template the use case template which describes the workflow
7969
*/
8070
public WorkflowRequest(@Nullable String workflowId, @Nullable Template template) {
81-
this(workflowId, template, new String[] { "all" }, false, Collections.emptyMap(), null, Collections.emptyMap(), false);
71+
this(workflowId, template, new String[] { "all" }, false, Collections.emptyMap(), false);
8272
}
8373

8474
/**
@@ -88,28 +78,7 @@ public WorkflowRequest(@Nullable String workflowId, @Nullable Template template)
8878
* @param params The parameters from the REST path
8979
*/
9080
public WorkflowRequest(@Nullable String workflowId, @Nullable Template template, Map<String, String> params) {
91-
this(workflowId, template, new String[] { "all" }, true, params, null, Collections.emptyMap(), false);
92-
}
93-
94-
/**
95-
* Instantiates a new WorkflowRequest with params map, set validation to all, provisioning to true
96-
* @param workflowId the documentId of the workflow
97-
* @param template the use case template which describes the workflow
98-
* @param useCase the default use case give by user
99-
* @param defaultParams The parameters from the REST body when a use case is given
100-
*/
101-
public WorkflowRequest(@Nullable String workflowId, @Nullable Template template, String useCase, Map<String, String> defaultParams) {
102-
this(workflowId, template, new String[] { "all" }, false, Collections.emptyMap(), useCase, defaultParams, false);
103-
}
104-
105-
/**
106-
* Instantiates a new WorkflowRequest, set validation to all, sets reprovision flag
107-
* @param workflowId the documentId of the workflow
108-
* @param template the updated template
109-
* @param reprovision the reprovision flag
110-
*/
111-
public WorkflowRequest(String workflowId, Template template, boolean reprovision) {
112-
this(workflowId, template, new String[] { "all" }, false, Collections.emptyMap(), null, Collections.emptyMap(), reprovision);
81+
this(workflowId, template, new String[] { "all" }, true, params, false);
11382
}
11483

11584
/**
@@ -119,8 +88,6 @@ public WorkflowRequest(String workflowId, Template template, boolean reprovision
11988
* @param validation flag to indicate if validation is necessary
12089
* @param provisionOrUpdate provision or updateFields flag. Only one may be true, the presence of update_fields key in map indicates if updating fields, otherwise true means it's provisioning.
12190
* @param params map of REST path params. If provisionOrUpdate is false, must be an empty map. If update_fields key is present, must be only key.
122-
* @param useCase default use case given
123-
* @param defaultParams the params to be used in the substitution based on the default use case.
12491
* @param reprovision flag to indicate if request is to reprovision
12592
*/
12693
public WorkflowRequest(
@@ -129,8 +96,6 @@ public WorkflowRequest(
12996
String[] validation,
13097
boolean provisionOrUpdate,
13198
Map<String, String> params,
132-
String useCase,
133-
Map<String, String> defaultParams,
13499
boolean reprovision
135100
) {
136101
this.workflowId = workflowId;
@@ -142,8 +107,6 @@ public WorkflowRequest(
142107
throw new IllegalArgumentException("Params may only be included when provisioning.");
143108
}
144109
this.params = this.updateFields ? Collections.emptyMap() : params;
145-
this.useCase = useCase;
146-
this.defaultParams = defaultParams;
147110
this.reprovision = reprovision;
148111
}
149112

@@ -222,22 +185,6 @@ public Map<String, String> getParams() {
222185
return Map.copyOf(this.params);
223186
}
224187

225-
/**
226-
* Gets the use case
227-
* @return the use case
228-
*/
229-
public String getUseCase() {
230-
return this.useCase;
231-
}
232-
233-
/**
234-
* Gets the params map
235-
* @return the params map
236-
*/
237-
public Map<String, String> getDefaultParams() {
238-
return Map.copyOf(this.defaultParams);
239-
}
240-
241188
/**
242189
* Gets the reprovision flag
243190
* @return the reprovision boolean

src/test/java/org/opensearch/flowframework/transport/CreateWorkflowTransportActionTests.java

+8-75
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void testMaxWorkflow() {
252252

253253
@SuppressWarnings("unchecked")
254254
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
255-
WorkflowRequest workflowRequest = new WorkflowRequest(null, template, new String[] { "off" }, false, Collections.emptyMap(), null, Collections.emptyMap(), false);
255+
WorkflowRequest workflowRequest = new WorkflowRequest(null, template, new String[] { "off" }, false, Collections.emptyMap(), false);
256256

257257
doAnswer(invocation -> {
258258
ActionListener<SearchResponse> searchListener = invocation.getArgument(1);
@@ -289,16 +289,7 @@ public void onFailure(Exception e) {
289289
public void testFailedToCreateNewWorkflow() {
290290
@SuppressWarnings("unchecked")
291291
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
292-
WorkflowRequest workflowRequest = new WorkflowRequest(
293-
null,
294-
template,
295-
new String[] { "off" },
296-
false,
297-
Collections.emptyMap(),
298-
null,
299-
Collections.emptyMap(),
300-
false
301-
);
292+
WorkflowRequest workflowRequest = new WorkflowRequest(null, template, new String[] { "off" }, false, Collections.emptyMap(), false);
302293

303294
// Bypass checkMaxWorkflows and force onResponse
304295
doAnswer(invocation -> {
@@ -329,16 +320,7 @@ public void testFailedToCreateNewWorkflow() {
329320
public void testCreateNewWorkflow() {
330321
@SuppressWarnings("unchecked")
331322
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
332-
WorkflowRequest workflowRequest = new WorkflowRequest(
333-
null,
334-
template,
335-
new String[] { "off" },
336-
false,
337-
Collections.emptyMap(),
338-
null,
339-
Collections.emptyMap(),
340-
false
341-
);
323+
WorkflowRequest workflowRequest = new WorkflowRequest(null, template, new String[] { "off" }, false, Collections.emptyMap(), false);
342324

343325
// Bypass checkMaxWorkflows and force onResponse
344326
doAnswer(invocation -> {
@@ -402,16 +384,7 @@ public void testCreateWithUserAndFilterOn() {
402384
);
403385

404386
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
405-
WorkflowRequest workflowRequest = new WorkflowRequest(
406-
null,
407-
template,
408-
new String[] { "off" },
409-
false,
410-
Collections.emptyMap(),
411-
null,
412-
Collections.emptyMap(),
413-
false
414-
);
387+
WorkflowRequest workflowRequest = new WorkflowRequest(null, template, new String[] { "off" }, false, Collections.emptyMap(), false);
415388

416389
// Bypass checkMaxWorkflows and force onResponse
417390
doAnswer(invocation -> {
@@ -475,16 +448,7 @@ public void testFailedToCreateNewWorkflowWithNullUser() {
475448

476449
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
477450

478-
WorkflowRequest workflowRequest = new WorkflowRequest(
479-
null,
480-
template,
481-
new String[] { "off" },
482-
false,
483-
Collections.emptyMap(),
484-
null,
485-
Collections.emptyMap(),
486-
false
487-
);
451+
WorkflowRequest workflowRequest = new WorkflowRequest(null, template, new String[] { "off" }, false, Collections.emptyMap(), false);
488452

489453
createWorkflowTransportAction1.doExecute(mock(Task.class), workflowRequest, listener);
490454
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
@@ -519,16 +483,7 @@ public void testFailedToCreateNewWorkflowWithNoBackendRoleUser() {
519483

520484
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
521485

522-
WorkflowRequest workflowRequest = new WorkflowRequest(
523-
null,
524-
template,
525-
new String[] { "off" },
526-
false,
527-
Collections.emptyMap(),
528-
null,
529-
Collections.emptyMap(),
530-
false
531-
);
486+
WorkflowRequest workflowRequest = new WorkflowRequest(null, template, new String[] { "off" }, false, Collections.emptyMap(), false);
532487

533488
createWorkflowTransportAction1.doExecute(mock(Task.class), workflowRequest, listener);
534489
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
@@ -542,16 +497,7 @@ public void testFailedToCreateNewWorkflowWithNoBackendRoleUser() {
542497
public void testUpdateWorkflowWithReprovision() throws IOException {
543498
@SuppressWarnings("unchecked")
544499
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
545-
WorkflowRequest workflowRequest = new WorkflowRequest(
546-
"1",
547-
template,
548-
new String[] { "off" },
549-
false,
550-
Collections.emptyMap(),
551-
null,
552-
Collections.emptyMap(),
553-
true
554-
);
500+
WorkflowRequest workflowRequest = new WorkflowRequest("1", template, new String[] { "off" }, false, Collections.emptyMap(), true);
555501

556502
doAnswer(invocation -> {
557503
ActionListener<GetResponse> getListener = invocation.getArgument(1);
@@ -595,16 +541,7 @@ public void testUpdateWorkflowWithReprovision() throws IOException {
595541
public void testFailedToUpdateWorkflowWithReprovision() throws IOException {
596542
@SuppressWarnings("unchecked")
597543
ActionListener<WorkflowResponse> listener = mock(ActionListener.class);
598-
WorkflowRequest workflowRequest = new WorkflowRequest(
599-
"1",
600-
template,
601-
new String[] { "off" },
602-
false,
603-
Collections.emptyMap(),
604-
null,
605-
Collections.emptyMap(),
606-
true
607-
);
544+
WorkflowRequest workflowRequest = new WorkflowRequest("1", template, new String[] { "off" }, false, Collections.emptyMap(), true);
608545

609546
doAnswer(invocation -> {
610547
ActionListener<GetResponse> getListener = invocation.getArgument(1);
@@ -904,8 +841,6 @@ public void testCreateWorkflow_withValidation_withProvision_Success() throws Exc
904841
new String[] { "all" },
905842
true,
906843
Collections.emptyMap(),
907-
null,
908-
Collections.emptyMap(),
909844
false
910845
);
911846

@@ -966,8 +901,6 @@ public void testCreateWorkflow_withValidation_withProvision_FailedProvisioning()
966901
new String[] { "all" },
967902
true,
968903
Collections.emptyMap(),
969-
null,
970-
Collections.emptyMap(),
971904
false
972905
);
973906

src/test/java/org/opensearch/flowframework/transport/WorkflowRequestResponseTests.java

+1-62
Original file line numberDiff line numberDiff line change
@@ -153,69 +153,10 @@ public void testWorkflowRequestWithParams() throws IOException {
153153
assertEquals("bar", streamInputRequest.getParams().get("foo"));
154154
}
155155

156-
public void testWorkflowRequestWithUseCase() throws IOException {
157-
WorkflowRequest workflowRequest = new WorkflowRequest("123", template, "cohere-embedding_model_deploy", Collections.emptyMap());
158-
assertNotNull(workflowRequest.getWorkflowId());
159-
assertEquals(template, workflowRequest.getTemplate());
160-
assertNull(workflowRequest.validate());
161-
assertFalse(workflowRequest.isProvision());
162-
assertFalse(workflowRequest.isUpdateFields());
163-
assertTrue(workflowRequest.getDefaultParams().isEmpty());
164-
assertEquals(workflowRequest.getUseCase(), "cohere-embedding_model_deploy");
165-
166-
BytesStreamOutput out = new BytesStreamOutput();
167-
workflowRequest.writeTo(out);
168-
BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()));
169-
170-
WorkflowRequest streamInputRequest = new WorkflowRequest(in);
171-
172-
assertEquals(workflowRequest.getWorkflowId(), streamInputRequest.getWorkflowId());
173-
assertEquals(workflowRequest.getTemplate().toString(), streamInputRequest.getTemplate().toString());
174-
assertNull(streamInputRequest.validate());
175-
assertFalse(streamInputRequest.isProvision());
176-
assertFalse(streamInputRequest.isUpdateFields());
177-
// THESE TESTS FAIL
178-
// assertTrue(streamInputRequest.getDefaultParams().isEmpty());
179-
// assertEquals(streamInputRequest.getUseCase(), "cohere-embedding_model_deploy");
180-
}
181-
182-
public void testWorkflowRequestWithUseCaseAndParamsInBody() throws IOException {
183-
WorkflowRequest workflowRequest = new WorkflowRequest("123", template, "cohere-embedding_model_deploy", Map.of("step", "model"));
184-
assertNotNull(workflowRequest.getWorkflowId());
185-
assertEquals(template, workflowRequest.getTemplate());
186-
assertNull(workflowRequest.validate());
187-
assertFalse(workflowRequest.isProvision());
188-
assertFalse(workflowRequest.isUpdateFields());
189-
assertEquals(workflowRequest.getDefaultParams().get("step"), "model");
190-
191-
BytesStreamOutput out = new BytesStreamOutput();
192-
workflowRequest.writeTo(out);
193-
BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()));
194-
195-
WorkflowRequest streamInputRequest = new WorkflowRequest(in);
196-
197-
assertEquals(workflowRequest.getWorkflowId(), streamInputRequest.getWorkflowId());
198-
assertEquals(workflowRequest.getTemplate().toString(), streamInputRequest.getTemplate().toString());
199-
assertNull(streamInputRequest.validate());
200-
assertFalse(streamInputRequest.isProvision());
201-
assertFalse(streamInputRequest.isUpdateFields());
202-
// THIS TEST FAILS
203-
// assertEquals(streamInputRequest.getDefaultParams().get("step"), "model");
204-
}
205-
206156
public void testWorkflowRequestWithParamsNoProvision() throws IOException {
207157
IllegalArgumentException ex = assertThrows(
208158
IllegalArgumentException.class,
209-
() -> new WorkflowRequest(
210-
"123",
211-
template,
212-
new String[] { "all" },
213-
false,
214-
Map.of("foo", "bar"),
215-
null,
216-
Collections.emptyMap(),
217-
false
218-
)
159+
() -> new WorkflowRequest("123", template, new String[] { "all" }, false, Map.of("foo", "bar"), false)
219160
);
220161
assertEquals("Params may only be included when provisioning.", ex.getMessage());
221162
}
@@ -227,8 +168,6 @@ public void testWorkflowRequestWithOnlyUpdateParamNoProvision() throws IOExcepti
227168
new String[] { "all" },
228169
true,
229170
Map.of(UPDATE_WORKFLOW_FIELDS, "true"),
230-
null,
231-
Collections.emptyMap(),
232171
false
233172
);
234173
assertNotNull(workflowRequest.getWorkflowId());

0 commit comments

Comments
 (0)