-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: wrap with grpc factory, add health check (#148)
- Loading branch information
1 parent
19cf407
commit 60ab34b
Showing
12 changed files
with
75 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 @@ | ||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api("org.hypertrace.core.serviceframework:platform-grpc-service-framework:0.1.35") | ||
|
||
implementation(project(":query-service-impl")) | ||
implementation("com.google.inject:guice:5.0.1") | ||
} |
24 changes: 24 additions & 0 deletions
24
...-service-factory/src/main/java/org/hypertrace/core/query/service/QueryServiceFactory.java
This file contains 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,24 @@ | ||
package org.hypertrace.core.query.service; | ||
|
||
import com.google.inject.Guice; | ||
import java.util.List; | ||
import org.hypertrace.core.query.service.api.QueryServiceGrpc.QueryServiceImplBase; | ||
import org.hypertrace.core.serviceframework.grpc.GrpcPlatformService; | ||
import org.hypertrace.core.serviceframework.grpc.GrpcPlatformServiceFactory; | ||
import org.hypertrace.core.serviceframework.grpc.GrpcServiceContainerEnvironment; | ||
|
||
public class QueryServiceFactory implements GrpcPlatformServiceFactory { | ||
private static final String SERVICE_NAME = "query-service"; | ||
private static final String QUERY_SERVICE_CONFIG = "service.config"; | ||
|
||
@Override | ||
public List<GrpcPlatformService> buildServices(GrpcServiceContainerEnvironment environment) { | ||
return List.of( | ||
new GrpcPlatformService( | ||
Guice.createInjector( | ||
new QueryServiceModule( | ||
environment.getConfig(SERVICE_NAME).getConfig(QUERY_SERVICE_CONFIG), | ||
environment.getChannelRegistry())) | ||
.getInstance(QueryServiceImplBase.class))); | ||
} | ||
} |
This file contains 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
This file contains 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
15 changes: 0 additions & 15 deletions
15
query-service-impl/src/main/java/org/hypertrace/core/query/service/QueryServiceFactory.java
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
76 changes: 5 additions & 71 deletions
76
query-service/src/main/java/org/hypertrace/core/query/service/QueryServiceStarter.java
This file contains 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 |
---|---|---|
@@ -1,82 +1,16 @@ | ||
package org.hypertrace.core.query.service; | ||
|
||
import io.grpc.Server; | ||
import io.grpc.ServerBuilder; | ||
import java.io.IOException; | ||
import org.hypertrace.core.grpcutils.server.InterceptorUtil; | ||
import org.hypertrace.core.serviceframework.PlatformService; | ||
import org.hypertrace.core.serviceframework.config.ConfigClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class QueryServiceStarter extends PlatformService { | ||
private static final String SERVICE_NAME_CONFIG = "service.name"; | ||
private static final String SERVICE_PORT_CONFIG = "service.port"; | ||
private static final String QUERY_SERVICE_CONFIG = "service.config"; | ||
private static final Logger LOG = LoggerFactory.getLogger(QueryServiceStarter.class); | ||
private String serviceName; | ||
private int serverPort; | ||
private Server queryServiceServer; | ||
import org.hypertrace.core.serviceframework.grpc.GrpcPlatformServiceFactory; | ||
import org.hypertrace.core.serviceframework.grpc.StandAloneGrpcPlatformServiceContainer; | ||
|
||
public class QueryServiceStarter extends StandAloneGrpcPlatformServiceContainer { | ||
public QueryServiceStarter(ConfigClient configClient) { | ||
super(configClient); | ||
} | ||
|
||
@Override | ||
protected void doInit() { | ||
this.serviceName = getAppConfig().getString(SERVICE_NAME_CONFIG); | ||
this.serverPort = getAppConfig().getInt(SERVICE_PORT_CONFIG); | ||
|
||
LOG.info("Creating the Query Service Server on port {}", serverPort); | ||
|
||
queryServiceServer = | ||
ServerBuilder.forPort(serverPort) | ||
.addService( | ||
InterceptorUtil.wrapInterceptors( | ||
QueryServiceFactory.build( | ||
getAppConfig().getConfig(QUERY_SERVICE_CONFIG), this.getLifecycle()))) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected void doStart() { | ||
LOG.info("Attempting to start Query Service on port {}", serverPort); | ||
|
||
try { | ||
queryServiceServer.start(); | ||
LOG.info("Started Query Service on port {}", serverPort); | ||
} catch (IOException e) { | ||
LOG.error("Unable to start the Query Service"); | ||
throw new RuntimeException(e); | ||
} | ||
|
||
try { | ||
queryServiceServer.awaitTermination(); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected void doStop() { | ||
LOG.info("Shutting down service: {}", serviceName); | ||
while (!queryServiceServer.isShutdown()) { | ||
queryServiceServer.shutdown(); | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException ignore) { | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean healthCheck() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getServiceName() { | ||
return serviceName; | ||
protected GrpcPlatformServiceFactory getServiceFactory() { | ||
return new QueryServiceFactory(); | ||
} | ||
} |
This file contains 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