Skip to content

Commit

Permalink
[Backport 2.x] Remove Demo Classes, add No-Op Step (#132)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent 4effda0 commit dd1963b
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 344 deletions.
4 changes: 0 additions & 4 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
codecov:
require_ci_to_pass: true

# ignore files in demo package
ignore:
- "src/main/java/demo"

coverage:
precision: 2
round: down
Expand Down
93 changes: 0 additions & 93 deletions src/main/java/demo/Demo.java

This file was deleted.

52 changes: 0 additions & 52 deletions src/main/java/demo/DemoWorkflowStep.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/demo/README.txt

This file was deleted.

75 changes: 0 additions & 75 deletions src/main/java/demo/TemplateParseDemo.java

This file was deleted.

32 changes: 32 additions & 0 deletions src/main/java/org/opensearch/flowframework/workflow/NoOpStep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.flowframework.workflow;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
* A workflow step that does nothing. May be used for synchronizing other actions.
*/
public class NoOpStep implements WorkflowStep {

/** The name of this step, used as a key in the template and the {@link WorkflowStepFactory} */
public static final String NAME = "noop";

@Override
public CompletableFuture<WorkflowData> execute(List<WorkflowData> data) throws IOException {
return CompletableFuture.completedFuture(WorkflowData.EMPTY);
}

@Override
public String getName() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

import org.opensearch.client.Client;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.ml.client.MachineLearningNodeClient;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import demo.DemoWorkflowStep;

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

private void populateMap(ClusterService clusterService, Client client, MachineLearningNodeClient mlClient) {
stepMap.put(NoOpStep.NAME, new NoOpStep());
stepMap.put(CreateIndexStep.NAME, new CreateIndexStep(clusterService, client));
stepMap.put(CreateIngestPipelineStep.NAME, new CreateIngestPipelineStep(client));
stepMap.put(RegisterModelStep.NAME, new RegisterModelStep(mlClient));
stepMap.put(DeployModelStep.NAME, new DeployModelStep(mlClient));
stepMap.put(CreateConnectorStep.NAME, new CreateConnectorStep(mlClient));
stepMap.put(ModelGroupStep.NAME, new ModelGroupStep(mlClient));

// TODO: These are from the demo class as placeholders, remove when demos are deleted
stepMap.put("demo_delay_3", new DemoWorkflowStep(3000));
stepMap.put("demo_delay_5", new DemoWorkflowStep(5000));

// Use as a default until all the actual implementations are ready
stepMap.put("placeholder", new WorkflowStep() {
@Override
public CompletableFuture<WorkflowData> execute(List<WorkflowData> data) {
CompletableFuture<WorkflowData> future = new CompletableFuture<>();
future.complete(WorkflowData.EMPTY);
return future;
}

@Override
public String getName() {
return "placeholder";
}
});
}

/**
Expand All @@ -75,8 +55,6 @@ public WorkflowStep createStep(String type) {
if (stepMap.containsKey(type)) {
return stepMap.get(type);
}
// TODO: replace this with a FlowFrameworkException
// https://github.com/opensearch-project/opensearch-ai-flow-framework/pull/43
return stepMap.get("placeholder");
throw new FlowFrameworkException("Workflow step type [" + type + "] is not implemented.", RestStatus.NOT_IMPLEMENTED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.flowframework.workflow.NoOpStep;

import java.io.IOException;
import java.util.List;
Expand All @@ -27,7 +28,7 @@
public class TemplateTestJsonUtil {

public static String node(String id) {
return nodeWithType(id, "placeholder");
return nodeWithType(id, NoOpStep.NAME);
}

public static String nodeWithType(String id, String type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.flowframework.workflow;

import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

public class NoOpStepTests extends OpenSearchTestCase {

public void testNoOpStep() throws IOException {
NoOpStep noopStep = new NoOpStep();
assertEquals(NoOpStep.NAME, noopStep.getName());
CompletableFuture<WorkflowData> future = noopStep.execute(Collections.emptyList());
assertTrue(future.isDone());
assertFalse(future.isCompletedExceptionally());
}
}
Loading

0 comments on commit dd1963b

Please sign in to comment.