Skip to content

Commit

Permalink
Initial implementation of MLClient and workflow interface (#25)
Browse files Browse the repository at this point in the history
* Initial implementation of MLClient and interface

Signed-off-by: Owais Kazi <[email protected]>

* Addressed PR Comments

Signed-off-by: Owais Kazi <[email protected]>

---------

Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 authored Sep 11, 2023
1 parent a1bf2c0 commit b1bc703
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ opensearchplugin {
noticeFile rootProject.file('NOTICE')
}

dependencyLicenses.enabled = false
// This requires an additional Jar not published as part of build-tools
loggerUsageCheck.enabled = false

Expand All @@ -62,6 +63,20 @@ validateNebulaPom.enabled = false
buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'
plugin_no_snapshot = opensearch_build
if (buildVersionQualifier) {
opensearch_build += "-${buildVersionQualifier}"
plugin_no_snapshot += "-${buildVersionQualifier}"
}
if (isSnapshot) {
opensearch_build += "-SNAPSHOT"
}
opensearch_group = "org.opensearch"
opensearch_no_snapshot = opensearch_build.replace("-SNAPSHOT","")
System.setProperty('tests.security.manager', 'false')
}

Expand Down Expand Up @@ -89,7 +104,9 @@ repositories {

dependencies {
implementation "org.opensearch:opensearch:${opensearch_version}"
implementation 'org.junit.jupiter:junit-jupiter:5.8.1'
compileOnly "com.google.guava:guava:32.1.2-jre"
api group: 'org.opensearch', name:'opensearch-ml-client', version: "${opensearch_build}"

configurations.all {
resolutionStrategy {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/opensearch/flowframework/client/MLClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.client;

import org.opensearch.client.node.NodeClient;
import org.opensearch.ml.client.MachineLearningNodeClient;

/**
Class to initiate an instance of MLClient
*/
public class MLClient {
private static MachineLearningNodeClient INSTANCE;

private MLClient() {}

/**
* Creates machine learning client.
*
* @param nodeClient node client of OpenSearch.
* @return machine learning client from ml-commons.
*/
public static MachineLearningNodeClient createMLClient(NodeClient nodeClient) {
if (INSTANCE == null) {
INSTANCE = new MachineLearningNodeClient(nodeClient);
}
return INSTANCE;
}
}
26 changes: 26 additions & 0 deletions src/main/java/org/opensearch/flowframework/workflow/Workflow.java
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 java.util.concurrent.CompletableFuture;

/**
* Interface for the workflow setup of different building blocks.
*/
public interface Workflow {

/**
* Triggers the processing of the building block.
*
* @return CompletableFuture of the building block.
* @throws Exception if execution fails
*/
CompletableFuture<Workflow> execute() throws Exception;

}
7 changes: 7 additions & 0 deletions src/main/plugin-metadata/plugin-security.policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
grant {
//ml-commons client
permission java.lang.RuntimePermission "getClassLoader";
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.lang.RuntimePermission "setContextClassLoader";
};

0 comments on commit b1bc703

Please sign in to comment.