-
Notifications
You must be signed in to change notification settings - Fork 1
chore: expose hybrid service framework #110
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| plugins { | ||
| `java-library` | ||
| jacoco | ||
| id("org.hypertrace.publish-plugin") | ||
| id("org.hypertrace.jacoco-report-plugin") | ||
| } | ||
|
|
||
| dependencies { | ||
| api(project(":platform-grpc-service-framework")) | ||
| api(project(":platform-http-service-framework")) | ||
| api(project(":platform-service-framework")) | ||
|
|
||
| annotationProcessor("org.projectlombok:lombok:1.18.24") | ||
| compileOnly("org.projectlombok:lombok:1.18.24") | ||
| } |
10 changes: 10 additions & 0 deletions
10
...k/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridHttpHandlerFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.hypertrace.core.serviceframework.hybrid; | ||
|
|
||
| import java.util.List; | ||
| import org.hypertrace.core.serviceframework.http.HttpHandlerDefinition; | ||
|
|
||
| @FunctionalInterface | ||
| public interface HybridHttpHandlerFactory { | ||
|
|
||
| List<HttpHandlerDefinition> buildHandlers(HybridServiceContainerEnvironment containerEnvironment); | ||
| } |
79 changes: 79 additions & 0 deletions
79
...work/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package org.hypertrace.core.serviceframework.hybrid; | ||
|
|
||
| import com.google.common.collect.Streams; | ||
| import io.grpc.protobuf.services.HealthStatusManager; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.hypertrace.core.grpcutils.client.InProcessGrpcChannelRegistry; | ||
| import org.hypertrace.core.serviceframework.config.ConfigClient; | ||
| import org.hypertrace.core.serviceframework.grpc.GrpcPlatformServerDefinition; | ||
| import org.hypertrace.core.serviceframework.grpc.StandAloneGrpcPlatformServiceContainer; | ||
| import org.hypertrace.core.serviceframework.http.HttpContainer; | ||
| import org.hypertrace.core.serviceframework.http.HttpHandlerDefinition; | ||
| import org.hypertrace.core.serviceframework.http.HttpHandlerFactory; | ||
| import org.hypertrace.core.serviceframework.http.jetty.JettyHttpServerBuilder; | ||
|
|
||
| @Slf4j | ||
| public abstract class HybridPlatformService extends StandAloneGrpcPlatformServiceContainer { | ||
|
|
||
| private HttpContainer httpContainer; | ||
|
|
||
| public HybridPlatformService(ConfigClient configClient) { | ||
| super(configClient); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doStart() { | ||
| this.httpContainer.start(); | ||
| super.doStart(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doStop() { | ||
| this.httpContainer.stop(); | ||
| super.doStop(); | ||
| } | ||
|
|
||
| protected abstract List<GrpcPlatformServerDefinition> getServerDefinitions(); | ||
|
|
||
| protected List<HttpHandlerFactory> getHttpHandlerFactories() { | ||
| return List.of(); | ||
| } | ||
|
|
||
| protected List<HybridHttpHandlerFactory> getHybridHttpHandlerFactories() { | ||
| return List.of(); | ||
| } | ||
|
|
||
| @Override | ||
| protected HybridServiceContainerEnvironment buildContainerEnvironment( | ||
| InProcessGrpcChannelRegistry channelRegistry, HealthStatusManager healthStatusManager) { | ||
| HybridServiceContainerEnvironment containerEnvironment = | ||
| new StandAloneHybridServiceContainerEnvironment( | ||
| channelRegistry, | ||
| healthStatusManager, | ||
| this.configClient, | ||
| this.getInProcessServerName(), | ||
| this.getLifecycle()); | ||
| this.httpContainer = this.buildHttpContainer(containerEnvironment); | ||
| return containerEnvironment; | ||
| } | ||
|
|
||
| private HttpContainer buildHttpContainer(HybridServiceContainerEnvironment environment) { | ||
| return new JettyHttpServerBuilder() | ||
| .addHandlers(this.buildHandlerDefinitions(environment)) | ||
| .build(); | ||
| } | ||
|
|
||
| private List<HttpHandlerDefinition> buildHandlerDefinitions( | ||
| HybridServiceContainerEnvironment environment) { | ||
| return Streams.concat( | ||
| this.getHttpHandlerFactories().stream() | ||
| .map(handlerFactory -> handlerFactory.buildHandlers(environment)), | ||
| this.getHybridHttpHandlerFactories().stream() | ||
| .map(handlerFactory -> handlerFactory.buildHandlers(environment))) | ||
| .flatMap(Collection::stream) | ||
| .collect(Collectors.toUnmodifiableList()); | ||
| } | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
...n/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.hypertrace.core.serviceframework.hybrid; | ||
|
|
||
| import org.hypertrace.core.serviceframework.grpc.GrpcServiceContainerEnvironment; | ||
| import org.hypertrace.core.serviceframework.http.HttpContainerEnvironment; | ||
|
|
||
| public interface HybridServiceContainerEnvironment | ||
| extends GrpcServiceContainerEnvironment, HttpContainerEnvironment {} |
33 changes: 33 additions & 0 deletions
33
.../hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package org.hypertrace.core.serviceframework.hybrid; | ||
|
|
||
| import com.typesafe.config.Config; | ||
| import io.grpc.health.v1.HealthCheckResponse.ServingStatus; | ||
| import io.grpc.protobuf.services.HealthStatusManager; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.hypertrace.core.grpcutils.client.InProcessGrpcChannelRegistry; | ||
| import org.hypertrace.core.serviceframework.config.ConfigClient; | ||
| import org.hypertrace.core.serviceframework.spi.PlatformServiceLifecycle; | ||
|
|
||
| @AllArgsConstructor | ||
| class StandAloneHybridServiceContainerEnvironment implements HybridServiceContainerEnvironment { | ||
|
|
||
| @Getter private final InProcessGrpcChannelRegistry channelRegistry; | ||
| private final HealthStatusManager healthStatusManager; | ||
|
|
||
| private final ConfigClient configClient; | ||
|
|
||
| @Getter private final String inProcessChannelName; | ||
|
|
||
| @Getter private final PlatformServiceLifecycle lifecycle; | ||
|
|
||
| @Override | ||
| public void reportServiceStatus(String serviceName, ServingStatus status) { | ||
| this.healthStatusManager.setStatus(serviceName, status); | ||
| } | ||
|
|
||
| @Override | ||
| public Config getConfig(String serviceName) { | ||
| return this.configClient.getConfig(serviceName, null, null, null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extra interface is a variant of the existing HttpHandlerFactory that gives the construction context access to the GRPC environment as well. The handlers the factory returns are no different, but these extra arguments are only available to hybrid containers. This is typically used for an HTTP handler to then turn around and make a call to the GRPC container.