use of ai.grakn.engine.lock.LockProvider in project grakn by graknlabs.
the class EngineContext method startGraknEngineServer.
private GraknEngineServer startGraknEngineServer(RedisWrapper redisWrapper) throws IOException {
EngineID id = EngineID.me();
GraknEngineStatus status = new GraknEngineStatus();
MetricRegistry metricRegistry = new MetricRegistry();
// distributed locks
LockProvider lockProvider = new JedisLockProvider(redisWrapper.getJedisPool());
graknKeyspaceStore = GraknKeyspaceStoreImpl.create(new GraknSystemKeyspaceSession(config));
// tx-factory
engineGraknTxFactory = EngineGraknTxFactory.create(lockProvider, config, graknKeyspaceStore);
// post-processing
IndexStorage indexStorage = RedisIndexStorage.create(redisWrapper.getJedisPool(), metricRegistry);
CountStorage countStorage = RedisCountStorage.create(redisWrapper.getJedisPool(), metricRegistry);
IndexPostProcessor indexPostProcessor = IndexPostProcessor.create(lockProvider, indexStorage);
CountPostProcessor countPostProcessor = CountPostProcessor.create(config, engineGraknTxFactory, lockProvider, metricRegistry, countStorage);
PostProcessor postProcessor = PostProcessor.create(indexPostProcessor, countPostProcessor);
GrpcOpenRequestExecutor requestExecutor = new GrpcOpenRequestExecutorImpl(engineGraknTxFactory);
Server server = ServerBuilder.forPort(0).addService(new GrpcGraknService(requestExecutor, postProcessor)).build();
GrpcServer grpcServer = GrpcServer.create(server);
GraknTestUtil.allocateSparkPort(config);
QueueSanityCheck queueSanityCheck = new RedisSanityCheck(redisWrapper);
GraknEngineServer graknEngineServer = GraknEngineServerFactory.createGraknEngineServer(id, config, status, spark, Collections.emptyList(), grpcServer, engineGraknTxFactory, metricRegistry, queueSanityCheck, lockProvider, postProcessor, graknKeyspaceStore);
graknEngineServer.start();
// Read the automatically allocated ports and write them back into the config
config.setConfigProperty(GraknConfigKey.GRPC_PORT, server.getPort());
return graknEngineServer;
}
use of ai.grakn.engine.lock.LockProvider in project grakn by graknlabs.
the class GraknEngineServerFactory method createGraknEngineServer.
/**
* Create a {@link GraknEngineServer} configured for Grakn Core. Grakn Queue (which is needed for post-processing and distributed locks) is implemented with Redis as the backend store
*
* @return a {@link GraknEngineServer} instance configured for Grakn Core
*/
public static GraknEngineServer createGraknEngineServer() {
// grakn engine configuration
EngineID engineId = EngineID.me();
GraknConfig config = GraknConfig.create();
GraknEngineStatus status = new GraknEngineStatus();
MetricRegistry metricRegistry = new MetricRegistry();
// redis
RedisWrapper redisWrapper = RedisWrapper.create(config);
QueueSanityCheck queueSanityCheck = new RedisSanityCheck(redisWrapper);
// distributed locks
LockProvider lockProvider = new JedisLockProvider(redisWrapper.getJedisPool());
SystemKeyspaceSession systemKeyspaceSession = new GraknSystemKeyspaceSession(config);
GraknKeyspaceStore graknKeyspaceStore = GraknKeyspaceStoreImpl.create(systemKeyspaceSession);
// tx-factory
EngineGraknTxFactory engineGraknTxFactory = EngineGraknTxFactory.create(lockProvider, config, graknKeyspaceStore);
// post-processing
IndexStorage indexStorage = RedisIndexStorage.create(redisWrapper.getJedisPool(), metricRegistry);
CountStorage countStorage = RedisCountStorage.create(redisWrapper.getJedisPool(), metricRegistry);
IndexPostProcessor indexPostProcessor = IndexPostProcessor.create(lockProvider, indexStorage);
CountPostProcessor countPostProcessor = CountPostProcessor.create(config, engineGraknTxFactory, lockProvider, metricRegistry, countStorage);
PostProcessor postProcessor = PostProcessor.create(indexPostProcessor, countPostProcessor);
// http services: spark, http controller, and gRPC server
Service sparkHttp = Service.ignite();
Collection<HttpController> httpControllers = Collections.emptyList();
GrpcServer grpcServer = configureGrpcServer(config, engineGraknTxFactory, postProcessor);
return createGraknEngineServer(engineId, config, status, sparkHttp, httpControllers, grpcServer, engineGraknTxFactory, metricRegistry, queueSanityCheck, lockProvider, postProcessor, graknKeyspaceStore);
}
use of ai.grakn.engine.lock.LockProvider in project grakn by graknlabs.
the class IndexPostProcessorTest method setupMocks.
@BeforeClass
public static void setupMocks() {
indexStorage = mock(RedisIndexStorage.class);
LockProvider mock = mock(LockProvider.class);
when(mock.getLock(any())).thenReturn(new ReentrantLock());
indexPostProcessor = IndexPostProcessor.create(mock, indexStorage);
}
use of ai.grakn.engine.lock.LockProvider in project grakn by graknlabs.
the class GraknEngineServerTest method createGraknEngineServer.
private GraknEngineServer createGraknEngineServer(RedisWrapper redisWrapper) {
// grakn engine configuration
EngineID engineId = EngineID.me();
GraknEngineStatus status = new GraknEngineStatus();
MetricRegistry metricRegistry = new MetricRegistry();
// distributed locks
LockProvider lockProvider = new JedisLockProvider(redisWrapper.getJedisPool());
graknKeyspaceStore = GraknKeyspaceStoreFake.of();
// tx-factory
EngineGraknTxFactory engineGraknTxFactory = EngineGraknTxFactory.create(lockProvider, config, graknKeyspaceStore);
// post-processing
IndexStorage indexStorage = RedisIndexStorage.create(redisWrapper.getJedisPool(), metricRegistry);
CountStorage countStorage = RedisCountStorage.create(redisWrapper.getJedisPool(), metricRegistry);
IndexPostProcessor indexPostProcessor = IndexPostProcessor.create(lockProvider, indexStorage);
CountPostProcessor countPostProcessor = CountPostProcessor.create(config, engineGraknTxFactory, lockProvider, metricRegistry, countStorage);
PostProcessor postProcessor = PostProcessor.create(indexPostProcessor, countPostProcessor);
// http services: spark, http controller, and gRPC server
Service sparkHttp = Service.ignite();
Collection<HttpController> httpControllers = Collections.emptyList();
int grpcPort = config.getProperty(GraknConfigKey.GRPC_PORT);
GrpcOpenRequestExecutor requestExecutor = new GrpcOpenRequestExecutorImpl(engineGraknTxFactory);
Server server = ServerBuilder.forPort(grpcPort).addService(new GrpcGraknService(requestExecutor, postProcessor)).build();
GrpcServer grpcServer = GrpcServer.create(server);
QueueSanityCheck queueSanityCheck = new RedisSanityCheck(redisWrapper);
return GraknEngineServerFactory.createGraknEngineServer(engineId, config, status, sparkHttp, httpControllers, grpcServer, engineGraknTxFactory, metricRegistry, queueSanityCheck, lockProvider, postProcessor, graknKeyspaceStore);
}
Aggregations