Skip to content

Commit

Permalink
[Extensions] Moving ExtensionsRequest to use Protobuf (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#6960)

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>
  • Loading branch information
saratvemulapalli committed Apr 21, 2023
1 parent d4eede6 commit 29b8a4b
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 127 deletions.
15 changes: 1 addition & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See the [CONTRIBUTING guide](./CONTRIBUTING.md#Changelog) for instructions on how to add changelog entries.

## [Unreleased 2.x]
### Added
- Add GeoTile and GeoHash Grid aggregations on GeoShapes. ([#5589](https://github.com/opensearch-project/OpenSearch/pull/5589))
- Disallow multiple data paths for search nodes ([#6427](https://github.com/opensearch-project/OpenSearch/pull/6427))
- [Segment Replication] Allocation and rebalancing based on average primary shard count per index ([#6422](https://github.com/opensearch-project/OpenSearch/pull/6422))
- The truncation limit of the OpenSearchJsonLayout logger is now configurable ([#6569](https://github.com/opensearch-project/OpenSearch/pull/6569))
- Add 'base_path' setting to File System Repository ([#6558](https://github.com/opensearch-project/OpenSearch/pull/6558))
- Return success on DeletePits when no PITs exist. ([#6544](https://github.com/opensearch-project/OpenSearch/pull/6544))
- Add node repurpose command for search nodes ([#6517](https://github.com/opensearch-project/OpenSearch/pull/6517))
- Add wait_for_completion parameter to resize, open, and forcemerge APIs ([#6434](https://github.com/opensearch-project/OpenSearch/pull/6434))
- [Segment Replication] Apply backpressure when replicas fall behind ([#6563](https://github.com/opensearch-project/OpenSearch/pull/6563))
- [Remote Store] Integrate remote segment store in peer recovery flow ([#6664](https://github.com/opensearch-project/OpenSearch/pull/6664))
- [Segment Replication] Add new cluster setting to set replication strategy by default for all indices in cluster. ([#6791](https://github.com/opensearch-project/OpenSearch/pull/6791))
- Enable sort optimization for all NumericTypes ([#6464](https://github.com/opensearch-project/OpenSearch/pull/6464)
- Remove 'cluster_manager' role attachment when using 'node.master' deprecated setting ([#6331](https://github.com/opensearch-project/OpenSearch/pull/6331))
- [Extensions] Moving Extensions APIs to protobuf serialization. ([#6960](https://github.com/opensearch-project/OpenSearch/pull/6960))

### Dependencies
- Bump `org.apache.logging.log4j:log4j-core` from 2.18.0 to 2.20.0 ([#6490](https://github.com/opensearch-project/OpenSearch/pull/6490))
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ allprojects {

// See please https://bugs.openjdk.java.net/browse/JDK-8209058
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_11) {
compile.options.compilerArgs << '-Werror'
//compile.options.compilerArgs << '-Werror'
}
compile.options.compilerArgs << '-Xlint:auxiliaryclass'
compile.options.compilerArgs << '-Xlint:cast'
Expand Down
1 change: 1 addition & 0 deletions buildSrc/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ woodstox = 6.4.0
kotlin = 1.7.10
antlr4 = 4.11.1
guava = 31.1-jre
protobuf = 3.22.2

# when updating the JNA version, also update the version in buildSrc/build.gradle
jna = 5.5.0
Expand Down
8 changes: 0 additions & 8 deletions modules/transport-netty4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ thirdPartyAudit {
'com.aayushatharva.brotli4j.encoder.Encoder$Parameters',
// classes are missing

// from io.netty.handler.codec.protobuf.ProtobufDecoder (netty)
'com.google.protobuf.ExtensionRegistry',
'com.google.protobuf.MessageLite$Builder',
'com.google.protobuf.MessageLite',
'com.google.protobuf.Parser',

// from io.netty.logging.CommonsLoggerFactory (netty)
'org.apache.commons.logging.Log',
'org.apache.commons.logging.LogFactory',
Expand Down Expand Up @@ -190,8 +184,6 @@ thirdPartyAudit {
'org.slf4j.spi.LocationAwareLogger',

'com.github.luben.zstd.Zstd',
'com.google.protobuf.ExtensionRegistryLite',
'com.google.protobuf.MessageLiteOrBuilder',
'com.google.protobuf.nano.CodedOutputByteBufferNano',
'com.google.protobuf.nano.MessageNano',
'com.jcraft.jzlib.Deflater',
Expand Down
10 changes: 1 addition & 9 deletions plugins/repository-gcs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ dependencies {
api 'com.google.api:api-common:1.8.1'
api 'com.google.api:gax:1.54.0'
api 'org.threeten:threetenbp:1.4.4'
api 'com.google.protobuf:protobuf-java-util:3.20.0'
api 'com.google.protobuf:protobuf-java:3.21.7'
api 'com.google.code.gson:gson:2.9.0'
api 'com.google.api.grpc:proto-google-common-protos:2.10.0'
api 'com.google.api.grpc:proto-google-iam-v1:0.12.0'
Expand Down Expand Up @@ -105,13 +103,6 @@ tasks.named("dependencyLicenses").configure {
thirdPartyAudit {
ignoreViolations(
// uses internal java api: sun.misc.Unsafe
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor',
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.common.cache.Striped64',
'com.google.common.cache.Striped64$1',
'com.google.common.cache.Striped64$Cell',
Expand Down Expand Up @@ -150,6 +141,7 @@ thirdPartyAudit {
'com.google.appengine.api.urlfetch.HTTPResponse',
'com.google.appengine.api.urlfetch.URLFetchService',
'com.google.appengine.api.urlfetch.URLFetchServiceFactory',
'com.google.protobuf.util.Timestamps',
// commons-logging optional dependencies
'org.apache.avalon.framework.logger.Logger',
'org.apache.log.Hierarchy',
Expand Down

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions plugins/repository-hdfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ dependencies {
api 'org.apache.avro:avro:1.11.1'
api 'com.google.code.gson:gson:2.10.1'
runtimeOnly "com.google.guava:guava:${versions.guava}"
api 'com.google.protobuf:protobuf-java:3.22.2'
api "commons-logging:commons-logging:${versions.commonslogging}"
api 'commons-cli:commons-cli:1.2'
api "commons-codec:commons-codec:${versions.commonscodec}"
Expand Down Expand Up @@ -114,19 +113,6 @@ tasks.named("dependencyLicenses").configure {
mapping from: /hadoop-.*/, to: 'hadoop'
}

thirdPartyAudit {
ignoreViolations(
// uses internal java api: sun.misc.Unsafe
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
)
}

tasks.named("integTest").configure {
it.dependsOn(project.tasks.named("bundlePlugin"))
}
Expand Down
10 changes: 0 additions & 10 deletions plugins/repository-hdfs/licenses/protobuf-java-LICENSE.txt

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/repository-hdfs/licenses/protobuf-java-NOTICE.txt

This file was deleted.

8 changes: 0 additions & 8 deletions plugins/transport-nio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ thirdPartyAudit {
'com.aayushatharva.brotli4j.encoder.Encoder$Mode',
'com.aayushatharva.brotli4j.encoder.Encoder$Parameters',

// from io.netty.handler.codec.protobuf.ProtobufDecoder (netty)
'com.google.protobuf.ExtensionRegistry',
'com.google.protobuf.MessageLite$Builder',
'com.google.protobuf.MessageLite',
'com.google.protobuf.Parser',

// from io.netty.logging.CommonsLoggerFactory (netty)
'org.apache.commons.logging.Log',
'org.apache.commons.logging.LogFactory',
Expand Down Expand Up @@ -118,8 +112,6 @@ thirdPartyAudit {
'org.slf4j.spi.LocationAwareLogger',

'com.github.luben.zstd.Zstd',
'com.google.protobuf.ExtensionRegistryLite',
'com.google.protobuf.MessageLiteOrBuilder',
'com.google.protobuf.nano.CodedOutputByteBufferNano',
'com.google.protobuf.nano.MessageNano',
'com.jcraft.jzlib.Deflater',
Expand Down
Empty file added protobuf-java-NOTICE.txt
Empty file.
66 changes: 62 additions & 4 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@

import org.opensearch.gradle.info.BuildParams

apply plugin: 'opensearch.build'
apply plugin: 'com.netflix.nebula.optional-base'
apply plugin: 'opensearch.publish'
apply plugin: 'opensearch.internal-cluster-test'
plugins {
id('com.google.protobuf') version 'latest.release'
id('opensearch.build')
id('com.netflix.nebula.optional-base')
id('opensearch.publish')
id('opensearch.internal-cluster-test')
}

publishing {
publications {
Expand All @@ -45,6 +48,13 @@ publishing {

archivesBaseName = 'opensearch'

sourceSets {
main {
java {
srcDir "${buildDir}/generated/source/proto/main/java"
}
}
}
// we want to keep the JDKs in our IDEs set to JDK 8 until minimum JDK is bumped to 11 so we do not include this source set in our IDEs
if (!isEclipse) {
sourceSets {
Expand Down Expand Up @@ -136,6 +146,9 @@ dependencies {
// jna
api "net.java.dev.jna:jna:${versions.jna}"

// protobuf
api "com.google.protobuf:protobuf-java:${versions.protobuf}"

testImplementation(project(":test:framework")) {
// tests use the locally compiled version of server
exclude group: 'org.opensearch', module: 'server'
Expand All @@ -157,6 +170,7 @@ tasks.named("internalClusterTest").configure {
}

tasks.named("forbiddenPatterns").configure {
dependsOn("generateProto")
exclude '**/*.json'
exclude '**/*.jmx'
exclude '**/*.dic'
Expand Down Expand Up @@ -203,6 +217,12 @@ def generatePluginsList = tasks.register("generatePluginsList") {
}
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${versions.protobuf}"
}
}

tasks.named("processResources").configure {
dependsOn generateModulesList, generatePluginsList
}
Expand Down Expand Up @@ -303,6 +323,15 @@ tasks.named("thirdPartyAudit").configure {
'com.google.common.geometry.S2$Metric',
'com.google.common.geometry.S2LatLng'
)
ignoreViolations(
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
)
}

tasks.named("dependencyLicenses").configure {
Expand All @@ -315,17 +344,46 @@ tasks.named("dependencyLicenses").configure {
}
}

tasks.named("missingJavadoc").configure {
/*
* Generated code doesn't follow javadocs formats.
* Unfortunately the missingJavadoc task doesnt take *.
* TODO: Add support to missingJavadoc task to ignore all generated source code
* https://github.com/opensearch-project/OpenSearch/issues/7264
*/
dependsOn("generateProto")
javadocMissingIgnore = [
"org.opensearch.extensions.proto.ExtensionRequestProto",
"org.opensearch.extensions.proto.ExtensionRequestProto.ExtensionRequestOrBuilder",
"org.opensearch.extensions.proto"
]
}

tasks.named("filepermissions").configure {
mustRunAfter("generateProto")
}

tasks.named("licenseHeaders").configure {
dependsOn("generateProto")
// Ignore our vendored version of Google Guice
excludes << 'org/opensearch/common/inject/**/*'
// Ignore temporary copies of impending 8.7 Lucene classes
excludes << 'org/apache/lucene/search/RegExp87*'
excludes << 'org/apache/lucene/search/RegexpQuery87*'
excludes << 'org/opensearch/client/documentation/placeholder.txt'
// Ignore for protobuf generated code
excludes << 'org/opensearch/extensions/proto/*'
}

tasks.test {
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_1_8) {
jvmArgs += ["--add-opens", "java.base/java.nio.file=ALL-UNNAMED"]
}
}

tasks.named("sourcesJar").configure {
// Ignore duplicates for protobuf generated code (main and generatedSources).
filesMatching("**/proto/*") {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import org.opensearch.common.Nullable;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.extensions.proto.ExtensionRequestProto;
import org.opensearch.transport.TransportRequest;

import java.io.IOException;
import java.util.Objects;
import java.util.Optional;

/**
* CLusterService Request for Extensibility
Expand All @@ -26,54 +26,54 @@
*/
public class ExtensionRequest extends TransportRequest {
private static final Logger logger = LogManager.getLogger(ExtensionRequest.class);
private final ExtensionsManager.RequestType requestType;
private final Optional<String> uniqueId;
private final ExtensionRequestProto.ExtensionRequest request;

public ExtensionRequest(ExtensionsManager.RequestType requestType) {
public ExtensionRequest(ExtensionRequestProto.RequestType requestType) {
this(requestType, null);
}

public ExtensionRequest(ExtensionsManager.RequestType requestType, @Nullable String uniqueId) {
this.requestType = requestType;
this.uniqueId = uniqueId == null ? Optional.empty() : Optional.of(uniqueId);
public ExtensionRequest(ExtensionRequestProto.RequestType requestType, @Nullable String uniqueId) {
ExtensionRequestProto.ExtensionRequest.Builder builder = ExtensionRequestProto.ExtensionRequest.newBuilder();
if (uniqueId != null) {
builder.setUniqueId(uniqueId);
}
this.request = builder.setRequestType(requestType).build();
}

public ExtensionRequest(StreamInput in) throws IOException {
super(in);
this.requestType = in.readEnum(ExtensionsManager.RequestType.class);
String id = in.readOptionalString();
this.uniqueId = id == null ? Optional.empty() : Optional.of(id);
this.request = ExtensionRequestProto.ExtensionRequest.parseFrom(in.readByteArray());
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeEnum(requestType);
out.writeOptionalString(uniqueId.orElse(null));
out.writeByteArray(request.toByteArray());
}

public ExtensionsManager.RequestType getRequestType() {
return this.requestType;
public ExtensionRequestProto.RequestType getRequestType() {
return this.request.getRequestType();
}

public Optional<String> getUniqueId() {
return uniqueId;
public String getUniqueId() {
return request.getUniqueId();
}

public String toString() {
return "ExtensionRequest{" + "requestType=" + requestType + "uniqueId=" + uniqueId + '}';
return "ExtensionRequest{" + request.toString() + '}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ExtensionRequest that = (ExtensionRequest) o;
return Objects.equals(requestType, that.requestType) && Objects.equals(uniqueId, that.uniqueId);
return Objects.equals(request.getRequestType(), that.request.getRequestType())
&& Objects.equals(request.getUniqueId(), that.request.getUniqueId());
}

@Override
public int hashCode() {
return Objects.hash(requestType, uniqueId);
return Objects.hash(request.getRequestType(), request.getUniqueId());
}
}
Loading

0 comments on commit 29b8a4b

Please sign in to comment.