Skip to content

Commit

Permalink
gRPC Client Implementation (#8423)
Browse files Browse the repository at this point in the history
* Initial commit based on in-progress work from Tomas.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Additional work arounds tests and descriptors.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Simple unary method call without using stubs.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Basic support for unary, serverStream, streamClient and bidi invocations.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Support for sync and async gRPC calls.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Fixed problem with EOS and improved logging. All basic tests are passing.

* Initial support for gRPC stubs, async only for now.

* New test for gRPC that uses stubs. Fixes a number of checkstyle and copyright issues.

* Use WebClient to create GrpcClient(s).

* Fixed unary blocking test.

* Support for TLS. Switched tests to use TLS.

* Simplified and optimized implementation of gRPC unary calls.

* Moved test to webclient module.

* Removed currently unused types from grpc core module.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Cleanup of webserver gRPC module.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Test cleanup and copyright errors.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Adds support for setting up gRPC routes in tests. Updates gRPC tests to implement @SetupRoute methods.

* Removes currently unused types.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* - Simplifies the grpc.core module to the bare minimum that is needed now
- Cleans all module-info.java files
- Switches to System.Logger for logging

* Switches to socket context logging. Throws more detailed exception if baseUri is not present.

* Converts PriorityBag to WeightedBag.

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>

* Introduces support for client interceptors in low-level, stub-free API.

* Basic support for client interceptors with service stubs

* Improves support for empty server streams. Includes fix in Http2ClientStream to allow transitions from HEADERS to END. New tests.

* Adds more tests for client and server empty streams.

* Handles server EOS in HEADERS frame on the client side. Increased read timeout on client.

* Some new tests from JK and fixes to gRPC client code to handle: (1) exceptions thrown in gRPC methods and (2) larger payloads.

* Fixes problems in unary calls with large payloads.

* Use protobuf version for protoc.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>

* Basic support for gRPC protocol config settings

* Javadoc updates.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>

* Improves handling for server connection drops. On a read timeout, if the abort flag is not set, attempts to send a PING frame to verify the connection's health.

* Uses a separate virtual thread to check if the connection to the server has died. The period to check for that is configurable and set to 5 seconds by default.

* Sets heartbeat period to 0, thus disabling the feature by default.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>

* Fixes logging message and test.

* Refactors a few classes in grpc/core. Addresses other comments in PR review.

* Reduces the number of logging statements in favor of using low-level HTTP/2 logging instead.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>

* Some code reformatting using the Helidon scheme.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>

---------

Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas authored May 30, 2024
1 parent d0d7c64 commit 62adcbd
Show file tree
Hide file tree
Showing 66 changed files with 4,674 additions and 44 deletions.
4 changes: 4 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,10 @@
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-websocket</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-grpc</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-sse</artifactId>
Expand Down
16 changes: 16 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<artifactId>helidon-microprofile-graphql-server</artifactId>
<version>${helidon.version}</version>
</dependency>
<!-- GRPC -->
<dependency>
<groupId>io.helidon.grpc</groupId>
<artifactId>helidon-grpc-core</artifactId>
<version>${helidon.version}</version>
</dependency>
<!-- Micronaut integrations -->
<dependency>
<groupId>io.helidon.integrations.micronaut</groupId>
Expand Down Expand Up @@ -1257,6 +1263,11 @@
<artifactId>helidon-webserver-testing-junit5-websocket</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5-grpc</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-api</artifactId>
Expand All @@ -1282,6 +1293,11 @@
<artifactId>helidon-webclient-websocket</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-grpc</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-sse</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022, 2023 Oracle and/or its affiliates.
# Copyright (c) 2022, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
69 changes: 69 additions & 0 deletions grpc/core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018, 2024 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>helidon-grpc-project</artifactId>
<groupId>io.helidon.grpc</groupId>
<version>4.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>helidon-grpc-core</artifactId>
<name>Helidon gRPC related modules</name>

<dependencies>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.j2objc</groupId>
<artifactId>j2objc-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.grpc.core;

import com.google.protobuf.MessageLite;
import io.grpc.MethodDescriptor;

/**
* The default {@link MarshallerSupplier}.
*/
class DefaultMarshallerSupplier implements MarshallerSupplier {

private DefaultMarshallerSupplier() {
}

static DefaultMarshallerSupplier create() {
return new DefaultMarshallerSupplier();
}

private final ProtoMarshallerSupplier proto = ProtoMarshallerSupplier.create();

@Override
public <T> MethodDescriptor.Marshaller<T> get(Class<T> clazz) {
if (MessageLite.class.isAssignableFrom(clazz)) {
return proto.get(clazz);
}
String msg = String.format(
"Class %s must be a valid ProtoBuf message, or a custom marshaller for it must be specified explicitly",
clazz.getName());
throw new IllegalArgumentException(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.grpc.core;

/**
* gRPC interceptor weight classes. Higher weight means higher priority.
*/
public class InterceptorWeights {

/**
* Context weight.
* <p>
* Interceptors with this weight typically <b>only</b> perform tasks
* such as adding state to the call {@link io.grpc.Context}.
*/
public static final int CONTEXT = 5000;

/**
* Tracing weight.
* <p>
* Tracing and metrics interceptors are typically applied after any context
* interceptors so that they can trace and gather metrics on the whole call
* stack of remaining interceptors.
*/
public static final int TRACING = CONTEXT + 1;

/**
* Security authentication weight.
*/
public static final int AUTHENTICATION = 2000;

/**
* Security authorization weight.
*/
public static final int AUTHORIZATION = 2000;

/**
* User-level weight.
* <p>
* This value is also used as a default weight for application-supplied interceptors.
*/
public static final int USER = 1000;

/**
* Cannot create instances.
*/
private InterceptorWeights() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2019, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.grpc.core;

import io.grpc.MethodDescriptor;

/**
* A supplier of {@link MethodDescriptor.Marshaller} instances for specific
* classes.
*/
@FunctionalInterface
public interface MarshallerSupplier {

/**
* Obtain a {@link MethodDescriptor.Marshaller} for a type.
*
* @param clazz the {@link Class} of the type to obtain the {@link MethodDescriptor.Marshaller} for
* @param <T> the type to be marshalled
* @return a {@link MethodDescriptor.Marshaller} for a type
*/
<T> MethodDescriptor.Marshaller<T> get(Class<T> clazz);

/**
* Creates a default marshaller supplier.
*
* @return the default marshaller supplier
*/
static MarshallerSupplier create() {
return DefaultMarshallerSupplier.create();
}
}
Loading

0 comments on commit 62adcbd

Please sign in to comment.