Skip to content

Commit

Permalink
Created ScriptExtension interface #318 (#534) (#549)
Browse files Browse the repository at this point in the history
* Created ScriptExtension interface #318



* Created ScriptExtension interface #318



* Created ScriptExtension interface #318



---------



(cherry picked from commit 18b1802)

Signed-off-by: Aisara Imangaliyeva <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Aisara Imangaliyeva <[email protected]>
  • Loading branch information
3 people authored Mar 9, 2023
1 parent 980dd82 commit 7442d1a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/org/opensearch/sdk/ScriptExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.sdk;

import org.opensearch.common.settings.Settings;
import org.opensearch.script.ScriptContext;
import org.opensearch.script.ScriptEngine;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* An additional extension point for {@link Extension}s that extends OpenSearch's scripting functionality.
*/
public interface ScriptExtension {

/**
* Returns a {@link ScriptEngine} instance or <code>null</code> if this extension doesn't add a new script engine.
* @param settings Node settings
* @param contexts The contexts that {@link ScriptEngine#compile(String, String, ScriptContext, Map)} may be called with
*/
default ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
return null;
}

/**
* Return script contexts this extension wants to allow using.
*/
default List<ScriptContext<?>> getContexts() {
return Collections.emptyList();
}
}
9 changes: 9 additions & 0 deletions src/test/java/org/opensearch/sdk/TestExtensionInterfaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ void testActionExtension() {
assertTrue(actionExtension.mappingRequestValidators().isEmpty());
}

@Test
void testScriptExtension() {
ScriptExtension scriptExtension = new ScriptExtension() {
};
assertNull(scriptExtension.getScriptEngine(null, null));
assertTrue(scriptExtension.getContexts().isEmpty());

}

@Test
void testEngineExtension() {
EngineExtension engineExtension = new EngineExtension() {
Expand Down

0 comments on commit 7442d1a

Please sign in to comment.