Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions platform-hybrid-service-framework/build.gradle.kts
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")
}
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);
}
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() {
Copy link
Contributor Author

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.

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());
}
}
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 {}
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);
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading