diff --git a/client/build.gradle b/client/build.gradle index 08a3b587cd..0cf6e22f86 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -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' diff --git a/ml-algorithms/build.gradle b/ml-algorithms/build.gradle index f1dc06785e..02eec4cad2 100644 --- a/ml-algorithms/build.gradle +++ b/ml-algorithms/build.gradle @@ -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}" diff --git a/plugin/build.gradle b/plugin/build.gradle index b389360e0b..8988d90868 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -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') diff --git a/settings.gradle b/settings.gradle index b6d0b19113..faa8d06d4e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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' diff --git a/spi/build.gradle b/spi/build.gradle new file mode 100644 index 0000000000..0f3f5a77a4 --- /dev/null +++ b/spi/build.gradle @@ -0,0 +1,143 @@ +/* + * 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' +apply plugin: 'opensearch.testclusters' +apply plugin: 'opensearch.java-rest-test' + +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 + +testClusters.javaRestTest { + testDistribution = 'INTEG_TEST' +} + +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:git@github.com:opensearch-project/ml-commons.git" + developerConnection = "scm:git@github.com:opensearch-project/ml-commons.git" + url = "git@github.com: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" + } + } + } + } + } +} diff --git a/spi/src/main/java/org/opensearch/ml/common/spi/memory/Memory.java b/spi/src/main/java/org/opensearch/ml/common/spi/memory/Memory.java new file mode 100644 index 0000000000..61e695f6a0 --- /dev/null +++ b/spi/src/main/java/org/opensearch/ml/common/spi/memory/Memory.java @@ -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 + */ +public interface Memory { + + /** + * 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 void save(String id, T message, ActionListener listener){} + + /** + * Get messages of memory id. + * @param id memory id + * @return + */ + default T[] getMessages(String id){return null;} + default void getMessages(String id, ActionListener listener){} + + /** + * Clear all memory. + */ + void clear(); + + /** + * Remove memory of specific id. + * @param id memory id + */ + void remove(String id); + + interface Factory { + /** + * Create an instance of this Memory. + * + * @param params Parameters for the memory + * @param listener Action listern for the memory creation action + */ + void create(Map params, ActionListener listener); + } +} diff --git a/spi/src/main/java/org/opensearch/ml/common/spi/memory/Message.java b/spi/src/main/java/org/opensearch/ml/common/spi/memory/Message.java new file mode 100644 index 0000000000..148cc769e3 --- /dev/null +++ b/spi/src/main/java/org/opensearch/ml/common/spi/memory/Message.java @@ -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(); +}