Skip to content

Commit

Permalink
Initial commit based on in-progress work from Tomas.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericasgeertsen <[email protected]>
  • Loading branch information
spericas committed Jan 26, 2024
1 parent 0be9a97 commit 9c98259
Show file tree
Hide file tree
Showing 48 changed files with 3,231 additions and 11 deletions.
4 changes: 4 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,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 @@ -1247,6 +1253,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 @@ -1272,6 +1283,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
36 changes: 32 additions & 4 deletions examples/webserver/protocols/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-http2</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-websocket</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-grpc</artifactId>
Expand All @@ -53,12 +61,12 @@
<artifactId>helidon-webclient-http2</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-websocket</artifactId>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-websocket</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-http2</artifactId>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient-grpc</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -70,6 +78,26 @@
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5-http2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5-websocket</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5-grpc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,23 @@ public static void main(String[] args) {
.unary(Strings.getDescriptor(),
"StringService",
"Upper",
ProtocolsMain::grpcUpper))
ProtocolsMain::grpcUpper)
.unary(Strings.getDescriptor(),
"StringService",
"Upper",
ProtocolsMain::blockingGrpcUpper))
.addRouting(WsRouting.builder()
.endpoint("/tyrus/echo", ProtocolsMain::wsEcho))
.build()
.start();
}

private static Strings.StringMessage blockingGrpcUpper(Strings.StringMessage reqT) {
return Strings.StringMessage.newBuilder()
.setText(reqT.getText().toUpperCase(Locale.ROOT))
.build();
}

private static void grpcUpper(Strings.StringMessage request, StreamObserver<Strings.StringMessage> observer) {
String requestText = request.getText();
System.out.println("grpc request: " + requestText);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.examples.webserver.protocols;

import io.helidon.webserver.testing.junit5.ServerTest;

@ServerTest
class ProtocolsTest {
}
85 changes: 85 additions & 0 deletions grpc/core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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-context</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.tracing</groupId>
<artifactId>helidon-tracing</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</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>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</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>
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, 2021 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() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2022 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.util.Optional;

import io.grpc.Context;
import io.helidon.tracing.Span;

/**
* Contextual information related to Tracing.
*/
public final class GrpcTracingContext {
private static final String SPAN_KEY_NAME = "io.helidon.tracing.active-span";

/**
* Context key for Span instance.
*/
public static final Context.Key<Span> SPAN_KEY = Context.key(SPAN_KEY_NAME);

/**
* Get the current active span associated with the context.
*
* @return span if one is in current context
*/
public static Optional<Span> activeSpan() {
return Optional.ofNullable(SPAN_KEY.get());
}

private GrpcTracingContext() {
}
}
32 changes: 32 additions & 0 deletions grpc/core/src/main/java/io/helidon/grpc/core/GrpcTracingName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 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;

/**
* Name generator for span operation name.
*/
@FunctionalInterface
public interface GrpcTracingName {
/**
* Constructs a span's operation name from the gRPC method.
*
* @param method method to extract a name from
* @return operation name
*/
String name(MethodDescriptor<?, ?> method);
}
Loading

0 comments on commit 9c98259

Please sign in to comment.