Search in sources :

Example 1 with EntityQueryServiceImpl

use of org.hypertrace.entity.query.service.EntityQueryServiceImpl in project entity-service by hypertrace.

the class EntityService method doInit.

@Override
protected void doInit() {
    serviceName = getAppConfig().getString(SERVICE_NAME_CONFIG);
    int port = getAppConfig().getInt(SERVICE_PORT_CONFIG);
    Config config = getAppConfig().getConfig(ENTITY_SERVICE_CONFIG);
    EntityServiceConfig entityServiceConfig = new EntityServiceConfig(config);
    Config dataStoreConfig = entityServiceConfig.getDataStoreConfig(entityServiceConfig.getDataStoreType());
    this.datastore = DatastoreProvider.getDatastore(entityServiceConfig.getDataStoreType(), dataStoreConfig);
    GrpcChannelRegistry channelRegistry = new GrpcChannelRegistry();
    this.getLifecycle().shutdownComplete().thenRun(channelRegistry::shutdown);
    Channel localChannel = channelRegistry.forAddress("localhost", port);
    EntityChangeEventGenerator entityChangeEventGenerator = EntityChangeEventGeneratorFactory.getInstance().createEntityChangeEventGenerator(getAppConfig(), Clock.systemUTC());
    server = ServerBuilder.forPort(port).addService(InterceptorUtil.wrapInterceptors(new org.hypertrace.entity.type.service.EntityTypeServiceImpl(datastore))).addService(InterceptorUtil.wrapInterceptors(new EntityTypeServiceImpl(datastore))).addService(InterceptorUtil.wrapInterceptors(new EntityDataServiceImpl(datastore, localChannel, entityChangeEventGenerator))).addService(InterceptorUtil.wrapInterceptors(new EntityQueryServiceImpl(datastore, getAppConfig(), channelRegistry))).build();
    scheduledExecutorService.scheduleAtFixedRate(() -> {
        if (!datastore.healthCheck()) {
            consecutiveFailedHealthCheck++;
            if (consecutiveFailedHealthCheck > 5) {
                LOG.warn("Failed 5 times to connect to data store, shut down EntityService...");
                System.exit(2);
            }
        } else {
            consecutiveFailedHealthCheck = 0;
        }
    }, 60, 60, TimeUnit.SECONDS);
}
Also used : EntityQueryServiceImpl(org.hypertrace.entity.query.service.EntityQueryServiceImpl) GrpcChannelRegistry(org.hypertrace.core.grpcutils.client.GrpcChannelRegistry) EntityDataServiceImpl(org.hypertrace.entity.data.service.EntityDataServiceImpl) Config(com.typesafe.config.Config) Channel(io.grpc.Channel) EntityTypeServiceImpl(org.hypertrace.entity.type.service.v2.EntityTypeServiceImpl) EntityChangeEventGenerator(org.hypertrace.entity.service.change.event.api.EntityChangeEventGenerator)

Aggregations

Config (com.typesafe.config.Config)1 Channel (io.grpc.Channel)1 GrpcChannelRegistry (org.hypertrace.core.grpcutils.client.GrpcChannelRegistry)1 EntityDataServiceImpl (org.hypertrace.entity.data.service.EntityDataServiceImpl)1 EntityQueryServiceImpl (org.hypertrace.entity.query.service.EntityQueryServiceImpl)1 EntityChangeEventGenerator (org.hypertrace.entity.service.change.event.api.EntityChangeEventGenerator)1 EntityTypeServiceImpl (org.hypertrace.entity.type.service.v2.EntityTypeServiceImpl)1