Skip to content

Commit 23c3062

Browse files
chore: expose hybrid service framework (#110)
* chore: expose hybrid service framework * style: format * chore: add hybrid http factory
1 parent eb17102 commit 23c3062

File tree

6 files changed

+145
-0
lines changed

6 files changed

+145
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
`java-library`
3+
jacoco
4+
id("org.hypertrace.publish-plugin")
5+
id("org.hypertrace.jacoco-report-plugin")
6+
}
7+
8+
dependencies {
9+
api(project(":platform-grpc-service-framework"))
10+
api(project(":platform-http-service-framework"))
11+
api(project(":platform-service-framework"))
12+
13+
annotationProcessor("org.projectlombok:lombok:1.18.24")
14+
compileOnly("org.projectlombok:lombok:1.18.24")
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.hypertrace.core.serviceframework.hybrid;
2+
3+
import java.util.List;
4+
import org.hypertrace.core.serviceframework.http.HttpHandlerDefinition;
5+
6+
@FunctionalInterface
7+
public interface HybridHttpHandlerFactory {
8+
9+
List<HttpHandlerDefinition> buildHandlers(HybridServiceContainerEnvironment containerEnvironment);
10+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.hypertrace.core.serviceframework.hybrid;
2+
3+
import com.google.common.collect.Streams;
4+
import io.grpc.protobuf.services.HealthStatusManager;
5+
import java.util.Collection;
6+
import java.util.List;
7+
import java.util.stream.Collectors;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.hypertrace.core.grpcutils.client.InProcessGrpcChannelRegistry;
10+
import org.hypertrace.core.serviceframework.config.ConfigClient;
11+
import org.hypertrace.core.serviceframework.grpc.GrpcPlatformServerDefinition;
12+
import org.hypertrace.core.serviceframework.grpc.StandAloneGrpcPlatformServiceContainer;
13+
import org.hypertrace.core.serviceframework.http.HttpContainer;
14+
import org.hypertrace.core.serviceframework.http.HttpHandlerDefinition;
15+
import org.hypertrace.core.serviceframework.http.HttpHandlerFactory;
16+
import org.hypertrace.core.serviceframework.http.jetty.JettyHttpServerBuilder;
17+
18+
@Slf4j
19+
public abstract class HybridPlatformService extends StandAloneGrpcPlatformServiceContainer {
20+
21+
private HttpContainer httpContainer;
22+
23+
public HybridPlatformService(ConfigClient configClient) {
24+
super(configClient);
25+
}
26+
27+
@Override
28+
protected void doStart() {
29+
this.httpContainer.start();
30+
super.doStart();
31+
}
32+
33+
@Override
34+
protected void doStop() {
35+
this.httpContainer.stop();
36+
super.doStop();
37+
}
38+
39+
protected abstract List<GrpcPlatformServerDefinition> getServerDefinitions();
40+
41+
protected List<HttpHandlerFactory> getHttpHandlerFactories() {
42+
return List.of();
43+
}
44+
45+
protected List<HybridHttpHandlerFactory> getHybridHttpHandlerFactories() {
46+
return List.of();
47+
}
48+
49+
@Override
50+
protected HybridServiceContainerEnvironment buildContainerEnvironment(
51+
InProcessGrpcChannelRegistry channelRegistry, HealthStatusManager healthStatusManager) {
52+
HybridServiceContainerEnvironment containerEnvironment =
53+
new StandAloneHybridServiceContainerEnvironment(
54+
channelRegistry,
55+
healthStatusManager,
56+
this.configClient,
57+
this.getInProcessServerName(),
58+
this.getLifecycle());
59+
this.httpContainer = this.buildHttpContainer(containerEnvironment);
60+
return containerEnvironment;
61+
}
62+
63+
private HttpContainer buildHttpContainer(HybridServiceContainerEnvironment environment) {
64+
return new JettyHttpServerBuilder()
65+
.addHandlers(this.buildHandlerDefinitions(environment))
66+
.build();
67+
}
68+
69+
private List<HttpHandlerDefinition> buildHandlerDefinitions(
70+
HybridServiceContainerEnvironment environment) {
71+
return Streams.concat(
72+
this.getHttpHandlerFactories().stream()
73+
.map(handlerFactory -> handlerFactory.buildHandlers(environment)),
74+
this.getHybridHttpHandlerFactories().stream()
75+
.map(handlerFactory -> handlerFactory.buildHandlers(environment)))
76+
.flatMap(Collection::stream)
77+
.collect(Collectors.toUnmodifiableList());
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.hypertrace.core.serviceframework.hybrid;
2+
3+
import org.hypertrace.core.serviceframework.grpc.GrpcServiceContainerEnvironment;
4+
import org.hypertrace.core.serviceframework.http.HttpContainerEnvironment;
5+
6+
public interface HybridServiceContainerEnvironment
7+
extends GrpcServiceContainerEnvironment, HttpContainerEnvironment {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.hypertrace.core.serviceframework.hybrid;
2+
3+
import com.typesafe.config.Config;
4+
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
5+
import io.grpc.protobuf.services.HealthStatusManager;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Getter;
8+
import org.hypertrace.core.grpcutils.client.InProcessGrpcChannelRegistry;
9+
import org.hypertrace.core.serviceframework.config.ConfigClient;
10+
import org.hypertrace.core.serviceframework.spi.PlatformServiceLifecycle;
11+
12+
@AllArgsConstructor
13+
class StandAloneHybridServiceContainerEnvironment implements HybridServiceContainerEnvironment {
14+
15+
@Getter private final InProcessGrpcChannelRegistry channelRegistry;
16+
private final HealthStatusManager healthStatusManager;
17+
18+
private final ConfigClient configClient;
19+
20+
@Getter private final String inProcessChannelName;
21+
22+
@Getter private final PlatformServiceLifecycle lifecycle;
23+
24+
@Override
25+
public void reportServiceStatus(String serviceName, ServingStatus status) {
26+
this.healthStatusManager.setStatus(serviceName, status);
27+
}
28+
29+
@Override
30+
public Config getConfig(String serviceName) {
31+
return this.configClient.getConfig(serviceName, null, null, null);
32+
}
33+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ plugins {
1414

1515
include(":platform-grpc-service-framework")
1616
include(":platform-http-service-framework")
17+
include(":platform-hybrid-service-framework")
1718
include(":platform-service-framework")
1819
include(":platform-metrics")
1920
include(":docstore-metrics")

0 commit comments

Comments
 (0)