Skip to content

Commit 8e581f7

Browse files
* memory interface Signed-off-by: Jing Zhang <jngz@amazon.com> * remove unused test plugin from gradle Signed-off-by: Jing Zhang <jngz@amazon.com> --------- Signed-off-by: Jing Zhang <jngz@amazon.com> (cherry picked from commit 7cc9399) Co-authored-by: Jing Zhang <jngz@amazon.com>
1 parent 0a1b4b5 commit 8e581f7

File tree

7 files changed

+227
-0
lines changed

7 files changed

+227
-0
lines changed

client/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ plugins {
1414
}
1515

1616
dependencies {
17+
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
1718
implementation project(':opensearch-ml-common')
1819
compileOnly group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
1920
testImplementation group: 'junit', name: 'junit', version: '4.13.2'

ml-algorithms/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ repositories {
1818

1919
dependencies {
2020
compileOnly group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
21+
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
2122
implementation project(':opensearch-ml-common')
2223
implementation "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
2324
testImplementation "org.opensearch.test:framework:${opensearch_version}"

plugin/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ opensearchplugin {
4646
}
4747

4848
dependencies {
49+
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
4950
implementation project(':opensearch-ml-common')
5051
implementation project(':opensearch-ml-algorithms')
5152
implementation project(':opensearch-ml-search-processors')

settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ rootProject.name = 'opensearch-ml'
77

88
include 'client'
99
project(":client").name = rootProject.name + "-client"
10+
include 'spi'
11+
project(":spi").name = rootProject.name + "-spi"
1012
include 'common'
1113
project(":common").name = rootProject.name + "-common"
1214
include 'plugin'

spi/build.gradle

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin
7+
import org.opensearch.gradle.test.RestIntegTestTask
8+
9+
plugins {
10+
id 'com.github.johnrengelman.shadow'
11+
id 'jacoco'
12+
id 'maven-publish'
13+
id 'signing'
14+
}
15+
16+
apply plugin: 'opensearch.java'
17+
18+
repositories {
19+
mavenLocal()
20+
mavenCentral()
21+
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
22+
}
23+
24+
ext {
25+
projectSubstitutions = [:]
26+
licenseFile = rootProject.file('LICENSE.txt')
27+
noticeFile = rootProject.file('NOTICE')
28+
}
29+
30+
jacoco {
31+
toolVersion = '0.8.7'
32+
reportsDirectory = file("$buildDir/JacocoReport")
33+
}
34+
35+
jacocoTestReport {
36+
reports {
37+
xml.required = false
38+
csv.required = false
39+
html.destination file("${buildDir}/jacoco/")
40+
}
41+
}
42+
check.dependsOn jacocoTestReport
43+
44+
def slf4j_version_of_cronutils = "1.7.36"
45+
dependencies {
46+
compileOnly "org.opensearch:opensearch:${opensearch_version}"
47+
48+
testImplementation "org.opensearch.test:framework:${opensearch_version}"
49+
testImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}"
50+
}
51+
52+
configurations.all {
53+
if (it.state != Configuration.State.UNRESOLVED) return
54+
resolutionStrategy {
55+
force "org.slf4j:slf4j-api:${slf4j_version_of_cronutils}"
56+
}
57+
}
58+
59+
shadowJar {
60+
archiveClassifier = null
61+
}
62+
63+
test {
64+
doFirst {
65+
test.classpath -= project.files(project.tasks.named('shadowJar'))
66+
test.classpath -= project.configurations.getByName(ShadowBasePlugin.CONFIGURATION_NAME)
67+
test.classpath += project.extensions.getByType(SourceSetContainer).getByName(SourceSet.MAIN_SOURCE_SET_NAME).runtimeClasspath
68+
}
69+
systemProperty 'tests.security.manager', 'false'
70+
}
71+
72+
task integTest(type: RestIntegTestTask) {
73+
description 'Run integ test with opensearch test framework'
74+
group 'verification'
75+
systemProperty 'tests.security.manager', 'false'
76+
dependsOn test
77+
}
78+
check.dependsOn integTest
79+
80+
task sourcesJar(type: Jar) {
81+
archiveClassifier.set 'sources'
82+
from sourceSets.main.allJava
83+
}
84+
85+
task javadocJar(type: Jar) {
86+
archiveClassifier.set 'javadoc'
87+
from javadoc.destinationDir
88+
dependsOn javadoc
89+
}
90+
91+
publishing {
92+
repositories {
93+
maven {
94+
name = 'staging'
95+
url = "${rootProject.buildDir}/local-staging-repo"
96+
}
97+
maven {
98+
name = "Snapshots" // optional target repository name
99+
url = "https://aws.oss.sonatype.org/content/repositories/snapshots"
100+
credentials {
101+
username "$System.env.SONATYPE_USERNAME"
102+
password "$System.env.SONATYPE_PASSWORD"
103+
}
104+
}
105+
}
106+
publications {
107+
shadow(MavenPublication) { publication ->
108+
project.shadow.component(publication)
109+
artifact sourcesJar
110+
artifact javadocJar
111+
112+
pom {
113+
name = "OpenSearch ML Commons SPI"
114+
packaging = "jar"
115+
url = "https://github.com/opensearch-project/ml-commons"
116+
description = "OpenSearch ML spi"
117+
scm {
118+
connection = "scm:git@github.com:opensearch-project/ml-commons.git"
119+
developerConnection = "scm:git@github.com:opensearch-project/ml-commons.git"
120+
url = "git@github.com:opensearch-project/ml-commons.git"
121+
}
122+
licenses {
123+
license {
124+
name = "The Apache License, Version 2.0"
125+
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
126+
}
127+
}
128+
developers {
129+
developer {
130+
name = "OpenSearch"
131+
url = "https://github.com/opensearch-project/ml-commons"
132+
}
133+
}
134+
}
135+
}
136+
}
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.ml.common.spi.memory;
7+
8+
import org.opensearch.core.action.ActionListener;
9+
10+
import java.util.Map;
11+
12+
/**
13+
* A general memory interface.
14+
* @param <T>
15+
*/
16+
public interface Memory<T extends Message> {
17+
18+
/**
19+
* Get memory type.
20+
* @return
21+
*/
22+
String getType();
23+
24+
/**
25+
* Save message to id.
26+
* @param id memory id
27+
* @param message message to be saved
28+
*/
29+
default void save(String id, T message) {}
30+
31+
default <S> void save(String id, T message, ActionListener<S> listener){}
32+
33+
/**
34+
* Get messages of memory id.
35+
* @param id memory id
36+
* @return
37+
*/
38+
default T[] getMessages(String id){return null;}
39+
default void getMessages(String id, ActionListener<T> listener){}
40+
41+
/**
42+
* Clear all memory.
43+
*/
44+
void clear();
45+
46+
/**
47+
* Remove memory of specific id.
48+
* @param id memory id
49+
*/
50+
void remove(String id);
51+
52+
interface Factory<T extends Memory> {
53+
/**
54+
* Create an instance of this Memory.
55+
*
56+
* @param params Parameters for the memory
57+
* @param listener Action listern for the memory creation action
58+
*/
59+
void create(Map<String, Object> params, ActionListener<T> listener);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.ml.common.spi.memory;
7+
8+
/**
9+
* General message interface.
10+
*/
11+
public interface Message {
12+
13+
/**
14+
* Get message type.
15+
* @return
16+
*/
17+
String getType();
18+
19+
/**
20+
* Get message content.
21+
* @return
22+
*/
23+
String getContent();
24+
}

0 commit comments

Comments
 (0)