From d00d6de8f8cd4ec147fb0fbcc3f8caf27a7f9911 Mon Sep 17 00:00:00 2001 From: Aaron Steinfeld Date: Mon, 6 Jan 2025 15:46:41 -0500 Subject: [PATCH 1/3] chore: expose hybrid service framework --- .../build.gradle.kts | 15 ++++ .../hybrid/HybridPlatformService.java | 68 +++++++++++++++++++ .../HybridServiceContainerEnvironment.java | 9 +++ ...loneHybridServiceContainerEnvironment.java | 38 +++++++++++ settings.gradle.kts | 1 + 5 files changed, 131 insertions(+) create mode 100644 platform-hybrid-service-framework/build.gradle.kts create mode 100644 platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java create mode 100644 platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java create mode 100644 platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java diff --git a/platform-hybrid-service-framework/build.gradle.kts b/platform-hybrid-service-framework/build.gradle.kts new file mode 100644 index 0000000..2d3b041 --- /dev/null +++ b/platform-hybrid-service-framework/build.gradle.kts @@ -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") +} diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java new file mode 100644 index 0000000..09e5f1f --- /dev/null +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java @@ -0,0 +1,68 @@ +package org.hypertrace.core.serviceframework.hybrid; + +import io.grpc.protobuf.services.HealthStatusManager; +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.HttpContainerEnvironment; +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 getServerDefinitions(); + + protected abstract List getHandlerFactories(); + + @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(HttpContainerEnvironment environment) { + return new JettyHttpServerBuilder() + .addHandlers(this.buildHandlerDefinitions(environment)) + .build(); + } + + private List buildHandlerDefinitions( + HttpContainerEnvironment environment) { + return this.getHandlerFactories().stream() + .flatMap(handlerFactory -> handlerFactory.buildHandlers(environment).stream()) + .collect(Collectors.toUnmodifiableList()); + } + +} diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java new file mode 100644 index 0000000..ff39314 --- /dev/null +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java @@ -0,0 +1,9 @@ +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 { + +} diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java new file mode 100644 index 0000000..7e4d40e --- /dev/null +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java @@ -0,0 +1,38 @@ +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); + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index d54c8f8..651dfb6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,6 +14,7 @@ plugins { include(":platform-grpc-service-framework") include(":platform-http-service-framework") +include(":platform-hybrid-service-framework") include(":platform-service-framework") include(":platform-metrics") include(":docstore-metrics") From 6c0221ce524dc18439ab1b4f978611953aeecd3f Mon Sep 17 00:00:00 2001 From: Aaron Steinfeld Date: Mon, 6 Jan 2025 15:54:13 -0500 Subject: [PATCH 2/3] style: format --- .../hybrid/HybridPlatformService.java | 14 +++++++------- .../hybrid/HybridServiceContainerEnvironment.java | 4 +--- ...tandAloneHybridServiceContainerEnvironment.java | 13 ++++--------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java index 09e5f1f..f593c52 100644 --- a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java @@ -42,12 +42,13 @@ protected void doStop() { @Override protected HybridServiceContainerEnvironment buildContainerEnvironment( InProcessGrpcChannelRegistry channelRegistry, HealthStatusManager healthStatusManager) { - HybridServiceContainerEnvironment containerEnvironment = new StandAloneHybridServiceContainerEnvironment( - channelRegistry, - healthStatusManager, - this.configClient, - this.getInProcessServerName(), - this.getLifecycle()); + HybridServiceContainerEnvironment containerEnvironment = + new StandAloneHybridServiceContainerEnvironment( + channelRegistry, + healthStatusManager, + this.configClient, + this.getInProcessServerName(), + this.getLifecycle()); this.httpContainer = this.buildHttpContainer(containerEnvironment); return containerEnvironment; } @@ -64,5 +65,4 @@ private List buildHandlerDefinitions( .flatMap(handlerFactory -> handlerFactory.buildHandlers(environment).stream()) .collect(Collectors.toUnmodifiableList()); } - } diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java index ff39314..640e086 100644 --- a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridServiceContainerEnvironment.java @@ -4,6 +4,4 @@ import org.hypertrace.core.serviceframework.http.HttpContainerEnvironment; public interface HybridServiceContainerEnvironment - extends GrpcServiceContainerEnvironment, HttpContainerEnvironment { - -} + extends GrpcServiceContainerEnvironment, HttpContainerEnvironment {} diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java index 7e4d40e..e923c13 100644 --- a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/StandAloneHybridServiceContainerEnvironment.java @@ -10,21 +10,16 @@ import org.hypertrace.core.serviceframework.spi.PlatformServiceLifecycle; @AllArgsConstructor -class StandAloneHybridServiceContainerEnvironment - implements HybridServiceContainerEnvironment { +class StandAloneHybridServiceContainerEnvironment implements HybridServiceContainerEnvironment { - @Getter - private final InProcessGrpcChannelRegistry channelRegistry; + @Getter private final InProcessGrpcChannelRegistry channelRegistry; private final HealthStatusManager healthStatusManager; private final ConfigClient configClient; - @Getter - private final String inProcessChannelName; - - @Getter - private final PlatformServiceLifecycle lifecycle; + @Getter private final String inProcessChannelName; + @Getter private final PlatformServiceLifecycle lifecycle; @Override public void reportServiceStatus(String serviceName, ServingStatus status) { From 69b316204abf33cbd5cb1e2346e0ef93c03726e9 Mon Sep 17 00:00:00 2001 From: Aaron Steinfeld Date: Mon, 6 Jan 2025 16:37:32 -0500 Subject: [PATCH 3/3] chore: add hybrid http factory --- .../hybrid/HybridHttpHandlerFactory.java | 10 ++++++++ .../hybrid/HybridPlatformService.java | 23 ++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridHttpHandlerFactory.java diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridHttpHandlerFactory.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridHttpHandlerFactory.java new file mode 100644 index 0000000..08e7c42 --- /dev/null +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridHttpHandlerFactory.java @@ -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 buildHandlers(HybridServiceContainerEnvironment containerEnvironment); +} diff --git a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java index f593c52..8bca9a8 100644 --- a/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java +++ b/platform-hybrid-service-framework/src/main/java/org/hypertrace/core/serviceframework/hybrid/HybridPlatformService.java @@ -1,6 +1,8 @@ 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; @@ -9,7 +11,6 @@ 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.HttpContainerEnvironment; import org.hypertrace.core.serviceframework.http.HttpHandlerDefinition; import org.hypertrace.core.serviceframework.http.HttpHandlerFactory; import org.hypertrace.core.serviceframework.http.jetty.JettyHttpServerBuilder; @@ -37,7 +38,13 @@ protected void doStop() { protected abstract List getServerDefinitions(); - protected abstract List getHandlerFactories(); + protected List getHttpHandlerFactories() { + return List.of(); + } + + protected List getHybridHttpHandlerFactories() { + return List.of(); + } @Override protected HybridServiceContainerEnvironment buildContainerEnvironment( @@ -53,16 +60,20 @@ protected HybridServiceContainerEnvironment buildContainerEnvironment( return containerEnvironment; } - private HttpContainer buildHttpContainer(HttpContainerEnvironment environment) { + private HttpContainer buildHttpContainer(HybridServiceContainerEnvironment environment) { return new JettyHttpServerBuilder() .addHandlers(this.buildHandlerDefinitions(environment)) .build(); } private List buildHandlerDefinitions( - HttpContainerEnvironment environment) { - return this.getHandlerFactories().stream() - .flatMap(handlerFactory -> handlerFactory.buildHandlers(environment).stream()) + 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()); } }