Skip to content

Commit 29ca685

Browse files
committed
Upgrade opensearch-protobufs dependency to 0.7.0 and update transport-grpc module compatibility
- Upgrade protobufs dependency from 0.6.0 to 0.7.0 in transport-grpc module - Update all protobuf utility classes to handle API changes in 0.7.0 - Fix enum structure changes (simple enums to message with oneof fields) - Update field name changes (setIndex -> setUnderscoreIndex, etc.) - Handle new OperationContainer pattern for bulk operations - Update all corresponding unit and integration tests - Add new SHA for protobufs-0.7.0.jar and remove old 0.6.0 SHA Signed-off-by: sakrah <sakrah@uber.com>
1 parent 5f3185c commit 29ca685

33 files changed

+392
-447
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55

66
## [Unreleased 3.x]
77
### Added
8+
- Upgrade opensearch-protobufs dependency to 0.7.0 and update transport-grpc module compatibility
89

910
### Changed
1011

modules/transport-grpc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
implementation "io.grpc:grpc-stub:${versions.grpc}"
3535
implementation "io.grpc:grpc-util:${versions.grpc}"
3636
implementation "io.perfmark:perfmark-api:0.27.0"
37-
implementation "org.opensearch:protobufs:0.6.0"
37+
implementation "org.opensearch:protobufs:0.7.0"
3838
testImplementation project(':test:framework')
3939
}
4040

modules/transport-grpc/licenses/protobufs-0.6.0.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d83e08f04da8ec6a5b8925934e5a599b7592aba0

modules/transport-grpc/src/internalClusterTest/java/org/opensearch/transport/grpc/DocumentServiceIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public void testDocumentServiceBulk() throws Exception {
3737
DocumentServiceGrpc.DocumentServiceBlockingStub documentStub = DocumentServiceGrpc.newBlockingStub(channel);
3838

3939
// Create a bulk request with an index operation
40-
IndexOperation indexOp = IndexOperation.newBuilder().setIndex(indexName).setId("1").build();
40+
IndexOperation indexOp = IndexOperation.newBuilder().setUnderscoreIndex(indexName).setUnderscoreId("1").build();
4141

4242
BulkRequestBody requestBody = BulkRequestBody.newBuilder()
43-
.setIndex(indexOp)
44-
.setDoc(com.google.protobuf.ByteString.copyFromUtf8(DEFAULT_DOCUMENT_SOURCE))
43+
.setOperationContainer(org.opensearch.protobufs.OperationContainer.newBuilder().setIndex(indexOp).build())
44+
.setObject(com.google.protobuf.ByteString.copyFromUtf8(DEFAULT_DOCUMENT_SOURCE))
4545
.build();
4646

4747
BulkRequest bulkRequest = BulkRequest.newBuilder().addRequestBody(requestBody).build();

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/common/FetchSourceContextProtoUtils.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ public static FetchSourceContext parseFromProtoRequest(org.opensearch.protobufs.
4343
String[] sourceIncludes = null;
4444

4545
// Set up source context if source parameters are provided
46-
if (request.hasSource()) {
47-
switch (request.getSource().getSourceConfigParamCase()) {
48-
case SourceConfigParam.SourceConfigParamCase.BOOL_VALUE:
49-
fetchSource = request.getSource().getBoolValue();
46+
if (request.hasUnderscoreSource()) {
47+
switch (request.getUnderscoreSource().getSourceConfigParamCase()) {
48+
case BOOL_VALUE:
49+
fetchSource = request.getUnderscoreSource().getBoolValue();
5050
break;
51-
case SourceConfigParam.SourceConfigParamCase.STRING_ARRAY:
52-
sourceIncludes = request.getSource().getStringArray().getStringArrayList().toArray(new String[0]);
51+
case STRING_ARRAY:
52+
sourceIncludes = request.getUnderscoreSource().getStringArray().getStringArrayList().toArray(new String[0]);
5353
break;
5454
default:
5555
throw new UnsupportedOperationException("Invalid sourceConfig provided.");
5656
}
5757
}
5858

59-
if (request.getSourceIncludesList().size() > 0) {
60-
sourceIncludes = request.getSourceIncludesList().toArray(new String[0]);
59+
if (request.getUnderscoreSourceIncludesCount() > 0) {
60+
sourceIncludes = request.getUnderscoreSourceIncludesList().toArray(new String[0]);
6161
}
6262

63-
if (request.getSourceExcludesList().size() > 0) {
64-
sourceExcludes = request.getSourceExcludesList().toArray(new String[0]);
63+
if (request.getUnderscoreSourceExcludesCount() > 0) {
64+
sourceExcludes = request.getUnderscoreSourceExcludesList().toArray(new String[0]);
6565
}
6666
if (fetchSource != null || sourceIncludes != null || sourceExcludes != null) {
6767
return new FetchSourceContext(fetchSource == null ? true : fetchSource, sourceIncludes, sourceExcludes);
@@ -118,22 +118,16 @@ public static FetchSourceContext fromProto(SourceConfig sourceConfig) {
118118
String[] excludes = Strings.EMPTY_ARRAY;
119119
if (sourceConfig.getSourceConfigCase() == SourceConfig.SourceConfigCase.FETCH) {
120120
fetchSource = sourceConfig.getFetch();
121-
} else if (sourceConfig.hasIncludes()) {
122-
ArrayList<String> list = new ArrayList<>();
123-
for (String string : sourceConfig.getIncludes().getStringArrayList()) {
124-
list.add(string);
125-
}
126-
includes = list.toArray(new String[0]);
127121
} else if (sourceConfig.hasFilter()) {
128122
SourceFilter sourceFilter = sourceConfig.getFilter();
129-
if (!sourceFilter.getIncludesList().isEmpty()) {
123+
if (sourceFilter.getIncludesCount() > 0) {
130124
List<String> includesList = new ArrayList<>();
131125
for (String s : sourceFilter.getIncludesList()) {
132126
includesList.add(s);
133127
}
134128
includes = includesList.toArray(new String[0]);
135129
}
136-
if (!sourceFilter.getExcludesList().isEmpty()) {
130+
if (sourceFilter.getExcludesCount() > 0) {
137131
List<String> excludesList = new ArrayList<>();
138132
for (String s : sourceFilter.getExcludesList()) {
139133
excludesList.add(s);

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/common/OpTypeProtoUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ private OpTypeProtoUtils() {
3232
*/
3333
public static DocWriteRequest.OpType fromProto(OpType opType) {
3434

35-
switch (opType) {
35+
switch (opType.getOpTypeCase()) {
3636
case OP_TYPE_CREATE:
3737
return DocWriteRequest.OpType.CREATE;
3838
case OP_TYPE_INDEX:
3939
return DocWriteRequest.OpType.INDEX;
40+
case OPTYPE_NOT_SET:
4041
default:
4142
throw new UnsupportedOperationException("Invalid optype: " + opType);
4243
}

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/common/RefreshProtoUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ private RefreshProtoUtils() {
3030
* @return The corresponding OpenSearch refresh policy string value
3131
*/
3232
public static String getRefreshPolicy(org.opensearch.protobufs.Refresh refresh) {
33-
switch (refresh) {
33+
switch (refresh.getRefreshCase()) {
3434
case REFRESH_TRUE:
3535
return WriteRequest.RefreshPolicy.IMMEDIATE.getValue();
3636
case REFRESH_WAIT_FOR:
3737
return WriteRequest.RefreshPolicy.WAIT_UNTIL.getValue();
3838
case REFRESH_FALSE:
39-
case REFRESH_UNSPECIFIED:
39+
case REFRESH_NOT_SET:
4040
default:
4141
return WriteRequest.RefreshPolicy.NONE.getValue();
4242
}

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/common/ScriptProtoUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public static Script parseFromProtoRequest(org.opensearch.protobufs.Script scrip
5656
private static Script parseFromProtoRequest(org.opensearch.protobufs.Script script, String defaultLang) {
5757
Objects.requireNonNull(defaultLang);
5858

59-
if (script.hasInlineScript()) {
60-
return parseInlineScript(script.getInlineScript(), defaultLang);
61-
} else if (script.hasStoredScriptId()) {
62-
return parseStoredScriptId(script.getStoredScriptId());
59+
if (script.hasInline()) {
60+
return parseInlineScript(script.getInline(), defaultLang);
61+
} else if (script.hasStored()) {
62+
return parseStoredScriptId(script.getStored());
6363
} else {
6464
throw new UnsupportedOperationException("No valid script type detected");
6565
}
@@ -118,10 +118,10 @@ public static Script parseStoredScriptId(StoredScriptId storedScriptId) {
118118
* @throws UnsupportedOperationException if no language was specified
119119
*/
120120
public static String parseScriptLanguage(ScriptLanguage language, String defaultLang) {
121-
if (language.hasStringValue()) {
122-
return language.getStringValue();
121+
if (language.hasCustom()) {
122+
return language.getCustom();
123123
}
124-
switch (language.getBuiltinScriptLanguage()) {
124+
switch (language.getBuiltin()) {
125125
case BUILTIN_SCRIPT_LANGUAGE_EXPRESSION:
126126
return "expression";
127127
case BUILTIN_SCRIPT_LANGUAGE_JAVA:

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/document/bulk/ActiveShardCountProtoUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ private ActiveShardCountProtoUtils() {
3838
public static ActiveShardCount parseProto(WaitForActiveShards waitForActiveShards) {
3939

4040
switch (waitForActiveShards.getWaitForActiveShardsCase()) {
41-
case WaitForActiveShards.WaitForActiveShardsCase.WAIT_FOR_ACTIVE_SHARD_OPTIONS:
42-
switch (waitForActiveShards.getWaitForActiveShardOptions()) {
43-
case WAIT_FOR_ACTIVE_SHARD_OPTIONS_UNSPECIFIED:
44-
throw new UnsupportedOperationException("No mapping for WAIT_FOR_ACTIVE_SHARD_OPTIONS_UNSPECIFIED");
41+
case WAIT_FOR_ACTIVE_SHARD_OPTIONS:
42+
switch (waitForActiveShards.getWaitForActiveShardOptions().getWaitForActiveShardOptionsCase()) {
4543
case WAIT_FOR_ACTIVE_SHARD_OPTIONS_ALL:
4644
return ActiveShardCount.ALL;
45+
case NULL_VALUE:
46+
case WAITFORACTIVESHARDOPTIONS_NOT_SET:
4747
default:
4848
return ActiveShardCount.DEFAULT;
4949
}
50-
case WaitForActiveShards.WaitForActiveShardsCase.INT32_VALUE:
50+
case INT32_VALUE:
5151
return ActiveShardCount.from(waitForActiveShards.getInt32Value());
52+
case WAITFORACTIVESHARDS_NOT_SET:
5253
default:
5354
return ActiveShardCount.DEFAULT;
5455
}

0 commit comments

Comments
 (0)