-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
686 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# 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. | ||
# | ||
# Modifications Copyright OpenSearch Contributors. See | ||
# GitHub history for details. | ||
# | ||
|
||
|
||
# Enable build caching | ||
org.gradle.caching=true | ||
org.gradle.warning.mode=none | ||
org.gradle.parallel=true | ||
# Workaround for https://github.com/diffplug/spotless/issues/834 | ||
org.gradle.jvmargs=-Xmx3g -XX:+HeapDumpOnOutOfMemoryError -Xss2m \ | ||
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ | ||
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ | ||
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ | ||
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ | ||
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED | ||
options.forkOptions.memoryMaximumSize=2g | ||
|
||
# Disable duplicate project id detection | ||
# See https://docs.gradle.org/current/userguide/upgrading_version_6.html#duplicate_project_names_may_cause_publication_to_fail | ||
systemProp.org.gradle.dependency.duplicate.project.detection=false | ||
|
||
# Enforce the build to fail on deprecated gradle api usage | ||
systemProp.org.gradle.warning.mode=fail | ||
|
||
# forcing to use TLS1.2 to avoid failure in vault | ||
# see https://github.com/hashicorp/vault/issues/8750#issuecomment-631236121 | ||
systemProp.jdk.tls.client.protocols=TLSv1.2 | ||
|
||
# jvm args for faster test execution by default | ||
systemProp.tests.jvm.argline=-XX:TieredStopAtLevel=1 -XX:ReservedCodeCacheSize=64m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/org/opensearch/flowframework/workflow/DeployModelStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.flowframework.client.MLClient; | ||
import org.opensearch.ml.client.MachineLearningNodeClient; | ||
import org.opensearch.ml.common.transport.deploy.MLDeployModelResponse; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static org.opensearch.flowframework.common.CommonValue.MODEL_ID; | ||
|
||
/** | ||
* Step to deploy a model | ||
*/ | ||
public class DeployModelStep implements WorkflowStep { | ||
private static final Logger logger = LogManager.getLogger(DeployModelStep.class); | ||
|
||
private Client client; | ||
static final String NAME = "deploy_model"; | ||
|
||
/** | ||
* Instantiate this class | ||
* @param client client to instantiate MLClient | ||
*/ | ||
public DeployModelStep(Client client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<WorkflowData> execute(List<WorkflowData> data) { | ||
|
||
CompletableFuture<WorkflowData> deployModelFuture = new CompletableFuture<>(); | ||
|
||
MachineLearningNodeClient machineLearningNodeClient = MLClient.createMLClient(client); | ||
|
||
ActionListener<MLDeployModelResponse> actionListener = new ActionListener<>() { | ||
@Override | ||
public void onResponse(MLDeployModelResponse mlDeployModelResponse) { | ||
logger.info("Model deployment state {}", mlDeployModelResponse.getStatus()); | ||
deployModelFuture.complete( | ||
new WorkflowData(Map.ofEntries(Map.entry("deploy_model_status", mlDeployModelResponse.getStatus()))) | ||
); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
logger.error("Model deployment failed"); | ||
deployModelFuture.completeExceptionally(e); | ||
} | ||
}; | ||
|
||
String modelId = null; | ||
|
||
for (WorkflowData workflowData : data) { | ||
if (workflowData.getContent().containsKey(MODEL_ID)) { | ||
modelId = (String) workflowData.getContent().get(MODEL_ID); | ||
break; | ||
} | ||
} | ||
machineLearningNodeClient.deploy(modelId, actionListener); | ||
return deployModelFuture; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/org/opensearch/flowframework/workflow/GetTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.common.SuppressForbidden; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.ml.client.MachineLearningNodeClient; | ||
import org.opensearch.ml.common.MLTask; | ||
import org.opensearch.ml.common.MLTaskState; | ||
import org.opensearch.ml.common.transport.task.MLTaskGetResponse; | ||
|
||
/** | ||
* Step to get modelID of a registered local model | ||
*/ | ||
@SuppressForbidden(reason = "This class is for the future work of registering local model") | ||
public class GetTask { | ||
|
||
private static final Logger logger = LogManager.getLogger(GetTask.class); | ||
private MachineLearningNodeClient machineLearningNodeClient; | ||
private String taskId; | ||
|
||
/** | ||
* Instantiate this class | ||
* @param machineLearningNodeClient client to instantiate ml-commons APIs | ||
* @param taskId taskID of the model | ||
*/ | ||
public GetTask(MachineLearningNodeClient machineLearningNodeClient, String taskId) { | ||
this.machineLearningNodeClient = machineLearningNodeClient; | ||
this.taskId = taskId; | ||
} | ||
|
||
/** | ||
* Invokes get task API of ml-commons | ||
*/ | ||
public void getTask() { | ||
|
||
ActionListener<MLTask> actionListener = new ActionListener<>() { | ||
@Override | ||
public void onResponse(MLTask mlTask) { | ||
if (mlTask.getState() == MLTaskState.COMPLETED) { | ||
logger.info("Model registration successful"); | ||
MLTaskGetResponse response = MLTaskGetResponse.builder().mlTask(mlTask).build(); | ||
logger.info("Response from task {}", response); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
logger.error("Model registration failed"); | ||
} | ||
}; | ||
|
||
machineLearningNodeClient.getTask(taskId, actionListener); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.