Skip to content

Commit

Permalink
Memory interface in spi (opensearch-project#1664)
Browse files Browse the repository at this point in the history
* memory interface

Signed-off-by: Jing Zhang <[email protected]>

* remove unused test plugin from gradle

Signed-off-by: Jing Zhang <[email protected]>

---------

Signed-off-by: Jing Zhang <[email protected]>
  • Loading branch information
jngz-es authored Nov 22, 2023
1 parent bfd53bc commit 7cc9399
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
}

dependencies {
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
implementation project(':opensearch-ml-common')
compileOnly group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
Expand Down
1 change: 1 addition & 0 deletions ml-algorithms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repositories {

dependencies {
compileOnly group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
implementation project(':opensearch-ml-common')
implementation "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
testImplementation "org.opensearch.test:framework:${opensearch_version}"
Expand Down
1 change: 1 addition & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ opensearchplugin {
}

dependencies {
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
implementation project(':opensearch-ml-common')
implementation project(':opensearch-ml-algorithms')
implementation project(':opensearch-ml-search-processors')
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ rootProject.name = 'opensearch-ml'

include 'client'
project(":client").name = rootProject.name + "-client"
include 'spi'
project(":spi").name = rootProject.name + "-spi"
include 'common'
project(":common").name = rootProject.name + "-common"
include 'plugin'
Expand Down
137 changes: 137 additions & 0 deletions spi/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin
import org.opensearch.gradle.test.RestIntegTestTask

plugins {
id 'com.github.johnrengelman.shadow'
id 'jacoco'
id 'maven-publish'
id 'signing'
}

apply plugin: 'opensearch.java'

repositories {
mavenLocal()
mavenCentral()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
}

ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE')
}

jacoco {
toolVersion = '0.8.7'
reportsDirectory = file("$buildDir/JacocoReport")
}

jacocoTestReport {
reports {
xml.required = false
csv.required = false
html.destination file("${buildDir}/jacoco/")
}
}
check.dependsOn jacocoTestReport

def slf4j_version_of_cronutils = "1.7.36"
dependencies {
compileOnly "org.opensearch:opensearch:${opensearch_version}"

testImplementation "org.opensearch.test:framework:${opensearch_version}"
testImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}"
}

configurations.all {
if (it.state != Configuration.State.UNRESOLVED) return
resolutionStrategy {
force "org.slf4j:slf4j-api:${slf4j_version_of_cronutils}"
}
}

shadowJar {
archiveClassifier = null
}

test {
doFirst {
test.classpath -= project.files(project.tasks.named('shadowJar'))
test.classpath -= project.configurations.getByName(ShadowBasePlugin.CONFIGURATION_NAME)
test.classpath += project.extensions.getByType(SourceSetContainer).getByName(SourceSet.MAIN_SOURCE_SET_NAME).runtimeClasspath
}
systemProperty 'tests.security.manager', 'false'
}

task integTest(type: RestIntegTestTask) {
description 'Run integ test with opensearch test framework'
group 'verification'
systemProperty 'tests.security.manager', 'false'
dependsOn test
}
check.dependsOn integTest

task sourcesJar(type: Jar) {
archiveClassifier.set 'sources'
from sourceSets.main.allJava
}

task javadocJar(type: Jar) {
archiveClassifier.set 'javadoc'
from javadoc.destinationDir
dependsOn javadoc
}

publishing {
repositories {
maven {
name = 'staging'
url = "${rootProject.buildDir}/local-staging-repo"
}
maven {
name = "Snapshots" // optional target repository name
url = "https://aws.oss.sonatype.org/content/repositories/snapshots"
credentials {
username "$System.env.SONATYPE_USERNAME"
password "$System.env.SONATYPE_PASSWORD"
}
}
}
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
artifact sourcesJar
artifact javadocJar

pom {
name = "OpenSearch ML Commons SPI"
packaging = "jar"
url = "https://github.com/opensearch-project/ml-commons"
description = "OpenSearch ML spi"
scm {
connection = "scm:[email protected]:opensearch-project/ml-commons.git"
developerConnection = "scm:[email protected]:opensearch-project/ml-commons.git"
url = "[email protected]:opensearch-project/ml-commons.git"
}
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
name = "OpenSearch"
url = "https://github.com/opensearch-project/ml-commons"
}
}
}
}
}
}
61 changes: 61 additions & 0 deletions spi/src/main/java/org/opensearch/ml/common/spi/memory/Memory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.spi.memory;

import org.opensearch.core.action.ActionListener;

import java.util.Map;

/**
* A general memory interface.
* @param <T>
*/
public interface Memory<T extends Message> {

/**
* Get memory type.
* @return
*/
String getType();

/**
* Save message to id.
* @param id memory id
* @param message message to be saved
*/
default void save(String id, T message) {}

default <S> void save(String id, T message, ActionListener<S> listener){}

/**
* Get messages of memory id.
* @param id memory id
* @return
*/
default T[] getMessages(String id){return null;}
default void getMessages(String id, ActionListener<T> listener){}

/**
* Clear all memory.
*/
void clear();

/**
* Remove memory of specific id.
* @param id memory id
*/
void remove(String id);

interface Factory<T extends Memory> {
/**
* Create an instance of this Memory.
*
* @param params Parameters for the memory
* @param listener Action listern for the memory creation action
*/
void create(Map<String, Object> params, ActionListener<T> listener);
}
}
24 changes: 24 additions & 0 deletions spi/src/main/java/org/opensearch/ml/common/spi/memory/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.spi.memory;

/**
* General message interface.
*/
public interface Message {

/**
* Get message type.
* @return
*/
String getType();

/**
* Get message content.
* @return
*/
String getContent();
}

0 comments on commit 7cc9399

Please sign in to comment.