Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Demo Classes, add No-Op Step #129

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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
Loading