Skip to content

Commit c0f7c19

Browse files
[Extensions] Moving ExtensionsRequest to use Protobuf (opensearch-project#6960)
1 parent 4afc914 commit c0f7c19

20 files changed

+132
-112
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8080

8181
## [Unreleased 2.x]
8282
### Added
83+
- [Extensions] Moving Extensions APIs to protobuf serialization. ([#6960](https://github.com/opensearch-project/OpenSearch/pull/6960))
8384

8485
### Dependencies
8586

buildSrc/version.properties

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ woodstox = 6.4.0
2222
kotlin = 1.7.10
2323
antlr4 = 4.11.1
2424
guava = 31.1-jre
25+
protobuf = 3.22.2
2526

2627
# when updating the JNA version, also update the version in buildSrc/build.gradle
2728
jna = 5.5.0

modules/transport-netty4/build.gradle

-8
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ thirdPartyAudit {
132132
'com.aayushatharva.brotli4j.encoder.Encoder$Parameters',
133133
// classes are missing
134134

135-
// from io.netty.handler.codec.protobuf.ProtobufDecoder (netty)
136-
'com.google.protobuf.ExtensionRegistry',
137-
'com.google.protobuf.MessageLite$Builder',
138-
'com.google.protobuf.MessageLite',
139-
'com.google.protobuf.Parser',
140-
141135
// from io.netty.logging.CommonsLoggerFactory (netty)
142136
'org.apache.commons.logging.Log',
143137
'org.apache.commons.logging.LogFactory',
@@ -192,8 +186,6 @@ thirdPartyAudit {
192186
'org.slf4j.spi.LocationAwareLogger',
193187

194188
'com.github.luben.zstd.Zstd',
195-
'com.google.protobuf.ExtensionRegistryLite',
196-
'com.google.protobuf.MessageLiteOrBuilder',
197189
'com.google.protobuf.nano.CodedOutputByteBufferNano',
198190
'com.google.protobuf.nano.MessageNano',
199191
'com.jcraft.jzlib.Deflater',

plugins/repository-gcs/build.gradle

+4-9
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ dependencies {
6565
api 'com.google.api:api-common:1.8.1'
6666
api 'com.google.api:gax:2.17.0'
6767
api 'org.threeten:threetenbp:1.4.4'
68-
api 'com.google.protobuf:protobuf-java-util:3.22.2'
69-
api 'com.google.protobuf:protobuf-java:3.22.2'
7068
api 'com.google.code.gson:gson:2.9.0'
7169
api 'com.google.api.grpc:proto-google-common-protos:2.10.0'
7270
api 'com.google.api.grpc:proto-google-iam-v1:0.12.0'
@@ -105,13 +103,6 @@ tasks.named("dependencyLicenses").configure {
105103
thirdPartyAudit {
106104
ignoreViolations(
107105
// uses internal java api: sun.misc.Unsafe
108-
'com.google.protobuf.UnsafeUtil',
109-
'com.google.protobuf.UnsafeUtil$1',
110-
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
111-
'com.google.protobuf.UnsafeUtil$MemoryAccessor',
112-
'com.google.protobuf.MessageSchema',
113-
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
114-
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
115106
'com.google.common.cache.Striped64',
116107
'com.google.common.cache.Striped64$1',
117108
'com.google.common.cache.Striped64$Cell',
@@ -151,6 +142,10 @@ thirdPartyAudit {
151142
'com.google.appengine.api.urlfetch.URLFetchService',
152143
'com.google.appengine.api.urlfetch.URLFetchServiceFactory',
153144
'com.oracle.svm.core.configure.ResourcesRegistry',
145+
'com.google.protobuf.util.JsonFormat',
146+
'com.google.protobuf.util.JsonFormat$Parser',
147+
'com.google.protobuf.util.JsonFormat$Printer',
148+
'com.google.protobuf.util.Timestamps',
154149
// commons-logging optional dependencies
155150
'org.apache.avalon.framework.logger.Logger',
156151
'org.apache.log.Hierarchy',

plugins/repository-gcs/licenses/protobuf-java-util-3.22.2.jar.sha1

-1
This file was deleted.

plugins/repository-hdfs/build.gradle

-14
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ dependencies {
6969
api 'org.apache.avro:avro:1.11.1'
7070
api 'com.google.code.gson:gson:2.10.1'
7171
runtimeOnly "com.google.guava:guava:${versions.guava}"
72-
api 'com.google.protobuf:protobuf-java:3.22.3'
7372
api "commons-logging:commons-logging:${versions.commonslogging}"
7473
api 'commons-cli:commons-cli:1.5.0'
7574
api "commons-codec:commons-codec:${versions.commonscodec}"
@@ -114,19 +113,6 @@ tasks.named("dependencyLicenses").configure {
114113
mapping from: /hadoop-.*/, to: 'hadoop'
115114
}
116115

117-
thirdPartyAudit {
118-
ignoreViolations(
119-
// uses internal java api: sun.misc.Unsafe
120-
'com.google.protobuf.MessageSchema',
121-
'com.google.protobuf.UnsafeUtil',
122-
'com.google.protobuf.UnsafeUtil$1',
123-
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
124-
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
125-
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
126-
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
127-
)
128-
}
129-
130116
tasks.named("integTest").configure {
131117
it.dependsOn(project.tasks.named("bundlePlugin"))
132118
}

plugins/repository-hdfs/licenses/protobuf-java-3.22.3.jar.sha1

-1
This file was deleted.

plugins/repository-hdfs/licenses/protobuf-java-LICENSE.txt

-10
This file was deleted.

plugins/repository-hdfs/licenses/protobuf-java-NOTICE.txt

-2
This file was deleted.

plugins/transport-nio/build.gradle

-8
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ thirdPartyAudit {
6666
'com.aayushatharva.brotli4j.encoder.Encoder$Mode',
6767
'com.aayushatharva.brotli4j.encoder.Encoder$Parameters',
6868

69-
// from io.netty.handler.codec.protobuf.ProtobufDecoder (netty)
70-
'com.google.protobuf.ExtensionRegistry',
71-
'com.google.protobuf.MessageLite$Builder',
72-
'com.google.protobuf.MessageLite',
73-
'com.google.protobuf.Parser',
74-
7569
// from io.netty.logging.CommonsLoggerFactory (netty)
7670
'org.apache.commons.logging.Log',
7771
'org.apache.commons.logging.LogFactory',
@@ -118,8 +112,6 @@ thirdPartyAudit {
118112
'org.slf4j.spi.LocationAwareLogger',
119113

120114
'com.github.luben.zstd.Zstd',
121-
'com.google.protobuf.ExtensionRegistryLite',
122-
'com.google.protobuf.MessageLiteOrBuilder',
123115
'com.google.protobuf.nano.CodedOutputByteBufferNano',
124116
'com.google.protobuf.nano.MessageNano',
125117
'com.jcraft.jzlib.Deflater',

protobuf-java-NOTICE.txt

Whitespace-only changes.

server/build.gradle

+62-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030

3131
import org.opensearch.gradle.info.BuildParams
3232

33-
apply plugin: 'opensearch.build'
34-
apply plugin: 'com.netflix.nebula.optional-base'
35-
apply plugin: 'opensearch.publish'
36-
apply plugin: 'opensearch.internal-cluster-test'
33+
plugins {
34+
id('com.google.protobuf') version 'latest.release'
35+
id('opensearch.build')
36+
id('com.netflix.nebula.optional-base')
37+
id('opensearch.publish')
38+
id('opensearch.internal-cluster-test')
39+
}
3740

3841
publishing {
3942
publications {
@@ -45,6 +48,13 @@ publishing {
4548

4649
archivesBaseName = 'opensearch'
4750

51+
sourceSets {
52+
main {
53+
java {
54+
srcDir "${buildDir}/generated/source/proto/main/java"
55+
}
56+
}
57+
}
4858
// 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
4959
if (!isEclipse) {
5060
sourceSets {
@@ -136,6 +146,9 @@ dependencies {
136146
// jna
137147
api "net.java.dev.jna:jna:${versions.jna}"
138148

149+
// protobuf
150+
api "com.google.protobuf:protobuf-java:${versions.protobuf}"
151+
139152
testImplementation(project(":test:framework")) {
140153
// tests use the locally compiled version of server
141154
exclude group: 'org.opensearch', module: 'server'
@@ -157,6 +170,7 @@ tasks.named("internalClusterTest").configure {
157170
}
158171

159172
tasks.named("forbiddenPatterns").configure {
173+
dependsOn("generateProto")
160174
exclude '**/*.json'
161175
exclude '**/*.jmx'
162176
exclude '**/*.dic'
@@ -203,6 +217,12 @@ def generatePluginsList = tasks.register("generatePluginsList") {
203217
}
204218
}
205219

220+
protobuf {
221+
protoc {
222+
artifact = "com.google.protobuf:protoc:${versions.protobuf}"
223+
}
224+
}
225+
206226
tasks.named("processResources").configure {
207227
dependsOn generateModulesList, generatePluginsList
208228
}
@@ -303,6 +323,15 @@ tasks.named("thirdPartyAudit").configure {
303323
'com.google.common.geometry.S2$Metric',
304324
'com.google.common.geometry.S2LatLng'
305325
)
326+
ignoreViolations(
327+
'com.google.protobuf.MessageSchema',
328+
'com.google.protobuf.UnsafeUtil',
329+
'com.google.protobuf.UnsafeUtil$1',
330+
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
331+
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
332+
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
333+
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
334+
)
306335
}
307336

308337
tasks.named("dependencyLicenses").configure {
@@ -315,17 +344,46 @@ tasks.named("dependencyLicenses").configure {
315344
}
316345
}
317346

347+
tasks.named("missingJavadoc").configure {
348+
/*
349+
* Generated code doesn't follow javadocs formats.
350+
* Unfortunately the missingJavadoc task doesnt take *.
351+
* TODO: Add support to missingJavadoc task to ignore all generated source code
352+
* https://github.com/opensearch-project/OpenSearch/issues/7264
353+
*/
354+
dependsOn("generateProto")
355+
javadocMissingIgnore = [
356+
"org.opensearch.extensions.proto.ExtensionRequestProto",
357+
"org.opensearch.extensions.proto.ExtensionRequestProto.ExtensionRequestOrBuilder",
358+
"org.opensearch.extensions.proto"
359+
]
360+
}
361+
362+
tasks.named("filepermissions").configure {
363+
mustRunAfter("generateProto")
364+
}
365+
318366
tasks.named("licenseHeaders").configure {
367+
dependsOn("generateProto")
319368
// Ignore our vendored version of Google Guice
320369
excludes << 'org/opensearch/common/inject/**/*'
321370
// Ignore temporary copies of impending 8.7 Lucene classes
322371
excludes << 'org/apache/lucene/search/RegExp87*'
323372
excludes << 'org/apache/lucene/search/RegexpQuery87*'
324373
excludes << 'org/opensearch/client/documentation/placeholder.txt'
374+
// Ignore for protobuf generated code
375+
excludes << 'org/opensearch/extensions/proto/*'
325376
}
326377

327378
tasks.test {
328379
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_1_8) {
329380
jvmArgs += ["--add-opens", "java.base/java.nio.file=ALL-UNNAMED"]
330381
}
331382
}
383+
384+
tasks.named("sourcesJar").configure {
385+
// Ignore duplicates for protobuf generated code (main and generatedSources).
386+
filesMatching("**/proto/*") {
387+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
388+
}
389+
}

server/src/main/java/org/opensearch/extensions/ExtensionRequest.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import org.opensearch.common.Nullable;
1414
import org.opensearch.common.io.stream.StreamInput;
1515
import org.opensearch.common.io.stream.StreamOutput;
16+
import org.opensearch.extensions.proto.ExtensionRequestProto;
1617
import org.opensearch.transport.TransportRequest;
1718

1819
import java.io.IOException;
1920
import java.util.Objects;
20-
import java.util.Optional;
2121

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

32-
public ExtensionRequest(ExtensionsManager.RequestType requestType) {
31+
public ExtensionRequest(ExtensionRequestProto.RequestType requestType) {
3332
this(requestType, null);
3433
}
3534

36-
public ExtensionRequest(ExtensionsManager.RequestType requestType, @Nullable String uniqueId) {
37-
this.requestType = requestType;
38-
this.uniqueId = uniqueId == null ? Optional.empty() : Optional.of(uniqueId);
35+
public ExtensionRequest(ExtensionRequestProto.RequestType requestType, @Nullable String uniqueId) {
36+
ExtensionRequestProto.ExtensionRequest.Builder builder = ExtensionRequestProto.ExtensionRequest.newBuilder();
37+
if (uniqueId != null) {
38+
builder.setUniqueId(uniqueId);
39+
}
40+
this.request = builder.setRequestType(requestType).build();
3941
}
4042

4143
public ExtensionRequest(StreamInput in) throws IOException {
4244
super(in);
43-
this.requestType = in.readEnum(ExtensionsManager.RequestType.class);
44-
String id = in.readOptionalString();
45-
this.uniqueId = id == null ? Optional.empty() : Optional.of(id);
45+
this.request = ExtensionRequestProto.ExtensionRequest.parseFrom(in.readByteArray());
4646
}
4747

4848
@Override
4949
public void writeTo(StreamOutput out) throws IOException {
5050
super.writeTo(out);
51-
out.writeEnum(requestType);
52-
out.writeOptionalString(uniqueId.orElse(null));
51+
out.writeByteArray(request.toByteArray());
5352
}
5453

55-
public ExtensionsManager.RequestType getRequestType() {
56-
return this.requestType;
54+
public ExtensionRequestProto.RequestType getRequestType() {
55+
return this.request.getRequestType();
5756
}
5857

59-
public Optional<String> getUniqueId() {
60-
return uniqueId;
58+
public String getUniqueId() {
59+
return request.getUniqueId();
6160
}
6261

6362
public String toString() {
64-
return "ExtensionRequest{" + "requestType=" + requestType + "uniqueId=" + uniqueId + '}';
63+
return "ExtensionRequest{" + request.toString() + '}';
6564
}
6665

6766
@Override
6867
public boolean equals(Object o) {
6968
if (this == o) return true;
7069
if (o == null || getClass() != o.getClass()) return false;
7170
ExtensionRequest that = (ExtensionRequest) o;
72-
return Objects.equals(requestType, that.requestType) && Objects.equals(uniqueId, that.uniqueId);
71+
return Objects.equals(request.getRequestType(), that.request.getRequestType())
72+
&& Objects.equals(request.getUniqueId(), that.request.getUniqueId());
7373
}
7474

7575
@Override
7676
public int hashCode() {
77-
return Objects.hash(requestType, uniqueId);
77+
return Objects.hash(request.getRequestType(), request.getUniqueId());
7878
}
7979
}

0 commit comments

Comments
 (0)