Skip to content

Commit dd1963b

Browse files
opensearch-trigger-bot[bot]github-actions[bot]owaiskazi19
authored
[Backport 2.x] Remove Demo Classes, add No-Op Step (#132)
Remove Demo Classes, add No-Op Step (#129) * Remove Demo Classes, add No-Op Step * Add test coverage * Revert enum javadocs as they are handled by #119 --------- (cherry picked from commit 9dffc0a) Signed-off-by: Daniel Widdis <widdis@gmail.com> Signed-off-by: Owais Kazi <owaiskazi19@gmail.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Owais Kazi <owaiskazi19@gmail.com>
1 parent 4effda0 commit dd1963b

11 files changed

Lines changed: 73 additions & 344 deletions

File tree

.codecov.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
codecov:
22
require_ci_to_pass: true
33

4-
# ignore files in demo package
5-
ignore:
6-
- "src/main/java/demo"
7-
84
coverage:
95
precision: 2
106
round: down

src/main/java/demo/Demo.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/main/java/demo/DemoWorkflowStep.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/main/java/demo/README.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/demo/TemplateParseDemo.java

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
package org.opensearch.flowframework.workflow;
10+
11+
import java.io.IOException;
12+
import java.util.List;
13+
import java.util.concurrent.CompletableFuture;
14+
15+
/**
16+
* A workflow step that does nothing. May be used for synchronizing other actions.
17+
*/
18+
public class NoOpStep implements WorkflowStep {
19+
20+
/** The name of this step, used as a key in the template and the {@link WorkflowStepFactory} */
21+
public static final String NAME = "noop";
22+
23+
@Override
24+
public CompletableFuture<WorkflowData> execute(List<WorkflowData> data) throws IOException {
25+
return CompletableFuture.completedFuture(WorkflowData.EMPTY);
26+
}
27+
28+
@Override
29+
public String getName() {
30+
return NAME;
31+
}
32+
}

src/main/java/org/opensearch/flowframework/workflow/WorkflowStepFactory.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111
import org.opensearch.client.Client;
1212
import org.opensearch.cluster.service.ClusterService;
13+
import org.opensearch.core.rest.RestStatus;
14+
import org.opensearch.flowframework.exception.FlowFrameworkException;
1315
import org.opensearch.ml.client.MachineLearningNodeClient;
1416

1517
import java.util.HashMap;
16-
import java.util.List;
1718
import java.util.Map;
18-
import java.util.concurrent.CompletableFuture;
19-
20-
import demo.DemoWorkflowStep;
2119

2220
/**
2321
* Generates instances implementing {@link WorkflowStep}.
@@ -39,31 +37,13 @@ public WorkflowStepFactory(ClusterService clusterService, Client client, Machine
3937
}
4038

4139
private void populateMap(ClusterService clusterService, Client client, MachineLearningNodeClient mlClient) {
40+
stepMap.put(NoOpStep.NAME, new NoOpStep());
4241
stepMap.put(CreateIndexStep.NAME, new CreateIndexStep(clusterService, client));
4342
stepMap.put(CreateIngestPipelineStep.NAME, new CreateIngestPipelineStep(client));
4443
stepMap.put(RegisterModelStep.NAME, new RegisterModelStep(mlClient));
4544
stepMap.put(DeployModelStep.NAME, new DeployModelStep(mlClient));
4645
stepMap.put(CreateConnectorStep.NAME, new CreateConnectorStep(mlClient));
4746
stepMap.put(ModelGroupStep.NAME, new ModelGroupStep(mlClient));
48-
49-
// TODO: These are from the demo class as placeholders, remove when demos are deleted
50-
stepMap.put("demo_delay_3", new DemoWorkflowStep(3000));
51-
stepMap.put("demo_delay_5", new DemoWorkflowStep(5000));
52-
53-
// Use as a default until all the actual implementations are ready
54-
stepMap.put("placeholder", new WorkflowStep() {
55-
@Override
56-
public CompletableFuture<WorkflowData> execute(List<WorkflowData> data) {
57-
CompletableFuture<WorkflowData> future = new CompletableFuture<>();
58-
future.complete(WorkflowData.EMPTY);
59-
return future;
60-
}
61-
62-
@Override
63-
public String getName() {
64-
return "placeholder";
65-
}
66-
});
6747
}
6848

6949
/**
@@ -75,8 +55,6 @@ public WorkflowStep createStep(String type) {
7555
if (stepMap.containsKey(type)) {
7656
return stepMap.get(type);
7757
}
78-
// TODO: replace this with a FlowFrameworkException
79-
// https://github.com/opensearch-project/opensearch-ai-flow-framework/pull/43
80-
return stepMap.get("placeholder");
58+
throw new FlowFrameworkException("Workflow step type [" + type + "] is not implemented.", RestStatus.NOT_IMPLEMENTED);
8159
}
8260
}

src/test/java/org/opensearch/flowframework/model/TemplateTestJsonUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.opensearch.core.xcontent.ToXContent;
1515
import org.opensearch.core.xcontent.ToXContentObject;
1616
import org.opensearch.core.xcontent.XContentParser;
17+
import org.opensearch.flowframework.workflow.NoOpStep;
1718

1819
import java.io.IOException;
1920
import java.util.List;
@@ -27,7 +28,7 @@
2728
public class TemplateTestJsonUtil {
2829

2930
public static String node(String id) {
30-
return nodeWithType(id, "placeholder");
31+
return nodeWithType(id, NoOpStep.NAME);
3132
}
3233

3334
public static String nodeWithType(String id, String type) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
package org.opensearch.flowframework.workflow;
10+
11+
import org.opensearch.test.OpenSearchTestCase;
12+
13+
import java.io.IOException;
14+
import java.util.Collections;
15+
import java.util.concurrent.CompletableFuture;
16+
17+
public class NoOpStepTests extends OpenSearchTestCase {
18+
19+
public void testNoOpStep() throws IOException {
20+
NoOpStep noopStep = new NoOpStep();
21+
assertEquals(NoOpStep.NAME, noopStep.getName());
22+
CompletableFuture<WorkflowData> future = noopStep.execute(Collections.emptyList());
23+
assertTrue(future.isDone());
24+
assertFalse(future.isCompletedExceptionally());
25+
}
26+
}

0 commit comments

Comments
 (0)