From 3c506cb98faa27d8244c824c5b0f6f09e20c09e6 Mon Sep 17 00:00:00 2001 From: Sarat Vemulapalli Date: Wed, 15 Mar 2023 17:01:56 -0700 Subject: [PATCH] First commit for proto test Signed-off-by: Sarat Vemulapalli --- .idea/vcs.xml | 32 +- gradle/run.gradle | 1 + plugins/repository-gcs/build.gradle | 2 +- plugins/repository-hdfs/build.gradle | 2 +- server/build.gradle | 3 + .../discovery/InitializeExtensionRequest.java | 9 +- .../extensions/ExtensionRequest.java | 12 +- .../extensions/ExtensionsManager.java | 3 + .../extensions/proto/ExtensionOuterClass.java | 825 ++++++++++++++++++ .../proto/ExtensionProtoHelloWorld.java | 35 + .../extensions/proto/extension.proto | 8 + .../extensions/proto/package-info.java | 10 + 12 files changed, 922 insertions(+), 20 deletions(-) create mode 100644 server/src/main/java/org/opensearch/extensions/proto/ExtensionOuterClass.java create mode 100644 server/src/main/java/org/opensearch/extensions/proto/ExtensionProtoHelloWorld.java create mode 100644 server/src/main/java/org/opensearch/extensions/proto/extension.proto create mode 100644 server/src/main/java/org/opensearch/extensions/proto/package-info.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 48557884a8893..c668657daf908 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,20 +1,20 @@ - - - + + + - + - + \ No newline at end of file diff --git a/gradle/run.gradle b/gradle/run.gradle index 639479e97d28f..0284e9f1c30c5 100644 --- a/gradle/run.gradle +++ b/gradle/run.gradle @@ -39,6 +39,7 @@ testClusters { testDistribution = 'archive' if (numZones > 1) numberOfZones = numZones if (numNodes > 1) numberOfNodes = numNodes + systemProperty 'opensearch.experimental.feature.extensions.enabled', 'true' } } diff --git a/plugins/repository-gcs/build.gradle b/plugins/repository-gcs/build.gradle index 561119e9e2c30..079eee38d29c5 100644 --- a/plugins/repository-gcs/build.gradle +++ b/plugins/repository-gcs/build.gradle @@ -66,7 +66,7 @@ dependencies { api 'com.google.api:gax:2.17.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.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' diff --git a/plugins/repository-hdfs/build.gradle b/plugins/repository-hdfs/build.gradle index 182a0b04c9093..b8ab69c37863b 100644 --- a/plugins/repository-hdfs/build.gradle +++ b/plugins/repository-hdfs/build.gradle @@ -69,7 +69,7 @@ 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 'com.google.protobuf:protobuf-java:3.22.2' api "commons-logging:commons-logging:${versions.commonslogging}" api 'commons-cli:commons-cli:1.5.0' api "commons-codec:commons-codec:${versions.commonscodec}" diff --git a/server/build.gradle b/server/build.gradle index 2eea312699798..b6d4359b0d11f 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -136,6 +136,9 @@ dependencies { // jna api "net.java.dev.jna:jna:${versions.jna}" + // protobuf + implementation 'com.google.protobuf:protobuf-java:3.22.2' + testImplementation(project(":test:framework")) { // tests use the locally compiled version of server exclude group: 'org.opensearch', module: 'server' diff --git a/server/src/main/java/org/opensearch/discovery/InitializeExtensionRequest.java b/server/src/main/java/org/opensearch/discovery/InitializeExtensionRequest.java index b83e9080fa452..e72a89f2bf9b1 100644 --- a/server/src/main/java/org/opensearch/discovery/InitializeExtensionRequest.java +++ b/server/src/main/java/org/opensearch/discovery/InitializeExtensionRequest.java @@ -12,6 +12,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.extensions.DiscoveryExtensionNode; +import org.opensearch.extensions.proto.ExtensionOuterClass; import org.opensearch.transport.TransportRequest; import java.io.IOException; @@ -25,16 +26,19 @@ public class InitializeExtensionRequest extends TransportRequest { private final DiscoveryNode sourceNode; private final DiscoveryExtensionNode extension; + private final ExtensionOuterClass.Extension extensionProto; public InitializeExtensionRequest(DiscoveryNode sourceNode, DiscoveryExtensionNode extension) { this.sourceNode = sourceNode; this.extension = extension; + this.extensionProto = ExtensionOuterClass.Extension.newBuilder().setName("Sarat").setId(10).setAlias("vemsarat").build(); } public InitializeExtensionRequest(StreamInput in) throws IOException { super(in); sourceNode = new DiscoveryNode(in); extension = new DiscoveryExtensionNode(in); + this.extensionProto = ExtensionOuterClass.Extension.parseFrom(in.readByteArray()); } @Override @@ -42,6 +46,7 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); sourceNode.writeTo(out); extension.writeTo(out); + out.writeByteArray(extensionProto.toByteArray()); } public DiscoveryNode getSourceNode() { @@ -52,9 +57,11 @@ public DiscoveryExtensionNode getExtension() { return extension; } + public ExtensionOuterClass.Extension getExtensionProto() { return extensionProto; } + @Override public String toString() { - return "InitializeExtensionsRequest{" + "sourceNode=" + sourceNode + ", extension=" + extension + '}'; + return "InitializeExtensionsRequest{" + "sourceNode=" + sourceNode + ", extension=" + extension + extensionProto.toString() + '}'; } @Override diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionRequest.java b/server/src/main/java/org/opensearch/extensions/ExtensionRequest.java index bfe53bee27cd6..e9122cf8c5230 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionRequest.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionRequest.java @@ -13,6 +13,7 @@ import org.opensearch.common.Nullable; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.extensions.proto.ExtensionOuterClass; import org.opensearch.transport.TransportRequest; import java.io.IOException; @@ -29,6 +30,8 @@ public class ExtensionRequest extends TransportRequest { private final ExtensionsManager.RequestType requestType; private final Optional uniqueId; + private final ExtensionOuterClass.Extension extension; + public ExtensionRequest(ExtensionsManager.RequestType requestType) { this(requestType, null); } @@ -36,6 +39,7 @@ public ExtensionRequest(ExtensionsManager.RequestType requestType) { public ExtensionRequest(ExtensionsManager.RequestType requestType, @Nullable String uniqueId) { this.requestType = requestType; this.uniqueId = uniqueId == null ? Optional.empty() : Optional.of(uniqueId); + extension = ExtensionOuterClass.Extension.newBuilder().setName("Sarat").setId(10).build(); } public ExtensionRequest(StreamInput in) throws IOException { @@ -43,6 +47,7 @@ public ExtensionRequest(StreamInput in) throws IOException { this.requestType = in.readEnum(ExtensionsManager.RequestType.class); String id = in.readOptionalString(); this.uniqueId = id == null ? Optional.empty() : Optional.of(id); + this.extension = ExtensionOuterClass.Extension.parseFrom(in.readByteArray()); } @Override @@ -50,6 +55,7 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeEnum(requestType); out.writeOptionalString(uniqueId.orElse(null)); + out.writeByteArray(extension.toByteArray()); } public ExtensionsManager.RequestType getRequestType() { @@ -60,8 +66,12 @@ public Optional getUniqueId() { return uniqueId; } + public void extensionToString() { + logger.info(extension.toString()); + } + public String toString() { - return "ExtensionRequest{" + "requestType=" + requestType + "uniqueId=" + uniqueId + '}'; + return "ExtensionRequest{" + "requestType=" + requestType + "uniqueId=" + uniqueId + extension.toString() + '}'; } @Override diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index 4f852ca944966..6bcf41c5cc256 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -48,6 +48,7 @@ import org.opensearch.extensions.action.ExtensionActionResponse; import org.opensearch.extensions.action.ExtensionTransportActionsHandler; import org.opensearch.extensions.action.TransportActionRequestFromExtension; +import org.opensearch.extensions.proto.ExtensionProtoHelloWorld; import org.opensearch.extensions.rest.RegisterRestActionsRequest; import org.opensearch.extensions.rest.RestActionsRequestHandler; import org.opensearch.extensions.settings.CustomSettingsRequestHandler; @@ -155,6 +156,8 @@ public ExtensionsManager(Settings settings, Path extensionsPath) throws IOExcept this.client = null; this.extensionTransportActionsHandler = null; + ExtensionProtoHelloWorld protoHelloWorld = new ExtensionProtoHelloWorld(); + /* * Now Discover extensions */ diff --git a/server/src/main/java/org/opensearch/extensions/proto/ExtensionOuterClass.java b/server/src/main/java/org/opensearch/extensions/proto/ExtensionOuterClass.java new file mode 100644 index 0000000000000..3d0b70e4a064d --- /dev/null +++ b/server/src/main/java/org/opensearch/extensions/proto/ExtensionOuterClass.java @@ -0,0 +1,825 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: server/src/main/java/org/opensearch/extensions/proto/extension.proto + +package org.opensearch.extensions.proto; + +public final class ExtensionOuterClass { + private ExtensionOuterClass() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + public interface ExtensionOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.opensearch.extensions.proto.Extension) + com.google.protobuf.MessageOrBuilder { + + /** + * string name = 1; + * @return The name. + */ + java.lang.String getName(); + /** + * string name = 1; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + * int32 id = 2; + * @return The id. + */ + int getId(); + + /** + * string alias = 3; + * @return The alias. + */ + java.lang.String getAlias(); + /** + * string alias = 3; + * @return The bytes for alias. + */ + com.google.protobuf.ByteString + getAliasBytes(); + } + /** + * Protobuf type {@code org.opensearch.extensions.proto.Extension} + */ + public static final class Extension extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.opensearch.extensions.proto.Extension) + ExtensionOrBuilder { + private static final long serialVersionUID = 0L; + // Use Extension.newBuilder() to construct. + private Extension(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private Extension() { + name_ = ""; + alias_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new Extension(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.opensearch.extensions.proto.ExtensionOuterClass.internal_static_org_opensearch_extensions_proto_Extension_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.opensearch.extensions.proto.ExtensionOuterClass.internal_static_org_opensearch_extensions_proto_Extension_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.opensearch.extensions.proto.ExtensionOuterClass.Extension.class, org.opensearch.extensions.proto.ExtensionOuterClass.Extension.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * string name = 1; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * string name = 1; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int ID_FIELD_NUMBER = 2; + private int id_ = 0; + /** + * int32 id = 2; + * @return The id. + */ + @java.lang.Override + public int getId() { + return id_; + } + + public static final int ALIAS_FIELD_NUMBER = 3; + @SuppressWarnings("serial") + private volatile java.lang.Object alias_ = ""; + /** + * string alias = 3; + * @return The alias. + */ + @java.lang.Override + public java.lang.String getAlias() { + java.lang.Object ref = alias_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + alias_ = s; + return s; + } + } + /** + * string alias = 3; + * @return The bytes for alias. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getAliasBytes() { + java.lang.Object ref = alias_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + alias_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + if (id_ != 0) { + output.writeInt32(2, id_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(alias_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, alias_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + if (id_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(2, id_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(alias_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, alias_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.opensearch.extensions.proto.ExtensionOuterClass.Extension)) { + return super.equals(obj); + } + org.opensearch.extensions.proto.ExtensionOuterClass.Extension other = (org.opensearch.extensions.proto.ExtensionOuterClass.Extension) obj; + + if (!getName() + .equals(other.getName())) return false; + if (getId() + != other.getId()) return false; + if (!getAlias() + .equals(other.getAlias())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (37 * hash) + ID_FIELD_NUMBER; + hash = (53 * hash) + getId(); + hash = (37 * hash) + ALIAS_FIELD_NUMBER; + hash = (53 * hash) + getAlias().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(org.opensearch.extensions.proto.ExtensionOuterClass.Extension prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.opensearch.extensions.proto.Extension} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.opensearch.extensions.proto.Extension) + org.opensearch.extensions.proto.ExtensionOuterClass.ExtensionOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.opensearch.extensions.proto.ExtensionOuterClass.internal_static_org_opensearch_extensions_proto_Extension_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.opensearch.extensions.proto.ExtensionOuterClass.internal_static_org_opensearch_extensions_proto_Extension_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.opensearch.extensions.proto.ExtensionOuterClass.Extension.class, org.opensearch.extensions.proto.ExtensionOuterClass.Extension.Builder.class); + } + + // Construct using org.opensearch.extensions.proto.ExtensionOuterClass.Extension.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + id_ = 0; + alias_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.opensearch.extensions.proto.ExtensionOuterClass.internal_static_org_opensearch_extensions_proto_Extension_descriptor; + } + + @java.lang.Override + public org.opensearch.extensions.proto.ExtensionOuterClass.Extension getDefaultInstanceForType() { + return org.opensearch.extensions.proto.ExtensionOuterClass.Extension.getDefaultInstance(); + } + + @java.lang.Override + public org.opensearch.extensions.proto.ExtensionOuterClass.Extension build() { + org.opensearch.extensions.proto.ExtensionOuterClass.Extension result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public org.opensearch.extensions.proto.ExtensionOuterClass.Extension buildPartial() { + org.opensearch.extensions.proto.ExtensionOuterClass.Extension result = new org.opensearch.extensions.proto.ExtensionOuterClass.Extension(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(org.opensearch.extensions.proto.ExtensionOuterClass.Extension result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.id_ = id_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.alias_ = alias_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.opensearch.extensions.proto.ExtensionOuterClass.Extension) { + return mergeFrom((org.opensearch.extensions.proto.ExtensionOuterClass.Extension)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.opensearch.extensions.proto.ExtensionOuterClass.Extension other) { + if (other == org.opensearch.extensions.proto.ExtensionOuterClass.Extension.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (other.getId() != 0) { + setId(other.getId()); + } + if (!other.getAlias().isEmpty()) { + alias_ = other.alias_; + bitField0_ |= 0x00000004; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 16: { + id_ = input.readInt32(); + bitField0_ |= 0x00000002; + break; + } // case 16 + case 26: { + alias_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * string name = 1; + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string name = 1; + * @return The bytes for name. + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string name = 1; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + if (value == null) { throw new NullPointerException(); } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * string name = 1; + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * string name = 1; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private int id_ ; + /** + * int32 id = 2; + * @return The id. + */ + @java.lang.Override + public int getId() { + return id_; + } + /** + * int32 id = 2; + * @param value The id to set. + * @return This builder for chaining. + */ + public Builder setId(int value) { + + id_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * int32 id = 2; + * @return This builder for chaining. + */ + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000002); + id_ = 0; + onChanged(); + return this; + } + + private java.lang.Object alias_ = ""; + /** + * string alias = 3; + * @return The alias. + */ + public java.lang.String getAlias() { + java.lang.Object ref = alias_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + alias_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string alias = 3; + * @return The bytes for alias. + */ + public com.google.protobuf.ByteString + getAliasBytes() { + java.lang.Object ref = alias_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + alias_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string alias = 3; + * @param value The alias to set. + * @return This builder for chaining. + */ + public Builder setAlias( + java.lang.String value) { + if (value == null) { throw new NullPointerException(); } + alias_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * string alias = 3; + * @return This builder for chaining. + */ + public Builder clearAlias() { + alias_ = getDefaultInstance().getAlias(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + /** + * string alias = 3; + * @param value The bytes for alias to set. + * @return This builder for chaining. + */ + public Builder setAliasBytes( + com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + checkByteStringIsUtf8(value); + alias_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:org.opensearch.extensions.proto.Extension) + } + + // @@protoc_insertion_point(class_scope:org.opensearch.extensions.proto.Extension) + private static final org.opensearch.extensions.proto.ExtensionOuterClass.Extension DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new org.opensearch.extensions.proto.ExtensionOuterClass.Extension(); + } + + public static org.opensearch.extensions.proto.ExtensionOuterClass.Extension getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public Extension parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.opensearch.extensions.proto.ExtensionOuterClass.Extension getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_opensearch_extensions_proto_Extension_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_opensearch_extensions_proto_Extension_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\nDserver/src/main/java/org/opensearch/ex" + + "tensions/proto/extension.proto\022\037org.open" + + "search.extensions.proto\"4\n\tExtension\022\014\n\004" + + "name\030\001 \001(\t\022\n\n\002id\030\002 \001(\005\022\r\n\005alias\030\003 \001(\tb\006p" + + "roto3" + }; + descriptor = com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }); + internal_static_org_opensearch_extensions_proto_Extension_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_org_opensearch_extensions_proto_Extension_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_opensearch_extensions_proto_Extension_descriptor, + new java.lang.String[] { "Name", "Id", "Alias", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/server/src/main/java/org/opensearch/extensions/proto/ExtensionProtoHelloWorld.java b/server/src/main/java/org/opensearch/extensions/proto/ExtensionProtoHelloWorld.java new file mode 100644 index 0000000000000..304b46de013c2 --- /dev/null +++ b/server/src/main/java/org/opensearch/extensions/proto/ExtensionProtoHelloWorld.java @@ -0,0 +1,35 @@ +/* + * 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. + */ + +package org.opensearch.extensions.proto; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.extensions.ExtensionRequest; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * ExtensionOuterClass Request for Extensibility + * + * @opensearch.internal + */ +public class ExtensionProtoHelloWorld { + + private static final Logger logger = LogManager.getLogger(ExtensionProtoHelloWorld.class); + public ExtensionProtoHelloWorld() throws IOException { + ExtensionOuterClass.Extension.Builder extension = ExtensionOuterClass.Extension.newBuilder(); + extension.setName("My first extension"); + extension.setId(10010); + + //FileOutputStream output = new FileOutputStream("extension-test.txt"); + logger.info(extension.build().toByteArray()); + } +} diff --git a/server/src/main/java/org/opensearch/extensions/proto/extension.proto b/server/src/main/java/org/opensearch/extensions/proto/extension.proto new file mode 100644 index 0000000000000..cebe8818a2f58 --- /dev/null +++ b/server/src/main/java/org/opensearch/extensions/proto/extension.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package org.opensearch.extensions.proto; + +message Extension { + string name = 1; + int32 id = 2; + string alias = 3; +} diff --git a/server/src/main/java/org/opensearch/extensions/proto/package-info.java b/server/src/main/java/org/opensearch/extensions/proto/package-info.java new file mode 100644 index 0000000000000..a31f62cf4d4b7 --- /dev/null +++ b/server/src/main/java/org/opensearch/extensions/proto/package-info.java @@ -0,0 +1,10 @@ +/* + * 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. + */ + +/** Proto classes for the extensions package. OpenSearch extensions provide extensibility to OpenSearch.*/ +package org.opensearch.extensions.proto;