-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 2.x] Introduce global-context index and related operations (#…
…76) Introduce global-context index and related operations (#65) * Add global context index and indices handler * Update global context index mapping * correct checkstyle errors * skip index handler integ tests * remove indices integration tests for now * rebase - add global-context index handler * Add unit tests * remove duplicate index name file * refactor package and file names * spotless apply * add javax ws dependency * remove visible for testing * add final keyword to map in Template ToXContect parser * spotless apply * disable checkStyleTest * Add more unit tests * use OpenSearch rest status code * Addressing comments * update resposnes field name to userOutputs * spotlessApply --------- (cherry picked from commit c4f1fc7) Signed-off-by: Jackie Han <[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>
- Loading branch information
1 parent
882af17
commit 3aa4c9e
Showing
20 changed files
with
877 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/org/opensearch/flowframework/common/CommonValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.flowframework.common; | ||
|
||
/** | ||
* Representation of common values that are used across project | ||
*/ | ||
public class CommonValue { | ||
|
||
public static Integer NO_SCHEMA_VERSION = 0; | ||
public static final String META = "_meta"; | ||
public static final String SCHEMA_VERSION_FIELD = "schema_version"; | ||
public static final String GLOBAL_CONTEXT_INDEX = ".plugins-ai-global-context"; | ||
public static final String GLOBAL_CONTEXT_INDEX_MAPPING = "mappings/global-context.json"; | ||
public static final Integer GLOBAL_CONTEXT_INDEX_VERSION = 1; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/opensearch/flowframework/common/ThrowingSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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.flowframework.common; | ||
|
||
/** | ||
* A supplier that can throw checked exception | ||
* | ||
* @param <T> method parameter type | ||
* @param <E> Exception type | ||
*/ | ||
@FunctionalInterface | ||
public interface ThrowingSupplier<T, E extends Exception> { | ||
/** | ||
* Gets a result or throws an exception if unable to produce a result. | ||
* | ||
* @return the result | ||
* @throws E if unable to produce a result | ||
*/ | ||
T get() throws E; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/opensearch/flowframework/common/ThrowingSupplierWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.flowframework.common; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Wrapper for throwing checked exception inside places that does not allow to do so | ||
*/ | ||
public class ThrowingSupplierWrapper { | ||
|
||
private ThrowingSupplierWrapper() {} | ||
|
||
/** | ||
* Utility method to use a method throwing checked exception inside a place | ||
* that does not allow throwing the corresponding checked exception (e.g., | ||
* enum initialization). | ||
* Convert the checked exception thrown by throwingConsumer to a RuntimeException | ||
* so that the compiler won't complain. | ||
* @param <T> the method's return type | ||
* @param throwingSupplier the method reference that can throw checked exception | ||
* @return converted method reference | ||
*/ | ||
public static <T> Supplier<T> throwingSupplierWrapper(ThrowingSupplier<T, Exception> throwingSupplier) { | ||
|
||
return () -> { | ||
try { | ||
return throwingSupplier.get(); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
}; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.flowframework.exception; | ||
|
||
import org.opensearch.core.rest.RestStatus; | ||
|
||
/** | ||
* Representation of Flow Framework Exceptions | ||
*/ | ||
public class FlowFrameworkException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final RestStatus restStatus; | ||
|
||
/** | ||
* Constructor with error message. | ||
* | ||
* @param message message of the exception | ||
* @param restStatus HTTP status code of the response | ||
*/ | ||
public FlowFrameworkException(String message, RestStatus restStatus) { | ||
super(message); | ||
this.restStatus = restStatus; | ||
} | ||
|
||
/** | ||
* Constructor with specified cause. | ||
* @param cause exception cause | ||
* @param restStatus HTTP status code of the response | ||
*/ | ||
public FlowFrameworkException(Throwable cause, RestStatus restStatus) { | ||
super(cause); | ||
this.restStatus = restStatus; | ||
} | ||
|
||
/** | ||
* Constructor with specified error message adn cause. | ||
* @param message error message | ||
* @param cause exception cause | ||
* @param restStatus HTTP status code of the response | ||
*/ | ||
public FlowFrameworkException(String message, Throwable cause, RestStatus restStatus) { | ||
super(message, cause); | ||
this.restStatus = restStatus; | ||
} | ||
|
||
/** | ||
* Getter for restStatus. | ||
* | ||
* @return the HTTP status code associated with the exception | ||
*/ | ||
public RestStatus getRestStatus() { | ||
return restStatus; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.flowframework.indices; | ||
|
||
import org.opensearch.flowframework.common.ThrowingSupplierWrapper; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX; | ||
import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX_VERSION; | ||
|
||
/** | ||
* An enumeration of Flow Framework indices | ||
*/ | ||
public enum FlowFrameworkIndex { | ||
GLOBAL_CONTEXT( | ||
GLOBAL_CONTEXT_INDEX, | ||
ThrowingSupplierWrapper.throwingSupplierWrapper(GlobalContextHandler::getGlobalContextMappings), | ||
GLOBAL_CONTEXT_INDEX_VERSION | ||
); | ||
|
||
private final String indexName; | ||
private final String mapping; | ||
private final Integer version; | ||
|
||
FlowFrameworkIndex(String name, Supplier<String> mappingSupplier, Integer version) { | ||
this.indexName = name; | ||
this.mapping = mappingSupplier.get(); | ||
this.version = version; | ||
} | ||
|
||
public String getIndexName() { | ||
return indexName; | ||
} | ||
|
||
public String getMapping() { | ||
return mapping; | ||
} | ||
|
||
public Integer getVersion() { | ||
return version; | ||
} | ||
} |
Oops, something went wrong.