Skip to content

Commit

Permalink
Merge branch 'main' into UpdateGoogleHTTP
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com>
  • Loading branch information
stephen-crawford committed Jun 6, 2023
2 parents f849e2c + 74ef776 commit 5374ac6
Show file tree
Hide file tree
Showing 269 changed files with 4,229 additions and 2,157 deletions.
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Allow mmap to use new JDK-19 preview APIs in Apache Lucene 9.4+ ([#5151](https://github.com/opensearch-project/OpenSearch/pull/5151))
- Add events correlation engine plugin ([#6854](https://github.com/opensearch-project/OpenSearch/issues/6854))
- Add support for ignoring missing Javadoc on generated code using annotation ([#7604](https://github.com/opensearch-project/OpenSearch/pull/7604))
- Implement concurrent aggregations support without profile option ([#7514](https://github.com/opensearch-project/OpenSearch/pull/7514))

### Dependencies
- Bump `log4j-core` from 2.18.0 to 2.19.0
Expand Down Expand Up @@ -46,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- OpenJDK Update (April 2023 Patch releases) ([#7344](https://github.com/opensearch-project/OpenSearch/pull/7344)
- Bump `com.amazonaws` 1.12.270 to `software.amazon.awssdk` 2.20.55 ([7372](https://github.com/opensearch-project/OpenSearch/pull/7372/))
- Bump `com.google.http-client:google-http-client:1.43.2` from 1.42.0 to 1.43.2 ([7928](https://github.com/opensearch-project/OpenSearch/pull/7928)))
- Bump `com.azure:azure-storage-blob` from 12.21.1 to 12.22.2 ([7930](https://github.com/opensearch-project/OpenSearch/pull/7930))

### Changed
- [CCR] Add getHistoryOperationsFromTranslog method to fetch the history snapshot from translogs ([#3948](https://github.com/opensearch-project/OpenSearch/pull/3948))
Expand Down Expand Up @@ -87,7 +89,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Security

## [Unreleased 2.x]
### Added
### Add TokenManager Interface ([#7452](https://github.com/opensearch-project/OpenSearch/pull/7452))

### Dependencies
- Bump `jackson` from 2.15.1 to 2.15.2 ([#7897](https://github.com/opensearch-project/OpenSearch/pull/7897))
Expand All @@ -102,6 +104,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Removed

### Fixed
- Fixing error: adding a new/forgotten parameter to the configuration for checking the config on startup in plugins/repository-s3 #7924

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
*/
package org.opensearch;

import org.opensearch.common.CheckedFunction;
import org.opensearch.common.Nullable;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.io.stream.BaseStreamInput;
import org.opensearch.core.common.logging.LoggerMessageFormat;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.ToXContentFragment;
Expand All @@ -41,10 +43,12 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import static java.util.Collections.singletonMap;

Expand Down Expand Up @@ -434,4 +438,98 @@ private String getShardIdString() {
}
return null;
}

/**
* An ExceptionHandle for registering Exceptions that can be serialized over the transport wire
*
* @opensearch.internal
*/
protected static abstract class BaseOpenSearchExceptionHandle {
final Class<? extends BaseOpenSearchException> exceptionClass;
final CheckedFunction<? extends BaseStreamInput, ? extends BaseOpenSearchException, IOException> constructor;
final int id;
final Version versionAdded;

<E extends BaseOpenSearchException, S extends BaseStreamInput> BaseOpenSearchExceptionHandle(
Class<E> exceptionClass,
CheckedFunction<S, E, IOException> constructor,
int id,
Version versionAdded
) {
// We need the exceptionClass because you can't dig it out of the constructor reliably.
this.exceptionClass = exceptionClass;
this.constructor = constructor;
this.versionAdded = versionAdded;
this.id = id;
}
}

@SuppressWarnings("unchecked")
public static <T extends BaseStreamInput> BaseOpenSearchException readException(T input, int id) throws IOException {
CheckedFunction<T, ? extends BaseOpenSearchException, IOException> opensearchException = (CheckedFunction<
T,
? extends BaseOpenSearchException,
IOException>) OpenSearchExceptionHandleRegistry.getSupplier(id);
if (opensearchException == null) {
throw new IllegalStateException("unknown exception for id: " + id);
}
return opensearchException.apply(input);
}

/**
* Registry of ExceptionHandlers
*
* @opensearch.internal
*/
public static class OpenSearchExceptionHandleRegistry {
/** Registry mapping from unique Ordinal to the Exception Constructor */
private static final Map<
Integer,
CheckedFunction<? extends BaseStreamInput, ? extends BaseOpenSearchException, IOException>> ID_TO_SUPPLIER_REGISTRY =
new ConcurrentHashMap<>();
/** Registry mapping from Exception class to the Exception Handler */
private static final Map<
Class<? extends BaseOpenSearchException>,
BaseOpenSearchExceptionHandle> CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY = new ConcurrentHashMap<>();

/** returns the Exception constructor function from a given ordinal */
public static CheckedFunction<? extends BaseStreamInput, ? extends BaseOpenSearchException, IOException> getSupplier(final int id) {
return ID_TO_SUPPLIER_REGISTRY.get(id);
}

/** registers the Exception handler */
public static void registerExceptionHandle(final BaseOpenSearchExceptionHandle handle) {
ID_TO_SUPPLIER_REGISTRY.put(handle.id, handle.constructor);
CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.put(handle.exceptionClass, handle);
}

/** Gets the unique ordinal id of the Exception from the given class */
public static int getId(final Class<? extends BaseOpenSearchException> exception) {
return CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.get(exception).id;
}

/** returns a set of ids */
public static Set<Integer> ids() {
return ID_TO_SUPPLIER_REGISTRY.keySet();
}

/** returns a collection of handles */
public static Collection<BaseOpenSearchExceptionHandle> handles() {
return CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.values();
}

/** checks that the exception class is registered */
public static boolean isRegistered(final Class<? extends Throwable> exception, final Version version) {
BaseOpenSearchExceptionHandle openSearchExceptionHandle = CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.get(exception);
if (openSearchExceptionHandle != null) {
return version.onOrAfter(openSearchExceptionHandle.versionAdded);
}
return false;
}

/** returns a set of registered exception classes */
public static Set<Class<? extends BaseOpenSearchException>> getRegisteredKeys() { // for testing
return CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE_REGISTRY.keySet();
}
}
}
Loading

0 comments on commit 5374ac6

Please sign in to comment.