-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Extensions] Moving ExtensionsRequest to use Protobuf #6960
Changes from 11 commits
6ed4085
6c0f1a2
65dfbb9
4b4c9e2
f1940e0
49a937a
cdc5718
e926b8d
f6a2170
f65a19d
c91bb9c
b6af3af
7873d2c
08b76ba
96a157a
2c40329
84019a7
b71ec29
33e500a
1089388
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,10 @@ | |
|
||
import org.opensearch.gradle.info.BuildParams | ||
|
||
plugins { | ||
id('com.google.protobuf') version '0.8.19' | ||
saratvemulapalli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
apply plugin: 'opensearch.build' | ||
apply plugin: 'com.netflix.nebula.optional-base' | ||
apply plugin: 'opensearch.publish' | ||
|
@@ -45,6 +49,13 @@ publishing { | |
|
||
archivesBaseName = 'opensearch' | ||
|
||
sourceSets { | ||
main { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
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 { | ||
|
@@ -136,6 +147,9 @@ dependencies { | |
// jna | ||
api "net.java.dev.jna:jna:${versions.jna}" | ||
|
||
// protobuf | ||
api 'com.google.protobuf:protobuf-java:3.22.2' | ||
saratvemulapalli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
testImplementation(project(":test:framework")) { | ||
// tests use the locally compiled version of server | ||
exclude group: 'org.opensearch', module: 'server' | ||
|
@@ -203,6 +217,12 @@ def generatePluginsList = tasks.register("generatePluginsList") { | |
} | ||
} | ||
|
||
protobuf { | ||
protoc { | ||
artifact = "com.google.protobuf:protoc:3.22.2" | ||
} | ||
} | ||
|
||
tasks.named("processResources").configure { | ||
dependsOn generateModulesList, generatePluginsList | ||
} | ||
|
@@ -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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -26,54 +26,54 @@ | |
*/ | ||
public class ExtensionRequest extends TransportRequest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have the generated protobuf class generate the transport request required methods while its at it? I'd love to get rid of the error prone equals/hash/tostring also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One step at a time :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
private static final Logger logger = LogManager.getLogger(ExtensionRequest.class); | ||
private final ExtensionsManager.RequestType requestType; | ||
private final Optional<String> uniqueId; | ||
private final ExtensionRequestProto.ExtensionRequest request; | ||
owaiskazi19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) { | ||
saratvemulapalli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
syntax = "proto3"; | ||
package org.opensearch.extensions.proto; | ||
|
||
option java_outer_classname = "ExtensionRequestProto"; | ||
|
||
enum RequestType { | ||
REQUEST_EXTENSION_CLUSTER_STATE = 0; | ||
REQUEST_EXTENSION_CLUSTER_SETTINGS = 1; | ||
REQUEST_EXTENSION_REGISTER_REST_ACTIONS = 2; | ||
REQUEST_EXTENSION_REGISTER_SETTINGS = 3; | ||
REQUEST_EXTENSION_ENVIRONMENT_SETTINGS = 4; | ||
REQUEST_EXTENSION_DEPENDENCY_INFORMATION = 5; | ||
CREATE_COMPONENT = 6; | ||
ON_INDEX_MODULE = 7; | ||
GET_SETTINGS = 8; | ||
} | ||
|
||
message ExtensionRequest { | ||
RequestType requestType = 1; | ||
string uniqueId = 2; | ||
} | ||
saratvemulapalli marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup we do. We are removing these violations from the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I wasn't clear. I meant do we need
thirdPartyAudit
task here anymore in this build.gradle? Can we remove the task from this build.gradleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I missed that. It makes sense.