Skip to content

Commit

Permalink
[BWC and API enforcement] Decorate the existing APIs with proper anno…
Browse files Browse the repository at this point in the history
…tations (part 1) (#9520)

* [BWC and API enforcement] Decorate the existing APIs with proper annotations (part 1)

Signed-off-by: Andriy Redko <[email protected]>

* Address code review comments

Signed-off-by: Andriy Redko <[email protected]>

---------

Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta authored Aug 30, 2023
1 parent 8324b88 commit 78eea27
Show file tree
Hide file tree
Showing 57 changed files with 200 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Feature] Expose term frequency in Painless script score context ([#9081](https://github.com/opensearch-project/OpenSearch/pull/9081))
- Add support for reading partial files to HDFS repository ([#9513](https://github.com/opensearch-project/OpenSearch/issues/9513))
- Add support for extensions to search responses using SearchExtBuilder ([#9379](https://github.com/opensearch-project/OpenSearch/pull/9379))
- [BWC and API enforcement] Decorate the existing APIs with proper annotations (part 1) ([#9520](https://github.com/opensearch-project/OpenSearch/pull/9520))

### Dependencies
- Bump `org.apache.logging.log4j:log4j-core` from 2.17.1 to 2.20.0 ([#8307](https://github.com/opensearch-project/OpenSearch/pull/8307))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@

package org.opensearch.common;

import org.opensearch.common.annotation.PublicApi;

import java.util.function.Consumer;

/**
* A {@link Consumer}-like interface which allows throwing checked exceptions.
*
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
@FunctionalInterface
public interface CheckedConsumer<T, E extends Exception> {
void accept(T t) throws E;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.common.action;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.unit.TimeValue;

import java.util.concurrent.Future;
Expand All @@ -42,6 +43,7 @@
*
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public interface ActionFuture<T> extends Future<T> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.common.lifecycle;

import org.opensearch.common.annotation.PublicApi;

/**
* Lifecycle state. Allows the following transitions:
* <ul>
Expand Down Expand Up @@ -73,15 +75,17 @@
* }
* </pre>
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class Lifecycle {

/**
* State in the lifecycle
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public enum State {
INITIALIZED,
STOPPED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@

package org.opensearch.common.lifecycle;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.lease.Releasable;

/**
* Base interface for a lifecycle component.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public interface LifecycleComponent extends Releasable {

Lifecycle.State lifecycleState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.common.unit;

import org.opensearch.common.annotation.PublicApi;

import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
Expand All @@ -41,6 +43,7 @@
*
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class TimeValue implements Comparable<TimeValue> {

/** How many nano-seconds in one milli-second */
Expand Down
2 changes: 2 additions & 0 deletions libs/core/src/main/java/org/opensearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch;

import org.opensearch.common.SuppressForbidden;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;

Expand All @@ -50,6 +51,7 @@
*
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class Version implements Comparable<Version>, ToXContentFragment {
/*
* The logic for ID is: XXYYZZAA, where XX is major version, YY is minor version, ZZ is revision, and AA is alpha/beta/rc indicator AA
Expand Down
5 changes: 5 additions & 0 deletions libs/core/src/main/java/org/opensearch/core/ParseField.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package org.opensearch.core;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.XContentLocation;

Expand All @@ -43,7 +44,11 @@
/**
* Holds a field that can be found in a request while parsing and its different
* variants, which may be deprecated.
*
* @opensearch.api
*
*/
@PublicApi(since = "1.0.0")
public class ParseField {
private final String name;
private final String[] deprecatedNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opensearch.common.CheckedFunction;
import org.opensearch.common.CheckedRunnable;
import org.opensearch.common.CheckedSupplier;
import org.opensearch.common.annotation.PublicApi;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -48,6 +49,7 @@
*
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public interface ActionListener<Response> {
/**
* Handle action response. This response may constitute a failure or a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefIterator;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.io.stream.BytesStream;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.util.ByteArray;
Expand All @@ -50,8 +51,9 @@
/**
* A reference to bytes.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public interface BytesReference extends Comparable<BytesReference>, ToXContentFragment {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.core.common.io.stream;

import org.opensearch.common.annotation.PublicApi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -45,15 +47,17 @@
* The registration is keyed by the combination of the category class of {@link NamedWriteable}, and a name unique
* to that category.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class NamedWriteableRegistry {

/**
* An entry in the registry, made up of a category class and name, and a reader for that category class.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public static class Entry {

/** The superclass of a {@link NamedWriteable} which will be read by {@link #reader}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.opensearch.Version;
import org.opensearch.common.CharArrays;
import org.opensearch.common.Nullable;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.bytes.BytesArray;
Expand Down Expand Up @@ -104,8 +105,9 @@
* lists, either by storing {@code List}s internally or just converting to and from a {@code List} when calling. This comment is repeated
* on {@link StreamInput}.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public abstract class StreamInput extends InputStream {

private Version version = Version.CURRENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.opensearch.Version;
import org.opensearch.common.CharArrays;
import org.opensearch.common.Nullable;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.bytes.BytesArray;
import org.opensearch.core.common.bytes.BytesReference;
Expand Down Expand Up @@ -96,8 +97,9 @@
* lists, either by storing {@code List}s internally or just converting to and from a {@code List} when calling. This comment is repeated
* on {@link StreamInput}.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public abstract class StreamOutput extends OutputStream {

private static final int MAX_NESTED_EXCEPTION_LEVEL = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@

package org.opensearch.core.common.settings;

import org.opensearch.common.annotation.PublicApi;

import java.io.Closeable;
import java.util.Arrays;
import java.util.Objects;

/**
* A String implementations which allows clearing the underlying char array.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public final class SecureString implements CharSequence, Closeable {

private char[] chars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.core.common.unit;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
Expand All @@ -45,8 +46,9 @@
* helps organize and use size representations that may be maintained
* separately across various contexts.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public enum ByteSizeUnit implements Writeable {
BYTES {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.core.common.unit;

import org.opensearch.OpenSearchParseException;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand All @@ -47,8 +48,9 @@
/**
* A byte size value
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class ByteSizeValue implements Writeable, Comparable<ByteSizeValue>, ToXContentFragment {

public static final ByteSizeValue ZERO = new ByteSizeValue(0, ByteSizeUnit.BYTES);
Expand Down
4 changes: 3 additions & 1 deletion libs/core/src/main/java/org/opensearch/core/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.core.index;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.ParseField;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.io.stream.StreamInput;
Expand All @@ -48,8 +49,9 @@
/**
* A value class representing the basic required properties of an OpenSearch index.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class Index implements Writeable, ToXContentObject {

public static final Index[] EMPTY_ARRAY = new Index[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.core.index.shard;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand All @@ -45,8 +46,9 @@
/**
* Allows for shard level components to be injected with the shard id.
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public class ShardId implements Comparable<ShardId>, ToXContentFragment, Writeable {

private final Index index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.core.rest;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.action.ShardOperationFailedException;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand All @@ -47,6 +48,7 @@
*
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public enum RestStatus {
/**
* The client SHOULD continue with its request. This interim response is used to inform the client that the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.core.tasks;

import org.opensearch.OpenSearchParseException;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand All @@ -45,8 +46,9 @@
/**
* Task id that consists of node id and id of the task on the node
*
* @opensearch.internal
* @opensearch.api
*/
@PublicApi(since = "1.0.0")
public final class TaskId implements Writeable {

public static final TaskId EMPTY_TASK_ID = new TaskId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.core.xcontent;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.io.stream.Writeable;

import java.io.IOException;
Expand All @@ -42,7 +43,10 @@
* Abstracts a <a href="http://en.wikipedia.org/wiki/Internet_media_type">Media Type</a> and a format parameter.
* Media types are used as values on Content-Type and Accept headers
* format is an URL parameter, specifies response media type.
*
* @opensearch.api
*/
@PublicApi(since = "2.1.0")
public interface MediaType extends Writeable {
/**
* Returns a type part of a MediaType
Expand Down
Loading

0 comments on commit 78eea27

Please sign in to comment.