Skip to content

Commit bcb98c7

Browse files
refactor: use service factory abstraction for container (#129)
* refactor: use service factory abstraction for container * chore: remove snapshots after publish * fix: update config resolution for integration tests * chore: update snyk ignore for unpatched dep
1 parent df4249e commit bcb98c7

File tree

6 files changed

+41
-97
lines changed

6 files changed

+41
-97
lines changed

.snyk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ ignore:
55
SNYK-JAVA-IONETTY-1042268:
66
- '*':
77
reason: No replacement available
8-
expires: 2022-05-30T00:00:00.000Z
8+
expires: 2022-08-31T00:00:00.000Z
99
patch: {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
`java-library`
3+
}
4+
5+
dependencies {
6+
api("org.hypertrace.core.serviceframework:platform-grpc-service-framework:0.1.35")
7+
8+
// Only required because AttributeService constructor test overload uses a doc store API
9+
compileOnly("org.hypertrace.core.documentstore:document-store:0.6.15")
10+
11+
implementation(project(":attribute-service-impl"))
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.hypertrace.core.attribute.service;
2+
3+
import java.util.List;
4+
import org.hypertrace.core.serviceframework.grpc.GrpcPlatformService;
5+
import org.hypertrace.core.serviceframework.grpc.GrpcPlatformServiceFactory;
6+
import org.hypertrace.core.serviceframework.grpc.GrpcServiceContainerEnvironment;
7+
8+
public class AttributeServiceFactory implements GrpcPlatformServiceFactory {
9+
private static final String SERVICE_NAME = "attribute-service";
10+
11+
@Override
12+
public List<GrpcPlatformService> buildServices(GrpcServiceContainerEnvironment environment) {
13+
return List.of(
14+
new GrpcPlatformService(new AttributeServiceImpl(environment.getConfig(SERVICE_NAME))));
15+
}
16+
}

attribute-service/build.gradle.kts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,16 @@ tasks.integrationTest {
5454
}
5555

5656
dependencies {
57-
implementation(project(":attribute-service-impl"))
58-
59-
implementation("org.hypertrace.core.serviceframework:platform-service-framework:0.1.33")
60-
implementation("org.hypertrace.core.grpcutils:grpc-server-utils:0.7.2")
61-
implementation("org.hypertrace.core.grpcutils:grpc-client-utils:0.7.2")
62-
implementation("org.hypertrace.core.documentstore:document-store:0.6.15")
63-
implementation("io.grpc:grpc-services")
64-
65-
// Logging
66-
implementation("org.slf4j:slf4j-api:1.7.32")
57+
implementation(project(":attribute-service-factory"))
58+
implementation("org.hypertrace.core.serviceframework:platform-grpc-service-framework:0.1.35")
6759
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.17.1")
6860
runtimeOnly("io.grpc:grpc-netty")
69-
constraints {
70-
runtimeOnly("io.netty:netty-codec-http2:4.1.77.Final")
71-
}
72-
73-
// Config
74-
implementation("com.typesafe:config:1.4.1")
7561

7662
// Integration test dependencies
7763
integrationTestImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
7864
integrationTestImplementation("com.google.guava:guava:31.1-jre")
7965
integrationTestImplementation(project(":attribute-service-client"))
80-
integrationTestImplementation("org.hypertrace.core.serviceframework:integrationtest-service-framework:0.1.33")
66+
integrationTestImplementation("org.hypertrace.core.serviceframework:integrationtest-service-framework:0.1.35")
8167
}
8268

8369
application {
@@ -86,7 +72,7 @@ application {
8672

8773
// Config for gw run to be able to run this locally. Just execute gw run here on Intellij or on the console.
8874
tasks.run<JavaExec> {
89-
jvmArgs = listOf("-Dbootstrap.config.uri=file:$projectDir/src/main/resources/configs", "-Dservice.name=${project.name}")
75+
jvmArgs = listOf("-Dservice.name=${project.name}")
9076
}
9177

9278
tasks.jacocoIntegrationTestReport {
Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,23 @@
11
package org.hypertrace.core.attribute.service;
22

3-
import static java.util.concurrent.TimeUnit.MINUTES;
4-
import static java.util.concurrent.TimeUnit.SECONDS;
5-
6-
import io.grpc.Deadline;
7-
import io.grpc.Server;
8-
import io.grpc.ServerBuilder;
9-
import io.grpc.health.v1.HealthCheckRequest;
10-
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
11-
import io.grpc.health.v1.HealthGrpc;
12-
import io.grpc.health.v1.HealthGrpc.HealthBlockingStub;
13-
import io.grpc.protobuf.services.HealthStatusManager;
14-
import java.io.IOException;
15-
import org.hypertrace.core.grpcutils.client.GrpcChannelRegistry;
16-
import org.hypertrace.core.grpcutils.server.InterceptorUtil;
17-
import org.hypertrace.core.grpcutils.server.ServerManagementUtil;
18-
import org.hypertrace.core.serviceframework.PlatformService;
193
import org.hypertrace.core.serviceframework.config.ConfigClient;
20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
4+
import org.hypertrace.core.serviceframework.grpc.GrpcPlatformServiceFactory;
5+
import org.hypertrace.core.serviceframework.grpc.StandAloneGrpcPlatformServiceContainer;
226

23-
public class AttributeServiceEntry extends PlatformService {
24-
private static final String SERVICE_NAME_CONFIG = "service.name";
25-
private static final Logger LOGGER = LoggerFactory.getLogger(AttributeServiceEntry.class);
7+
public class AttributeServiceEntry extends StandAloneGrpcPlatformServiceContainer {
268
static final String PORT_PATH = "attributes.type.server.port";
279

28-
private String serviceName;
29-
private Server server;
30-
private HealthBlockingStub healthClient;
31-
private final HealthStatusManager healthStatusManager = new HealthStatusManager();
32-
private final GrpcChannelRegistry grpcChannelRegistry = new GrpcChannelRegistry();
33-
3410
public AttributeServiceEntry(ConfigClient configClient) {
3511
super(configClient);
3612
}
3713

3814
@Override
39-
protected void doInit() {
40-
serviceName = getAppConfig().getString(SERVICE_NAME_CONFIG);
41-
int port = getAppConfig().getInt(PORT_PATH);
42-
server =
43-
ServerBuilder.forPort(port)
44-
.addService(InterceptorUtil.wrapInterceptors(new AttributeServiceImpl(getAppConfig())))
45-
.addService(healthStatusManager.getHealthService())
46-
.build();
47-
healthClient =
48-
HealthGrpc.newBlockingStub(this.grpcChannelRegistry.forPlaintextAddress("localhost", port));
49-
}
50-
51-
@Override
52-
protected void doStart() {
53-
try {
54-
try {
55-
server.start();
56-
} catch (IOException e) {
57-
LOGGER.error("Unable to start server");
58-
throw new RuntimeException(e);
59-
}
60-
server.awaitTermination();
61-
} catch (InterruptedException e) {
62-
Thread.currentThread().interrupt();
63-
throw new RuntimeException(e);
64-
}
65-
}
66-
67-
@Override
68-
protected void doStop() {
69-
healthStatusManager.enterTerminalState();
70-
grpcChannelRegistry.shutdown(Deadline.after(10, SECONDS));
71-
ServerManagementUtil.shutdownServer(
72-
this.server, this.getServiceName(), Deadline.after(1, MINUTES));
73-
}
74-
75-
@Override
76-
public boolean healthCheck() {
77-
try {
78-
// Intentionally using overly generous deadline to respect health check timeout from config
79-
return healthClient
80-
.withDeadlineAfter(10, SECONDS)
81-
.check(HealthCheckRequest.getDefaultInstance())
82-
.getStatus()
83-
.equals(ServingStatus.SERVING);
84-
} catch (Exception e) {
85-
LOGGER.debug("health check error", e);
86-
return false;
87-
}
15+
public GrpcPlatformServiceFactory getServiceFactory() {
16+
return new AttributeServiceFactory();
8817
}
8918

9019
@Override
91-
public String getServiceName() {
92-
return serviceName;
20+
protected int getServicePort() {
21+
return getAppConfig().getInt(PORT_PATH);
9322
}
9423
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ include(":attribute-service-api")
1616
include(":attribute-service-client")
1717
include(":attribute-service-impl")
1818
include(":attribute-service")
19+
include(":attribute-service-factory")
1920
include(":attribute-service-tenant-api")
2021
include(":caching-attribute-service-client")
2122
include(":attribute-projection-functions")

0 commit comments

Comments
 (0)