Skip to content
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

gRPC MP Implementation #8878

Merged
merged 30 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
46f35e7
Ports helidon-microprofile-core module from 3.x and moves additional …
spericas May 30, 2024
31a9f38
Ports helidon-microprofile-server module from 3.x. Implementation is …
spericas Jun 4, 2024
5264aa7
Restores unit tests in MP gRPC module.
spericas Jun 6, 2024
1d3a2a2
Complete end-to-end gRPC MP test passing.
spericas Jun 11, 2024
29b7a7e
Additional testing with different method types.
spericas Jun 11, 2024
b21099d
New test that implements GrpcService instead of using annotations.
spericas Jun 11, 2024
3021ba9
Adds support for services that implement the BindableService interfac…
spericas Jun 12, 2024
4ed225a
Initial support for server interceptors.
spericas Jun 12, 2024
cf79308
Adds support for ContextSettingServerInterceptor.
spericas Jun 13, 2024
67e99f6
Adds support for a simplified SPI with support for GrpcMpExtension.
spericas Jun 13, 2024
34facc9
Adds initial support for gRPC tracing.
spericas Jun 14, 2024
091c3a4
Adds support for gRPC tracing configuration.
spericas Jun 17, 2024
bbcbcf2
Adds test for GrpcHelper.
spericas Jun 17, 2024
3e45b8f
Cleans up some modules and poms.
spericas Jun 18, 2024
dbd72ce
Fixes a number of compiler warnings.
spericas Jun 18, 2024
dc5b70f
Relocates class CollectingObserver to grpc-core.
spericas Jun 18, 2024
79f8819
Fixes a few additional warnings.
spericas Jun 18, 2024
95d103d
First pass cleaning and simplifying module-info's.
spericas Jun 18, 2024
6ae9de0
Changes in grpc/core package to better support gRPC MP client.
spericas Jun 20, 2024
10b7506
Removes redundant class.
spericas Jun 21, 2024
e06e141
Cleans up poms and modules. Restores ResponseHelper in webserver for …
spericas Jul 2, 2024
4cafb2f
Switches loggers to use System.
spericas Jul 2, 2024
a33ca67
Refactors Collecting observer according to our guidelines.
spericas Jul 3, 2024
c29a86b
Replaces Priority by Weight in service loader.
spericas Jul 3, 2024
eb55297
Moves all gRPC annotations to a new API package.
spericas Jul 3, 2024
7b69f5f
Renames Instance to InstanceSupplier to avoid confusions.
spericas Jul 5, 2024
615a4c2
Moves gRPC tracing support into a new module. Creates a new module fo…
spericas Jul 5, 2024
4c819ed
Simplifies gRPC API annotations by using value() instead of name() wh…
spericas Jul 17, 2024
5081ce1
Moves helidon-microprofile-grpc-api to helidon-grpc-api in order to s…
spericas Jul 18, 2024
dbb1d4c
Creates Grpc namespace for Grpc annotations. Renames old Grpc to Grpc…
spericas Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
<artifactId>helidon-grpc-core</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
spericas marked this conversation as resolved.
Show resolved Hide resolved
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-core</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-server</artifactId>
<version>${helidon.version}</version>
</dependency>
<!-- Micronaut integrations -->
<dependency>
<groupId>io.helidon.integrations.micronaut</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.google.protobuf.Descriptors;
import io.grpc.stub.StreamObserver;

import static io.helidon.webserver.grpc.ResponseHelper.complete;
import static io.helidon.grpc.core.ResponseHelper.complete;
spericas marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings("ALL")
class ServerSnippets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

import io.grpc.stub.StreamObserver;

import static io.helidon.grpc.core.ResponseHelper.complete;
import static io.helidon.http.Method.GET;
import static io.helidon.webserver.grpc.ResponseHelper.complete;

/**
* Example showing supported protocols.
Expand Down
30 changes: 29 additions & 1 deletion grpc/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,41 @@
<modelVersion>4.0.0</modelVersion>

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

<dependencies>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-configurable</artifactId>
</dependency>
<dependency>
spericas marked this conversation as resolved.
Show resolved Hide resolved
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata</artifactId>
spericas marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-context</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.http</groupId>
<artifactId>helidon-http</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.tracing</groupId>
<artifactId>helidon-tracing</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</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 All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.helidon.webserver.grpc;
package io.helidon.grpc.core;
spericas marked this conversation as resolved.
Show resolved Hide resolved

import java.util.Objects;
import java.util.Optional;
Expand All @@ -25,69 +25,69 @@
import io.grpc.stub.StreamObserver;

/**
* A {@link StreamObserver}.
* Utility {@link StreamObserver} mostly used for testing.
*
* @param <T> ToDo: Add JavaDoc
* @param <V> ToDo: Add JavaDoc
* @param <U> ToDo: Add JavaDoc
* @param <A> ToDo: Add JavaDoc
* @param <R> ToDo: Add JavaDoc
* @param <T> the type of input elements to the reduction operation
* @param <A> the mutable accumulation type of the reduction operation
* @param <R> the result type of the reduction operation
* @param <U> the type of values observed
* @param <V> the request type before conversion
*/
public class CollectingObserver<T, V, U, A, R> implements StreamObserver<V> {

private final Collector<T, A, R> collector;
private final StreamObserver<U> responseObserver;
private final Function<V, T> requestConverter;
private final Function<R, U> responseConverter;
private final Consumer<Throwable> errorHandler;

private final A accumulator;

/**
* ToDo: Add JavaDoc.
* Constructor.
*
* @param collector ToDo: Add JavaDoc
* @param responseObserver ToDo: Add JavaDoc
* @param collector the collector
* @param observer the observer
*/
public CollectingObserver(Collector<T, A, R> collector, StreamObserver<U> responseObserver) {
this(collector, responseObserver, null, null, null);
public CollectingObserver(Collector<T, A, R> collector, StreamObserver<U> observer) {
this(collector, observer, null, null, null);
spericas marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* ToDo: Add JavaDoc.
* Constructor.
*
* @param collector ToDo: Add JavaDoc
* @param responseObserver ToDo: Add JavaDoc
* @param errorHandler ToDo: Add JavaDoc
* @param collector the collector
* @param observer the observer
* @param errorHandler the error handler
*/
public CollectingObserver(Collector<T, A, R> collector,
StreamObserver<U> responseObserver,
StreamObserver<U> observer,
Consumer<Throwable> errorHandler) {
this(collector, responseObserver, null, null, errorHandler);
this(collector, observer, null, null, errorHandler);
}

/**
* ToDo: Add JavaDoc.
* Constructor.
*
* @param collector ToDo: Add JavaDoc
* @param responseObserver ToDo: Add JavaDoc
* @param requestConverter ToDo: Add JavaDoc
* @param responseConverter ToDo: Add JavaDoc
* @param collector the collector
* @param observer the observer
* @param requestConverter the request converter
* @param responseConverter the response converterr
*/
public CollectingObserver(Collector<T, A, R> collector,
StreamObserver<U> responseObserver,
StreamObserver<U> observer,
Function<V, T> requestConverter,
Function<R, U> responseConverter) {
this(collector, responseObserver, requestConverter, responseConverter, null);
this(collector, observer, requestConverter, responseConverter, null);
}

/**
* ToDo: Add JavaDoc.
* Constructor.
*
* @param collector ToDo: Add JavaDoc
* @param observer ToDo: Add JavaDoc
* @param requestConverter ToDo: Add JavaDoc
* @param responseConverter ToDo: Add JavaDoc
* @param errorHandler ToDo: Add JavaDoc
* @param collector the collector
* @param observer the observer
* @param requestConverter the request converter
* @param responseConverter the response converter
* @param errorHandler the error handler
*/
@SuppressWarnings("unchecked")
public CollectingObserver(Collector<T, A, R> collector,
Expand All @@ -99,8 +99,7 @@ public CollectingObserver(Collector<T, A, R> collector,
this.responseObserver = Objects.requireNonNull(observer, "The observer parameter cannot be null");
this.requestConverter = Optional.ofNullable(requestConverter).orElse(v -> (T) v);
this.responseConverter = Optional.ofNullable(responseConverter).orElse(r -> (U) r);
this.errorHandler = Optional.ofNullable(errorHandler).orElse(t -> {
});
this.errorHandler = Optional.ofNullable(errorHandler).orElse(t -> {});
this.accumulator = collector.supplier().get();
}

Expand Down
52 changes: 52 additions & 0 deletions grpc/core/src/main/java/io/helidon/grpc/core/ContextKeys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 java.lang.reflect.Method;

import io.grpc.Context;
import io.grpc.Metadata;

/**
* A collection of common gRPC {@link Context.Key} and
* {@link Metadata.Key} instances.
*/
public final class ContextKeys {
/**
* The {@link Metadata.Key} to use to obtain the authorization data.
*/
public static final Metadata.Key<String> AUTHORIZATION =
Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER);

/**
* The gRPC context key to use to obtain the Helidon {@link io.helidon.common.context.Context}
* from the gRPC {@link Context}.
*/
public static final Context.Key<io.helidon.common.context.Context> HELIDON_CONTEXT =
Context.key(io.helidon.common.context.Context.class.getCanonicalName());

/**
* The {@link Context.Key} to use to obtain the actual underlying rpc {@link Method}.
*/
public static final Context.Key<Method> SERVICE_METHOD = Context.key(Method.class.getName());

/**
* Private constructor for utility class.
*/
private ContextKeys() {
}
}
Loading