Skip to content

Commit 44bbc73

Browse files
dayana-jreta
andauthored
gRPC support for opensearch-java (#2062)
* feat: add transparent gRPC transport as separate java-client-grpc module Adds a transparent gRPC transport layer that routes bulk operations over gRPC for improved performance while falling back to REST for all other operations. Isolated in a separate java-client-grpc module to prevent classpath conflicts. Includes: - GrpcTransport + HybridTransport (automatic routing and fallback) - Translation layer (BulkRequest/Response <-> protobuf conversion) - TLS support (trust cert, trust store, mTLS, insecure, hostname override) - Basic auth, AWS SigV4, and JWT authentication interceptors - Channel health monitoring via gRPC connectivity state machine - Integration tests (framework-compliant, version-gated to 3.5.0+) - Sample code and CI configuration Signed-off-by: Dayana Jean <jeadayao@amazon.com> * ci: retrigger CI Signed-off-by: Dayana Jean <jeadayao@amazon.com> * Making the FieldMappingUtil package private Co-authored-by: Andriy Redko <drreta@gmail.com> Signed-off-by: Dayana <jeandayana28@gmail.com> * Making this package private Apply suggestion from @reta Co-authored-by: Andriy Redko <drreta@gmail.com> Signed-off-by: Dayana <jeandayana28@gmail.com> * Making BasicAuthInterceptor package private Apply suggestion from @reta Co-authored-by: Andriy Redko <drreta@gmail.com> Signed-off-by: Dayana <jeandayana28@gmail.com> * Remove unused toHttpStatus method and fix test package for package-private classes - Removed GrpcStatusConverter.toHttpStatus() which was unused anywhere in the codebase (per maintainer feedback) - Moved TranslationTest to the translation package so it can access package-private FieldMappingUtil and GrpcStatusConverter.convert() Signed-off-by: Dayana Jean <jeadayao@amazon.com> * refactor: split AWS SigV4 into AwsGrpcTransport per maintainer feedback Follows the same pattern as ApacheHttpClient5Transport (general) vs AwsSdk2Transport (AWS-specific) in the existing codebase. Changes: - Created AwsGrpcTransport: extends GrpcTransport, adds SigV4 signing - AwsGrpcTransport.awsBuilder(host, port).sigV4(...).tls(...).build() - Requires sigV4Config and TLS - Overrides preProcessBulk() for payload hash computation - Removed SigV4 from GrpcTransport: - Removed .sigV4() builder method - Removed sigV4Interceptor field - Added protected preProcessBulk() hook for subclasses - GrpcTransport is now purely general-purpose (basic auth, JWT, TLS) - Updated tests to use AwsGrpcTransport for SigV4 tests Signed-off-by: Dayana Jean <jeadayao@amazon.com> * refactor: remove silent REST fallback from HybridTransport Per maintainer feedback: if the intent is to use gRPC for a supported endpoint, errors should propagate to the user rather than silently falling back to REST. Changes: - HybridTransport no longer catches gRPC errors and retries via REST - Removed fallbackOnError constructor parameter and field - Routing behavior preserved: unsupported endpoints → REST directly - gRPC-supported endpoints: errors propagate to caller - Simplified performRequest/performRequestAsync (no try/catch) - Updated tests: testGrpcErrorPropagatesForSupportedEndpoint Behavior: client.bulk(req) → gRPC (errors propagate if gRPC fails) client.search(req) → REST (not supported by gRPC, routed directly) Signed-off-by: Dayana Jean <jeadayao@amazon.com> * docs: update comments to reflect routing instead of fallback Stale references to 'automatic REST fallback' replaced with accurate 'REST routing for unsupported endpoints' language throughout. - GrpcTransport: updated javadoc and error message - GrpcDemo: rewrote Demo 3 to show REST routing (not fallback on error) - GrpcAwsSigV4: updated to use AwsGrpcTransport.awsBuilder() - GrpcBulkIT: renamed testRestFallback → testRestRouting Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: make integration test base classes self-contained Per maintainer feedback: OpenSearchJavaClientTestCase and TestcontainersThreadFilter are internal test classes not exposed for external module use. Changes: - AbstractGrpcIT: now extends nothing, uses standard JUnit 4 + Assume - Removed dependency on OpenSearchJavaClientTestCase - Removed @ThreadLeakFilters(TestcontainersThreadFilter) - Uses Assume.assumeTrue() with manual version parsing - Reads cluster config from system properties directly - GrpcTransportSupport: converted from interface (extending OpenSearchTransportSupport) to utility class - GrpcBulkIT: no longer implements GrpcTransportSupport interface Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: lower java-client-grpc baseline from JDK 11 to JDK 8 Per maintainer feedback: opensearch-java baseline is JDK 8 and gRPC-Java supports Java 8. No technical reason to require JDK 11. Changes: - build.gradle.kts: targetCompatibility/sourceCompatibility → 1.8 - GrpcSigV4Test: replaced 'var' (Java 10+) with explicit types Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: remove explicit jackson test deps (transitive via java-client) Per maintainer feedback: opensearch-java has a hard dependency on Jackson 3.x, so it comes transitively. No need to declare it again. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: wire up integration tests with java21 source set Per maintainer feedback: integration tests were not being compiled or run. Added the standard java21 source set configuration used by java-client to java-client-grpc. Changes: - Added unitTest/integrationTest task definitions - Added java21 source set (src/test/java11) gated on JDK 21+ - Added test framework, testcontainers, opensearch-testcontainers deps - Added static import for JUnit Assert in GrpcBulkIT - Integration tests now compile and will run with: ./gradlew :java-client-grpc:integrationTest -Dtests.opensearch.version=3.5.0 Signed-off-by: Dayana Jean <jeadayao@amazon.com> * ci: add OpenSearch 3.5.0 to integration test matrix Adds the first gRPC-capable version to the test matrix so the gRPC integration tests run in CI. Includes both Java 21 and Java 25. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: replace wildcard import with explicit imports (spotless) Spotless rejects wildcard imports. Replaced 'import static org.junit.Assert.*' with explicit imports for assertEquals, assertFalse, assertNotNull, assertTrue. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: remove java21 classes from unitTest task The java21 source set only contains integration tests (integTest package). Adding it to unitTest causes 'No tests found' failure since the filter excludes integTest classes. Only integrationTest needs the java21 classes. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: spotless formatting for samples (license header, import order) - GrpcDemo.java: replaced custom header with standard Apache-2.0 license - GrpcAwsSigV4.java: fixed import ordering (AwsGrpcTransport alphabetical) - Removed unused imports Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: skip gRPC integration tests when port is unreachable assumeGrpcSupported() now verifies both: 1. Server version is 3.5.0+ (via REST info endpoint) 2. gRPC port is actually reachable (TCP socket check) This prevents test failures when running integrationTest against OpenSearch versions that don't have gRPC enabled or when the gRPC port isn't exposed by testcontainers. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: only enable gRPC in testcontainer for OpenSearch 3.5.0+ GrpcTestContainerRule now checks the tests.opensearch.version property before adding gRPC configuration. Older versions (1.x, 2.x) don't support aux.transport.types and would fail to start. On pre-3.5.0 versions: - Container starts without gRPC config (REST only) - gRPC port not exposed - Tests skip via assumeGrpcSupported() (version check + port check) Signed-off-by: Dayana Jean <jeadayao@amazon.com> * ci: exclude grpc integration tests until OpenSearch 3.5.0 is released OpenSearch 3.5.0 Docker image is not yet published, so the gRPC integration tests cannot run in CI. Changes: - Exclude :java-client-grpc:integrationTest from the main CI run (all matrix versions are pre-3.5.0) - Comment out 3.5.0 entries in test matrix (uncomment when released) The gRPC integration tests can still be run locally against a container started manually or once 3.5.0 is published. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: graceful skip on container failure + re-enable 3.5.0 in CI OpenSearch 3.5.0 Docker image is published. Re-enabled in CI matrix. Changes: - GrpcTestContainerRule.before(): catches ContainerLaunchException and calls Assume.assumeTrue(false) to skip tests gracefully instead of failing the build - Added 5-minute startup timeout for CI environments - Removed duplicate disk watermark env var - Re-enabled 3.5.0 in test-integration.yml matrix - Removed -x :java-client-grpc:integrationTest exclusion On pre-3.5.0 versions: container starts without gRPC, tests skip via assumeGrpcSupported(). On 3.5.0+: if container fails for any reason, tests skip instead of failing the build. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: spotless formatting on GrpcTestContainerRule Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: remove grpcStatusToHttpStatus from FieldMappingUtil Per maintainer feedback: method was only used in tests, not in production code. Removed the method and its 7 associated tests. Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: skip gRPC tests early with assumeTrue for unsupported versions Per maintainer feedback: use assumeTrue in the class rule to skip tests immediately for older versions, rather than conditionally configuring the container. Changes: - GrpcTestContainerRule.before(): assumeTrue("OpenSearch should support gRPC", supportsGrpc(version)) skips for pre-3.5.0 - createContainer(): always configures gRPC (only reached for 3.5.0+) - Removed conditional gRPC config logic Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: make GrpcChannelFactory methods package-private Signed-off-by: Dayana Jean <jeadayao@amazon.com> * fix: apply maintainer suggestions on visibility and naming 1. BasicAuthInterceptor: constructor now package-private 2. GrpcChannelFactory: class now package-private (final class, no public) 3. GrpcTestContainerRule renamed to OpenSearchGrpcTestContainerRule 4. Updated references in AbstractGrpcIT Signed-off-by: Dayana Jean <jeadayao@amazon.com> --------- Signed-off-by: Dayana Jean <jeadayao@amazon.com> Signed-off-by: Dayana <jeandayana28@gmail.com> Co-authored-by: Andriy Redko <drreta@gmail.com>
1 parent 8a8289a commit 44bbc73

37 files changed

Lines changed: 5798 additions & 0 deletions

.ci/opensearch/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ ARG opensearch_yml=$opensearch_path/config/opensearch.yml
66

77
ARG SECURE_INTEGRATION
88
ENV OPENSEARCH_INITIAL_ADMIN_PASSWORD=0_aD^min_0
9+
10+
# Copy custom opensearch.yml with gRPC transport configuration
11+
COPY opensearch.yml $opensearch_yml
12+
913
RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then echo "plugins.security.disabled: true" >> $opensearch_yml; fi

.ci/opensearch/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ services:
1414
- bootstrap.memory_lock=true
1515
ports:
1616
- "9200:9200"
17+
- "9400:9400"
1718
user: opensearch

.ci/opensearch/opensearch.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
cluster.name: "docker-cluster"
22
network.host: 0.0.0.0
3+
4+
# gRPC transport configuration
5+
aux.transport.types: [transport-grpc]
6+
aux.transport.transport-grpc.port: '9400'

.github/workflows/test-integration.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
- { opensearch_version: 3.0.0, java: 21, os: ubuntu-latest }
3131
- { opensearch_version: 3.2.0, java: 21, os: ubuntu-latest }
3232
- { opensearch_version: 3.2.0, java: 25, os: ubuntu-latest }
33+
- { opensearch_version: 3.5.0, java: 21, os: ubuntu-latest }
34+
- { opensearch_version: 3.5.0, java: 25, os: ubuntu-latest }
3335
steps:
3436
- name: Checkout Java Client
3537
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2222
- Support Jackson 3.x release line ([#1810](https://github.com/opensearch-project/opensearch-java/pull/1810))
2323
- Added `equals()` and `hashCode()` implementations to `FieldValue` ([#1998](https://github.com/opensearch-project/opensearch-java/pull/1998))
2424
- Add document lifecycle guide and runnable sample ([#2017](https://github.com/opensearch-project/opensearch-java/pull/2017))
25+
- Add transparent gRPC transport with HybridTransport (bulk over gRPC, REST fallback), translation layer, TLS, basic auth, AWS SigV4, and JWT support ([#2062](https://github.com/opensearch-project/opensearch-java/pull/2062))
2526

2627
### Fixed
2728

java-client-grpc/build.gradle.kts

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
plugins {
10+
java
11+
`java-library`
12+
`maven-publish`
13+
id("opensearch-java.spotless-conventions")
14+
}
15+
16+
repositories {
17+
mavenLocal()
18+
maven(url = "https://ci.opensearch.org/ci/dbc/snapshots/maven/")
19+
mavenCentral()
20+
}
21+
22+
java {
23+
targetCompatibility = JavaVersion.VERSION_1_8
24+
sourceCompatibility = JavaVersion.VERSION_1_8
25+
26+
withJavadocJar()
27+
withSourcesJar()
28+
}
29+
30+
val opensearchVersion = "3.5.0-SNAPSHOT"
31+
val grpcVersion = "1.68.0"
32+
val protobufVersion = "3.25.5"
33+
val opensearchProtobufVersion = "1.2.0"
34+
35+
dependencies {
36+
// Depend on java-client core
37+
api(project(":java-client"))
38+
39+
// gRPC runtime
40+
api("io.grpc", "grpc-api", grpcVersion)
41+
api("io.grpc", "grpc-stub", grpcVersion)
42+
api("io.grpc", "grpc-protobuf", grpcVersion)
43+
api("io.grpc", "grpc-netty-shaded", grpcVersion)
44+
api("com.google.protobuf", "protobuf-java", protobufVersion)
45+
46+
// OpenSearch Protobufs (compiled protobuf Java classes)
47+
api("org.opensearch", "protobufs", opensearchProtobufVersion)
48+
49+
// For AwsSdk2 SigV4 support (optional, compile-only)
50+
compileOnly("software.amazon.awssdk", "sdk-core", "[2.21,3.0)")
51+
compileOnly("software.amazon.awssdk", "auth", "[2.21,3.0)")
52+
compileOnly("software.amazon.awssdk", "http-auth-aws", "[2.21,3.0)")
53+
54+
// Test dependencies
55+
testImplementation("io.grpc", "grpc-testing", grpcVersion)
56+
testImplementation("junit", "junit", "4.13.2")
57+
testImplementation("org.opensearch.client", "opensearch-rest-client", opensearchVersion)
58+
testImplementation("software.amazon.awssdk", "sdk-core", "[2.21,3.0)")
59+
testImplementation("software.amazon.awssdk", "auth", "[2.21,3.0)")
60+
testImplementation("software.amazon.awssdk", "http-auth-aws", "[2.21,3.0)")
61+
}
62+
63+
tasks.test {
64+
systemProperty("tests.security.manager", "false")
65+
}
66+
67+
val unitTest = tasks.register<Test>("unitTest") {
68+
filter {
69+
excludeTestsMatching("org.opensearch.client.opensearch.integTest.*")
70+
}
71+
systemProperty("tests.security.manager", "false")
72+
}
73+
74+
val integrationTest = tasks.register<Test>("integrationTest") {
75+
filter {
76+
includeTestsMatching("org.opensearch.client.opensearch.integTest.*")
77+
}
78+
systemProperty("tests.security.manager", "false")
79+
systemProperty("https", System.getProperty("https", "false"))
80+
systemProperty("user", System.getProperty("user", "admin"))
81+
systemProperty("password", System.getProperty("password", "admin"))
82+
systemProperty("tests.opensearch.testcontainers.enabled",
83+
System.getProperty("tests.opensearch.testcontainers.enabled", "true"))
84+
systemProperty("tests.opensearch.version",
85+
System.getProperty("tests.opensearch.version", opensearchVersion))
86+
}
87+
88+
// Integration tests require Java 21+ and live in src/test/java11
89+
val runtimeJavaVersion = (System.getProperty("runtime.java")?.toInt())?.let(JavaVersion::toVersion) ?: JavaVersion.current()
90+
if (runtimeJavaVersion >= JavaVersion.VERSION_21) {
91+
val java21: SourceSet = sourceSets.create("java21") {
92+
java {
93+
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
94+
runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output
95+
srcDir("src/test/java11")
96+
}
97+
}
98+
99+
configurations[java21.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
100+
configurations[java21.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get())
101+
102+
dependencies {
103+
"java21Implementation"("org.opensearch.test", "framework", opensearchVersion) {
104+
exclude(group = "org.hamcrest")
105+
}
106+
"java21Implementation"("org.opensearch:opensearch-testcontainers:4.1.0")
107+
"java21Implementation"("org.testcontainers:testcontainers:2.0.5")
108+
}
109+
110+
tasks.named<JavaCompile>("compileJava21Java") {
111+
targetCompatibility = JavaVersion.VERSION_21.toString()
112+
sourceCompatibility = JavaVersion.VERSION_21.toString()
113+
}
114+
115+
tasks.named<JavaCompile>("compileTestJava") {
116+
targetCompatibility = JavaVersion.VERSION_21.toString()
117+
sourceCompatibility = JavaVersion.VERSION_21.toString()
118+
}
119+
120+
integrationTest.configure {
121+
testClassesDirs += java21.output.classesDirs
122+
classpath = sourceSets["java21"].runtimeClasspath
123+
}
124+
}
125+
126+
tasks.withType<Jar> {
127+
manifest {
128+
attributes["Implementation-Title"] = "OpenSearch Java Client - gRPC Transport"
129+
attributes["Implementation-Vendor"] = "OpenSearch"
130+
attributes["Implementation-URL"] = "https://github.com/opensearch-project/opensearch-java/"
131+
}
132+
133+
metaInf {
134+
from("../LICENSE.txt")
135+
from("../NOTICE.txt")
136+
}
137+
}
138+
139+
publishing {
140+
publications {
141+
create<MavenPublication>("publishMaven") {
142+
from(components["java"])
143+
pom {
144+
name.set("OpenSearch Java Client - gRPC Transport")
145+
packaging = "jar"
146+
artifactId = "opensearch-java-grpc"
147+
description.set("gRPC transport for the OpenSearch Java Client.")
148+
url.set("https://github.com/opensearch-project/opensearch-java/")
149+
}
150+
}
151+
}
152+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.client.transport.grpc;
10+
11+
import io.grpc.ManagedChannel;
12+
import javax.annotation.Nullable;
13+
import org.opensearch.client.json.JsonpMapper;
14+
import org.opensearch.client.transport.TransportOptions;
15+
16+
/**
17+
* AWS-specific gRPC transport that adds SigV4 signing to the gRPC channel.
18+
* <p>
19+
* This follows the same pattern as {@code AwsSdk2Transport} vs
20+
* {@code ApacheHttpClient5Transport} — separating general transport from
21+
* AWS-specific authentication.
22+
* <p>
23+
* Usage:
24+
* <pre>{@code
25+
* var grpcTransport = AwsGrpcTransport.builder("domain.us-east-1.es.amazonaws.com", 9400)
26+
* .jsonpMapper(new JacksonJsonpMapper())
27+
* .tls(GrpcTlsConfig.builder().build())
28+
* .sigV4(GrpcSigV4Config.builder()
29+
* .region(Region.US_EAST_1)
30+
* .service("es")
31+
* .credentialsProvider(DefaultCredentialsProvider.create())
32+
* .build())
33+
* .build();
34+
* }</pre>
35+
*/
36+
public class AwsGrpcTransport extends GrpcTransport {
37+
38+
private final GrpcSigV4Interceptor sigV4Interceptor;
39+
40+
AwsGrpcTransport(
41+
ManagedChannel channel,
42+
JsonpMapper jsonpMapper,
43+
GrpcTransportOptions grpcOptions,
44+
@Nullable TransportOptions transportOptions,
45+
GrpcSigV4Interceptor sigV4Interceptor
46+
) {
47+
super(channel, jsonpMapper, grpcOptions, transportOptions);
48+
this.sigV4Interceptor = sigV4Interceptor;
49+
}
50+
51+
@Override
52+
protected void preProcessBulk(org.opensearch.protobufs.BulkRequest protoRequest) {
53+
if (sigV4Interceptor != null) {
54+
String payloadHash = GrpcSigV4Interceptor.computePayloadHash(protoRequest.toByteArray());
55+
sigV4Interceptor.setPayloadHash(payloadHash);
56+
}
57+
}
58+
59+
/**
60+
* Creates a builder for AwsGrpcTransport.
61+
*
62+
* @param host the gRPC server hostname
63+
* @param port the gRPC server port (default: 9400)
64+
*/
65+
public static Builder awsBuilder(String host, int port) {
66+
return new Builder(host, port);
67+
}
68+
69+
public static final class Builder {
70+
private final String host;
71+
private final int port;
72+
private JsonpMapper jsonpMapper;
73+
private GrpcTransportOptions grpcOptions = GrpcTransportOptions.defaults();
74+
private TransportOptions transportOptions;
75+
private GrpcTlsConfig tlsConfig;
76+
private GrpcSigV4Config sigV4Config;
77+
private ManagedChannel channel;
78+
79+
Builder(String host, int port) {
80+
this.host = host;
81+
this.port = port;
82+
}
83+
84+
public Builder jsonpMapper(JsonpMapper mapper) {
85+
this.jsonpMapper = mapper;
86+
return this;
87+
}
88+
89+
public Builder grpcOptions(GrpcTransportOptions options) {
90+
this.grpcOptions = options;
91+
return this;
92+
}
93+
94+
public Builder transportOptions(TransportOptions options) {
95+
this.transportOptions = options;
96+
return this;
97+
}
98+
99+
/**
100+
* Configures TLS for the gRPC channel. Required for SigV4.
101+
*/
102+
public Builder tls(GrpcTlsConfig tlsConfig) {
103+
this.tlsConfig = tlsConfig;
104+
return this;
105+
}
106+
107+
/**
108+
* Configures AWS SigV4 signing for the gRPC channel.
109+
* TLS is required when using SigV4.
110+
*
111+
* @param sigV4Config the SigV4 configuration (region, service, credentials)
112+
*/
113+
public Builder sigV4(GrpcSigV4Config sigV4Config) {
114+
this.sigV4Config = sigV4Config;
115+
return this;
116+
}
117+
118+
/**
119+
* Inject a pre-built channel (primarily for testing).
120+
*/
121+
public Builder channel(ManagedChannel channel) {
122+
this.channel = channel;
123+
return this;
124+
}
125+
126+
public AwsGrpcTransport build() {
127+
if (jsonpMapper == null) {
128+
throw new IllegalArgumentException("jsonpMapper is required");
129+
}
130+
if (sigV4Config == null) {
131+
throw new IllegalArgumentException("sigV4 config is required for AwsGrpcTransport. Use GrpcTransport for non-AWS usage.");
132+
}
133+
if (tlsConfig == null) {
134+
throw new IllegalStateException("TLS is required when using SigV4 signing. Configure TLS with .tls() before .sigV4().");
135+
}
136+
137+
ManagedChannel ch = this.channel;
138+
GrpcSigV4Interceptor sigV4InterceptorRef = null;
139+
140+
if (ch == null) {
141+
java.util.List<io.grpc.ClientInterceptor> interceptors = new java.util.ArrayList<>();
142+
143+
sigV4InterceptorRef = new GrpcSigV4Interceptor(sigV4Config, host);
144+
interceptors.add(sigV4InterceptorRef);
145+
146+
try {
147+
ch = GrpcChannelFactory.createChannel(host, port, tlsConfig, grpcOptions, interceptors);
148+
} catch (java.io.IOException e) {
149+
throw new IllegalStateException("Failed to create gRPC channel: " + e.getMessage(), e);
150+
}
151+
}
152+
153+
return new AwsGrpcTransport(ch, jsonpMapper, grpcOptions, transportOptions, sigV4InterceptorRef);
154+
}
155+
}
156+
}

0 commit comments

Comments
 (0)