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

Memory interface in spi #1664

Merged
merged 2 commits into from
Nov 22, 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
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"
}
}
}
}
}
}
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);
}
}
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();
}
Loading